Hi David,
I used "wc_InitRsaKey(&key, NULL);" but the result is the same "RsaUnPad error, bad formatting" with the RSA test application. Should a "wc_InitRsaKey(&key)" call be available?
I tried 1024 and 2048 bits long keys with the RSA test application and the HTTPS server both resulting in the same error. The attached cert is the 2048 bits in der format. I tried this same cert converted to pem format with the HTTPS server.
I enabled HAVE_TLS_EXTENSIONS and HAVE_SUPPORTED_CURVES without success.
I am really curious why the simple RSA encrypt/decrypt application is not working and it returns the same "RsaUnPad error, bad formatting" that the HTTPS server does. I supose that solving the RsaUnPad error will make the HTTPS server work too.
I posted the complete application that performs the RSA encrypt/decrypt. I am disclosing the private key because it was generated only for this test and will never be used for anything else.
Anyway, I will make the HTTPS server available on my return from the holidays.
Thanks,
Carlos
#include <arch.h>
#include <eth.h>
#include <guest_interrupts.h>
#include <hypercalls.h>
#include <platform.h>
#include <libc.h>
#include <eth.h>
#include <wolfssl/ssl.h>
#include <wolfssl/wolfcrypt/rsa.h>
#include <wolfssl/wolfcrypt/memory.h>
#include <wolfssl/wolfcrypt/error-crypt.h>
volatile unsigned int pico_ms_tick = 0;
int close(int __fildes){
return 0;
}
#define byte char
#define HEAP_HINT 0
#define FOURK_BUF 4096
/* privkey.der, 2048-bit */
const unsigned char privkey_der_2048[] =
{
0x30, 0x82, 0x04, 0xA4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01,
0x01, 0x00, 0xC2, 0x54, 0x7D, 0xA8, 0x88, 0x36, 0xC6, 0x06,
0x15, 0xA9, 0xF4, 0x37, 0x26, 0x67, 0xA7, 0x64, 0xB5, 0xB1,
0xA2, 0x4C, 0xB1, 0xDC, 0x92, 0x6A, 0x34, 0xF3, 0xE5, 0xFB,
0x6F, 0x5F, 0x13, 0xEC, 0xB2, 0x7D, 0x2C, 0x26, 0x71, 0x96,
0x4D, 0xB7, 0x23, 0x29, 0x76, 0x54, 0x24, 0xA1, 0xB8, 0x63,
0xB8, 0xAB, 0x6D, 0x38, 0x0E, 0x4A, 0x11, 0x4E, 0x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
0xD0, 0x44, 0xC7, 0x3B, 0xFD, 0x8F, 0x91, 0xCD, 0x2C, 0xDB,
0xCD, 0x93, 0x74, 0x3B, 0xF7, 0xBB, 0x1D, 0x67, 0x1A, 0xCD,
0x58, 0xE6
};
int rsa_test(void)
{
byte* tmp;
size_t bytes;
RsaKey key;
WC_RNG rng;
word32 idx = 0;
int ret;
byte in[] = "Everyone gets Friday off.";
word32 inLen = (word32)XSTRLEN((char*)in);
byte out[256];
byte plain[256];
tmp = (byte*)XMALLOC(FOURK_BUF, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (tmp == NULL)
return -40;
XMEMCPY(tmp, privkey_der_2048, sizeof(privkey_der_2048));
bytes = sizeof(privkey_der_2048);
ret = wc_InitRsaKey(&key, NULL);
if (ret != 0) {
XFREE(tmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER);
return -39;
}
ret = wc_RsaPrivateKeyDecode(tmp, &idx, &key, (word32)bytes);
if (ret != 0) {
XFREE(tmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER);
return -41;
}
ret = wc_InitRng(&rng);
if (ret != 0) {
XFREE(tmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER);
return -42;
}
ret = wc_RsaPublicEncrypt(in, inLen, out, sizeof(out), &key, &rng);
if (ret < 0) {
XFREE(tmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER);
return -43;
}
idx = ret; /* save off encrypted length */
ret = wc_RsaPrivateDecrypt(out, idx, plain, sizeof(plain), &key);
printf("\n%d", ret);
if (ret < 0) {
XFREE(tmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER);
return -44;
}
return 0;
}
int main()
{
uint8_t mac[6];
uint32_t timer = 0;
wolfSSL_Debugging_ON();
wolfCrypt_Init();
if (CheckCtcSettings() != 1)
printf("\nBuild vs runtime math mismatch\n", -1234);
if (CheckFastMathSettings() != 1)
printf("\nBuild vs runtime fastmath FP_MAX_BITS mismatch\n", -1235);
int32_t ret = rsa_test();
printf("\nret %d", ret);
return 0;
}