IRSA encrypt problem | developer.brewmp.com IRSA encrypt problem | developer.brewmp.com

Developer

IRSA encrypt problem

Forums:

Hi,

{

pMe->szmod = (char *)MALLOC(5);
pMe->szmod1 = (char *)MALLOC(5);
pMe->szmod2 = (char *)MALLOC(5);
pMe->sz_output = (char *) MALLOC(4);
pMe->sz_input = (char *)MALLOC(4);

STRCPY(pMe->szmod, "3233");

pMe->mod = (byte*)pMe->szmod;

STRCPY(pMe->szmod1, "2753");
pMe->priExp = (byte*)pMe->szmod1;

STRCPY(pMe->szmod2, "17");
pMe->pubExp = (byte*)pMe->szmod2;

STRCPY(pMe->sz_input, "123");
pMe->stringinput = (byte *)pMe->sz_input;
pMe->stringOutput = (byte *)pMe->sz_output;
pMe->sz_output_length = STRLEN(pMe->stringinput) + 14;

if(ISHELL_CreateInstance(pMe->pIShell, AEECLSID_RSA, (void **)&pMe->pIRsa) != SUCCESS)
return FALSE;

pMe->key = IRSA_Init(pMe->pIRsa, pMe->mod, STRLEN(pMe->szmod), pMe->pubExp, STRLEN(pMe->szmod2));

DBGPRINTF("key = %d", pMe->key);

CALLBACK_Init(&pMe->pRsacallback, (PFNNOTIFY)CallbackDecrypt, pMe);

//IRSA_ModExp(pMe->pIRsa, szmod, STRLEN(szmod), &pMe->sz_output,&pMe->sz_output_length, &pMe->pdwResult, &pMe->pRsacallback);

IRSA_Encrypt(pMe->pIRsa, pMe->stringinput , STRLEN(pMe->sz_input) + 1, pMe->stringOutput, &pMe->sz_output_length, AEE_RSA_PKCS1TYPE1_PADDING , &pMe->pdwResult, &pMe->pRsacallback);

if(pMe->pdwResult == AEE_CRYPT_INVALID_KEY)
DBGPRINTF("Invalid");
else if(pMe->pdwResult == AEE_CRYPT_INVALID_SIZE)
DBGPRINTF("size");
DBGPRINTF("pdwResult = %d", pMe->pdwResult);

}

This is my code. Here while encryption, it is throwing AEE_CRYPT_PAD_ERROR error. What may b the reason?

Your output buffer is too small.
If length of input buffer is greater than bytes to encrypt (length of output buffer)-11, AEE_CRYPT_PAD_ERROR error is returned.

Your output buffer is too small.
If length of input buffer is greater than bytes to encrypt (length of output buffer)-11, AEE_CRYPT_PAD_ERROR error is returned.

Hi
Thanks for the reply.
This is fine now. I'm getting success for encryption.
But dont know the encrypted data is correct or not. I passed "1234" for IRSA_Encrypt and the encrypted data is ")ßVÚØ…qT" . Will it be in this format?
And again i used this value ")ßVÚØ…qT" in IRSA_Decrypt for decryption. So here i'm getting success. I guess in encryption i should get "1234" back. But i'm getting some junk value "}à™qT".
I'm getting success value. I'm not getting any errors. I have checked in LG VX10000 simulator.

Hi
Thanks for the reply.
This is fine now. I'm getting success for encryption.
But dont know the encrypted data is correct or not. I passed "1234" for IRSA_Encrypt and the encrypted data is ")ßVÚØ…qT" . Will it be in this format?
And again i used this value ")ßVÚØ…qT" in IRSA_Decrypt for decryption. So here i'm getting success. I guess in encryption i should get "1234" back. But i'm getting some junk value "}à™qT".
I'm getting success value. I'm not getting any errors. I have checked in LG VX10000 simulator.

Hi
Thanks for the reply.
This is fine now. I'm getting success for encryption.
But dont know the encrypted data is correct or not. I passed "1234" for IRSA_Encrypt and the encrypted data is ")ßVÚØ…qT" . Will it be in this format?
And again i used this value ")ßVÚØ…qT" in IRSA_Decrypt for decryption. So here i'm getting success. I guess in encryption i should get "1234" back. But i'm getting some junk value "}à™qT".
I'm getting success value. I'm not getting any errors. I have checked in LG VX10000 simulator.

