From: ian Date: Fri, 6 Sep 2002 18:19:36 +0000 (+0000) Subject: Two serpents X-Git-Tag: debian/1.1.1~167 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-tcl.git;a=commitdiff_plain;h=6347c760d4dae4f5a7239ca660b1478ccc48eabf;ds=sidebyside Two serpents --- diff --git a/crypto/algtables.c b/crypto/algtables.c index 87b365b..7729986 100644 --- a/crypto/algtables.c +++ b/crypto/algtables.c @@ -9,7 +9,7 @@ #include "sha1.h" #include "md5.h" -static void alg_serpent_byteswap_block(Byte *b) { +static void alg_serpent_b_byteswap_block(Byte *b) { uint32_t t, *a= (void*)b; t= htonl(a[0]); @@ -21,6 +21,22 @@ static void alg_serpent_byteswap_block(Byte *b) { a[2]= t; } +static void alg_serpent_l_byteswap_block(Byte *b) { + uint32_t t, *a= (void*)b; + int i; + + if (htonl(0x01020304UL) == 0x04030201UL) /* little endian */ + return; + + for (i=0; i<4; i++) { + t= htonl(a[i]); + a[i]= ((t & 0x000000ffUL) << 24 | + (t & 0x0000ff00UL) << 8 | + (t & 0x00ff0000UL) >> 8 | + (t & 0xff000000UL) >> 24); + } +} + static void alg_serpent_makekey(void *schedule, const Byte *key, int keylen) { serpent_makekey(schedule, keylen*8, key); } @@ -34,8 +50,12 @@ static void alg_serpent_decrypt(const void *sch, const void *in, void *out) { } const BlockCipherAlgInfo blockcipheralginfos[]= { - { "serpent", 16, sizeof(struct SerpentKeyInstance), 16,32, - alg_serpent_byteswap_block, + { "serpent-l", 16, sizeof(struct SerpentKeyInstance), 16,32, + alg_serpent_l_byteswap_block, + { alg_serpent_makekey, alg_serpent_encrypt }, + { alg_serpent_makekey, alg_serpent_decrypt } }, + { "serpent-b", 16, sizeof(struct SerpentKeyInstance), 16,32, + alg_serpent_b_byteswap_block, { alg_serpent_makekey, alg_serpent_encrypt }, { alg_serpent_makekey, alg_serpent_decrypt } }, { 0 }