------=_Part_106_16054919.1203690666214
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi all,


I'm encrypt a file using RSA_private_encrypt, this work fine.

My problem is when I try to decrypt using RSA_public_decrypt, I recive the
errors:
2945:error:0407006A:lib(4):func(112):reason(106):r sa_pk1.c:100
2945:error:04067072:lib(4):func(103):reason(114):r sa_eay.c:699

My function that encrypt:

int chipperWithPrivateKey(EVP_PKEY *privKey, const char *in, int inSize,
unsigned char **to){
int rsasize = RSA_size(privKey->pkey.rsa);
int maxBlockLen = rsasize - 12;
int bytesToRead = inSize;
int bytesRead = 0;
*to = NULL;
int toSize = 0;
const char *tmp = in;
bool hasError = false;
while (bytesRead < inSize && hasError == false){
if (bytesToRead >= maxBlockLen){
bytesToRead = maxBlockLen;
}
unsigned char *bufferout = (unsigned char *)calloc(sizeof(char),
rsasize);
int r = RSA_private_encrypt(bytesToRead, (const unsigned char *)tmp,
bufferout, privKey->pkey.rsa, RSA_PKCS1_PADDING);
if (r == -1){
char error[120];
ERR_error_string(ERR_get_error(), error);
printf("\n%s\n", error);
hasError = true;
} else {
bytesRead += bytesToRead;
*to = (unsigned char *)realloc(*to, toSize + r);
unsigned char *to2 = *to;
if (toSize == 0){
memcpy(to2, bufferout, r);
} else {
memcpy( &(to2[toSize + 1]), bufferout, r);
}
toSize += r;
tmp += bytesToRead;
bytesToRead = inSize - bytesRead;
}
free(bufferout);
bufferout = NULL;
}
if (hasError == true){
free(*to);
*to = NULL;
return -1;
}
return toSize;
}

And my decrypt function:

int dechipperWithPublicKey(EVP_PKEY *publicKey, const char *in, int inSize,
unsigned char **to){
int rsaSize = RSA_size(publicKey->pkey.rsa);
int bytesToRead = inSize;
int bytesRead = 0;
*to = NULL;
int toSize = 0;
const char *tmp = in;
bool hasError = false;
while (bytesRead < inSize && hasError == false){
if (bytesToRead >= rsaSize){
bytesToRead = rsaSize;
}
unsigned char *bufferout = (unsigned char *)calloc(sizeof(char),
rsaSize);
int r = RSA_public_decrypt(bytesToRead, (const unsigned char *)tmp,
bufferout, publicKey->pkey.rsa, RSA_PKCS1_PADDING);
if (r == -1) {
hasError = true;
/*char error[120];
ERR_error_string(ERR_get_error(), error);
printf("\n%s\n", error);*/
ERR_print_errors_fp(stdout);
} else {
bytesRead += bytesToRead;
*to = (unsigned char *)realloc(*to, toSize + r);
unsigned char *to2 = *to;
if (toSize == 0){
memcpy(to2, bufferout, r);
} else {
memcpy( &(to2[toSize + 1]), bufferout, r);
}
toSize += r;
tmp += bytesToRead;

bytesToRead = inSize - bytesRead;
}
free(bufferout);
bufferout = NULL;
}
if (hasError == true){
free(*to);
*to = NULL;
return -1;
}
return toSize;
}

The problem occurs when try to decrypt th second block of chipper text.

My rsa_size is 256 bytes;

If someone can help me I will be grateful.

Pedro Begalli
Belo Horizonte/MG - Brasil

------=_Part_106_16054919.1203690666214
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi all,


I'm encrypt a file using RSA_private_encrypt, this work fine.

My problem is when I try to decrypt using RSA_public_decrypt, I recive the errors:
2945:error:0407006A:lib(4):func(112):reason(106):r sa_pk1.c:100

2945:error:04067072:lib(4):func(103):reason(114):r sa_eay.c:699

My function that encrypt:

int chipperWithPrivateKey(EVP_PKEY *privKey, const char *in, int inSize, unsigned char **to){
    int rsasize = RSA_size(privKey->pkey.rsa); 

    int maxBlockLen =  rsasize - 12;
    int bytesToRead = inSize;
    int bytesRead = 0;
    *to = NULL;
    int toSize = 0;  
    const char *tmp = in;  
    bool hasError = false;  
    while (bytesRead < inSize && hasError == false){      

        if (bytesToRead >= maxBlockLen){
            bytesToRead = maxBlockLen;
        }
        unsigned char *bufferout = (unsigned char *)calloc(sizeof(char), rsasize);      
        int r = RSA_private_encrypt(bytesToRead, (const unsigned char *)tmp, bufferout, privKey->pkey.rsa, RSA_PKCS1_PADDING);

        if (r == -1){
            char error[120];
            ERR_error_string(ERR_get_error(), error);
            printf("\n%s\n", error);
            hasError = true;          
        } else {

            bytesRead += bytesToRead;
            *to = (unsigned char *)realloc(*to, toSize + r);
            unsigned char *to2 = *to;
            if (toSize == 0){
                memcpy(to2, bufferout, r);

            } else {
                memcpy( &(to2[toSize + 1]), bufferout, r);
            }
            toSize += r;
            tmp += bytesToRead;          
            bytesToRead = inSize - bytesRead;

        }
        free(bufferout);
        bufferout = NULL;
    }
    if (hasError == true){
        free(*to);
        *to = NULL;
        return -1;
    }
    return toSize;
}

And my decrypt function:


int dechipperWithPublicKey(EVP_PKEY *publicKey, const char *in, int inSize, unsigned char **to){ 
    int rsaSize = RSA_size(publicKey->pkey.rsa);
    int bytesToRead = inSize;
    int bytesRead = 0;

    *to = NULL;
    int toSize = 0;
    const char *tmp = in;  
    bool hasError = false;  
    while (bytesRead < inSize && hasError == false){
        if (bytesToRead >= rsaSize){
            bytesToRead = rsaSize;

        }      
        unsigned char *bufferout = (unsigned char *)calloc(sizeof(char), rsaSize);      
        int r = RSA_public_decrypt(bytesToRead, (const unsigned char *)tmp, bufferout, publicKey->pkey.rsa, RSA_PKCS1_PADDING);

        if (r == -1) {
            hasError = true;
            /*char error[120];
            ERR_error_string(ERR_get_error(), error);
            printf("\n%s\n", error);*/
            ERR_print_errors_fp(stdout);

        } else {
            bytesRead += bytesToRead;          
            *to = (unsigned char *)realloc(*to, toSize + r);
            unsigned char *to2 = *to;
            if (toSize == 0){
                memcpy(to2, bufferout, r);

            } else {
                memcpy( &(to2[toSize + 1]), bufferout, r);
            }
            toSize += r;
            tmp += bytesToRead;
           
            bytesToRead = inSize - bytesRead;         

        }
        free(bufferout);
        bufferout = NULL;
    }  
    if (hasError == true){
        free(*to);
        *to = NULL;
        return -1;
    }  
    return toSize;
}


The problem occurs when try to decrypt th second block of chipper text.

My rsa_size is 256 bytes;

If someone can help me I will be grateful.

Pedro Begalli
Belo Horizonte/MG - Brasil


------=_Part_106_16054919.1203690666214--
__________________________________________________ ____________________
OpenSSL Project http://www.openssl.org
User Support Mailing List openssl-users@openssl.org
Automated List Manager majordomo@openssl.org