ARMmbed

Public key encryption with no padding

Trying to do RSA encryption with 128 byte modulus, 16 byte exponent and no padding but output buffer just gets filled with zeros. I am trying to port code that was using openssl to an embedded device. The original code runs on a Mac and encrypts 128 bytes at a time using RSA_public_encrypt(len, inBfr, outBfr, rsa, RSA_NO_PADDING); This is what I tried with mbedtls:

static const unsigned char modulus[] =
{
    0x37, 0xba, 0x18, 0xea, 0x63, 0x3a, 0x3a, 0x74, 0x35, 0x74, 0x61, 0xae, 0x75, 0x47, 0xb1, 0xb4,
    0x06, 0xb7, 0x5e, 0x3d, 0x74, 0x6d, 0x60, 0x7f, 0x74, 0xbf, 0xd3, 0x73, 0xd7, 0x4e, 0x3b, 0x53,
    0x1d, 0x31, 0x5a, 0x7b, 0x10, 0x38, 0x3f, 0x41, 0x80, 0xbb, 0x0f, 0xbe, 0xbb, 0xd5, 0xde, 0x4d,
    0x11, 0x60, 0x30, 0x33, 0x57, 0xa7, 0xd5, 0x76, 0x3b, 0x71, 0x6a, 0x37, 0x3b, 0xb1, 0x47, 0x50,
    0x85, 0xf3, 0xa7, 0xe8, 0x07, 0x43, 0x74, 0x4d, 0xb0, 0x85, 0x66, 0x37, 0x47, 0x14, 0x7f, 0xd7,
    0x7a, 0xf3, 0x56, 0x7e, 0x41, 0xb5, 0x06, 0x5a, 0x7e, 0xa7, 0x0f, 0xb3, 0xbd, 0x3f, 0x78, 0x7d,
    0x6b, 0x35, 0x46, 0xab, 0xa1, 0x6f, 0x1b, 0xb7, 0xba, 0xa4, 0x71, 0x73, 0x63, 0x68, 0xf4, 0x3a,
    0xa3, 0xdb, 0x63, 0x78, 0xed, 0x80, 0x5b, 0xe6, 0xbb, 0x74, 0xa0, 0xdb, 0x8b, 0x53, 0x81, 0x3b
};

static const unsigned char expon[] =
{
    0x83, 0x05, 0x91, 0xab, 0x32, 0x47, 0x1e, 0x1b, 0x28, 0x31, 0x33, 0x47, 0xf1, 0xb8, 0x61, 0x75
};

unsigned char outbfr[128] = {0};
mbedtls_rsa_context rsa;

mbedtls_rsa_init(&rsa, MBEDTLS_RSA_PKCS_V15, 0);
mbedtls_rsa_import_raw(&rsa, modulus, sizeof(modulus), NULL, 0, NULL, 0, NULL, 0, expon, sizeof(expon));
mbedtls_rsa_complete(&rsa);
mbedtls_rsa_public(&rsa, (const unsigned char*) inbfr, outbfr);
mbedtls_rsa_free(&rsa);

HI @vrobin99
I have tried you example and I get an output buffer which is not all zeros.
The only differnce is that my inbfr is a buffer in the stack ( as I don’t know how you defined this buffer in your code).
Have you checked the return code of all the rsa operations/?
Regards,
Mbed TLS Support
Ron