+uint8_t ecc_affine_point_alloc(ecc_affine_point_t *p, uint16_t length_b){
+ size_t len = (length_b + BIGINT_WORD_SIZE - 1)/ BIGINT_WORD_SIZE;
+ if (! (p->x.wordv = malloc(len))){
+ return 1;
+ }
+ if (! (p->y.wordv = malloc(len))){
+ free(p->x.wordv);
+ return 2;
+ }
+ return 0;
+}
+
+void ecc_affine_point_free(ecc_affine_point_t *p){
+ free(p->x.wordv);
+ free(p->y.wordv);
+}
+
+
+void testrun_square(void){
+ bigint_word_t a_w[] = {
+ 0x82, 0x6f, 0x79, 0x39, 0x47, 0x06, 0x26, 0x9f,
+ 0x4b, 0xe2, 0x15, 0x61, 0x6f, 0xa1, 0xd4, 0x0c,
+ 0x1f, 0x24, 0x3a, 0xd4, 0xc2, 0x6d, 0xe8, 0xb6
+ };
+
+ bigint_word_t b_w[2 * 192 / BIGINT_WORD_SIZE];
+ bigint_t a, b;
+
+ a.wordv = a_w;
+ a.length_W = sizeof(a_w);
+ a.info = 7;
+
+ b.wordv = b_w;
+ b.info = 0;
+ b.length_W = 0;
+
+ printf_P(PSTR("\n a = "));
+ bigint_print_hex(&a);
+ bigint_square(&b, &a);
+ printf_P(PSTR("\n a^2 = "));
+ bigint_print_hex(&b);
+ bigint_reduce_p192(&b);
+ printf_P(PSTR("\n a^2 %% p = "));
+ bigint_print_hex(&b);
+ putchar('\n');
+
+
+}
+
+#if 1
+/*
+0: b3cfed2634516540528622e16c396c229e50bbdf773f8423
+1: b6e86dc2d43a241f0cd4a16f6115e24b9f26064739796f82
+2: 563f557e41731f268f82fe81c8fed959600dd46649ebeeee
+3: 5e45169bd87475db886b8a7833bb0845f5b011a7ce0c1766
+4: 4abf34c505a73308a804dcefacbd8f7b10b59fa6ac6421a
+*/
+uint8_t test_point_x_w[] = {
+ 0x23, 0x84, 0x3f, 0x77, 0xdf, 0xbb, 0x50, 0x9e,
+ 0x22, 0x6c, 0x39, 0x6c, 0xe1, 0x22, 0x86, 0x52,
+ 0x40, 0x65, 0x51, 0x34, 0x26, 0xed, 0xcf, 0xb3
+};
+
+uint8_t test_point_y_w[] = {
+ 0x82, 0x6f, 0x79, 0x39, 0x47, 0x06, 0x26, 0x9f,
+ 0x4b, 0xe2, 0x15, 0x61, 0x6f, 0xa1, 0xd4, 0x0c,
+ 0x1f, 0x24, 0x3a, 0xd4, 0xc2, 0x6d, 0xe8, 0xb6
+};
+
+uint8_t test_point_z1_w[] = {
+ 0xee, 0xee, 0xeb, 0x49, 0x66, 0xd4, 0x0d, 0x60,
+ 0x59, 0xd9, 0xfe, 0xc8, 0x81, 0xfe, 0x82, 0x8f,
+ 0x26, 0x1f, 0x73, 0x41, 0x7e, 0x55, 0x3f, 0x56
+};
+
+uint8_t test_point_z2_w[] = {
+ 0x66, 0x17, 0x0c, 0xce, 0xa7, 0x11, 0xb0, 0xf5,
+ 0x45, 0x08, 0xbb, 0x33, 0x78, 0x8a, 0x6b, 0x88,
+ 0xdb, 0x75, 0x74, 0xd8, 0x9b, 0x16, 0x45, 0x5e
+};
+
+uint8_t test_point_z3_w[] = {
+ 0x1a, 0x42, 0xc6, 0x6a, 0xfa, 0x59, 0x0b, 0xb1,
+ 0xf7, 0xd8, 0xcb, 0xfa, 0xce, 0x4d, 0x80, 0x8a,
+ 0x30, 0x73, 0x5a, 0x50, 0x4c, 0xf3, 0xab, 0x04
+};
+
+ecc_combi_point_t test_point = {
+ .chudnovsky = {
+ .x = {
+ .wordv = test_point_x_w,
+ .length_W = sizeof(test_point_x_w),
+ .info = 7
+ },
+ .y = {
+ .wordv = test_point_y_w,
+ .length_W = sizeof(test_point_y_w),
+ .info = 7
+ },
+ .z1 = {
+ .wordv = test_point_z1_w,
+ .length_W = sizeof(test_point_z1_w),
+ .info = 6
+ },
+ .z2 = {
+ .wordv = test_point_z2_w,
+ .length_W = sizeof(test_point_z2_w),
+ .info = 6
+ },
+ .z3 = {
+ .wordv = test_point_z3_w,
+ .length_W = sizeof(test_point_z3_w),
+ .info = 2
+ }
+ }
+};
+void testrun_genkey2(void){
+ ecc_chudnovsky_point_t q;
+ ecc_affine_point_t qa;
+
+ printf_P(PSTR("\n== testing key generation (2) ==\n"));
+
+ if(ecc_chudnovsky_point_alloc(&q, 192)){
+ printf_P(PSTR("ERROR: OOM! <%s %s %d>\n"), __FILE__, __func__, __LINE__);
+ return;
+ }
+ if(ecc_affine_point_alloc(&qa, 192)){
+ printf_P(PSTR("ERROR: OOM! <%s %s %d>\n"), __FILE__, __func__, __LINE__);
+ return;
+ }
+
+ ecc_chudnovsky_point_print(&test_point.chudnovsky);
+ ecc_chudnovsky_to_affine_point(&qa, &test_point.chudnovsky, &nist_curve_p192);
+ printf_P(PSTR("\n Qx: "));
+ bigint_print_hex(&qa.x);
+ printf_P(PSTR("\n Qy: "));
+ bigint_print_hex(&qa.y);
+ printf_P(PSTR("\n================\n"));
+ ecc_chudnovsky_point_double_sp(&q, &test_point.chudnovsky, &nist_curve_p192);
+ ecc_chudnovsky_point_print(&q);
+
+ ecc_chudnovsky_to_affine_point(&qa, &q, &nist_curve_p192);
+
+ printf_P(PSTR("\n Qx: "));
+ bigint_print_hex(&qa.x);
+ printf_P(PSTR("\n Qy: "));
+ bigint_print_hex(&qa.y);
+ puts("\n");
+
+}
+
+void testrun_genkey1(void){
+ ecc_chudnovsky_point_t q;
+ ecc_affine_point_t qa;
+
+ uint8_t k_w[] = {
+ // e5ce89a34adddf25ff3bf1ffe6803f57d0220de3118798ea
+ 0xea, 0x98, 0x87, 0x11, 0xe3, 0x0d, 0x22, 0xd0,
+ 0x57, 0x3f, 0x80, 0xe6, 0xff, 0xf1, 0x3b, 0xff,
+ 0x25, 0xdf, 0xdd, 0x4a, 0xa3, 0x89, 0xce, 0xe5
+ };
+
+ bigint_t k = {
+ .length_W = sizeof(k_w),
+ .wordv = k_w,
+ .info = 7
+ };
+
+ printf_P(PSTR("\n== testing key generation ==\n"));
+
+ if(ecc_chudnovsky_point_alloc(&q, 192)){
+ printf_P(PSTR("ERROR: OOM! <%s %s %d>\n"), __FILE__, __func__, __LINE__);
+ return;
+ }
+ if(ecc_affine_point_alloc(&qa, 192)){
+ printf_P(PSTR("ERROR: OOM! <%s %s %d>\n"), __FILE__, __func__, __LINE__);
+ return;
+ }
+
+ printf_P(PSTR(" k: "));
+ bigint_print_hex(&k);
+ ecc_chudnovsky_multiplication(&q, &k, &nist_curve_p192_basepoint.chudnovsky, &nist_curve_p192);
+ ecc_chudnovsky_to_affine_point(&qa, &q, &nist_curve_p192);
+
+ printf_P(PSTR("\n Qx: "));
+ bigint_print_hex(&qa.x);
+ printf_P(PSTR("\n Qy: "));
+ bigint_print_hex(&qa.y);
+ puts("\n");
+}
+
+void testrun_genkey3(void){
+ ecc_chudnovsky_point_t q;
+ ecc_affine_point_t qa;
+
+ uint8_t k_w[] = {
+ 0xb2, 0x51, 0x97, 0xc3, 0x7c, 0x61, 0xf8, 0x8f,
+ 0x19, 0x91, 0xcc, 0x67, 0xb5, 0x1c, 0x34, 0x23,
+ 0xff, 0x13, 0xad, 0x14, 0x57, 0x43, 0x14, 0x7d
+ };
+
+ bigint_t k = {
+ .length_W = sizeof(k_w),
+ .wordv = k_w,
+ .info = 6
+ };
+
+ printf_P(PSTR("\n== testing key generation ==\n"));
+
+ if(ecc_chudnovsky_point_alloc(&q, 192)){
+ printf_P(PSTR("ERROR: OOM! <%s %s %d>\n"), __FILE__, __func__, __LINE__);
+ return;
+ }
+ if(ecc_affine_point_alloc(&qa, 192)){
+ printf_P(PSTR("ERROR: OOM! <%s %s %d>\n"), __FILE__, __func__, __LINE__);
+ return;
+ }
+
+ printf_P(PSTR(" k: "));
+ bigint_print_hex(&k);
+ ecc_chudnovsky_double_and_add(&q, &k, &nist_curve_p192_basepoint.chudnovsky, &nist_curve_p192);
+ ecc_chudnovsky_to_affine_point(&qa, &q, &nist_curve_p192);
+
+ printf_P(PSTR("\n Qx: "));
+ bigint_print_hex(&qa.x);
+ printf_P(PSTR("\n Qy: "));
+ bigint_print_hex(&qa.y);
+ puts("\n");
+}
+
+void testrun_genkey(void){
+ ecc_chudnovsky_point_t q;
+ ecc_affine_point_t qa;
+ uint32_t time;
+ bigint_t k;
+ uint8_t r;
+
+ printf_P(PSTR("\n== testing key generation ==\n"));
+
+ printf_P(PSTR("enter secret key d: "));
+ bigint_read_hex_echo(&k);
+ putchar('\n');
+
+ if(ecc_chudnovsky_point_alloc(&q, 192)){
+ printf_P(PSTR("ERROR: OOM! <%s %s %d>\n"), __FILE__, __func__, __LINE__);
+ return;
+ }
+ if(ecc_affine_point_alloc(&qa, 192)){
+ ecc_chudnovsky_point_free(&q);
+ printf_P(PSTR("ERROR: OOM! <%s %s %d>\n"), __FILE__, __func__, __LINE__);
+ return;
+ }
+
+ printf_P(PSTR("(naf) k: "));
+ bigint_print_hex(&k);
+ startTimer(1);
+ START_TIMER;
+ r = ecc_chudnovsky_naf_multiplication(&q, &k, &nist_curve_p192_basepoint.chudnovsky, &nist_curve_p192);
+ STOP_TIMER;
+ time = stopTimer();
+ ecc_chudnovsky_to_affine_point(&qa, &q, &nist_curve_p192);
+
+ printf_P(PSTR("\n Qx: "));
+ bigint_print_hex(&qa.x);
+ printf_P(PSTR("\n Qy: "));
+ bigint_print_hex(&qa.y);
+ printf_P(PSTR("\n time: %"PRIu32" cycles (r code: %"PRIu8")\n"), time, r);
+
+ printf_P(PSTR("(d&a) k: "));
+ bigint_print_hex(&k);
+ startTimer(1);
+ START_TIMER;
+ r = ecc_chudnovsky_double_and_add(&q, &k, &nist_curve_p192_basepoint.chudnovsky, &nist_curve_p192);
+ STOP_TIMER;
+ time = stopTimer();
+ ecc_chudnovsky_to_affine_point(&qa, &q, &nist_curve_p192);
+
+ printf_P(PSTR("\n Qx: "));
+ bigint_print_hex(&qa.x);
+ printf_P(PSTR("\n Qy: "));
+ bigint_print_hex(&qa.y);
+ printf_P(PSTR("\n time: %"PRIu32" cycles (r code: %"PRIu8")\n"), time, r);
+ free(k.wordv);
+ ecc_chudnovsky_point_free(&q);
+ ecc_affine_point_free(&qa);
+}
+
+
+#endif
+
+const uint8_t ecdsa_test_1_msg[] PROGMEM = {
+/*
+ 0xcf, 0x71, 0xa0, 0xe4, 0xce, 0x59, 0x43, 0x11,
+ 0x77, 0x88, 0x50, 0x87, 0x53, 0x78, 0xd0, 0xee,
+ 0xa3, 0xc0, 0x32, 0xa4, 0xbc, 0xc0, 0xdc, 0x1c,
+ 0xf2, 0x9d, 0x01, 0xb9, 0xc5, 0x10, 0x78, 0x9c,
+ 0xd5, 0x2f, 0xc3, 0x8c, 0x74, 0xe6, 0xa4, 0x27,
+ 0x87, 0xd0, 0xf2, 0x7c, 0xe2, 0x93, 0x20, 0x7a,
+ 0xfd, 0xd0, 0x11, 0x7a, 0xcc, 0x71, 0xb9, 0x16,
+ 0x63, 0x06, 0xce, 0x56, 0xf1, 0xa7, 0xf1, 0xc6,
+ 0x0a, 0x9d, 0x68, 0x7d, 0x12, 0x5e, 0xb0, 0x7e,
+ 0x26, 0xe5, 0x51, 0xdc, 0x14, 0x0e, 0x8a, 0x04,
+ 0xaf, 0xa2, 0xa1, 0x6f, 0x98, 0xb5, 0x1b, 0xa9,
+ 0x18, 0x96, 0xbf, 0x32, 0x0f, 0xd4, 0xd6, 0xf1,
+ 0xa4, 0x4b, 0x46, 0xf3, 0x3d, 0xae, 0x39, 0xcc,
+ 0x24, 0xf0, 0x4a, 0x5d, 0x86, 0x0c, 0xb1, 0x4f,
+ 0x6b, 0x6e, 0x8a, 0x69, 0x73, 0xb4, 0x9f, 0xd2,
+ 0xa7, 0xbc, 0xeb, 0x48, 0xd7, 0x48, 0xf7, 0xeb
+*/
+ 0xeb, 0xf7, 0x48, 0xd7, 0x48, 0xeb, 0xbc, 0xa7,
+ 0xd2, 0x9f, 0xb4, 0x73, 0x69, 0x8a, 0x6e, 0x6b,
+ 0x4f, 0xb1, 0x0c, 0x86, 0x5d, 0x4a, 0xf0, 0x24,
+ 0xcc, 0x39, 0xae, 0x3d, 0xf3, 0x46, 0x4b, 0xa4,
+ 0xf1, 0xd6, 0xd4, 0x0f, 0x32, 0xbf, 0x96, 0x18,
+ 0xa9, 0x1b, 0xb5, 0x98, 0x6f, 0xa1, 0xa2, 0xaf,
+ 0x04, 0x8a, 0x0e, 0x14, 0xdc, 0x51, 0xe5, 0x26,
+ 0x7e, 0xb0, 0x5e, 0x12, 0x7d, 0x68, 0x9d, 0x0a,
+ 0xc6, 0xf1, 0xa7, 0xf1, 0x56, 0xce, 0x06, 0x63,
+ 0x16, 0xb9, 0x71, 0xcc, 0x7a, 0x11, 0xd0, 0xfd,
+ 0x7a, 0x20, 0x93, 0xe2, 0x7c, 0xf2, 0xd0, 0x87,
+ 0x27, 0xa4, 0xe6, 0x74, 0x8c, 0xc3, 0x2f, 0xd5,
+ 0x9c, 0x78, 0x10, 0xc5, 0xb9, 0x01, 0x9d, 0xf2,
+ 0x1c, 0xdc, 0xc0, 0xbc, 0xa4, 0x32, 0xc0, 0xa3,
+ 0xee, 0xd0, 0x78, 0x53, 0x87, 0x50, 0x88, 0x77,
+ 0x11, 0x43, 0x59, 0xce, 0xe4, 0xa0, 0x71, 0xcf
+};
+
+const uint8_t ecdsa_test_1_d[] PROGMEM = {
+ 0xf3, 0xd7, 0x60, 0xd6, 0x75, 0xf2, 0xcc, 0xeb,
+ 0xf0, 0xd2, 0xfd, 0xb3, 0xb9, 0x41, 0x3f, 0xb0,
+ 0xf8, 0x4f, 0x37, 0xd1, 0xb3, 0x37, 0x4f, 0xe1
+};
+
+const uint8_t ecdsa_test_1_k[] PROGMEM = {
+ 0x25, 0x5f, 0x68, 0x89, 0xa2, 0x31, 0xbc, 0x57,
+ 0x4d, 0x15, 0xc4, 0x12, 0xfb, 0x56, 0x45, 0x68,
+ 0x83, 0x07, 0xa1, 0x43, 0x70, 0xbc, 0x0a, 0xcb
+};
+
+void hash_mem_P(const hfdesc_t *hfdesc, void *dest, const void *msg, uint16_t msg_len_b){
+ uint16_t blocksize = hfal_hash_getBlocksize(hfdesc);
+ uint8_t block[blocksize / 8];
+ hfgen_ctx_t ctx;
+ hfal_hash_init(hfdesc, &ctx);
+ while(msg_len_b > blocksize){
+ memcpy_P(block, msg, blocksize / 8);
+ msg = (uint8_t*)msg + blocksize / 8;
+ msg_len_b -= blocksize;
+ hfal_hash_nextBlock(&ctx, block);
+ }
+ memcpy_P(block, msg, (msg_len_b + 7) / 8);
+ hfal_hash_lastBlock(&ctx, block, msg_len_b);
+ hfal_hash_ctx2hash(dest, &ctx);
+ hfal_hash_free(&ctx);
+}
+
+const uint8_t ecdsa_test_2_msg[] PROGMEM = {
+ 0x66, 0xa2, 0x51, 0x3d, 0x7b, 0x60, 0x45, 0xe5,
+ 0x66, 0x79, 0xb0, 0x32, 0xca, 0xd4, 0x5f, 0xb1,
+ 0x82, 0x28, 0x9c, 0xa7, 0x6a, 0x88, 0xc0, 0x6d,
+ 0x78, 0xc8, 0x5f, 0x3d, 0xd3, 0x80, 0x45, 0x90,
+ 0x20, 0x5b, 0x73, 0xa7, 0x84, 0x24, 0x9a, 0x0a,
+ 0x0c, 0x8b, 0xf2, 0xf2, 0x21, 0x45, 0xd1, 0x05,
+ 0x21, 0x9b, 0x48, 0x0d, 0x74, 0x60, 0x7c, 0x02,
+ 0xb8, 0xa6, 0xb6, 0xb4, 0x59, 0x25, 0x9e, 0x4f,
+ 0xdf, 0xe2, 0xbd, 0xb4, 0xab, 0x22, 0x38, 0x01,
+ 0x75, 0x35, 0x29, 0x1d, 0x7a, 0xc1, 0xab, 0xda,
+ 0x66, 0xc4, 0xf6, 0xdc, 0xea, 0x9e, 0x5d, 0x0b,
+ 0xf0, 0x5a, 0x93, 0x06, 0xf3, 0x33, 0xb0, 0x0e,
+ 0x56, 0x34, 0x2f, 0x75, 0x53, 0x40, 0x21, 0x1a,
+ 0xc2, 0x94, 0xac, 0x21, 0xa7, 0xc2, 0xb2, 0x67,
+ 0x12, 0xb8, 0x79, 0x95, 0x1b, 0x2e, 0x23, 0xf6,
+ 0x48, 0x7e, 0x4d, 0x39, 0x89, 0x9f, 0xe3, 0x74
+};
+
+const uint8_t ecdsa_test_2_d[] PROGMEM = {
+ 0xeb, 0x8e, 0x9f, 0x04, 0x7d, 0xb5, 0x9a, 0x80,
+ 0x34, 0x6f, 0xcd, 0xf1, 0xcc, 0x33, 0xbb, 0x78,
+ 0xbe, 0xc6, 0xb8, 0x76, 0xaf, 0x9f, 0x4b, 0x69
+};
+
+const uint8_t ecdsa_test_2_k[] PROGMEM = {
+ 0x8e, 0xd5, 0x00, 0x34, 0x08, 0x09, 0x60, 0x36,
+ 0x2e, 0xfe, 0x16, 0xd0, 0x53, 0x37, 0xa2, 0xf5,
+ 0x47, 0xfa, 0x11, 0xbc, 0xb1, 0xc2, 0xe8, 0x41
+};
+
+void test_sign1(void){
+ bigint_word_t d_w[sizeof(ecdsa_test_1_d)];
+ uint8_t rnd[sizeof(ecdsa_test_1_k)];
+ uint8_t *hash;
+ bigint_t d;
+ const hfdesc_t *hash_desc;
+ ecc_combi_point_t q;
+ ecdsa_signature_t sign;
+ ecdsa_ctx_t ctx;
+ uint8_t r;
+
+ putchar('\n');
+ d.wordv = d_w;
+ memcpy_P(rnd, ecdsa_test_1_k, sizeof(ecdsa_test_1_k));
+ memcpy_P(d_w, ecdsa_test_1_d, sizeof(ecdsa_test_1_d) * sizeof(bigint_word_t));
+ d.length_W = sizeof(ecdsa_test_1_d) / sizeof(bigint_word_t);
+ d.info = 0;
+ bigint_adjust(&d);
+
+ hash_desc = &sha1_desc; //hash_select();
+ hash = malloc(hfal_hash_getHashsize(hash_desc) / 8);
+ if(hash == NULL){
+ printf_P(PSTR("DBG: XXX <%S %s %d>\n"), PSTR(__FILE__), __func__, __LINE__);
+ }
+ hash_mem_P(hash_desc, hash, ecdsa_test_1_msg, sizeof(ecdsa_test_1_msg) * 8);
+ printf_P(PSTR("msg hash: "));
+ cli_hexdump(hash, hfal_hash_getHashsize(hash_desc) / 8);
+ putchar('\n');
+
+ ecc_chudnovsky_point_alloc(&q.chudnovsky, nist_curve_p192_p.length_W * sizeof(bigint_word_t));
+ ctx.basepoint = &nist_curve_p192_basepoint.chudnovsky;
+ ctx.priv = &d;
+ ctx.curve = &nist_curve_p192;
+
+ printf("\n d: ");
+ bigint_print_hex(&d);
+ printf_P(PSTR("\n Gx: "));
+ bigint_print_hex(&nist_curve_p192_basepoint.affine.x);
+ printf_P(PSTR("\n Gy: "));
+ bigint_print_hex(&nist_curve_p192_basepoint.affine.y);
+
+ r = ecc_chudnovsky_multiplication(&q.chudnovsky, &d, &nist_curve_p192_basepoint.chudnovsky, &nist_curve_p192);
+ if(r){
+ printf_P(PSTR("ERROR: ecc_chudnovsky_multiplication() returned: %"PRIu8"\n"), r);
+ }
+ r = ecc_chudnovsky_to_affine_point(&q.affine, &q.chudnovsky, &nist_curve_p192);
+ if(r){
+ printf_P(PSTR("ERROR: ecc_chudnovsky_to_affine_point() returned: %"PRIu8"\n"), r);
+ }
+
+ printf_P(PSTR("\n Qx: "));
+ bigint_print_hex(&q.affine.x);
+ printf_P(PSTR("\n Qy: "));
+ bigint_print_hex(&q.affine.y);
+ putchar('\n');
+ ctx.pub = &q.affine;
+
+ ecdsa_signature_alloc(&sign, sizeof(ecdsa_test_1_d) * sizeof(bigint_word_t));
+
+ r = ecdsa_sign_hash(&sign, hash, hfal_hash_getHashsize(hash_desc) / 8, &ctx, rnd);
+ if(r){
+ printf_P(PSTR("ERROR: ecdsa_sign_message() returned: %"PRIu8"\n"), r);
+ }
+ printf_P(PSTR(" r: "));
+ bigint_print_hex(&sign.r);
+ printf_P(PSTR("\n s: "));
+ bigint_print_hex(&sign.s);
+
+ free(hash);
+ ecdsa_signature_free(&sign);
+ ecc_chudnovsky_point_free(&q.chudnovsky);
+}
+
+void test_sign2(void){
+ bigint_word_t d_w[sizeof(ecdsa_test_2_d)];
+ uint8_t rnd[sizeof(ecdsa_test_2_k)];
+ uint8_t *hash;
+ bigint_t d;
+ const hfdesc_t *hash_desc;
+ ecc_combi_point_t q;
+ ecdsa_signature_t sign;
+ ecdsa_ctx_t ctx;
+ uint8_t r;
+
+ putchar('\n');
+ d.wordv = d_w;
+ memcpy_P(rnd, ecdsa_test_2_k, sizeof(ecdsa_test_2_k));
+ memcpy_P(d_w, ecdsa_test_2_d, sizeof(ecdsa_test_2_d) * sizeof(bigint_word_t));
+ d.length_W = sizeof(ecdsa_test_2_d) / sizeof(bigint_word_t);
+ d.info = 0;
+ bigint_adjust(&d);
+
+ hash_desc = &sha224_desc; //hash_select();
+ hash = malloc(hfal_hash_getHashsize(hash_desc) / 8);
+ if(hash == NULL){
+ printf_P(PSTR("DBG: XXX <%S %s %d>\n"), PSTR(__FILE__), __func__, __LINE__);
+ }
+ hash_mem_P(hash_desc, hash, ecdsa_test_2_msg, sizeof(ecdsa_test_1_msg) * 8);
+ printf_P(PSTR("msg hash: "));
+ cli_hexdump(hash, hfal_hash_getHashsize(hash_desc) / 8);
+ putchar('\n');
+
+ ecc_chudnovsky_point_alloc(&q.chudnovsky, nist_curve_p192_p.length_W * sizeof(bigint_word_t));
+ ctx.basepoint = &nist_curve_p192_basepoint.chudnovsky;
+ ctx.priv = &d;
+ ctx.curve = &nist_curve_p192;
+
+ printf("\n d: ");
+ bigint_print_hex(&d);
+ printf_P(PSTR("\n Gx: "));
+ bigint_print_hex(&nist_curve_p192_basepoint.affine.x);
+ printf_P(PSTR("\n Gy: "));
+ bigint_print_hex(&nist_curve_p192_basepoint.affine.y);
+
+ r = ecc_chudnovsky_multiplication(&q.chudnovsky, &d, &nist_curve_p192_basepoint.chudnovsky, &nist_curve_p192);
+ if(r){
+ printf_P(PSTR("ERROR: ecc_chudnovsky_multiplication() returned: %"PRIu8"\n"), r);
+ }
+ r = ecc_chudnovsky_to_affine_point(&q.affine, &q.chudnovsky, &nist_curve_p192);
+ if(r){
+ printf_P(PSTR("ERROR: ecc_chudnovsky_to_affine_point() returned: %"PRIu8"\n"), r);
+ }
+
+ printf_P(PSTR("\n Qx: "));
+ bigint_print_hex(&q.affine.x);
+ printf_P(PSTR("\n Qy: "));
+ bigint_print_hex(&q.affine.y);
+ putchar('\n');
+ ctx.pub = &q.affine;
+
+ ecdsa_signature_alloc(&sign, sizeof(ecdsa_test_2_d) * sizeof(bigint_word_t));
+
+ r = ecdsa_sign_hash(&sign, hash, hfal_hash_getHashsize(hash_desc) / 8, &ctx, rnd);
+ if(r){
+ printf_P(PSTR("ERROR: ecdsa_sign_message() returned: %"PRIu8"\n"), r);
+ }
+ printf_P(PSTR(" r: "));
+ bigint_print_hex(&sign.r);
+ printf_P(PSTR("\n s: "));
+ bigint_print_hex(&sign.s);
+
+ free(hash);
+ ecdsa_signature_free(&sign);
+ ecc_chudnovsky_point_free(&q.chudnovsky);
+}