chiark / gitweb /
Use nettle for hash functions.
[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
10 #include <nettle/md5.h>
11 #include <nettle/sha.h>
12
13 static void alg_serpent_makekey(void *schedule, const void *key, int keylen) {
14   serpent_makekey(schedule, key, keylen);
15 }
16
17 static void alg_serpent_encrypt(const void *sch, const void *in, void *out) {
18   serpent_encrypt(in, out, sch);
19 }
20   
21 static void alg_serpent_decrypt(const void *sch, const void *in, void *out) {
22   serpent_decrypt(in, out, sch);
23 }
24
25 const BlockCipherAlgInfo blockcipheralginfos[]= {
26   { "serpent", 16, sizeof(SerpentKeySchedule), 16,32,
27     serpent_byteswap_block,
28     { alg_serpent_makekey, alg_serpent_encrypt },
29     { alg_serpent_makekey, alg_serpent_decrypt } },
30   { 0 }
31 };
32
33 #define NETTLE_DIGESTS                          \
34   DO(sha1,   SHA1)                              \
35   DO(sha256, SHA256)                            \
36   DO(md5,    MD5)
37
38 #define DO(name,NAME)                                                         \
39   static void alg_##name##_init(void *state) {                                \
40     name##_init(state);                                                       \
41   }                                                                           \
42   static void alg_##name##_update(void *state, const void *data, int len) {   \
43     name##_update(state, len, data);                                          \
44   }                                                                           \
45   static void alg_##name##_final(void *state, void *digest) {                 \
46     name##_digest(state,NAME##_DIGEST_SIZE,digest);                           \
47   }                                                                           \
48   static void alg_##name##_oneshot(void *digest, const void *data, int len) { \
49     struct name##_ctx ctx;                                                    \
50     name##_init(&ctx);                                                        \
51     name##_update(&ctx, len, data);                                           \
52     name##_digest(&ctx,NAME##_DIGEST_SIZE,digest);                            \
53   }
54   NETTLE_DIGESTS
55 #undef DO
56
57 const HashAlgInfo hashalginfos[]= {
58 #define DO(name,NAME)                                                       \
59   { #name, NAME##_DIGEST_SIZE, NAME##_DATA_SIZE, sizeof(struct name##_ctx), \
60     alg_##name##_init, alg_##name##_update, alg_##name##_final,             \
61     alg_##name##_oneshot },
62   NETTLE_DIGESTS
63 #undef DO
64   { 0 }
65 };