void test_num_get_set_hex(void) { secp256k1_num_t n1,n2; random_num_order_test(&n1); char c[64]; secp256k1_num_get_hex(c, 64, &n1); secp256k1_num_set_hex(&n2, c, 64); CHECK(secp256k1_num_eq(&n1, &n2)); for (int i=0; i<64; i++) { /* check whether the lower 4 bits correspond to the last hex character */ int low1 = secp256k1_num_shift(&n1, 4); int lowh = c[63]; int low2 = ((lowh>>6)*9+(lowh-'0'))&15; CHECK(low1 == low2); /* shift bits off the hex representation, and compare */ memmove(c+1, c, 63); c[0] = '0'; secp256k1_num_set_hex(&n2, c, 64); CHECK(secp256k1_num_eq(&n1, &n2)); } }
void test_num_get_set_hex() { secp256k1_num_t n1,n2; secp256k1_num_init(&n1); secp256k1_num_init(&n2); random_num_order_test(&n1); char c[64]; secp256k1_num_get_hex(c, 64, &n1); secp256k1_num_set_hex(&n2, c, 64); assert(secp256k1_num_cmp(&n1, &n2) == 0); for (int i=0; i<64; i++) { // check whether the lower 4 bits correspond to the last hex character int low1 = secp256k1_num_shift(&n1, 4); int lowh = c[63]; int low2 = (lowh>>6)*9+(lowh-'0')&15; assert(low1 == low2); // shift bits off the hex representation, and compare memmove(c+1, c, 63); c[0] = '0'; secp256k1_num_set_hex(&n2, c, 64); assert(secp256k1_num_cmp(&n1, &n2) == 0); } secp256k1_num_free(&n2); secp256k1_num_free(&n1); }