X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/c5885da83814455af8341d1697d6848ddb0c1a91..5c3f75ec49019d160806489824fc76652a2ef444:/blkc.h diff --git a/blkc.h b/blkc.h index 1debf54..77ecf0e 100644 --- a/blkc.h +++ b/blkc.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: blkc.h,v 1.3 2000/06/17 10:47:06 mdw Exp $ + * $Id: blkc.h,v 1.8 2004/04/17 09:58:36 mdw Exp $ * * Common definitions for block ciphers * @@ -27,20 +27,6 @@ * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: blkc.h,v $ - * Revision 1.3 2000/06/17 10:47:06 mdw - * Slight support for 96-bit ciphers. Support for counter-mode ciphers. - * - * Revision 1.2 1999/12/10 23:29:48 mdw - * Change header file guard names. - * - * Revision 1.1 1999/09/03 08:41:11 mdw - * Initial import. - * - */ - #ifndef CATACOMB_BLKC_H #define CATACOMB_BLKC_H @@ -115,6 +101,10 @@ BLKC_GLUE(BLKC_STEP_X_, BLKC_ENDIAN(PRE)) \ (PRE, w) +#define BLKC_ZERO(PRE, w) \ + BLKC_GLUE(BLKC_ZERO_, BLKC_TYPE(PRE)) \ + (PRE, w, BLKC_BITS(PRE)) + #define BLKC_SET(PRE, w, x) \ BLKC_GLUE(BLKC_SET_X_, BLKC_ENDIAN(PRE)) \ (PRE, w, x) @@ -168,6 +158,9 @@ BLKC_SKEL_X(PRE, BLKC_W(w); const BLKC_WX(wx);, \ *_w ^= *_wx; _w++; _wx++; ) \ +#define BLKC_ZERO_X(PRE, w, n) \ + BLKC_SKEL_X(PRE, BLKC_W(w);, *_w++ = 0;) + #define BLKC_STEP_X_B(PRE, w) do { \ unsigned _i = PRE##_BLKSZ / 4; BLKC_W(w); uint32 _x = 0; \ while (_i && !_x) { _i--; _w[_i] = _x = U32(_w[_i] + 1); } \ @@ -206,12 +199,23 @@ #define BLKC_SKEL_128(PRE, decl, op, guts) \ BLKC_SKEL(PRE, decl, guts(op, 0); guts(op, 1); guts(op, 2); guts(op, 3);) +#define BLKC_SKEL_192(PRE, decl, op, guts) \ + BLKC_SKEL(PRE, decl, \ + guts(op, 0); guts(op, 1); guts(op, 2); guts(op, 3); \ + guts(op, 4); guts(op, 5);) + +#define BLKC_SKEL_256(PRE, decl, op, guts) \ + BLKC_SKEL(PRE, decl, \ + guts(op, 0); guts(op, 1); guts(op, 2); guts(op, 3); \ + guts(op, 4); guts(op, 5); guts(op, 6); guts(op, 7);) + #define BLKC_STORE_GUTS(op, i) op(_p + 4 * i, _w[i]) #define BLKC_XSTORE_GUTS(op, i) op(_p + 4 * i, _w[i] ^ _wx[i]) #define BLKC_LOAD_GUTS(op, i) _w[i] = op(_p + 4 * i) #define BLKC_XLOAD_GUTS(op, i) _w[i] ^= op(_p + 4 * i) #define BLKC_MOVE_GUTS(op, i) _w[i] = _wx[i] #define BLKC_XMOVE_GUTS(op, i) _w[i] ^= _wx[i] +#define BLKC_ZERO_GUTS(op, i) _w[i] = 0 #define BLKC_STORE_N(PRE, b, w, op, n) \ BLKC_GLUE(BLKC_SKEL_, n) \ @@ -234,6 +238,10 @@ BLKC_GLUE(BLKC_SKEL_, n) \ (PRE, BLKC_W(w); const BLKC_WX(wx);, op, BLKC_MOVE_GUTS) +#define BLKC_ZERO_N(PRE, w, n) \ + BLKC_GLUE(BLKC_SKEL_, n) \ + (PRE, BLKC_W(w); , op, BLKC_ZERO_GUTS) + #define BLKC_XMOVE_N(PRE, w, wx, n) \ BLKC_GLUE(BLKC_SKEL_, n) \ (PRE, BLKC_W(w); const BLKC_WX(wx);, op, BLKC_XMOVE_GUTS) @@ -252,9 +260,9 @@ #include #include -#define BLKC_TEST(PRE, pre) \ +#define BLKC_VERIFY(PRE, pre) \ \ -static int verify(dstr *v) \ +static int pre##_verify(dstr *v) \ { \ pre##_ctx k; \ uint32 p[PRE##_BLKSZ / 4]; \ @@ -306,11 +314,14 @@ static int verify(dstr *v) \ /* --- Return --- */ \ \ return (ok); \ -} \ +} + +#define BLKC_TEST(PRE, pre) \ + \ +BLKC_VERIFY(PRE, pre) \ \ -static test_chunk defs[] = { \ - { #pre, verify, { &type_hex, &type_hex, &type_hex, 0 } }, \ - { #pre "-sched", verify, { &type_hex, &type_hex, &type_hex, 0 } }, \ +static const test_chunk defs[] = { \ + { #pre, pre##_verify, { &type_hex, &type_hex, &type_hex, 0 } }, \ { 0, 0, { 0 } } \ }; \ \ @@ -321,6 +332,7 @@ int main(int argc, char *argv[]) \ } #else +# define BLKC_VERIFY(PRE, pre) # define BLKC_TEST(PRE, pre) #endif