5 #include <netinet/in.h>
12 static void alg_serpent_b_byteswap_block(Byte *b) {
13 uint32_t t, *a= (void*)b;
24 static void alg_serpent_l_byteswap_block(Byte *b) {
25 uint32_t t, *a= (void*)b;
28 if (htonl(0x01020304UL) == 0x04030201UL) /* little endian */
33 a[i]= ((t & 0x000000ffUL) << 24 |
34 (t & 0x0000ff00UL) << 8 |
35 (t & 0x00ff0000UL) >> 8 |
36 (t & 0xff000000UL) >> 24);
40 static void alg_serpent_makekey(void *schedule, const Byte *key, int keylen) {
41 serpent_makekey(schedule, keylen*8, key);
44 static void alg_serpent_encrypt(const void *sch, const void *in, void *out) {
45 serpent_encrypt(sch, in, out);
48 static void alg_serpent_decrypt(const void *sch, const void *in, void *out) {
49 serpent_decrypt(sch, in, out);
52 const BlockCipherAlgInfo blockcipheralginfos[]= {
53 { "serpent-l", 16, sizeof(struct SerpentKeyInstance), 16,32,
54 alg_serpent_l_byteswap_block,
55 { alg_serpent_makekey, alg_serpent_encrypt },
56 { alg_serpent_makekey, alg_serpent_decrypt } },
57 { "serpent-b", 16, sizeof(struct SerpentKeyInstance), 16,32,
58 alg_serpent_b_byteswap_block,
59 { alg_serpent_makekey, alg_serpent_encrypt },
60 { alg_serpent_makekey, alg_serpent_decrypt } },
64 static void alg_sha1_init(void *state) { sha1_init(state); }
65 static void alg_sha1_update(void *state, const Byte *data, int len) {
66 sha1_update(state, data, len);
68 static void alg_sha1_final(void *state, Byte *digest) {
69 sha1_final(state, digest);
71 static void alg_sha1_oneshot(Byte *digest, const Byte *data, int len) {
72 sha1(data,len,digest);
75 static void alg_md5_init(void *state) { MD5Init(state); }
76 static void alg_md5_update(void *state, const Byte *data, int len) {
77 MD5Update(state, data, len);
79 static void alg_md5_final(void *state, Byte *digest) {
80 MD5Final(digest, state);
82 static void alg_md5_oneshot(Byte *digest, const Byte *data, int len) {
83 struct MD5Context ctx;
85 MD5Update(&ctx,data,len);
86 MD5Final(digest,&ctx);
89 const HashAlgInfo hashalginfos[]= {
90 { "sha1", 20, 64, sizeof(struct sha1_state),
91 alg_sha1_init, alg_sha1_update, alg_sha1_final, alg_sha1_oneshot },
92 { "md5", 16, 64, sizeof(struct MD5Context),
93 alg_md5_init, alg_md5_update, alg_md5_final, alg_md5_oneshot },