Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/src/modules/ecdh/tests_impl.h
Show First 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | for (i = 0; i < 100; ++i) { | ||||
CHECK(secp256k1_ec_pubkey_create(ctx, &point[0], s_one) == 1); | CHECK(secp256k1_ec_pubkey_create(ctx, &point[0], s_one) == 1); | ||||
CHECK(secp256k1_ec_pubkey_create(ctx, &point[1], s_b32) == 1); | CHECK(secp256k1_ec_pubkey_create(ctx, &point[1], s_b32) == 1); | ||||
/* compute using ECDH function with custom hash function */ | /* compute using ECDH function with custom hash function */ | ||||
CHECK(secp256k1_ecdh(ctx, output_ecdh, &point[0], s_b32, ecdh_hash_function_custom, NULL) == 1); | CHECK(secp256k1_ecdh(ctx, output_ecdh, &point[0], s_b32, ecdh_hash_function_custom, NULL) == 1); | ||||
/* compute "explicitly" */ | /* compute "explicitly" */ | ||||
CHECK(secp256k1_ec_pubkey_serialize(ctx, point_ser, &point_ser_len, &point[1], SECP256K1_EC_UNCOMPRESSED) == 1); | CHECK(secp256k1_ec_pubkey_serialize(ctx, point_ser, &point_ser_len, &point[1], SECP256K1_EC_UNCOMPRESSED) == 1); | ||||
/* compare */ | /* compare */ | ||||
CHECK(memcmp(output_ecdh, point_ser, 65) == 0); | CHECK(secp256k1_memcmp_var(output_ecdh, point_ser, 65) == 0); | ||||
/* compute using ECDH function with default hash function */ | /* compute using ECDH function with default hash function */ | ||||
CHECK(secp256k1_ecdh(ctx, output_ecdh, &point[0], s_b32, NULL, NULL) == 1); | CHECK(secp256k1_ecdh(ctx, output_ecdh, &point[0], s_b32, NULL, NULL) == 1); | ||||
/* compute "explicitly" */ | /* compute "explicitly" */ | ||||
CHECK(secp256k1_ec_pubkey_serialize(ctx, point_ser, &point_ser_len, &point[1], SECP256K1_EC_COMPRESSED) == 1); | CHECK(secp256k1_ec_pubkey_serialize(ctx, point_ser, &point_ser_len, &point[1], SECP256K1_EC_COMPRESSED) == 1); | ||||
secp256k1_sha256_initialize(&sha); | secp256k1_sha256_initialize(&sha); | ||||
secp256k1_sha256_write(&sha, point_ser, point_ser_len); | secp256k1_sha256_write(&sha, point_ser, point_ser_len); | ||||
secp256k1_sha256_finalize(&sha, output_ser); | secp256k1_sha256_finalize(&sha, output_ser); | ||||
/* compare */ | /* compare */ | ||||
CHECK(memcmp(output_ecdh, output_ser, 32) == 0); | CHECK(secp256k1_memcmp_var(output_ecdh, output_ser, 32) == 0); | ||||
} | } | ||||
} | } | ||||
void test_bad_scalar(void) { | void test_bad_scalar(void) { | ||||
unsigned char s_zero[32] = { 0 }; | unsigned char s_zero[32] = { 0 }; | ||||
unsigned char s_overflow[32] = { | unsigned char s_overflow[32] = { | ||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, | ||||
Show All 31 Lines |