Hi
Thanks for the reply.
This is fine now. I'm getting success for encryption.
But dont know the encrypted data is correct or not. I passed "1234" for IRSA_Encrypt and the encrypted data is ")ßVÚØ…qT" . Will it be in this format?
And again i used this value ")ßVÚØ…qT" in IRSA_Decrypt for decryption. So here i'm getting success. I guess in encryption i should get "1234" back. But i'm getting some junk value "}à™qT".
I'm getting success value. I'm not getting any errors. I have checked in LG VX10000 simulator.

Posting sample code snippet...might help you.
// 256-bit modulus 1
static const unsigned char s_pcRsa1mod256[] =
{
0xc0, 0xf0, 0x40, 0x5d, 0x7b, 0x46, 0x04, 0xfe, 0xc3, 0xbc, 0x1c,
0x5e, 0xed, 0xf9, 0xdf, 0x03, 0x89, 0x66, 0x3b, 0xaa, 0xde, 0xcb,
0x01, 0xe4, 0x0d, 0x9a, 0xd5, 0x7a, 0xf4, 0x8e, 0xd4, 0x9d
;
// 256-bit private key exponent 1
static const unsigned char s_pcRsa1pkexp256[] =
{
0x80, 0xa0, 0x2a, 0xe8, 0xfc, 0xd9, 0x58, 0xa9, 0xd7, 0xd2, 0xbd, 0x94,
0x9e, 0xa6, 0x94, 0xab, 0xdd, 0x23, 0x32, 0xc5, 0x81, 0xa8, 0x47, 0xa7,
0x9c, 0xe3, 0x57, 0xb8, 0x53, 0x67, 0xbf, 0xab
;
// public exponent 1
static const unsigned char s_pcpublicE1 = 0x03;
{
me->nErr = EFAILED;
me->nModSize = 488;
me->ePadType = AEE_RSA_PKCS1TYPE1_PADDING;
me->nEncSize = me->nOutSize = me->nInSize = me->nModSize/8;
ISHELL_CreateInstance(me->e.m_pIShell, AEECLSID_RSA, (void *) &me->m_pRSA);
IRSA_Init(me->m_pRSA, s_pcRsa1mod256, sizeof(s_pcRsa1mod256), s_pcRsa1pkexp256, sizeof(s_pcRsa1pkexp256);
if(me->ePadType != AEE_RSA_NO_PADDING) {
me->nInSize -= 11;
}
CALLBACK_Init(&me->m_CB, SimpleEncryptContinue, (void *)me);
IRSA_Encrypt(me->m_pRSA, me->szIn, me->nInSize, me->szEnc, &me->nEncSize,
me->ePadType, (uint32 *)&me->nErr, &me->m_CB);
}
static void SimpleEncryptContinue(void *pv)
{
if(me->nErr != SUCCESS)
//Encryption failed
if(MEMCMP(me->szIn, me->szEnc, me->nInSize) == 0) {
//Not encrypted properly
}
IRSA_Init(me->m_pRSA, s_pcRsa1mod256, sizeof(s_pcRsa1mod256), &s_pcpublicE1, sizeof(s_pcpublicE1));
IRSA_Decrypt(me->m_pRSA, me->szEnc, me->nEncSize, me->szOut, &me->nOutSize,
me->ePadType, (uint32 *)&me->nErr, NULL);
if(me->nErr != SUCCESS)
//Decryption failed
if(me->nInSize != me->nOutSize)
//Encrypt/Decrypt size mismatch
if( MEMCMP(me->szIn, me->szOut, me->nOutSize) != 0) {
//Decryption failed
}

Posting sample code snippet...might help you.
// 256-bit modulus 1
static const unsigned char s_pcRsa1mod256[] =
{
0xc0, 0xf0, 0x40, 0x5d, 0x7b, 0x46, 0x04, 0xfe, 0xc3, 0xbc, 0x1c,
0x5e, 0xed, 0xf9, 0xdf, 0x03, 0x89, 0x66, 0x3b, 0xaa, 0xde, 0xcb,
0x01, 0xe4, 0x0d, 0x9a, 0xd5, 0x7a, 0xf4, 0x8e, 0xd4, 0x9d
;
// 256-bit private key exponent 1
static const unsigned char s_pcRsa1pkexp256[] =
{
0x80, 0xa0, 0x2a, 0xe8, 0xfc, 0xd9, 0x58, 0xa9, 0xd7, 0xd2, 0xbd, 0x94,
0x9e, 0xa6, 0x94, 0xab, 0xdd, 0x23, 0x32, 0xc5, 0x81, 0xa8, 0x47, 0xa7,
0x9c, 0xe3, 0x57, 0xb8, 0x53, 0x67, 0xbf, 0xab
;
// public exponent 1
static const unsigned char s_pcpublicE1 = 0x03;
{
me->nErr = EFAILED;
me->nModSize = 488;
me->ePadType = AEE_RSA_PKCS1TYPE1_PADDING;
me->nEncSize = me->nOutSize = me->nInSize = me->nModSize/8;
ISHELL_CreateInstance(me->e.m_pIShell, AEECLSID_RSA, (void *) &me->m_pRSA);
IRSA_Init(me->m_pRSA, s_pcRsa1mod256, sizeof(s_pcRsa1mod256), s_pcRsa1pkexp256, sizeof(s_pcRsa1pkexp256);
if(me->ePadType != AEE_RSA_NO_PADDING) {
me->nInSize -= 11;
}
CALLBACK_Init(&me->m_CB, SimpleEncryptContinue, (void *)me);
IRSA_Encrypt(me->m_pRSA, me->szIn, me->nInSize, me->szEnc, &me->nEncSize,
me->ePadType, (uint32 *)&me->nErr, &me->m_CB);
}
static void SimpleEncryptContinue(void *pv)
{
if(me->nErr != SUCCESS)
//Encryption failed
if(MEMCMP(me->szIn, me->szEnc, me->nInSize) == 0) {
//Not encrypted properly
}
IRSA_Init(me->m_pRSA, s_pcRsa1mod256, sizeof(s_pcRsa1mod256), &s_pcpublicE1, sizeof(s_pcpublicE1));
IRSA_Decrypt(me->m_pRSA, me->szEnc, me->nEncSize, me->szOut, &me->nOutSize,
me->ePadType, (uint32 *)&me->nErr, NULL);
if(me->nErr != SUCCESS)
//Decryption failed
if(me->nInSize != me->nOutSize)
//Encrypt/Decrypt size mismatch
if( MEMCMP(me->szIn, me->szOut, me->nOutSize) != 0) {
//Decryption failed
}

Hi,
Thanks. This worked. But i have few doubts.
// 256-bit modulus 1
static const unsigned char s_pcRsa1mod256[] =
{
0xc0, 0xf0, 0x40, 0x5d, 0x7b, 0x46, 0x04, 0xfe, 0xc3, 0xbc, 0x1c,
0x5e, 0xed, 0xf9, 0xdf, 0x03, 0x89, 0x66, 0x3b, 0xaa, 0xde, 0xcb,
0x01, 0xe4, 0x0d, 0x9a, 0xd5, 0x7a, 0xf4, 0x8e, 0xd4, 0x9d
;
// 256-bit private key exponent 1
static const unsigned char s_pcRsa1pkexp256[] =
{
0x80, 0xa0, 0x2a, 0xe8, 0xfc, 0xd9, 0x58, 0xa9, 0xd7, 0xd2, 0xbd, 0x94,
0x9e, 0xa6, 0x94, 0xab, 0xdd, 0x23, 0x32, 0xc5, 0x81, 0xa8, 0x47, 0xa7,
0x9c, 0xe3, 0x57, 0xb8, 0x53, 0x67, 0xbf, 0xab
;
// public exponent 1
static const unsigned char s_pcpublicE1 = 0x03;
U have used these things as private key and public key exponent. I have used "3233" and "17" as public and private key exponents. Is this the problem? Is there any specific format?

Hi,
Thanks. This worked. But i have few doubts.
// 256-bit modulus 1
static const unsigned char s_pcRsa1mod256[] =
{
0xc0, 0xf0, 0x40, 0x5d, 0x7b, 0x46, 0x04, 0xfe, 0xc3, 0xbc, 0x1c,
0x5e, 0xed, 0xf9, 0xdf, 0x03, 0x89, 0x66, 0x3b, 0xaa, 0xde, 0xcb,
0x01, 0xe4, 0x0d, 0x9a, 0xd5, 0x7a, 0xf4, 0x8e, 0xd4, 0x9d
;
// 256-bit private key exponent 1
static const unsigned char s_pcRsa1pkexp256[] =
{
0x80, 0xa0, 0x2a, 0xe8, 0xfc, 0xd9, 0x58, 0xa9, 0xd7, 0xd2, 0xbd, 0x94,
0x9e, 0xa6, 0x94, 0xab, 0xdd, 0x23, 0x32, 0xc5, 0x81, 0xa8, 0x47, 0xa7,
0x9c, 0xe3, 0x57, 0xb8, 0x53, 0x67, 0xbf, 0xab
;
// public exponent 1
static const unsigned char s_pcpublicE1 = 0x03;
U have used these things as private key and public key exponent. I have used "3233" and "17" as public and private key exponents. Is this the problem? Is there any specific format?