Mercurial > dropbear
comparison libtomcrypt/testprof/dsa_test.c @ 293:9d110777f345 contrib-blacklist
propagate from branch 'au.asn.ucc.matt.dropbear' (head 7ad1775ed65e75dbece27fe6b65bf1a234db386a)
to branch 'au.asn.ucc.matt.dropbear.contrib.blacklist' (head 1d86a4f0a401cc68c2670d821a2f6366c37af143)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 10 Mar 2006 06:31:29 +0000 |
parents | 1b9e69c058d2 |
children | 0cbe8f6dbf9e |
comparison
equal
deleted
inserted
replaced
247:c07de41b53d7 | 293:9d110777f345 |
---|---|
1 #include <tomcrypt_test.h> | |
2 | |
3 #ifdef MDSA | |
4 | |
5 int dsa_test(void) | |
6 { | |
7 unsigned char msg[16], out[1024], out2[1024]; | |
8 unsigned long x; | |
9 int stat1, stat2; | |
10 dsa_key key, key2; | |
11 | |
12 /* make a random key */ | |
13 DO(dsa_make_key(&yarrow_prng, find_prng("yarrow"), 20, 128, &key)); | |
14 | |
15 /* verify it */ | |
16 DO(dsa_verify_key(&key, &stat1)); | |
17 if (stat1 == 0) { fprintf(stderr, "dsa_verify_key "); return 1; } | |
18 | |
19 /* sign the message */ | |
20 x = sizeof(out); | |
21 DO(dsa_sign_hash(msg, sizeof(msg), out, &x, &yarrow_prng, find_prng("yarrow"), &key)); | |
22 | |
23 /* verify it once */ | |
24 DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat1, &key)); | |
25 | |
26 /* Modify and verify again */ | |
27 msg[0] ^= 1; | |
28 DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat2, &key)); | |
29 msg[0] ^= 1; | |
30 if (!(stat1 == 1 && stat2 == 0)) { fprintf(stderr, "dsa_verify %d %d", stat1, stat2); return 1; } | |
31 | |
32 /* test exporting it */ | |
33 x = sizeof(out2); | |
34 DO(dsa_export(out2, &x, PK_PRIVATE, &key)); | |
35 DO(dsa_import(out2, x, &key2)); | |
36 | |
37 /* verify a signature with it */ | |
38 DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat1, &key2)); | |
39 if (stat1 == 0) { fprintf(stderr, "dsa_verify (import private) %d ", stat1); return 1; } | |
40 dsa_free(&key2); | |
41 | |
42 /* export as public now */ | |
43 x = sizeof(out2); | |
44 DO(dsa_export(out2, &x, PK_PUBLIC, &key)); | |
45 | |
46 DO(dsa_import(out2, x, &key2)); | |
47 /* verify a signature with it */ | |
48 DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat1, &key2)); | |
49 if (stat1 == 0) { fprintf(stderr, "dsa_verify (import public) %d ", stat1); return 1; } | |
50 dsa_free(&key2); | |
51 dsa_free(&key); | |
52 | |
53 return 0; | |
54 } | |
55 | |
56 #else | |
57 | |
58 int dsa_test(void) | |
59 { | |
60 fprintf(stderr, "NOP"); | |
61 return 0; | |
62 } | |
63 | |
64 #endif | |
65 | |
66 /* $Source: /cvs/libtom/libtomcrypt/testprof/dsa_test.c,v $ */ | |
67 /* $Revision: 1.8 $ */ | |
68 /* $Date: 2005/06/03 19:24:32 $ */ |