Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / nettle / testsuite / ecdsa-verify-test.c
blob5f880729b69d5813479e946829146fe0f16d4a93
1 #include "testutils.h"
3 static void
4 test_ecdsa (const struct ecc_curve *ecc,
5 /* Public key */
6 const char *xs, const char *ys,
7 /* Hash */
8 struct tstring *h,
9 /* Valid signature */
10 const char *r, const char *s)
12 struct ecc_point pub;
13 struct dsa_signature signature;
14 mpz_t x, y;
16 ecc_point_init (&pub, ecc);
17 dsa_signature_init (&signature);
19 mpz_init_set_str (x, xs, 16);
20 mpz_init_set_str (y, ys, 16);
22 if (!ecc_point_set (&pub, x, y))
23 die ("ecc_point_set failed.\n");
25 mpz_set_str (signature.r, r, 16);
26 mpz_set_str (signature.s, s, 16);
28 if (!ecdsa_verify (&pub, h->length, h->data, &signature))
30 fprintf (stderr, "ecdsa_verify failed with valid signature.\n");
31 fail:
32 fprintf (stderr, "bit_size = %u\n", ecc->bit_size);
33 gmp_fprintf (stderr, "x = %Zx\n", x);
34 gmp_fprintf (stderr, "y = %Zx\ndigest ", y);
35 print_hex (h->length, h->data);
36 gmp_fprintf (stderr, "r = %Zx\n", signature.r);
37 gmp_fprintf (stderr, "s = %Zx\n", signature.s);
38 abort();
41 mpz_combit (signature.r, ecc->bit_size / 3);
42 if (ecdsa_verify (&pub, h->length, h->data, &signature))
44 fprintf (stderr, "ecdsa_verify unexpectedly succeeded with invalid signature.\n");
45 goto fail;
47 mpz_combit (signature.r, ecc->bit_size / 3);
49 mpz_combit (signature.s, 4*ecc->bit_size / 5);
50 if (ecdsa_verify (&pub, h->length, h->data, &signature))
52 fprintf (stderr, "ecdsa_verify unexpectedly succeeded with invalid signature.\n");
53 goto fail;
55 mpz_combit (signature.s, 4*ecc->bit_size / 5);
57 h->data[2*h->length / 3] ^= 0x40;
58 if (ecdsa_verify (&pub, h->length, h->data, &signature))
60 fprintf (stderr, "ecdsa_verify unexpectedly succeeded with invalid signature.\n");
61 goto fail;
63 h->data[2*h->length / 3] ^= 0x40;
64 if (!ecdsa_verify (&pub, h->length, h->data, &signature))
66 fprintf (stderr, "ecdsa_verify failed, internal testsuite error.\n");
67 goto fail;
70 ecc_point_clear (&pub);
71 dsa_signature_clear (&signature);
72 mpz_clear (x);
73 mpz_clear (y);
76 void
77 test_main (void)
79 /* From RFC 4754 */
80 test_ecdsa (&nettle_secp_256r1,
81 "2442A5CC 0ECD015F A3CA31DC 8E2BBC70"
82 "BF42D60C BCA20085 E0822CB0 4235E970", /* x */
84 "6FC98BD7 E50211A4 A27102FA 3549DF79"
85 "EBCB4BF2 46B80945 CDDFE7D5 09BBFD7D", /* y */
87 SHEX("BA7816BF 8F01CFEA 414140DE 5DAE2223"
88 "B00361A3 96177A9C B410FF61 F20015AD"), /* h */
90 "CB28E099 9B9C7715 FD0A80D8 E47A7707"
91 "9716CBBF 917DD72E 97566EA1 C066957C", /* r */
92 "86FA3BB4 E26CAD5B F90B7F81 899256CE"
93 "7594BB1E A0C89212 748BFF3B 3D5B0315"); /* s */
95 test_ecdsa (&nettle_secp_384r1,
96 "96281BF8 DD5E0525 CA049C04 8D345D30"
97 "82968D10 FEDF5C5A CA0C64E6 465A97EA"
98 "5CE10C9D FEC21797 41571072 1F437922", /* x */
100 "447688BA 94708EB6 E2E4D59F 6AB6D7ED"
101 "FF9301D2 49FE49C3 3096655F 5D502FAD"
102 "3D383B91 C5E7EDAA 2B714CC9 9D5743CA", /* y */
104 SHEX("CB00753F 45A35E8B B5A03D69 9AC65007"
105 "272C32AB 0EDED163 1A8B605A 43FF5BED"
106 "8086072B A1E7CC23 58BAECA1 34C825A7"), /* h */
108 "FB017B91 4E291494 32D8BAC2 9A514640"
109 "B46F53DD AB2C6994 8084E293 0F1C8F7E"
110 "08E07C9C 63F2D21A 07DCB56A 6AF56EB3", /* r */
111 "B263A130 5E057F98 4D38726A 1B468741"
112 "09F417BC A112674C 528262A4 0A629AF1"
113 "CBB9F516 CE0FA7D2 FF630863 A00E8B9F"); /* s*/
115 test_ecdsa (&nettle_secp_521r1,
116 "0151518F 1AF0F563 517EDD54 85190DF9"
117 "5A4BF57B 5CBA4CF2 A9A3F647 4725A35F"
118 "7AFE0A6D DEB8BEDB CD6A197E 592D4018"
119 "8901CECD 650699C9 B5E456AE A5ADD190"
120 "52A8", /* x */
122 "006F3B14 2EA1BFFF 7E2837AD 44C9E4FF"
123 "6D2D34C7 3184BBAD 90026DD5 E6E85317"
124 "D9DF45CA D7803C6C 20035B2F 3FF63AFF"
125 "4E1BA64D 1C077577 DA3F4286 C58F0AEA"
126 "E643", /* y */
128 SHEX("DDAF35A1 93617ABA CC417349 AE204131"
129 "12E6FA4E 89A97EA2 0A9EEEE6 4B55D39A"
130 "2192992A 274FC1A8 36BA3C23 A3FEEBBD"
131 "454D4423 643CE80E 2A9AC94F A54CA49F"), /* h */
133 "0154FD38 36AF92D0 DCA57DD5 341D3053"
134 "988534FD E8318FC6 AAAAB68E 2E6F4339"
135 "B19F2F28 1A7E0B22 C269D93C F8794A92"
136 "78880ED7 DBB8D936 2CAEACEE 54432055"
137 "2251", /* r */
138 "017705A7 030290D1 CEB605A9 A1BB03FF"
139 "9CDD521E 87A696EC 926C8C10 C8362DF4"
140 "97536710 1F67D1CF 9BCCBF2F 3D239534"
141 "FA509E70 AAC851AE 01AAC68D 62F86647"
142 "2660"); /* s */