4 #include "chiark_tcl_crypto.h"
6 #include <nettle/md5.h>
7 #include <nettle/sha.h>
8 #include <nettle/serpent.h>
9 #include <nettle/twofish.h>
10 #include <nettle/aes.h>
11 #include <nettle/blowfish.h>
13 #define NETTLE_BLOCKCIPHERS \
14 DO(serpent, SERPENT) \
15 DO(twofish, TWOFISH) \
17 DO(blowfish, BLOWFISH) \
18 /* ALIAS(rijndael, aes, AES)*/
20 #define ALIAS(alias,name,NAME)
21 #define DO(name,NAME) \
22 static void alg_##name##_makekey(void *sch, const void *key, int keylen) { \
23 name##_set_key(sch, keylen, key); \
25 static void alg_##name##_encr(const void *sch, const void *in, void *out) { \
26 name##_encrypt((void*)sch, NAME##_BLOCK_SIZE, out, in); \
28 static void alg_##name##_decr(const void *sch, const void *in, void *out) { \
29 name##_decrypt((void*)sch, NAME##_BLOCK_SIZE, out, in); \
35 const BlockCipherAlgInfo cht_blockcipheralginfo_entries[]= {
36 #define ALIAS(alias,name,NAME) \
37 { #alias, NAME##_BLOCK_SIZE, sizeof(struct name##_ctx), \
38 NAME##_MIN_KEY_SIZE, NAME##_MAX_KEY_SIZE, \
39 { alg_##name##_makekey, alg_##name##_encr }, \
40 { alg_##name##_makekey, alg_##name##_decr } \
42 #define DO(name,NAME) ALIAS(name,name,NAME)
49 const BlockCipherPropInfo cht_blockcipherpropinfo_entries[]= {
50 { "blocklen", offsetof(BlockCipherAlgInfo, blocksize) },
51 { "minkeylen", offsetof(BlockCipherAlgInfo, key_min) },
52 { "maxkeylen", offsetof(BlockCipherAlgInfo, key_max) },
56 #define NETTLE_DIGESTS \
61 #define DO(name,NAME) \
62 static void alg_##name##_init(void *state) { \
65 static void alg_##name##_update(void *state, const void *data, int len) { \
66 name##_update(state, len, data); \
68 static void alg_##name##_final(void *state, void *digest) { \
69 name##_digest(state,NAME##_DIGEST_SIZE,digest); \
71 static void alg_##name##_oneshot(void *digest, const void *data, int len) { \
72 struct name##_ctx ctx; \
74 name##_update(&ctx, len, data); \
75 name##_digest(&ctx,NAME##_DIGEST_SIZE,digest); \
80 const HashAlgPropInfo cht_hashalgpropinfo_entries[]= {
81 { "hashlen", offsetof(HashAlgInfo, hashsize) },
82 { "blocklen", offsetof(HashAlgInfo, blocksize) },
86 const HashAlgInfo cht_hashalginfo_entries[]= {
87 #define DO(name,NAME) \
88 { #name, NAME##_DIGEST_SIZE, NAME##_DATA_SIZE, sizeof(struct name##_ctx), \
89 alg_##name##_init, alg_##name##_update, alg_##name##_final, \
90 alg_##name##_oneshot },