X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-tcl.git;a=blobdiff_plain;f=crypto%2Falgtables.c;h=8d7b0a27215a412ac71fd4100167e16ce2a5991c;hp=6f7a81cb894c32abd8923928d7a078708d2dffbd;hb=9af88eb2e41e2b6a73643948e31262eee08c5400;hpb=d1431da7660c2585f394d16c259b17b5358ac435 diff --git a/crypto/algtables.c b/crypto/algtables.c index 6f7a81c..8d7b0a2 100644 --- a/crypto/algtables.c +++ b/crypto/algtables.c @@ -5,28 +5,55 @@ #include #include "hbytes.h" -#include "serpent.h" #include #include +#include +#include +#include +#include -static void alg_serpent_makekey(void *schedule, const void *key, int keylen) { - serpent_makekey(schedule, key, keylen); -} +#define NETTLE_BLOCKCIPHERS \ + DO(serpent, SERPENT) \ + DO(twofish, TWOFISH) \ + DO(aes, AES) \ + DO(blowfish, BLOWFISH) \ + ALIAS(rijndael, aes, AES) -static void alg_serpent_encrypt(const void *sch, const void *in, void *out) { - serpent_encrypt(in, out, sch); -} - -static void alg_serpent_decrypt(const void *sch, const void *in, void *out) { - serpent_decrypt(in, out, sch); -} +#define ALIAS(alias,name,NAME) +#define DO(name,NAME) \ + static void alg_##name##_makekey(void *sch, const void *key, int keylen) { \ + name##_set_key(sch, keylen, key); \ + } \ + static void alg_##name##_encr(const void *sch, const void *in, void *out) { \ + ##name##_encrypt((void*)sch, NAME##_BLOCK_SIZE, out, in); \ + } \ + static void alg_##name##_decr(const void *sch, const void *in, void *out) { \ + ##name##_decrypt((void*)sch, NAME##_BLOCK_SIZE, out, in); \ + } + NETTLE_BLOCKCIPHERS +#undef DO +#undef ALIAS const BlockCipherAlgInfo blockcipheralginfos[]= { - { "serpent", 16, sizeof(SerpentKeySchedule), 16,32, - serpent_byteswap_block, - { alg_serpent_makekey, alg_serpent_encrypt }, - { alg_serpent_makekey, alg_serpent_decrypt } }, +#define ALIAS(alias,name,NAME) \ + { #alias, NAME##_BLOCK_SIZE, sizeof(struct name##_ctx), \ + NAME##_MIN_KEY_SIZE, NAME##_MAX_KEY_SIZE, \ + 0, \ + { alg_##name##_makekey, alg_##name##_encr }, \ + { alg_##name##_makekey, alg_##name##_decr } \ + }, +#define DO(name,NAME) ALIAS(name,name,NAME) + NETTLE_BLOCKCIPHERS +#undef DO +#undef ALIAS + { 0 } +}; + +const BlockCipherPropInfo blockcipherpropinfos[]= { + { "blocklen", offsetof(BlockCipherAlgInfo, blocksize) }, + { "minkeylen", offsetof(BlockCipherAlgInfo, key_min) }, + { "maxkeylen", offsetof(BlockCipherAlgInfo, key_max) }, { 0 } }; @@ -54,6 +81,12 @@ const BlockCipherAlgInfo blockcipheralginfos[]= { NETTLE_DIGESTS #undef DO +const HashAlgPropInfo hashalgpropinfos[]= { + { "hashlen", offsetof(HashAlgInfo, hashsize) }, + { "blocklen", offsetof(HashAlgInfo, blocksize) }, + { 0 } +}; + const HashAlgInfo hashalginfos[]= { #define DO(name,NAME) \ { #name, NAME##_DIGEST_SIZE, NAME##_DATA_SIZE, sizeof(struct name##_ctx), \