-O okey=val: offset into key (useful for block device keys, such as USB sticks).
authorAndrey Rys <rys@lynxlynx.ru>
Mon, 4 Feb 2019 15:18:00 +0000 (22:18 +0700)
committerAndrey Rys <rys@lynxlynx.ru>
Mon, 4 Feb 2019 15:18:00 +0000 (22:18 +0700)
sksum: now honors -O iseek= too to seek into source.

VERSION
tfc_error.c
tfc_skein.c
tfc_vars.c
tfcrypt.c
tfcrypt.h

diff --git a/VERSION b/VERSION
index 45a4fb75db864000d01701c0f7a51864bd4daabf..ec635144f60048986bc560c5576355344005e6e7 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-8
+9
index e33131504fa1051b22b1f419202fd137b0d23a97..e1793fe0b5ed6e540886334bcb3a3e3272a10ff2 100644 (file)
@@ -252,6 +252,7 @@ void usage(void)
        tfc_say("    oseek=val: seek destination file/device by these val bytes.");
        tfc_say("    count=val: process only these val bytes, both input and output.");
        tfc_say("    xkey=val: take only val bytes from user keyfile.");
+       tfc_say("    okey=val: seek the key before reading it (usually a device).");
        tfc_say("    xctr=val: specify size in bytes of initial counter prepended or read.");
        tfc_say("  -P: plain IO mode: disable encryption/decryption code at all.");
        tfc_say("\n");
index b3b2019d5875d446d3704ea854f8511c72f0ce34..fe86c20de71b1c595aa15e5e2d489223d1766d71 100644 (file)
@@ -49,7 +49,7 @@ void tf_key_tweak_compat(void *key)
        ukey[TF_TWEAK_WORD3] = ukey[TF_TWEAK_WORD1] ^ ukey[TF_TWEAK_WORD2];
 }
 
