2015-04-10 17:14:59 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include "bignum.h"
|
|
|
|
#include "ecdsa.h"
|
2016-04-25 15:15:02 +00:00
|
|
|
#include "bip32.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) {
|
2015-04-10 17:14:59 +00:00
|
|
|
int i,j,k;
|
2015-05-27 14:48:57 +00:00
|
|
|
if (argc != 2) {
|
|
|
|
printf("Usage: %s CURVE_NAME\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
const char *name = argv[1];
|
2016-04-25 15:49:17 +00:00
|
|
|
const curve_info *info = get_curve_by_name(name);
|
|
|
|
const ecdsa_curve *curve = info->params;
|
2015-05-27 14:48:57 +00:00
|
|
|
if (curve == 0) {
|
|
|
|
printf("Unknown curve '%s'\n", name);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
curve_point ng = curve->G;
|
|
|
|
curve_point pow2ig = curve->G;
|
2015-04-10 17:14:59 +00:00
|
|
|
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
|
|
|
|
#ifndef NDEBUG
|
|
|
|
curve_point checkresult;
|
|
|
|
bignum256 a;
|
|
|
|
bn_zero(&a);
|
|
|
|
a.val[(4*i) / 30] = ((uint32_t) 2*j+1) << ((4*i) % 30);
|
|
|
|
bn_normalize(&a);
|
2015-05-27 14:48:57 +00:00
|
|
|
point_multiply(curve, &a, &curve->G, &checkresult);
|
2015-04-10 17:14:59 +00:00
|
|
|
assert(point_is_equal(&checkresult, &ng));
|
|
|
|
#endif
|
|
|
|
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");
|
2015-05-27 14:48:57 +00:00
|
|
|
point_add(curve, &pow2ig, &ng);
|
2015-04-10 17:14:59 +00:00
|
|
|
}
|
2015-05-27 14:48:57 +00:00
|
|
|
point_add(curve, &pow2ig, &ng);
|
2015-04-10 17:14:59 +00:00
|
|
|
}
|
|
|
|
pow2ig = ng;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|