5 #include <netinet/in.h>
9 #include <nettle/md5.h>
10 #include <nettle/sha.h>
11 #include <nettle/serpent.h>
12 #include <nettle/twofish.h>
13 #include <nettle/aes.h>
14 #include <nettle/blowfish.h>
16 #define NETTLE_BLOCKCIPHERS \
17 DO(serpent, SERPENT) \
18 DO(twofish, TWOFISH) \
20 DO(blowfish, BLOWFISH) \
21 ALIAS(rijndael, aes, AES)
23 #define ALIAS(alias,name,NAME)
24 #define DO(name,NAME) \
25 static void alg_##name##_makekey(void *sch, const void *key, int keylen) { \
26 name##_set_key(sch, keylen, key); \
28 static void alg_##name##_encr(const void *sch, const void *in, void *out) { \
29 ##name##_encrypt((void*)sch, NAME##_BLOCK_SIZE, out, in); \
31 static void alg_##name##_decr(const void *sch, const void *in, void *out) { \
32 ##name##_decrypt((void*)sch, NAME##_BLOCK_SIZE, out, in); \
38 const BlockCipherAlgInfo blockcipheralginfos[]= {
39 #define ALIAS(alias,name,NAME) \
40 { #alias, NAME##_BLOCK_SIZE, sizeof(struct name##_ctx), \
41 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 },