2015-04-10 17:14:59 +00:00
|
|
|
#include <assert.h>
|
2019-03-29 14:44:55 +00:00
|
|
|
#include <stdio.h>
|
2015-04-10 17:14:59 +00:00
|
|
|
#include "bignum.h"
|
2016-04-25 15:15:02 +00:00
|
|
|
#include "bip32.h"
|
2019-03-29 14:44:55 +00:00
|
|
|
#include "ecdsa.h"
|
2016-04-25 15:49:17 +00:00
|
|
|
#include "rand.h"
|
2015-04-10 17:14:59 +00:00
|
|
|
|
|
|
|
/*
|
2015-07-07 07:38:16 +00:00
|
|
|
* This program prints the contents of the ecdsa_curve.cp array.
|
|
|
|
* The entry cp[i][j] contains the number (2*j+1)*16^i*G,
|
|
|
|
* where G is the generator of the specified elliptic curve.
|
2015-04-10 17:14:59 +00:00
|
|
|
*/
|
2015-05-27 14:48:57 +00:00
|
|
|
int main(int argc, char **argv) {
|
2019-03-29 14:44:55 +00:00
|
|
|
int i, j, k;
|
|
|
|
if (argc != 2) {
|
|
|
|
printf("Usage: %s CURVE_NAME\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
const char *name = argv[1];
|
|
|
|
const curve_info *info = get_curve_by_name(name);
|
|
|
|
const ecdsa_curve *curve = info->params;
|
|
|
|
if (curve == 0) {
|
|
|
|
printf("Unknown curve '%s'\n", name);
|
|
|
|
return 1;
|
|
|
|
}
|
2015-05-27 14:48:57 +00:00
|
|
|
|
2019-03-29 14:44:55 +00:00
|
|
|
curve_point ng = curve->G;
|
|
|
|
curve_point pow2ig = curve->G;
|
|
|
|
for (i = 0; i < 64; i++) {
|
|
|
|
// invariants:
|
|
|
|
// pow2ig = 16^i * G
|
|
|
|
// ng = pow2ig
|
|
|
|
printf("\t{\n");
|
|
|
|
for (j = 0; j < 8; j++) {
|
|
|
|
// invariants:
|
|
|
|
// pow2ig = 16^i * G
|
|
|
|
// ng = (2*j+1) * 16^i * G
|
2015-04-10 17:14:59 +00:00
|
|
|
#ifndef NDEBUG
|
2019-03-29 14:44:55 +00:00
|
|
|
curve_point checkresult;
|
|
|
|
bignum256 a;
|
|
|
|
bn_zero(&a);
|
|
|
|
a.val[(4 * i) / 30] = ((uint32_t)2 * j + 1) << ((4 * i) % 30);
|
|
|
|
bn_normalize(&a);
|
|
|
|
point_multiply(curve, &a, &curve->G, &checkresult);
|
|
|
|
assert(point_is_equal(&checkresult, &ng));
|
2015-04-10 17:14:59 +00:00
|
|
|
#endif
|
2019-03-29 14:44:55 +00:00
|
|
|
printf("\t\t/* %2d*16^%d*G: */\n\t\t{{{", 2 * j + 1, i);
|
|
|
|
// print x coordinate
|
|
|
|
for (k = 0; k < 9; k++) {
|
|
|
|
printf((k < 8 ? "0x%08x, " : "0x%04x"), ng.x.val[k]);
|
|
|
|
}
|
|
|
|
printf("}},\n\t\t {{");
|
|
|
|
// print y coordinate
|
|
|
|
for (k = 0; k < 9; k++) {
|
|
|
|
printf((k < 8 ? "0x%08x, " : "0x%04x"), ng.y.val[k]);
|
|
|
|
}
|
|
|
|
if (j == 7) {
|
|
|
|
printf("}}}\n\t},\n");
|
|
|
|
} else {
|
|
|
|
printf("}}},\n");
|
|
|
|
point_add(curve, &pow2ig, &ng);
|
|
|
|
}
|
|
|
|
point_add(curve, &pow2ig, &ng);
|
|
|
|
}
|
|
|
|
pow2ig = ng;
|
|
|
|
}
|
|
|
|
return 0;
|
2015-04-10 17:14:59 +00:00
|
|
|
}
|