Mercurial > dropbear
comparison testprof/dsa_test.c @ 210:4768b55c5240 libtomcrypt
propagate from branch 'au.asn.ucc.matt.ltc-orig' (head 33c416b902f1a44913d825bae7ad9a160f703ed3)
to branch 'au.asn.ucc.matt.dropbear.ltc' (head 4d6aec6e6121e13f68c11c149b6579c41cb63e74)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 06 Jul 2005 12:10:23 +0000 |
parents | 39d5d58461d6 |
children |
comparison
equal
deleted
inserted
replaced
199:8be64e2c86f4 | 210:4768b55c5240 |
---|---|
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) { printf("dsa_verify_key "); return 1; } | 17 if (stat1 == 0) { fprintf(stderr, "dsa_verify_key "); return 1; } |
18 | 18 |
19 /* sign the message */ | 19 /* sign the message */ |
20 x = sizeof(out); | 20 x = sizeof(out); |
21 DO(dsa_sign_hash(msg, sizeof(msg), out, &x, &yarrow_prng, find_prng("yarrow"), &key)); | 21 DO(dsa_sign_hash(msg, sizeof(msg), out, &x, &yarrow_prng, find_prng("yarrow"), &key)); |
22 | 22 |
25 | 25 |
26 /* Modify and verify again */ | 26 /* Modify and verify again */ |
27 msg[0] ^= 1; | 27 msg[0] ^= 1; |
28 DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat2, &key)); | 28 DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat2, &key)); |
29 msg[0] ^= 1; | 29 msg[0] ^= 1; |
30 if (!(stat1 == 1 && stat2 == 0)) { printf("dsa_verify %d %d", stat1, stat2); return 1; } | 30 if (!(stat1 == 1 && stat2 == 0)) { fprintf(stderr, "dsa_verify %d %d", stat1, stat2); return 1; } |
31 | 31 |
32 /* test exporting it */ | 32 /* test exporting it */ |
33 x = sizeof(out2); | 33 x = sizeof(out2); |
34 DO(dsa_export(out2, &x, PK_PRIVATE, &key)); | 34 DO(dsa_export(out2, &x, PK_PRIVATE, &key)); |
35 DO(dsa_import(out2, x, &key2)); | 35 DO(dsa_import(out2, x, &key2)); |
36 | 36 |
37 /* verify a signature with it */ | 37 /* verify a signature with it */ |
38 DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat1, &key2)); | 38 DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat1, &key2)); |
39 if (stat1 == 0) { printf("dsa_verify (import private) %d ", stat1); return 1; } | 39 if (stat1 == 0) { fprintf(stderr, "dsa_verify (import private) %d ", stat1); return 1; } |
40 dsa_free(&key2); | 40 dsa_free(&key2); |
41 | 41 |
42 /* export as public now */ | 42 /* export as public now */ |
43 x = sizeof(out2); | 43 x = sizeof(out2); |
44 DO(dsa_export(out2, &x, PK_PUBLIC, &key)); | 44 DO(dsa_export(out2, &x, PK_PUBLIC, &key)); |
45 | |
45 DO(dsa_import(out2, x, &key2)); | 46 DO(dsa_import(out2, x, &key2)); |
46 /* verify a signature with it */ | 47 /* verify a signature with it */ |
47 DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat1, &key2)); | 48 DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat1, &key2)); |
48 if (stat1 == 0) { printf("dsa_verify (import public) %d ", stat1); return 1; } | 49 if (stat1 == 0) { fprintf(stderr, "dsa_verify (import public) %d ", stat1); return 1; } |
49 dsa_free(&key2); | 50 dsa_free(&key2); |
50 dsa_free(&key); | 51 dsa_free(&key); |
51 | 52 |
52 return 0; | 53 return 0; |
53 } | 54 } |
54 | 55 |
55 #else | 56 #else |
56 | 57 |
57 int dsa_test(void) | 58 int dsa_test(void) |
58 { | 59 { |
59 printf("NOP"); | 60 fprintf(stderr, "NOP"); |
60 return 0; | 61 return 0; |
61 } | 62 } |
62 | 63 |
63 #endif | 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 $ */ |