How to convert a given public key in a byte array to a mbedtls_ecdsa_publickey struct to verify an ECDSA-signature?

Viewed 129

I am trying to convert a given publickey in a byte array to use it to verify a signature with mbedtls in my microcontroller program. This is what I tried. It compiles and runs, but I get the parsing does not work and i end up with the error output.

   static void parsePubkey (){

 mbedtls_printf("try parsing pubkey\n");

    unsigned char publickeyarray[]= {89,48,19,6,7,42,134,72,206,61,2,1,6,8,42,134,72,206,61,3,1,7,3,66,0,4,153,195,189,136,225,177,220,236,249,9,82,66,56,253,86,249,66,169,178,30,95,166,79,25,234,131,236,177,24,248,153,228,139,184,133,34,165,150,91,81,118,84,133,79,229,210,38,82,163,97,220,5,69,85,81,20,64,217,87,64,162,187,120,224};

    mbedtls_pk_context pk;
    mbedtls_pk_init(&pk);


    int pkret = mbedtls_pk_parse_public_key(&pk, publickeyarray, sizeof(publickeyarray));

        if (pkret != 0){
            mbedtls_printf("Error\n");
        }else{
            mbedtls_printf("parsed pubkey");
        }


}
0 Answers
Related