1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
10 /* Implements ECC over Z/pZ for curve y^2 = x^3 - 3x + b
12 * All curves taken from NIST recommendation paper of July 1999
13 * Available at http://csrc.nist.gov/cryptval/dss.htm
19 ECC Crypto, Tom St Denis
25 Perform on the ECC system
26 @return CRYPT_OK if successful
30 void *modulus, *order;
32 int i, err, primality;
34 if ((err = mp_init_multi(&modulus, &order, NULL)) != CRYPT_OK) {
38 G = ltc_ecc_new_point();
39 GG = ltc_ecc_new_point();
40 if (G == NULL || GG == NULL) {
41 mp_clear_multi(modulus, order, NULL);
43 ltc_ecc_del_point(GG);
47 for (i = 0; ltc_ecc_sets[i].size; i++) {
49 printf("Testing %d\n", ltc_ecc_sets[i].size);
51 if ((err = mp_read_radix(modulus, (char *)ltc_ecc_sets[i].prime, 16)) != CRYPT_OK) { goto done; }
52 if ((err = mp_read_radix(order, (char *)ltc_ecc_sets[i].order, 16)) != CRYPT_OK) { goto done; }
54 /* is prime actually prime? */
55 if ((err = mp_prime_is_prime(modulus, 8, &primality)) != CRYPT_OK) { goto done; }
57 err = CRYPT_FAIL_TESTVECTOR;
61 /* is order prime ? */
62 if ((err = mp_prime_is_prime(order, 8, &primality)) != CRYPT_OK) { goto done; }
64 err = CRYPT_FAIL_TESTVECTOR;
68 if ((err = mp_read_radix(G->x, (char *)ltc_ecc_sets[i].Gx, 16)) != CRYPT_OK) { goto done; }
69 if ((err = mp_read_radix(G->y, (char *)ltc_ecc_sets[i].Gy, 16)) != CRYPT_OK) { goto done; }
72 /* then we should have G == (order + 1)G */
73 if ((err = mp_add_d(order, 1, order)) != CRYPT_OK) { goto done; }
74 if ((err = ltc_mp.ecc_ptmul(order, G, GG, modulus, 1)) != CRYPT_OK) { goto done; }
75 if (mp_cmp(G->x, GG->x) != LTC_MP_EQ || mp_cmp(G->y, GG->y) != LTC_MP_EQ) {
76 err = CRYPT_FAIL_TESTVECTOR;
82 ltc_ecc_del_point(GG);
84 mp_clear_multi(order, modulus, NULL);
90 /* ref: $Format:%D$ */
91 /* git commit: $Format:%H$ */
92 /* commit time: $Format:%ai$ */