Hi,
I'm working on reading the ApplePay VAS loyalty passes. I have got the code working fine with OpenSSL but we can't build it for our payment terminal which is why we tried to achieve the same with WolfSSL as it provides the OpenSSL compatibility layer.
The first step of the algorithm says:
"Set the randomly generated ECDH public key as the X9.62 compressed coordinate of a point over GFp for group P-256 , assuming 0 as the y-bit."
This randomly generated ECDH public key comes from the phone.
Using OpenSSL code, we achieve this with the following code (the only missing piece when using WolfSSL is EC_POINT_set_compressed_coordinates_GFp ):
int message_public_key(size_t message_len, const uint8_t* message, EVP_PKEY *public_key)
{
int rc;
if (message_len < ECIES_PUBLIC_KEY_SIZE) {
rc = 0;
}
else {
BIGNUM *bn = NULL;
EC_GROUP *group = NULL;
EC_POINT *ecp = NULL;
EC_KEY *ephemeral_key = NULL;
do {
bn = BN_new();
BN_bin2bn(message, ECIES_PUBLIC_KEY_SIZE, bn);
group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1);
ecp = EC_POINT_new(group);
RC_CHECK(rc = EC_POINT_set_compressed_coordinates_GFp(group, ecp, bn, 0, NULL));
ephemeral_key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
RC_CHECK(rc = EC_KEY_set_public_key(ephemeral_key, ecp));
RC_CHECK(rc = EVP_PKEY_set1_EC_KEY(public_key, ephemeral_key));
} while (0);
if (bn) BN_free(bn);
if (group) EC_GROUP_free(group);
if (ecp) EC_POINT_free(ecp);
if (ephemeral_key) EC_KEY_free(ephemeral_key);
}
return rc;
}