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, \
42 { alg_##name##_makekey, alg_##name##_encr }, \
43 { alg_##name##_makekey, alg_##name##_decr } \
45 #define DO(name,NAME) ALIAS(name,name,NAME)
52 const BlockCipherPropInfo blockcipherpropinfos[]= {
53 { "blocklen", offsetof(BlockCipherAlgInfo, blocksize) },
54 { "minkeylen", offsetof(BlockCipherAlgInfo, key_min) },
55 { "maxkeylen", offsetof(BlockCipherAlgInfo, key_max) },
59 #define NETTLE_DIGESTS \
64 #define DO(name,NAME) \
65 static void alg_##name##_init(void *state) { \
68 static void alg_##name##_update(void *state, const void *data, int len) { \
69 name##_update(state, len, data); \
71 static void alg_##name##_final(void *state, void *digest) { \
72 name##_digest(state,NAME##_DIGEST_SIZE,digest); \
74 static void alg_##name##_oneshot(void *digest, const void *data, int len) { \
75 struct name##_ctx ctx; \
77 name##_update(&ctx, len, data); \
78 name##_digest(&ctx,NAME##_DIGEST_SIZE,digest); \
83 const HashAlgPropInfo hashalgpropinfos[]= {
84 { "hashlen", offsetof(HashAlgInfo, hashsize) },
85 { "blocklen", offsetof(HashAlgInfo, blocksize) },
89 const HashAlgInfo hashalginfos[]= {
90 #define DO(name,NAME) \
91 { #name, NAME##_DIGEST_SIZE, NAME##_DATA_SIZE, sizeof(struct name##_ctx), \
92 alg_##name##_init, alg_##name##_update, alg_##name##_final, \
93 alg_##name##_oneshot },