I have to parse a public ECDSA 256 public key using its X and Y points (see below [3]). The points are represented as base64url encoding of the octet string representation of the coordinate, as defined in Section 2.3.5 [1] of SEC1 [2].
I can’t find the MBEDTLS API for transforming these coordinates to a mbedtls_pk_context structure. Could you help me out?
Hi @doru91
Do you mean section 2.3.5 or section 2.3.4?
Have you considered using mbedtls_ecp_point_read_string()?
If X and Y are in binary form, you can use mbedtls_ecp_point_read_binary() , but you will need to have the first byte state the compression, and concatenate X and Y to the input binary buffer.
I suggest you call after that mbedtls_ecp_check_pubkey() with the group and point Q for checking the conversion was done correct.
Once you have the point Q, you can assign it to a mbedtls_ecp_keypair.
You should then call mbedtls_pk_setup with the relevant mbedtls_pk_info_t ( received by calling mbedtls_pk_info_from_type() )
Once you have the mbedtls_pk_context, and you know for sure it is en ECP key pair, you can simply assign the public key Q to the context:
Sorry for the extra delayed answer (I had to switch to another project).
The x and y points are encoded as OCTET STRING (see [1] and [2]) so I believe I meant section 2.3.4 of SEC1.
In this case, mbedtls_ecp_point_read_string() should work, right?