RSA crypto sample in SDK 2.5.0 fails on nRF5340 Development Kit board

Hi,

The RSA crypto sample from the 2.5.0 SDK fails at psa_generate_key() returning -134. The sample is by default configured to use 2048-bit keys. 
Note that, It fails with the same error code also when changing the sample code and configuration to use say for example - changing it to CONFIG_PSA_WANT_RSA_KEY_SIZE_1536=y or configuring CONFIG_PSA_WANT_RSA_KEY_SIZE_1024=y.

Please note, the AES samples and the ECDH samples from the 2.5.0 SDK works very well on this board. I don't understand why the RSA sample application fails with the UNSUPPORTED error code.

(1) When can the basic/default RSA sample application in SDK 2.5.0 fail on the nRF5340 Development Kit?
(2) We intend to use PSA API for RSA OAEP with key size CONFIG_PSA_WANT_RSA_KEY_SIZE_3072. Is this supported in SDK 2.5.0?

Thanks,

Mathi.

#PSA #Crypto #RSA #SDK 2.5.0 #SAMPLE#nRF5340 DK #keyformat#keygeneration #openssl-versus-PSA

Parents Reply Children
  • Hi, 

    Did you enable the config for PSA_ALG_SHA_1?

    Disclaimer from PSA Crypto API

    The SHA-1 hash is weak and deprecated and is only recommended for use in legacy protocols.

    -Amanda H.

  • I ran into another problem.
    If i import a RSA public key generated using openssl, then psa_asymmetric_enrypt() fails with (-147 = HARDWARE_FAILURE). Here, i use the pub_key_handle from psa_key_import().
    Does this mean, only keys generated on the device, are supported?
    Or Is there anything specific about the PSA key-format for RSA-OAEP-3072?

  • Another update -
    Case 1) I manually saved (in hex) the public key exported from PSA (using psa_generate_key()). And imported it in a different standalone application, encryption(RSA-OAEP-3072) worked.
    The length of the public key (with exponent) was 398 bytes 

    Case 2) Imported the public key from from openssl, encryption fails with (-147).
    The length of the public key (with exponent) was 388 bytes.

    Are there any special bytes to be included to the public key format when using PSA APIs
    Thanks,

    Mathi.

  • // Public key exported from PSA
    //const uint8_t ext_pub_key[] = {0x30,0x82,0x01,0x8A,0x02,0x82,0x01,0x81,0x00,0x87,0x0D,0xC9,0x5C,0xB8,0x9B,0xD1,0x28,0x09,0x62,0x34,0x27,0xAE,0x76,0x8A,0xA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,0xED,0x52,0xC3,0x19,0x41,0x6C,0xFD,0x5F,0x3A,0x0E,0x50,0x18,0xE9,0x0D,0x27,0x71,0xFE,0x7C,0x52,0xB3,0x1D,0x9F,0xA3,0xB6,0xE2,0x89,0x01,0xC1,0x65,0x10,0xF3,0x26,0x06,0xB3,0x37,0x1C,0x82,0x2D,0xAB,0x53,0xBD,0xFB,0x6E,0x4A,0x15,0x94,0x1C,0xCC,0xB9,0x5C,0x7F,0x5D,0x9E,0x34,0x1C,0x9D,0xFF,0x52,0x59,0x4B,0x5C,0x82,0xB6,0x06,0x87,0xB1,0x92,0xB2,0x80,0x08,0x83,0xB3,0x9B,0xA2,0x5A,0xF4,0xAA,0x13,0x80,0x9F,0xEE,0xA4,0x3D,0xEE,0x85,0xD0,0xA8,0xE6,0x2E,0x45,0x29,0xCC,0x9C,0xEF,0x98,0x33,0xA3,0x62,0xD2,0x59,0x78,0xFB,0x6E,0x6F,0xF1,0x27,0x9B,0x34,0xE6,0x8C,0x33,0xBC,0xDA,0x3A,0x5B,0x66,0xE5,0x76,0x3F,0xB7,0xCD,0x86,0x2B,0x58,0xF8,0x41,0x87,0xFC,0x51,0x40,0x2B,0x1D,0x2F,0x99,0xCF,0x0C,0x51,0xC3,0xAA,0x28,0x89,0x07,0x3A,0x3E,0xE5,0x27,0x02,0x03,0x01,0x00,0x01};

    // Public key exported from openssl
    const uint8_t ext_pub_key[] = {0x00,0xb5,0x97,0x11,0x7a,0x3f,0x80,0xdb,0x2f,0x24,0x7c,0x74,0x1e,0x7b,0xc7,0x50,0x9c,0xf1,0xfb,0x80,0x8d,0x80,0x52,0x97,0xf3,0xd7,0xb6,0x3f,0x02,0x30,0x77,0xa9,0xd1,0x8f,0x93,0xf9,0xa3,0x74,0x97,0xb9,0xd2,0x2c,0x3a,0x75,0x51,0x0d,0xfc,0x94,0x8b,0x29,0x33,0xea,0x84,0xc8,0xc6,0x49,0x99,0x91,0x73,0x2f,0x17,0x52,0x92,0x58,0xeb,0x99,0x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