catcrypt.c, catsign.c: Shorten chunk sizes.
[u/mdw/catacomb] / catcrypt.c
index a1e3495..6e4f245 100644 (file)
@@ -133,7 +133,7 @@ static int encrypt(int argc, char *argv[])
   const char *err;
   int i;
   int en;
   const char *err;
   int i;
   int en;
-  size_t n;
+  size_t n, chsz;
   dstr d = DSTR_INIT;
   octet *tag, *ct;
   buf b;
   dstr d = DSTR_INIT;
   octet *tag, *ct;
   buf b;
@@ -261,6 +261,7 @@ static int encrypt(int argc, char *argv[])
   assert(GC_CLASS(c)->blksz <= sizeof(bb));
   dstr_ensure(&d, sizeof(bb) + GM_CLASS(m)->hashsz);
   seq = 0;
   assert(GC_CLASS(c)->blksz <= sizeof(bb));
   dstr_ensure(&d, sizeof(bb) + GM_CLASS(m)->hashsz);
   seq = 0;
+  chsz = MASK16 - GM_CLASS(m)->hashsz;
   for (;;) {
     h = GM_INIT(m);
     GH_HASHU32(h, seq);
   for (;;) {
     h = GM_INIT(m);
     GH_HASHU32(h, seq);
@@ -269,7 +270,7 @@ static int encrypt(int argc, char *argv[])
       GC_ENCRYPT(cx, 0, bb, GC_CLASS(c)->blksz);
       GC_SETIV(c, bb);
     }
       GC_ENCRYPT(cx, 0, bb, GC_CLASS(c)->blksz);
       GC_SETIV(c, bb);
     }
-    n = fread(bb, 1, sizeof(bb), fp);
+    n = fread(bb, 1, chsz, fp);
     if (!n) break;
     buf_init(&b, d.buf, d.sz);
     tag = buf_get(&b, GM_CLASS(m)->hashsz);
     if (!n) break;
     buf_init(&b, d.buf, d.sz);
     tag = buf_get(&b, GM_CLASS(m)->hashsz);