chiark / gitweb /
Two serpents
authorian <ian>
Fri, 6 Sep 2002 18:19:36 +0000 (18:19 +0000)
committerian <ian>
Fri, 6 Sep 2002 18:19:36 +0000 (18:19 +0000)
crypto/algtables.c

index 87b365b412491a7b653f3282b9b30f89f15bc64d..772998685653abca1dff7c11db107b66e8915e0b 100644 (file)
@@ -9,7 +9,7 @@
 #include "sha1.h"
 #include "md5.h"
 
 #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]);
   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;
 }
 
   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);
 }
 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[]= {
 }
 
 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 }
     { alg_serpent_makekey, alg_serpent_encrypt },
     { alg_serpent_makekey, alg_serpent_decrypt } },
   { 0 }