comparison testprof/dsa_test.c @ 381:999a5eb4ed10 libtomcrypt-dropbear

propagate from branch 'au.asn.ucc.matt.ltc.orig' (head 52840647ac7f5c707c3bd158d119a15734a7ef28) to branch 'au.asn.ucc.matt.ltc.dropbear' (head 20dccfc09627970a312d77fb41dc2970b62689c3)
author Matt Johnston <matt@ucc.asn.au>
date Thu, 11 Jan 2007 02:39:21 +0000
parents d5faf4814ddb
children
comparison
equal deleted inserted replaced
281:997e6f7dc01e 381:999a5eb4ed10
3 #ifdef MDSA 3 #ifdef MDSA
4 4
5 int dsa_test(void) 5 int dsa_test(void)
6 { 6 {
7 unsigned char msg[16], out[1024], out2[1024]; 7 unsigned char msg[16], out[1024], out2[1024];
8 unsigned long x; 8 unsigned long x, y;
9 int stat1, stat2; 9 int stat1, stat2;
10 dsa_key key, key2; 10 dsa_key key, key2;
11 11
12 /* make a random key */ 12 /* make a random key */
13 DO(dsa_make_key(&yarrow_prng, find_prng("yarrow"), 20, 128, &key)); 13 DO(dsa_make_key(&yarrow_prng, find_prng("yarrow"), 20, 128, &key));
14 14
15 /* verify it */ 15 /* verify it */
16 DO(dsa_verify_key(&key, &stat1)); 16 DO(dsa_verify_key(&key, &stat1));
17 if (stat1 == 0) { fprintf(stderr, "dsa_verify_key "); return 1; } 17 if (stat1 == 0) { fprintf(stderr, "dsa_verify_key "); return 1; }
18
19 /* encrypt a message */
20 for (x = 0; x < 16; x++) { msg[x] = x; }
21 x = sizeof(out);
22 DO(dsa_encrypt_key(msg, 16, out, &x, &yarrow_prng, find_prng("yarrow"), find_hash("sha1"), &key));
23
24 /* decrypt */
25 y = sizeof(out2);
26 DO(dsa_decrypt_key(out, x, out2, &y, &key));
27
28 if (y != 16 || memcmp(out2, msg, 16)) {
29 fprintf(stderr, "dsa_decrypt failed, y == %lu\n", y);
30 return 1;
31 }
18 32
19 /* sign the message */ 33 /* sign the message */
20 x = sizeof(out); 34 x = sizeof(out);
21 DO(dsa_sign_hash(msg, sizeof(msg), out, &x, &yarrow_prng, find_prng("yarrow"), &key)); 35 DO(dsa_sign_hash(msg, sizeof(msg), out, &x, &yarrow_prng, find_prng("yarrow"), &key));
22 36
62 } 76 }
63 77
64 #endif 78 #endif
65 79
66 /* $Source: /cvs/libtom/libtomcrypt/testprof/dsa_test.c,v $ */ 80 /* $Source: /cvs/libtom/libtomcrypt/testprof/dsa_test.c,v $ */
67 /* $Revision: 1.8 $ */ 81 /* $Revision: 1.9 $ */
68 /* $Date: 2005/06/03 19:24:32 $ */ 82 /* $Date: 2005/10/30 18:49:14 $ */