From: <iro...@us...> - 2004-02-18 21:47:26
|
Update of /cvsroot/perl-openssl/Crypt/OpenSSL/RSA In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13434 Modified Files: README RSA.pm RSA.xs Log Message: Add private_encrypt and public_decrypt, contributed by Paul G. Weiss <pa...@we...> Index: README =================================================================== RCS file: /cvsroot/perl-openssl/Crypt/OpenSSL/RSA/README,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** README 16 Feb 2004 02:58:59 -0000 1.11 --- README 18 Feb 2004 21:37:32 -0000 1.12 *************** *** 10,14 **** using format compatibe with OpenSSL's command-line rsa tool ! encrypt, decrypt, sign, verify, use_pkcs1_oaep_padding, use_pkcs1_padding, use_sslv23_padding, use_no_padding --- 10,14 ---- using format compatibe with OpenSSL's command-line rsa tool ! encrypt, decrypt, private_encrypt, public_decrypt, sign, verify, use_pkcs1_oaep_padding, use_pkcs1_padding, use_sslv23_padding, use_no_padding Index: RSA.pm =================================================================== RCS file: /cvsroot/perl-openssl/Crypt/OpenSSL/RSA/RSA.pm,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** RSA.pm 17 Feb 2004 16:54:32 -0000 1.37 --- RSA.pm 18 Feb 2004 21:37:32 -0000 1.38 *************** *** 185,193 **** =item encrypt ! Encrypt a string using the public (portion of the) key =item sign ! Sign a string using the secret (portion of the) key =item verify --- 185,206 ---- =item encrypt ! Encrypt a binary "string" using the public (portion of the) key. ! ! =item decrypt ! ! Decrypt a binary "string". Croaks if the key is public only. ! ! =item private_encrypt ! ! Encrypt a binary "string" using the private key. Croaks if the key is ! public only. ! ! =item public_decrypt ! ! Decrypt a binary "string" using the public (portion of the) key. =item sign ! Sign a string using the secret (portion of the) key. =item verify *************** *** 195,202 **** Check the signature on a text. - =item decrypt - - Decrypt a binary "string". Croaks if the key is public only. - =item use_no_padding --- 208,211 ---- Index: RSA.xs =================================================================== RCS file: /cvsroot/perl-openssl/Crypt/OpenSSL/RSA/RSA.xs,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -d -r1.46 -r1.47 *** RSA.xs 18 Feb 2004 16:39:19 -0000 1.46 --- RSA.xs 18 Feb 2004 21:37:32 -0000 1.47 *************** *** 22,26 **** #define CHECK_OPEN_SSL(p_result) if (!(p_result)) \ ! croak("OpenSSL error in %s at %d: %s", \ __FILE__, __LINE__, ERR_reason_error_string(ERR_get_error())); --- 22,26 ---- #define CHECK_OPEN_SSL(p_result) if (!(p_result)) \ ! croak("%s:%d: OpenSSL error: %s", \ __FILE__, __LINE__, ERR_reason_error_string(ERR_get_error())); *************** *** 432,435 **** --- 432,514 ---- RETVAL + SV* + private_encrypt(p_rsa, plaintext_SV, ...) + rsaData* p_rsa; + SV* plaintext_SV; + PREINIT: + int plaintext_length; + unsigned char* plaintext; + unsigned char* ciphertext; + size_t size; + int ciphertext_length; + RSA* rsa; + + CODE: + if (! is_private(p_rsa)) + { + croak("Public keys cannot private_encrypt messages."); + } + + plaintext = SvPV(plaintext_SV, plaintext_length); + + rsa = p_rsa->rsa; + + size = RSA_size(rsa); + if (New(0,ciphertext, size, char) == NULL) + { + croak ("unable to allocate buffer for ciphertext in package " + PACKAGE_NAME); + } + + ciphertext_length = RSA_private_encrypt( + plaintext_length, plaintext, ciphertext, rsa, p_rsa->padding); + + if (ciphertext_length < 0) + { + Safefree(ciphertext); + CHECK_OPEN_SSL(0) + } + + RETVAL = newSVpv(ciphertext, size); + OUTPUT: + RETVAL + + + SV* + public_decrypt(p_rsa, ciphertext_SV) + rsaData* p_rsa; + SV* ciphertext_SV; + PREINIT: + int ciphertext_length; /* Needed to pass to SvPV */ + int plaintext_length; + char* plaintext; + char* ciphertext; + unsigned long size; + RSA* rsa; + CODE: + + ciphertext = SvPV(ciphertext_SV, ciphertext_length); + + rsa = p_rsa->rsa; + size = RSA_size(rsa); + if (New(0, plaintext, size, char) == NULL) + { + croak("unable to allocate buffer for plaintext in package " + PACKAGE_NAME); + } + + plaintext_length = RSA_public_decrypt( + size, ciphertext, plaintext, rsa, p_rsa->padding); + if (plaintext_length < 0) + { + Safefree(plaintext); + CHECK_OPEN_SSL(0) + } + + RETVAL = newSVpv(plaintext, plaintext_length); + Safefree(plaintext); + OUTPUT: + RETVAL + int size(p_rsa) |