2

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");
        }


}
Luca_Ro
  • 21
  • 2
  • 1
    Please specify the format of your public key. It would also helpful to know the key parameters you used (i.e. which curve). The function `mbedtls_pk_parse_public_key` expects a PEM or DER encoded public key ([link](https://tls.mbed.org/api/pk_8h.html#ade680bf8e87df7ccc3bb36b52e43972b)). I cannot decode your key with `openssl asn1parse -inform DER` or `openssl asn1parse -inform PEM`, so I assume it is in some other format. Is it just the raw key bits? – f9c69e9781fa194211448473495534 Jun 23 '20 at 17:21

0 Answers0