6 #include <netinet/in.h>
10 #include <nettle/md5.h>
11 #include <nettle/sha.h>
12 #include <nettle/serpent.h>
13 #include <nettle/twofish.h>
14 #include <nettle/aes.h>
15 #include <nettle/blowfish.h>
17 #define NETTLE_BLOCKCIPHERS \
18 DO(serpent, SERPENT) \
19 DO(twofish, TWOFISH) \
21 DO(blowfish, BLOWFISH) \
22 ALIAS(rijndael, aes, AES)
24 #define ALIAS(alias,name,NAME)
25 #define DO(name,NAME) \
26 static void alg_##name##_makekey(void *sch, const void *key, int keylen) { \
27 name##_set_key(sch, keylen, key); \
29 static void alg_##name##_encr(const void *sch, const void *in, void *out) { \
30 ##name##_encrypt((void*)sch, NAME##_BLOCK_SIZE, out, in); \
32 static void alg_##name##_decr(const void *sch, const void *in, void *out) { \
33 ##name##_decrypt((void*)sch, NAME##_BLOCK_SIZE, out, in); \
39 const BlockCipherAlgInfo blockcipheralginfos[]= {
40 #define ALIAS(alias,name,NAME) \
41 { #alias, NAME##_BLOCK_SIZE, sizeof(struct name##_ctx), \
42 NAME##_MIN_KEY_SIZE, NAME##_MAX_KEY_SIZE, \
43 { alg_##name##_makekey, alg_##name##_encr }, \
44 { alg_##name##_makekey, alg_##name##_decr } \
46 #define DO(name,NAME) ALIAS(name,name,NAME)
53 const BlockCipherPropInfo blockcipherpropinfos[]= {
54 { "blocklen", offsetof(BlockCipherAlgInfo, blocksize) },
55 { "minkeylen", offsetof(BlockCipherAlgInfo, key_min) },
56 { "maxkeylen", offsetof(BlockCipherAlgInfo, key_max) },
60 #define NETTLE_DIGESTS \
65 #define DO(name,NAME) \
66 static void alg_##name##_init(void *state) { \
69 static void alg_##name##_update(void *state, const void *data, int len) { \
70 name##_update(state, len, data); \
72 static void alg_##name##_final(void *state, void *digest) { \
73 name##_digest(state,NAME##_DIGEST_SIZE,digest); \
75 static void alg_##name##_oneshot(void *digest, const void *data, int len) { \
76 struct name##_ctx ctx; \
78 name##_update(&ctx, len, data); \
79 name##_digest(&ctx,NAME##_DIGEST_SIZE,digest); \
84 const HashAlgPropInfo hashalgpropinfos[]= {
85 { "hashlen", offsetof(HashAlgInfo, hashsize) },
86 { "blocklen", offsetof(HashAlgInfo, blocksize) },
90 const HashAlgInfo hashalginfos[]= {
91 #define DO(name,NAME) \
92 { #name, NAME##_DIGEST_SIZE, NAME##_DATA_SIZE, sizeof(struct name##_ctx), \
93 alg_##name##_init, alg_##name##_update, alg_##name##_final, \
94 alg_##name##_oneshot },