chiark / gitweb /
8fa24e4d626742c22fe92be35b9949f35ad5ba2d
[chiark-tcl.git] / crypto / algtables.c
1 /*
2  */
3
4 #include <stdint.h>
5 #include <netinet/in.h>
6
7 #include "hbytes.h"
8 #include "serpent.h"
9 #include "sha1.h"
10 #include "md5.h"
11
12 static void alg_serpent_makekey(void *schedule, const void *key, int keylen) {
13   serpent_makekey(schedule, key, keylen);
14 }
15
16 static void alg_serpent_encrypt(const void *sch, const void *in, void *out) {
17   serpent_encrypt(in, out, sch);
18 }
19   
20 static void alg_serpent_decrypt(const void *sch, const void *in, void *out) {
21   serpent_decrypt(in, out, sch);
22 }
23
24 const BlockCipherAlgInfo blockcipheralginfos[]= {
25   { "serpent", 16, sizeof(SerpentKeySchedule), 16,32,
26     serpent_byteswap_block,
27     { alg_serpent_makekey, alg_serpent_encrypt },
28     { alg_serpent_makekey, alg_serpent_decrypt } },
29   { 0 }
30 };
31
32 static void alg_sha1_init(void *state) { sha1_init(state); }
33 static void alg_sha1_update(void *state, const void *data, int len) {
34   sha1_update(state, data, len);
35 }
36 static void alg_sha1_final(void *state, void *digest) {
37   sha1_final(state, digest);
38 }
39 static void alg_sha1_oneshot(void *digest, const void *data, int len) {
40   sha1(data,len,digest);
41 }
42
43 static void alg_md5_init(void *state) { MD5Init(state); }
44 static void alg_md5_update(void *state, const void *data, int len) {
45   MD5Update(state, data, len);
46 }
47 static void alg_md5_final(void *state, void *digest) {
48   MD5Final(digest, state);
49 }
50 static void alg_md5_oneshot(void *digest, const void *data, int len) {
51   struct MD5Context ctx;
52   MD5Init(&ctx);
53   MD5Update(&ctx,data,len);
54   MD5Final(digest,&ctx);
55 }
56
57 const HashAlgInfo hashalginfos[]= {
58   { "sha1", 20, 64, sizeof(struct sha1_state),
59     alg_sha1_init, alg_sha1_update, alg_sha1_final, alg_sha1_oneshot },
60   { "md5", 16, 64, sizeof(struct MD5Context),
61     alg_md5_init, alg_md5_update, alg_md5_final, alg_md5_oneshot },
62   { 0 }
63 };