Heija everyone,
i think i’m missing something. I generated a private and public key pair with openSSL.
Lines used:
openssl ecparam -name secp256k1 -genkey -noout -out priv_key.pem
openssl ec -in .\priv_key.pem -pubout -out public_key.pem
This gives me my key pair. for example this
private key:
-----BEGIN EC PRIVATE KEY-----
MHQCAQEEIOBYwBnXMgYHsRSv99H4zgtzSClALIcNBN97QbBPNFzHoAcGBSuBBAAK
oUQDQgAESqPVjJtZ+f7Q5DnhBX/7Xy6CUWi0aEuNbA0JilgF4+T8ruuWl16vrOrI
3dSDDfsafxatLS3BytvtmyOQxye98Q==
-----END EC PRIVATE KEY-----
public key:
-----BEGIN PUBLIC KEY-----
MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAESqPVjJtZ+f7Q5DnhBX/7Xy6CUWi0aEuN
bA0JilgF4+T8ruuWl16vrOrI3dSDDfsafxatLS3BytvtmyOQxye98Q==
-----END PUBLIC KEY-----
Im trying to parse my public key with mbedtls_pk_parse_public_key to an pk_context. My code looks like this:
int32_t s32Err = 0;
mbedtls_pk_type_t pktype;
mbedtls_pk_init(&pk);
int32_t tempsize = strlen(ecdsaPublic);
s32Err = mbedtls_pk_parse_public_key(&pk, ecdsaPublic, tempsize + 1);
my public key (ecdsaPublic) is copy/pasted and formatted like the following:
const char* ecdsaPublic = "-----BEGIN PUBLIC KEY-----\n"
"MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAESqPVjJtZ+f7Q5DnhBX/7Xy6CUWi0aEuN\n"
"bA0JilgF4+T8ruuWl16vrOrI3dSDDfsafxatLS3BytvtmyOQxye98Q==\n"
"-----END PUBLIC KEY-----\n";
If I know let this run, i get 0xFFFFFFF0 as an error code in s32Err. Sadly I cant find this error code anywhere in the library or im not searching at the right place.
If I try the exact same code with another public key, like this one:
"-----BEGIN PUBLIC KEY-----\n"
"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMALAAUWI7loxRd++n5VG+E6gl1NEC8Z\n"
"yQmtyzKEdwwJ+qrC9BSi6f5FmutbJYqu1wR6QitVCEXUrtN1rOBCQ78CAwEAAQ==\n"
"-----END PUBLIC KEY-----\n";
The parsing returns 0.
Has anyone an idea or a hint?
Is my key generation wrong?
Best wishes and thanks for the help and suggestions!
Marc