From: Mark Wooding Date: Sat, 24 Nov 2018 21:53:58 +0000 (+0000) Subject: Merge branch '2.4.x' X-Git-Tag: 2.5.0~21 X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/commitdiff_plain/925ff94a516478164fdd01d53332637455e0074d?hp=f54be224946b5dede1c5279d47b9d4cb0766a9f9 Merge branch '2.4.x' * 2.4.x: progs/cc-progress.c: Use `fstat' to discover the file size. math/mpx-mul4-amd64-sse2.S: Always collect iteration count as 32 bits. math/mpx-mul4-amd64-sse2.S: Fix stack-argument offset for 64-bit Windows. symm/salsa20-x86ish-sse2.S: Fix typo in 64-bit Windows code. symm/desx.c, symm/desx.h (desx_init): Fix documentation. symm/t/rijndael256: Add tests for small key sizes. progs/cc-kem.c (getkem): Parse the `kdf' spec after bulk crypto. progs/..., symm/...: Fix 32-bit right-shift idiom. --- diff --git a/math/mpx-mul4-amd64-sse2.S b/math/mpx-mul4-amd64-sse2.S index 64460ca9..29939c1c 100644 --- a/math/mpx-mul4-amd64-sse2.S +++ b/math/mpx-mul4-amd64-sse2.S @@ -1329,7 +1329,7 @@ ENDFUNC # define ARG6 STKARG(2) # define ARG7 STKARG(3) # define ARG8 STKARG(4) -# define STKARG_OFFSET 40 +# define STKARG_OFFSET 224 #endif #define STKARG(i) [rsp + STKARG_OFFSET + 8*(i)] @@ -1386,7 +1386,7 @@ ENDFUNC mov rbx, r8 movdqu xmm8, [r9] movdqu xmm10, [rax] - mov r8, STKARG(1) + mov r8d, STKARG(1) mov r9, STKARG(2) mov r10, rdx mov r11, rcx @@ -1395,7 +1395,7 @@ ENDFUNC .ifeqs "\mode", "mont" mov rbx, rcx movdqu xmm8, [r8] - mov r8, r9 + mov r8d, r9d mov r9, STKARG(0) mov r10, rdx mov rcx, rsi @@ -1423,16 +1423,16 @@ ENDFUNC mov rbx, r9 movdqu xmm8, [r10] movdqu xmm10, [r11] - mov r8, STKARG(2) - mov r9, STKARG(3) mov r11, r8 + mov r8d, STKARG(2) + mov r9, STKARG(3) .endif .ifeqs "\mode", "smul" mov rdi, rcx mov rcx, rdx mov rbx, r8 movdqu xmm10, [r9] - mov r8, STKARG(0) + mov r8d, STKARG(0) mov r9, STKARG(1) .endif .ifeqs "\mode", "mmul" @@ -1443,10 +1443,10 @@ ENDFUNC mov rbx, STKARG(0) movdqu xmm8, [r10] movdqu xmm10, [r11] - mov r8, STKARG(3) - mov r9, STKARG(4) mov r10, r8 mov r11, r9 + mov r8d, STKARG(3) + mov r9, STKARG(4) .endif .ifeqs "\mode", "mont" mov r10, STKARG(0) @@ -1454,9 +1454,9 @@ ENDFUNC mov rcx, rdx mov rbx, r9 movdqu xmm8, [r10] - mov r8, STKARG(1) - mov r9, STKARG(2) mov r10, r8 + mov r8d, STKARG(1) + mov r9, STKARG(2) .endif #endif diff --git a/progs/cc-kem.c b/progs/cc-kem.c index cf53eaf1..1e99e05d 100644 --- a/progs/cc-kem.c +++ b/progs/cc-kem.c @@ -860,16 +860,6 @@ k_found:; halg, t.buf); } - dstr_reset(&d); - if ((q = key_getattr(0, k, "kdf")) == 0) { - dstr_putf(&d, "%s-mgf", kk->hc->name); - q = d.buf; - } - if ((kk->cxc = gcipher_byname(q)) == 0) { - die(EXIT_FAILURE, "encryption scheme (KDF) `%s' not found in key `%s'", - q, t.buf); - } - if (!balg) bt = bulktab; else { @@ -887,6 +877,16 @@ k_found:; *bc = bo->init(k, balg, kk->hc->name); (*bc)->ops = bo; + dstr_reset(&d); + if ((q = key_getattr(0, k, "kdf")) == 0) { + dstr_putf(&d, "%s-mgf", kk->hc->name); + q = d.buf; + } + if ((kk->cxc = gcipher_byname(q)) == 0) { + die(EXIT_FAILURE, "encryption scheme (KDF) `%s' not found in key `%s'", + q, t.buf); + } + /* --- Tidy up --- */ dstr_destroy(&d); diff --git a/progs/cc-progress.c b/progs/cc-progress.c index 918eb2c4..055556c3 100644 --- a/progs/cc-progress.c +++ b/progs/cc-progress.c @@ -31,6 +31,8 @@ #include "config.h" +#include + #include "cc.h" #ifndef PATHSEP @@ -129,16 +131,15 @@ static void prhuman_data(FILE *fp, off_t n) int fprogress_init(fprogress *f, const char *name, FILE *fp) { const char *p; + struct stat st; off_t o, sz = -1; size_t n; /* --- Set up the offset --- */ - if ((o = ftello(fp)) >= 0 && - fseeko(fp, 0, SEEK_END) >= 0 && - (sz = ftello(fp), - fseeko(fp, o, SEEK_SET) < 0)) - return (-1); + o = lseek(fileno(fp), 0, SEEK_CUR); + if (fstat(fileno(fp), &st)) return (-1); + sz = (S_ISREG(st.st_mode)) ? st.st_size : -1; if (o != -1 && sz != -1) sz -= o; f->o = f->olast = 0; f->sz = sz; diff --git a/progs/cookie.c b/progs/cookie.c index 6239eb0c..c6912ffd 100644 --- a/progs/cookie.c +++ b/progs/cookie.c @@ -80,7 +80,7 @@ typedef struct cookie { octet *_p = (octet *)(p); \ const cookie *_c = (c); \ STORE32(_p + 0, _c->k); \ - STORE32(_p + 4, ((_c->exp & ~MASK32) >> 16) >> 16); \ + STORE32(_p + 4, ((_c->exp & ~(unsigned long)MASK32) >> 16) >> 16); \ STORE32(_p + 8, _c->exp); \ } while (0) @@ -97,7 +97,8 @@ typedef struct cookie { cookie *_c = (c); \ const octet *_p = (const octet *)(p); \ _c->k = LOAD32(_p + 0); \ - _c->exp = ((time_t)(((LOAD32(_p + 4) << 16) << 16) & ~MASK32) | \ + _c->exp = ((time_t)(((LOAD32(_p + 4) << 16) << 16) & \ + ~(unsigned long)MASK32) | \ (time_t)LOAD32(_p + 8)); \ } while (0) diff --git a/progs/dsig.c b/progs/dsig.c index 5e5a3cfe..1377bcaa 100644 --- a/progs/dsig.c +++ b/progs/dsig.c @@ -233,7 +233,8 @@ static int bget(block *b, FILE *fp, unsigned bin) octet buf[8]; if (fread(buf, sizeof(buf), 1, fp) < 1) return (E_EOF); - b->t = ((time_t)(((LOAD32(buf + 0) << 16) << 16) & ~MASK32) | + b->t = ((time_t)(((LOAD32(buf + 0) << 16) << 16) & + ~(unsigned long)MASK32) | (time_t)LOAD32(buf + 4)); } else { if (getstring(fp, &b->d, GSF_FILE)) @@ -325,7 +326,8 @@ static void blob(block *b, dstr *d) STORE32(d->buf + d->len, 0xffffffff); STORE32(d->buf + d->len + 4, 0xffffffff); } else { - STORE32(d->buf + d->len, ((b->t & ~MASK32) >> 16) >> 16); + STORE32(d->buf + d->len, + ((b->t & ~(unsigned long)MASK32) >> 16) >> 16); STORE32(d->buf + d->len + 4, b->t); } d->len += 8; diff --git a/symm/blkc.h b/symm/blkc.h index e94e932b..e0837521 100644 --- a/symm/blkc.h +++ b/symm/blkc.h @@ -174,7 +174,7 @@ unsigned _i; BLKC_W(w); unsigned long _x = x; \ for (_i = 0; _i < PRE##_BLKSZ / 4; _i++) { \ *_w++ = U32(_x); \ - _x = ((_x & ~MASK32) >> 16) >> 16; \ + _x = ((_x & ~(unsigned long)MASK32) >> 16) >> 16; \ } \ } while (0) @@ -182,7 +182,7 @@ unsigned _i; BLKC_W(w); unsigned long _x = x; _w += PRE##_BLKSZ / 4; \ for (_i = 0; _i < PRE##_BLKSZ / 4; _i++) { \ *--_w = U32(_x); \ - _x = ((_x & ~MASK32) >> 16) >> 16; \ + _x = ((_x & ~(unsigned long)MASK32) >> 16) >> 16; \ } \ } while (0) diff --git a/symm/desx.c b/symm/desx.c index e9a77ed9..14115a57 100644 --- a/symm/desx.c +++ b/symm/desx.c @@ -61,7 +61,7 @@ const octet desx_keysz[] = { KSZ_SET, 23, 7, 8, 15, 16, 24, 0 }; * Use: Initializes a DESX key buffer. The key buffer contains, in * order, a single-DES key (either 7 or 8 bytes), an optional * 8-byte pre-whitening key, and an optional 8-byte - * port-whitening key. If no whitening keys are specified, the + * post-whitening key. If no whitening keys are specified, the * algorithm becomes the same as single-DES. */ diff --git a/symm/desx.h b/symm/desx.h index 62e8300d..005d1c45 100644 --- a/symm/desx.h +++ b/symm/desx.h @@ -76,10 +76,10 @@ typedef struct desx_ctx { * Returns: --- * * Use: Initializes a DESX key buffer. The key buffer contains, in - * order, an optional 8-byte pre-whitening key, a single-DES key - * (either 7 or 8 bytes), and an optional 8-byte port-whitening - * key. If no whitening keys are specified, the algorithm - * becomes the same as single-DES. + * order, a single-DES key (either 7 or 8 bytes), an optional + * 8-byte pre-whitening key, and an optional 8-byte + * post-whitening key. If no whitening keys are specified, the + * algorithm becomes the same as single-DES. */ extern void desx_init(desx_ctx */*k*/, const void */*buf*/, size_t /*sz*/); diff --git a/symm/has160.c b/symm/has160.c index 483b9fe8..0fbaf488 100644 --- a/symm/has160.c +++ b/symm/has160.c @@ -172,7 +172,7 @@ void has160_set(has160_ctx *ctx, const void *buf, unsigned long count) ctx->e = LOAD32_L(p + 16); ctx->off = 0; ctx->nl = U32(count); - ctx->nh = U32(((count & ~MASK32) >> 16) >> 16); + ctx->nh = U32(((count & ~(unsigned long)MASK32) >> 16) >> 16); } /* --- @has160_hash@ --- * diff --git a/symm/hash.h b/symm/hash.h index dc9ad024..eb3cd75e 100644 --- a/symm/hash.h +++ b/symm/hash.h @@ -68,10 +68,10 @@ \ { \ uint32 _l = U32(_bsz); \ - uint32 _h = ((_bsz & ~MASK32) >> 16) >> 16; \ + uint32 _h = ((_bsz & ~(size_t)MASK32) >> 16) >> 16; \ _bctx->nh += _h; \ _bctx->nl += _l; \ - if (_bctx->nl < _l || _bctx->nl & ~MASK32) \ + if (_bctx->nl < _l || _bctx->nl & ~(uint32)MASK32) \ _bctx->nh++; \ } \ \ diff --git a/symm/mars-mktab.c b/symm/mars-mktab.c index d43f7c07..53ce0f71 100644 --- a/symm/mars-mktab.c +++ b/symm/mars-mktab.c @@ -154,10 +154,10 @@ void sha_hash(sha_ctx *ctx, const void *buf, size_t sz) { uint32 _l = ((uint32) ((_bsz) & MASK32)); - uint32 _h = ((_bsz & ~MASK32) >> 16) >> 16; + uint32 _h = ((_bsz & ~(size_t)MASK32) >> 16) >> 16; _bctx->nh += _h; _bctx->nl += _l; - if (_bctx->nl < _l || _bctx->nl & ~MASK32) + if (_bctx->nl < _l || _bctx->nl & ~(uint32)MASK32) _bctx->nh++; } if (_bctx->off + _bsz < SHA_BUFSZ) { diff --git a/symm/md4.c b/symm/md4.c index eee5d6b3..15fb7503 100644 --- a/symm/md4.c +++ b/symm/md4.c @@ -185,7 +185,7 @@ void md4_set(md4_ctx *ctx, const void *buf, unsigned long count) ctx->d = LOAD32_L(p + 12); ctx->off = 0; ctx->nl = U32(count); - ctx->nh = U32(((count & ~MASK32) >> 16) >> 16); + ctx->nh = U32(((count & ~(unsigned long)MASK32) >> 16) >> 16); } /* --- @md4_hash@ --- * diff --git a/symm/md5.c b/symm/md5.c index f3b37e19..cf6b3355 100644 --- a/symm/md5.c +++ b/symm/md5.c @@ -204,7 +204,7 @@ void md5_set(md5_ctx *ctx, const void *buf, unsigned long count) ctx->d = LOAD32_L(p + 12); ctx->off = 0; ctx->nl = U32(count); - ctx->nh = U32(((count & ~MASK32) >> 16) >> 16); + ctx->nh = U32(((count & ~(unsigned long)MASK32) >> 16) >> 16); } /* --- @md5_hash@ --- * diff --git a/symm/rmd128.c b/symm/rmd128.c index 85b6c33e..606d0e57 100644 --- a/symm/rmd128.c +++ b/symm/rmd128.c @@ -284,7 +284,7 @@ void rmd128_set(rmd128_ctx *ctx, const void *buf, unsigned long count) ctx->d = LOAD32_L(p + 12); ctx->off = 0; ctx->nl = U32(count); - ctx->nh = U32(((count & ~MASK32) >> 16) >> 16); + ctx->nh = U32(((count & ~(unsigned long)MASK32) >> 16) >> 16); } /* --- @rmd128_hash@ --- * diff --git a/symm/rmd160.c b/symm/rmd160.c index bc7e8672..3dbb5210 100644 --- a/symm/rmd160.c +++ b/symm/rmd160.c @@ -325,7 +325,7 @@ void rmd160_set(rmd160_ctx *ctx, const void *buf, unsigned long count) ctx->e = LOAD32_L(p + 16); ctx->off = 0; ctx->nl = U32(count); - ctx->nh = U32(((count & ~MASK32) >> 16) >> 16); + ctx->nh = U32(((count & ~(unsigned long)MASK32) >> 16) >> 16); } /* --- @rmd160_hash@ --- * diff --git a/symm/rmd256.c b/symm/rmd256.c index 99648f5f..0a03065b 100644 --- a/symm/rmd256.c +++ b/symm/rmd256.c @@ -294,7 +294,7 @@ void rmd256_set(rmd256_ctx *ctx, const void *buf, unsigned long count) ctx->D = LOAD32_L(p + 28); ctx->off = 0; ctx->nl = U32(count); - ctx->nh = U32(((count & ~MASK32) >> 16) >> 16); + ctx->nh = U32(((count & ~(unsigned long)MASK32) >> 16) >> 16); } /* --- @rmd256_hash@ --- * diff --git a/symm/rmd320.c b/symm/rmd320.c index 022903e7..0ccd790e 100644 --- a/symm/rmd320.c +++ b/symm/rmd320.c @@ -340,7 +340,7 @@ void rmd320_set(rmd320_ctx *ctx, const void *buf, unsigned long count) ctx->E = LOAD32_L(p + 36); ctx->off = 0; ctx->nl = U32(count); - ctx->nh = U32(((count & ~MASK32) >> 16) >> 16); + ctx->nh = U32(((count & ~(unsigned long)MASK32) >> 16) >> 16); } /* --- @rmd320_hash@ --- * diff --git a/symm/salsa20-x86ish-sse2.S b/symm/salsa20-x86ish-sse2.S index ad4e322b..06ba3d2c 100644 --- a/symm/salsa20-x86ish-sse2.S +++ b/symm/salsa20-x86ish-sse2.S @@ -305,7 +305,7 @@ FUNC(salsa20_core_x86ish_sse2) #endif #if CPUFAM_AMD64 && ABI_WIN rstrxmm xmm6, 0 - rsrrxmm xmm7, 16 + rstrxmm xmm7, 16 stfree 64 + 8 #endif diff --git a/symm/sha.c b/symm/sha.c index 980fe802..35207273 100644 --- a/symm/sha.c +++ b/symm/sha.c @@ -210,7 +210,7 @@ void sha_set(sha_ctx *ctx, const void *buf, unsigned long count) ctx->e = LOAD32(p + 16); ctx->off = 0; ctx->nl = U32(count); - ctx->nh = U32(((count & ~MASK32) >> 16) >> 16); + ctx->nh = U32(((count & ~(unsigned long)MASK32) >> 16) >> 16); } /* --- @sha_hash@ --- * diff --git a/symm/sha256.c b/symm/sha256.c index 5de3966d..7f91ff74 100644 --- a/symm/sha256.c +++ b/symm/sha256.c @@ -212,7 +212,7 @@ void sha256_set(sha256_ctx *ctx, const void *buf, unsigned long count) ctx->h = LOAD32(p + 28); ctx->off = 0; ctx->nl = U32(count); - ctx->nh = U32(((count & ~MASK32) >> 16) >> 16); + ctx->nh = U32(((count & ~(unsigned long)MASK32) >> 16) >> 16); } /* --- @sha256_hash@, @sha224_hash@ --- * diff --git a/symm/sha3.c b/symm/sha3.c index 97a3f7a8..16967629 100644 --- a/symm/sha3.c +++ b/symm/sha3.c @@ -231,7 +231,7 @@ static void leftenc_sz(shake_ctx *ctx, size_t n) octet b[9]; unsigned i; - SET64(t, ((n&~MASK32) >> 16) >> 16, n&MASK32); + SET64(t, ((n&~(size_t)MASK32) >> 16) >> 16, n&MASK32); STORE64_B_(b + 1, t); for (i = 1; i < 8 && !b[i]; i++); i--; b[i] = 8 - i; @@ -244,7 +244,7 @@ static void rightenc_sz(shake_ctx *ctx, size_t n) octet b[9]; unsigned i; - SET64(t, ((n&~MASK32) >> 16) >> 16, n&MASK32); + SET64(t, ((n&~(size_t)MASK32) >> 16) >> 16, n&MASK32); STORE64_B_(b, t); for (i = 0; i < 7 && !b[i]; i++); b[8] = 8 - i; diff --git a/symm/sha512.c b/symm/sha512.c index a9a5180c..5c75eb8e 100644 --- a/symm/sha512.c +++ b/symm/sha512.c @@ -275,7 +275,7 @@ void sha512_set(sha512_ctx *ctx, const void *buf, unsigned long count) LOAD64_(ctx->h, p + 56); ctx->off = 0; ctx->nl = U32(count); - ctx->nh = U32(((count & ~MASK32) >> 16) >> 16); + ctx->nh = U32(((count & ~(unsigned long)MASK32) >> 16) >> 16); } /* --- @sha512_hash@, @sha384_hash@ --- * diff --git a/symm/t/rijndael256 b/symm/t/rijndael256 index 9a4b8664..732685f3 100644 --- a/symm/t/rijndael256 +++ b/symm/t/rijndael256 @@ -2882,3 +2882,16 @@ rijndael256 { 92128b45f2af927df41f3b200a872673a744956e2c58b0099f243b7911c50436 ce408d59a184170a267df8713a787464af6d75f5f46b8b64ddac88daabb50ecd; } + +rijndael256 { + ## Some tests for tiny keys. + e93a6283 + 511ad33d714994b1c61aa279fc973a9d859713ec6473f023401a88e3e8640e9d + ef36dccd7636fb28253fb591b5bacbf7e31f37f5f239a756d3bf848c559d92c6; + 717267580d3a01d9 + 0d6aa90050de49fabdd53aba1f6a903f32c6815810b7b2ce72aa3dc2246cdfdf + 84c75fa0db1a864eac23ae6b9c50024dda11d35cb4736ae7950961c61b35454a; + d3c9931798b0abc3b15129ae + 1188d6578860ceb90a80228c344c3d9e72e775cae5d41b0fd9ff9c60d0898fd0 + ec81f1cda5409281c7b4d5f698b6ca5d0ec79598571237a08a60a4a0724b739a; +} diff --git a/symm/tiger.c b/symm/tiger.c index 95faf56f..48896602 100644 --- a/symm/tiger.c +++ b/symm/tiger.c @@ -99,7 +99,7 @@ void tiger_set(tiger_ctx *ctx, const void *buf, unsigned long count) LOAD64_L_(ctx->c, p + 16); ctx->off = 0; ctx->nl = U32(count); - ctx->nh = U32(((count & ~MASK32) >> 16) >> 16); + ctx->nh = U32(((count & ~(unsigned long)MASK32) >> 16) >> 16); } /* --- @tiger_hash@ --- * diff --git a/symm/whirlpool.c b/symm/whirlpool.c index 708e3fce..f22a366a 100644 --- a/symm/whirlpool.c +++ b/symm/whirlpool.c @@ -206,7 +206,7 @@ void whirlpool_set(whirlpool_ctx *ctx, const void *buf, unsigned long count) } ctx->off = 0; ctx->nl = U32(count); - ctx->nh = U32(((count & ~MASK32) >> 16) >> 16); + ctx->nh = U32(((count & ~(unsigned long)MASK32) >> 16) >> 16); } /* --- @whirlpool_hash@, @whirlpool256_hash@ --- *