chiark / gitweb /
Fix memory and type management bugs.
[chiark-tcl.git] / crypto / algtables.c
index 87b365b412491a7b653f3282b9b30f89f15bc64d..8fa24e4d626742c22fe92be35b9949f35ad5ba2d 100644 (file)
@@ -9,57 +9,45 @@
 #include "sha1.h"
 #include "md5.h"
 
-static void alg_serpent_byteswap_block(Byte *b) {
-  uint32_t t, *a= (void*)b;
-
-  t=    htonl(a[0]);
-  a[0]= htonl(a[3]);
-  a[3]= t;
-
-  t=    htonl(a[1]);
-  a[1]= htonl(a[2]);
-  a[2]= t;
-}
-
-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 void *key, int keylen) {
+  serpent_makekey(schedule, key, keylen);
 }
 
 static void alg_serpent_encrypt(const void *sch, const void *in, void *out) {
-  serpent_encrypt(sch, in, out);
+  serpent_encrypt(in, out, sch);
 }
   
 static void alg_serpent_decrypt(const void *sch, const void *in, void *out) {
-  serpent_decrypt(sch, in, out);
+  serpent_decrypt(in, out, sch);
 }
 
 const BlockCipherAlgInfo blockcipheralginfos[]= {
-  { "serpent", 16, sizeof(struct SerpentKeyInstance), 16,32,
-    alg_serpent_byteswap_block,
+  { "serpent", 16, sizeof(SerpentKeySchedule), 16,32,
+    serpent_byteswap_block,
     { alg_serpent_makekey, alg_serpent_encrypt },
     { alg_serpent_makekey, alg_serpent_decrypt } },
   { 0 }
 };
 
 static void alg_sha1_init(void *state) { sha1_init(state); }
-static void alg_sha1_update(void *state, const Byte *data, int len) {
+static void alg_sha1_update(void *state, const void *data, int len) {
   sha1_update(state, data, len);
 }
-static void alg_sha1_final(void *state, Byte *digest) {
+static void alg_sha1_final(void *state, void *digest) {
   sha1_final(state, digest);
 }
-static void alg_sha1_oneshot(Byte *digest, const Byte *data, int len) {
+static void alg_sha1_oneshot(void *digest, const void *data, int len) {
   sha1(data,len,digest);
 }
 
 static void alg_md5_init(void *state) { MD5Init(state); }
-static void alg_md5_update(void *state, const Byte *data, int len) {
+static void alg_md5_update(void *state, const void *data, int len) {
   MD5Update(state, data, len);
 }
-static void alg_md5_final(void *state, Byte *digest) {
+static void alg_md5_final(void *state, void *digest) {
   MD5Final(digest, state);
 }
-static void alg_md5_oneshot(Byte *digest, const Byte *data, int len) {
+static void alg_md5_oneshot(void *digest, const void *data, int len) {
   struct MD5Context ctx;
   MD5Init(&ctx);
   MD5Update(&ctx,data,len);