-tfc_yesno skeinfd(void *hash, size_t bits, const void *key, int fd, tfc_fsize readto)
+tfc_yesno skeinfd(void *hash, size_t bits, const void *key, int fd, tfc_fsize offset, tfc_fsize readto)
 {
        static tfc_byte skblk[TFC_BLKSIZE];
 
@@ -62,9 +62,14 @@ tfc_yesno skeinfd(void *hash, size_t bits, const void *key, int fd, tfc_fsize re
        if (ctr_mode == TFC_MODE_SKSUM) total_processed_src = total_processed_dst = delta_processed = 0;
 
        if (fd == -1) goto _fail;
-       if (fd > 2 && readto == NOFSIZE) {
-               readto = tfc_fdsize(fd);
-               if (readto == NOFSIZE) goto _fail;
+       if (fd > 2) {
+               if (readto == NOFSIZE) {
+                       readto = tfc_fdsize(fd);
+                       if (readto == NOFSIZE) goto _fail;
+               }
+               if (offset != 0 && offset != NOFSIZE) {
+                       if (lseek(fd, (off_t)offset, SEEK_SET) == -1) goto _fail;
+               }
        }
 
        if (key) skein_init_key(&sk, key, bits);
@@ -226,7 +231,7 @@ _dothat:
                        }
 
                        if (status_timer) setup_next_alarm(status_timer);
-                       if (skeinfd(hash, bits, mackey_opt ? mackey : NULL, fd, maxlen) != YES) {
+                       if (skeinfd(hash, bits, mackey_opt ? mackey : NULL, fd, iseek, maxlen) != YES) {
                                xerror(YES, NO, YES, "%s", fname);
                                exitcode = 1;
                                continue;
@@ -278,7 +283,7 @@ _dothat:
                }
 
 _dohash:       if (status_timer) setup_next_alarm(status_timer);
-               if (skeinfd(hash, bits, mackey_opt ? mackey : NULL, fd, maxlen) != YES) {
+               if (skeinfd(hash, bits, mackey_opt ? mackey : NULL, fd, iseek, maxlen) != YES) {
                        xerror(YES, NO, YES, "%s", fargv[x]);
                        exitcode = 1;
                        continue;
index 5f75952bdad9601aa0fbad0108eb1250ffe9f626..d7b4818783b3ca85f1650cdb1130c2eb3886f9cd 100644 (file)
@@ -46,13 +46,14 @@ tfc_fsize total_processed_src, total_processed_dst;
 tfc_fsize delta_processed;
 tfc_fsize genrandom_nr_bytes, genzero_nr_bytes;
 tfc_fsize rdpos = NOFSIZE;
+tfc_fsize maxkeylen = NOFSIZE, keyoffset;
 int sfd, kfd = -1, dfd = 1;
 struct stat s_stat;
 size_t blksize = TFC_BLKSIZE, xtsblocks = TFC_XTSBLOCKS;
 char pwdask[512], pwdagain[512];
 
 size_t lio, lrem, ldone, lblock;
-size_t maxkeylen = NOSIZE, ctrsz = NOSIZE;
+size_t ctrsz = NOSIZE;
 
 struct sigaction sigact;
 
index 8608cf16011399202e66f08b8855211c6368a56e..df62420769d0b07b0db2a72a424cb72f6885d081 100644 (file)
--- a/tfcrypt.c
+++ b/tfcrypt.c
@@ -328,13 +328,25 @@ int main(int argc, char **argv)
                                                s += 5;
                                                maxkeylen = tfc_humanfsize(s, &stoi);
                                                if (!str_empty(stoi)) {
-                                                       maxkeylen = (size_t)tfc_fnamesize(s, YES);
-                                                       maxkeylen = (size_t)tfc_modifysize((tfc_fsize)maxkeylen, strchr(s, ':'));
+                                                       maxkeylen = tfc_fnamesize(s, YES);
+                                                       maxkeylen = tfc_modifysize(maxkeylen, strchr(s, ':'));
                                                        if (maxkeylen == NOSIZE)
                                                                xerror(NO, YES, YES,
                                                                "%s: invalid key length value", s);
                                                }
-                                               else maxkeylen = (size_t)tfc_modifysize((tfc_fsize)maxkeylen, strchr(s, ':'));
+                                               else maxkeylen = tfc_modifysize(maxkeylen, strchr(s, ':'));
+                                       }
+                                       else if (!strncmp(s, "okey", 4) && *(s+4) == '=') {
+                                               s += 5;
+                                               keyoffset = tfc_humanfsize(s, &stoi);
+                                               if (!str_empty(stoi)) {
+                                                       keyoffset = tfc_fnamesize(s, YES);
+                                                       keyoffset = tfc_modifysize(keyoffset, strchr(s, ':'));
+                                                       if (keyoffset == NOFSIZE)
+                                                               xerror(NO, YES, YES,
+                                                               "%s: invalid key offset value", s);
+                                               }
+                                               else keyoffset = tfc_modifysize(keyoffset, strchr(s, ':'));
                                        }
                                        else if (!strncmp(s, "xctr", 4) && *(s+4) == '=') {
                                                s += 5;
@@ -814,7 +826,7 @@ _pwdagain:  memset(&getps, 0, sizeof(struct getpasswd_state));
                memset(pwdagain, 0, sizeof(pwdagain));
        }
        else {
-               if (skeinfd(key, TFC_KEY_BITS, mackey_opt ? mackey : NULL, kfd, maxkeylen) != YES)
+               if (skeinfd(key, TFC_KEY_BITS, mackey_opt ? mackey : NULL, kfd, keyoffset, maxkeylen) != YES)
                        xerror(NO, NO, YES, "hashing key");
        }
 
index c469638f01e07172809c16993328c77fbab3c846..bf0d6d66e82886e4ee03e8ea3b160026d262f78d 100644 (file)
--- a/tfcrypt.h
+++ b/tfcrypt.h
@@ -139,12 +139,13 @@ extern tfc_fsize total_processed_src, total_processed_dst;
 extern tfc_fsize delta_processed;
 extern tfc_fsize genrandom_nr_bytes, genzero_nr_bytes;
 extern tfc_fsize rdpos;
+extern tfc_fsize maxkeylen, keyoffset;
 extern int sfd, kfd, dfd;
 extern struct stat s_stat;
 extern size_t blksize, xtsblocks;
 extern char pwdask[512], pwdagain[512];
 extern size_t lio, lrem, ldone, lblock;
-extern size_t maxkeylen, ctrsz;
+extern size_t ctrsz;
 extern struct sigaction sigact;
 extern size_t sksum_turns;
 extern int do_edcrypt, do_stop, quiet, error_action;
@@ -200,7 +201,7 @@ void change_status_timer(int signal);
 void setup_next_alarm(tfc_useconds useconds);
 void skein(void *hash, size_t bits, const void *key, const void *data, size_t szdata);
 void tf_key_tweak_compat(void *key);
-tfc_yesno skeinfd(void *hash, size_t bits, const void *key, int fd, tfc_fsize readto);
+tfc_yesno skeinfd(void *hash, size_t bits, const void *key, int fd, tfc_fsize offset, tfc_fsize readto);
 
 void gen_write_bytes(const char *foutname, tfc_fsize offset, tfc_fsize nrbytes);
 void do_edbase64(char **fargv);