From: Andrey Rys Date: Mon, 29 Apr 2019 15:48:37 +0000 (+0700) Subject: -c: pattern fill support. X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=7843812e68ebd194667b244cdd6f6cbd45beb3a5;p=tfcrypt.git -c: pattern fill support. 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. --- diff --git a/VERSION b/VERSION index 64bb6b7..e85087a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -30 +31 diff --git a/tfc_error.c b/tfc_error.c index 5729de0..7d21be6 100644 --- a/tfc_error.c +++ b/tfc_error.c @@ -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(" : 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)); diff --git a/tfcrypt.c b/tfcrypt.c index 7e9ef8c..4ba1dd5 100644 --- 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': diff --git a/tfcrypt.h b/tfcrypt.h index e33e858..e8bee1a 100644 --- 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