comparison testprof/der_tests.c @ 191:1c15b283127b libtomcrypt-orig

Import of libtomcrypt 1.02 with manual path rename rearrangement etc
author Matt Johnston <matt@ucc.asn.au>
date Fri, 06 May 2005 13:23:02 +0000
parents
children 39d5d58461d6
comparison
equal deleted inserted replaced
143:5d99163f7e32 191:1c15b283127b
1 #include <tomcrypt_test.h>
2
3 #ifndef LTC_DER
4
5 int der_tests(void)
6 {
7 printf("NOP");
8 return 0;
9 }
10
11 #else
12
13 int der_tests(void)
14 {
15 unsigned long x, y, z, zz;
16 unsigned char buf[2][4096];
17 mp_int a, b, c, d, e, f, g;
18
19 DO(mpi_to_ltc_error(mp_init_multi(&a, &b, &c, &d, &e, &f, &g, NULL)));
20 for (zz = 0; zz < 16; zz++) {
21 for (z = 0; z < 1024; z++) {
22 if (yarrow_read(buf[0], z, &yarrow_prng) != z) {
23 printf("Failed to read %lu bytes from yarrow\n", z);
24 return 1;
25 }
26 DO(mpi_to_ltc_error(mp_read_unsigned_bin(&a, buf[0], z)));
27 x = sizeof(buf[0]);
28 DO(der_encode_integer(&a, buf[0], &x));
29 y = x;
30 mp_zero(&b);
31 DO(der_decode_integer(buf[0], &y, &b));
32 if (y != x || mp_cmp(&a, &b) != MP_EQ) {
33 printf("%lu: %lu vs %lu\n", z, x, y);
34 #ifdef BN_MP_TORADIX_C
35 mp_todecimal(&a, buf[0]);
36 mp_todecimal(&b, buf[1]);
37 printf("a == %s\nb == %s\n", buf[0], buf[1]);
38 #endif
39 mp_clear_multi(&a, &b, &c, &d, &e, &f, &g, NULL);
40 return 1;
41 }
42 }
43 }
44
45
46 /* test the multi */
47 mp_set(&a, 1);
48 x = sizeof(buf[0]);
49 DO(der_put_multi_integer(buf[0], &x, &a, NULL));
50 y = x;
51 mp_zero(&a);
52 DO(der_get_multi_integer(buf[0], &y, &a, NULL));
53 if (x != y || mp_cmp_d(&a, 1)) {
54 printf("%lu, %lu, %d\n", x, y, mp_cmp_d(&a, 1));
55 mp_clear_multi(&a, &b, &c, &d, &e, &f, &g, NULL);
56 return 1;
57 }
58
59 mp_set(&a, 1);
60 mp_set(&b, 2);
61 x = sizeof(buf[0]);
62 DO(der_put_multi_integer(buf[0], &x, &a, &b, NULL));
63 y = x;
64 mp_zero(&a);
65 mp_zero(&b);
66 DO(der_get_multi_integer(buf[0], &y, &a, &b, NULL));
67 if (x != y || mp_cmp_d(&a, 1) || mp_cmp_d(&b, 2)) {
68 printf("%lu, %lu, %d, %d\n", x, y, mp_cmp_d(&a, 1), mp_cmp_d(&b, 2));
69 mp_clear_multi(&a, &b, &c, &d, &e, &f, &g, NULL);
70 return 1;
71 }
72
73 mp_set(&a, 1);
74 mp_set(&b, 2);
75 mp_set(&c, 3);
76 x = sizeof(buf[0]);
77 DO(der_put_multi_integer(buf[0], &x, &a, &b, &c, NULL));
78 y = x;
79 mp_zero(&a);
80 mp_zero(&b);
81 mp_zero(&c);
82 DO(der_get_multi_integer(buf[0], &y, &a, &b, &c, NULL));
83 if (x != y || mp_cmp_d(&a, 1) || mp_cmp_d(&b, 2) || mp_cmp_d(&c, 3)) {
84 printf("%lu, %lu, %d, %d, %d\n", x, y, mp_cmp_d(&a, 1), mp_cmp_d(&b, 2), mp_cmp_d(&c, 3));
85 mp_clear_multi(&a, &b, &c, &d, &e, &f, &g, NULL);
86 return 1;
87 }
88
89
90 mp_clear_multi(&a, &b, &c, &d, &e, &f, &g, NULL);
91 return 0;
92 }
93
94 #endif