-c: pattern fill support.
authorAndrey Rys <rys@lynxlynx.ru>
Mon, 29 Apr 2019 15:48:37 +0000 (22:48 +0700)
committerAndrey Rys <rys@lynxlynx.ru>
Mon, 29 Apr 2019 15:48:37 +0000 (22:48 +0700)
The syntax is:

        -c hexc:nr[,hexc:nr,...]

As example, filling with 16 byte counter with following:

        ffffffff3333337a7a7a7a88882a0b0c

is possible with following pattern:

        -c ff:4,33:3,7a:4,88:2,2a:1,0b:1,0c:1

To fill with zeroes (or any other static byte) is simple:

        -c 0:16

Note that any bytes that tend to overflow counter space are dropped, and any
unused bytes not filled by pattern are set to zeroes.

VERSION
tfc_error.c
tfcrypt.c
tfcrypt.h

diff --git a/VERSION b/VERSION
index 64bb6b746dceaf12b0ba8c08f310b0426babde44..e85087affded170efcbc6f9672a6fc671d839ed0 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-30
+31
index 5729de0f42ff26ad18db6e37da6f81c4d4c7e934..7d21be690123a6ade3bde0b9b8bcb7c45046dcfe 100644 (file)
@@ -176,6 +176,11 @@ void usage(void)
        tfc_say("    head: when decrypting, read CTR from beginning of stream,");
        tfc_say("    rand: generate random CTR and write it to beginning of stream,");
        tfc_say("    zero: assume zero CTR is used, do not read from and write it to stream,");
+       tfc_say("    hexc:nr[,hexc:nr,...]: construct counter from given pattern.");
+       tfc_say("      Example: \"ff:124,08:2,80:2\" will fill counter first with 124 0xff bytes,");
+       tfc_say("      then with 2 0x08 bytes, then 2 0x80 bytes. To fill with zeroes, it is");
+       tfc_say("      simple to specify just a \"0:128\" as a pattern. Note that bytes that");
+       tfc_say("      exceed CTR space will be just dropped, and any unused bytes are set to zeroes.");
        tfc_say("    <file>: read CTR from given file (both when encrypting/decrypting).");
        tfc_say("      default is to derive CTR from user provided password or keyfile with");
        tfc_say("      a single Skein function turn over derived, %u byte raw key", TFC_U(TF_KEY_SIZE));
index 7e9ef8c16915ddb15f7a718516f0ca9cdd518730..4ba1dd530cd179dd269abfa4cca8033c347f853b 100644 (file)
--- a/tfcrypt.c
+++ b/tfcrypt.c
@@ -149,6 +149,29 @@ _baddfname:
                                        counter_opt = TFC_CTR_RAND;
                                else if (!strcasecmp(optarg, "zero"))
                                        counter_opt = TFC_CTR_ZERO;
+                               else if (strchr(optarg, ':')) {
+                                       char *ss, chr;
+
+                                       counter_opt = TFC_CTR_SSET;
+                                       n = sizeof(ctr);
+
+                                       s = d = optarg; t = NULL;
+                                       while ((s = strtok_r(d, ",", &t))) {
+                                               if (d) d = NULL;
+
+                                               if (n == 0) break;
+                                               ss = strchr(s, ':');
+                                               if (!ss) continue;
+                                               *ss = 0; ss++;
+                                               chr = (char)strtoul(s, &stoi, 16);
+                                               if (!str_empty(stoi)) continue;
+                                               x = (size_t)strtoul(ss, &stoi, 10);
+                                               if (!str_empty(stoi)) continue;
+                                               if (x > n) x = n;
+                                               memset(ctr+(sizeof(ctr)-n), (int)chr, x);
+                                               n -= x;
+                                       }
+                               }
                                else counter_file = sksum_hashlist_file = optarg;
                                break;
                        case 'C':
index e33e858bdba66b027553426d0e98e719bc86afa0..e8bee1a12e5965acb007bf982c0f460dbce85fb9 100644 (file)
--- a/tfcrypt.h
+++ b/tfcrypt.h
@@ -227,6 +227,6 @@ enum {
        TFC_MODE_SKSUM = -2, TFC_MODE_PLAIN = -1, TFC_MODE_CTR = 1,
        TFC_MODE_STREAM, TFC_MODE_XTS, TFC_MODE_ECB, TFC_MODE_CBC, TFC_MODE_OCB
 };
-enum { TFC_CTR_SHOW = 1, TFC_CTR_HEAD, TFC_CTR_RAND, TFC_CTR_ZERO };
+enum { TFC_CTR_SHOW = 1, TFC_CTR_HEAD, TFC_CTR_RAND, TFC_CTR_ZERO, TFC_CTR_SSET };
 
 #endif