-O nobuf: disable IO buffering
authorAndrey Rys <rys@lynxlynx.ru>
Sun, 16 Jan 2022 11:21:54 +0000 (12:21 +0100)
committerAndrey Rys <rys@lynxlynx.ru>
Sun, 16 Jan 2022 11:21:54 +0000 (12:21 +0100)
useful for online "as user types" encrypting
cannot use CTR here because CTR increases counter each time message continuation appears

VERSION
tfc_error.c
tfc_misc.c
tfcrypt.c
tfcrypt.h

diff --git a/VERSION b/VERSION
index 4b9026d8e2aa237955be84bd9e06954bdd343190..900731ffd51ffc82db488b6554f719de735f12bd 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-63
+64
index a00b070328d7aad03311054dccf619067ca9ad45..2b50807f6071cedbafd386cb3bfcbda51967e0e5 100644 (file)
@@ -162,6 +162,7 @@ void usage(void)
                tfc_say("    when the whole status line width is smaller than tty width.");
                tfc_say("    statless: emit less information in status line (only processed data).");
                tfc_say("    iobs=val: set IO block size value. Must not exceed %u bytes.", TFC_U(TFC_BLKSIZE));
+               tfc_say("    nobuf: disable IO buffering, write as soon as data received (only for stream ciphers!)");
                tfc_say("    iseek=val: seek source file/device by these val bytes.");
                tfc_say("    oseek=val: seek destination file/device by these val bytes.");
                tfc_say("    ioseek=val: seek both source and destination.");
@@ -341,6 +342,7 @@ void usage(void)
        tfc_say("    shorthex: with -H, do not print printable characters, dump only hex string.");
        tfc_say("    logfile: (same as -o) redirect all messages to logfile instead of stderr.");
        tfc_say("    iobs=val: set IO block size value. Must not exceed %u bytes.", TFC_U(TFC_BLKSIZE));
+       tfc_say("    nobuf: disable IO buffering, write as soon as data received (only for stream ciphers!)");
        tfc_say("    xtsblocks=val: use these nr of TF blocks per XTS block. Default is %u.", TFC_U(TFC_XTSBLOCKS));
        tfc_say("    iseek=val: seek source file/device by these val bytes.");
        tfc_say("    Initial counter is adjusted automatically.");
index b140a8247125d616e97d331056ae5a64c43bbb40..01998f2f13a877e451fd007cfac347282a2c896d 100644 (file)
@@ -102,11 +102,10 @@ const char *tfc_modename(int mode)
        return NULL;
 }
 
-tfc_yesno tfc_is_stream(int mode)
+tfc_yesno tfc_is_freestream(int mode)
 {
        switch (mode) {
                case TFC_MODE_PLAIN:
-               case TFC_MODE_CTR:
                case TFC_MODE_STREAM: return YES;
        }
 
index 2b2a26f367aed57659c3f0d65f34203857a2ce4a..bad1d4372c1f55f9f30b2d6809a7687b1ad20325 100644 (file)
--- a/tfcrypt.c
+++ b/tfcrypt.c
@@ -30,6 +30,7 @@
 
 static tfc_byte svctr[TF_BLOCK_SIZE];
 static tfc_fsize rwd, do_read_loops, loopcnt;
+static tfc_yesno unbuffered;
 
 static void open_log(const char *logfile)
 {
@@ -346,6 +347,12 @@ _baddfname:
                                                show_when_done = YES;
                                        else if (!strcmp(s, "pid"))
                                                show_pid = YES;
+                                       else if (!strcmp(s, "nobuf")) {
+                                               if (!tfc_is_freestream(ctr_mode)) xerror(NO, YES, YES,
+                                                       "cannot activate unbuffered mode for non-stream cipher mode %s!",
+                                                       tfc_modename(ctr_mode));
+                                               else unbuffered = YES;
+                                       }
                                        else if (!strncmp(s, "readloops", 9) && *(s+9) == '=') {
                                                do_read_loops = tfc_humanfsize(s+10, &stoi);
                                                if (!str_empty(stoi)) do_read_loops = NOSIZE;
@@ -362,7 +369,7 @@ _baddfname:
                                                        "%s: invalid block size value", s);
                                                }
                                                else blksize = (size_t)tfc_modifysize((tfc_fsize)blksize, strchr(s, ':'));
-                                               if (!tfc_is_stream(ctr_mode) && blksize < TF_BLOCK_SIZE) xerror(NO, YES, YES,
+                                               if (!tfc_is_freestream(ctr_mode) && blksize < TF_BLOCK_SIZE) xerror(NO, YES, YES,
                                                        "%s: block size is lesser than TF_BLOCK_SIZE (%u bytes)", s, TFC_U(TF_BLOCK_SIZE));
                                                if (blksize > TFC_BLKSIZE) xerror(NO, YES, YES,
                                                        "%s: block size exceeds %u bytes",
@@ -1209,7 +1216,7 @@ _ragain:  lio = xread(sfd, pblk, lrem);
                                default: xerror(NO, NO, NO, "%s", srcfname); break;
                        }
                }
-               if (lio && lio < lrem) {
+               if (unbuffered == NO && lio && lio < lrem) {
                        pblk += lio;
                        lrem -= lio;
                        goto _ragain;
index 42088a1c6bbb17863698df0957cedddc3d463090..280661480c65787ed1a545e9bdbadc1dd25f278a 100644 (file)
--- a/tfcrypt.h
+++ b/tfcrypt.h
@@ -193,7 +193,7 @@ int xxopen(tfc_yesno noerr, const char *pathname, int flags);
 int xopen(const char *pathname, int flags);
 void xclose(int fd);
 const char *tfc_modename(int mode);
-tfc_yesno tfc_is_stream(int mode);
+tfc_yesno tfc_is_freestream(int mode);
 void tfc_getcurtime(tfc_useconds *tx);
 char *tfc_format_time(tfc_useconds t);
 char *tfc_format_pid(const char *str);