7
unsigned char msg[16], out[1024], out2[1024];
12
/* make a random key */
13
DO(dsa_make_key(&test_yarrow, find_prng("yarrow"), 20, 128, &key));
16
DO(dsa_verify_key(&key, &stat1));
17
if (stat1 == 0) { printf("dsa_verify_key "); return 1; }
19
/* sign the message */
21
DO(dsa_sign_hash(msg, sizeof(msg), out, &x, &test_yarrow, find_prng("yarrow"), &key));
24
DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat1, &key));
26
/* Modify and verify again */
28
DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat2, &key));
30
if (!(stat1 == 1 && stat2 == 0)) { printf("dsa_verify %d %d", stat1, stat2); return 1; }
32
/* test exporting it */
34
DO(dsa_export(out2, &x, PK_PRIVATE, &key));
35
DO(dsa_import(out2, x, &key2));
37
/* verify a signature with it */
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; }
42
/* export as public now */
44
DO(dsa_export(out2, &x, PK_PUBLIC, &key));
45
DO(dsa_import(out2, x, &key2));
46
/* verify a signature with it */
47
DO(dsa_verify_hash(out, x, msg, sizeof(msg), &stat1, &key2));
48
if (stat1 == 0) { printf("dsa_verify (import public) %d ", stat1); return 1; }