comparison src/c/mhash.c @ 1104:72670131dace

Basis.serialize; separate file for mhash; run transactional finishers in reverse order; set needs_sig properly
author Adam Chlipala <adamc@hcoop.net>
date Thu, 31 Dec 2009 11:41:57 -0500
parents
children 6249df767d4c
comparison
equal deleted inserted replaced
1103:2f42c61b8d0a 1104:72670131dace
1 #include <mhash.h>
2
3 #define KEYSIZE 16
4 #define PASSSIZE 4
5
6 #define HASH_ALGORITHM MHASH_SHA256
7 #define HASH_BLOCKSIZE 32
8 #define KEYGEN_ALGORITHM KEYGEN_MCRYPT
9
10 int uw_hash_blocksize = HASH_BLOCKSIZE;
11
12 static int password[PASSSIZE];
13 static unsigned char private_key[KEYSIZE];
14
15 void uw_init_crypto() {
16 KEYGEN kg = {{HASH_ALGORITHM, HASH_ALGORITHM}};
17 int i;
18
19 assert(mhash_get_block_size(HASH_ALGORITHM) == HASH_BLOCKSIZE);
20
21 for (i = 0; i < PASSSIZE; ++i)
22 password[i] = rand();
23
24 if (mhash_keygen_ext(KEYGEN_ALGORITHM, kg,
25 private_key, sizeof(private_key),
26 (unsigned char*)password, sizeof(password)) < 0) {
27 fprintf(stderr, "Key generation failed\n");
28 exit(1);
29 }
30 }
31
32 void uw_sign(const char *in, char *out) {
33 MHASH td;
34
35 td = mhash_hmac_init(HASH_ALGORITHM, private_key, sizeof(private_key),
36 mhash_get_hash_pblock(HASH_ALGORITHM));
37
38 mhash(td, in, strlen(in));
39 if (mhash_hmac_deinit(td, out) < 0)
40 fprintf(stderr, "Signing failed\n");
41 }