doc improvements
Karel Miko
10 years ago
181 | 181 | #Shared secret |
182 | 182 | my $shared_secret = dh_shared_secret('Alice_priv_dh1.key', 'Bob_pub_dh1.key'); |
183 | 183 | |
184 | =head1 FUNCTIONS | |
185 | ||
186 | =head2 dh_encrypt | |
187 | ||
188 | DH based encryption as implemented by libtomcrypt. See method L</encrypt> below. | |
189 | ||
190 | my $ct = dh_encrypt($pub_key_filename, $message); | |
191 | #or | |
192 | my $ct = dh_encrypt(\$buffer_containing_pub_key, $message); | |
193 | #or | |
194 | my $ct = dh_encrypt($pub_key_filename, $message, $hash_name); | |
195 | ||
196 | #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
197 | ||
198 | Encryption works similar to the L<Crypt::PK::ECC> encryption whereas shared DH key is computed, and | |
199 | the hash of the shared key XOR'ed against the plaintext forms the ciphertext. | |
200 | ||
201 | =head2 dh_decrypt | |
202 | ||
203 | DH based decryption as implemented by libtomcrypt. See method L</decrypt> below. | |
204 | ||
205 | my $pt = dh_decrypt($priv_key_filename, $ciphertext); | |
206 | #or | |
207 | my $pt = dh_decrypt(\$buffer_containing_priv_key, $ciphertext); | |
208 | ||
209 | =head2 dh_sign_message | |
210 | ||
211 | Generate DH signature as implemented by libtomcrypt. See method L</sign_message> below. | |
212 | ||
213 | my $sig = dh_sign_message($priv_key_filename, $message); | |
214 | #or | |
215 | my $sig = dh_sign_message(\$buffer_containing_priv_key, $message); | |
216 | #or | |
217 | my $sig = dh_sign_message($priv_key, $message, $hash_name); | |
218 | ||
219 | =head2 dh_verify_message | |
220 | ||
221 | Verify DH signature as implemented by libtomcrypt. See method L</verify_message> below. | |
222 | ||
223 | dh_verify_message($pub_key_filename, $signature, $message) or die "ERROR"; | |
224 | #or | |
225 | dh_verify_message(\$buffer_containing_pub_key, $signature, $message) or die "ERROR"; | |
226 | #or | |
227 | dh_verify_message($pub_key, $signature, $message, $hash_name) or die "ERROR"; | |
228 | ||
229 | =head2 dh_sign_hash | |
230 | ||
231 | Generate DH signature as implemented by libtomcrypt. See method L</sign_hash> below. | |
232 | ||
233 | my $sig = dh_sign_hash($priv_key_filename, $message_hash); | |
234 | #or | |
235 | my $sig = dh_sign_hash(\$buffer_containing_priv_key, $message_hash); | |
236 | ||
237 | =head2 dh_verify_hash | |
238 | ||
239 | Verify DH signature as implemented by libtomcrypt. See method L</verify_hash> below. | |
240 | ||
241 | dh_verify_hash($pub_key_filename, $signature, $message_hash) or die "ERROR"; | |
242 | #or | |
243 | dh_verify_hash(\$buffer_containing_pub_key, $signature, $message_hash) or die "ERROR"; | |
244 | ||
245 | =head2 dh_shared_secret | |
246 | ||
247 | DH based shared secret generation. See method L</shared_secret> below. | |
248 | ||
249 | #on Alice side | |
250 | my $shared_secret = dh_shared_secret('Alice_priv_dh1.key', 'Bob_pub_dh1.key'); | |
251 | ||
252 | #on Bob side | |
253 | my $shared_secret = dh_shared_secret('Bob_priv_dh1.key', 'Alice_pub_dh1.key'); | |
254 | ||
255 | 184 | =head1 METHODS |
256 | 185 | |
257 | 186 | =head2 new |
372 | 301 | y => "AB9AAA40774D3CD476B52F82E7EE2D8A8D40CD88BF4...", #public key |
373 | 302 | } |
374 | 303 | |
304 | =head1 FUNCTIONS | |
305 | ||
306 | =head2 dh_encrypt | |
307 | ||
308 | DH based encryption as implemented by libtomcrypt. See method L</encrypt> below. | |
309 | ||
310 | my $ct = dh_encrypt($pub_key_filename, $message); | |
311 | #or | |
312 | my $ct = dh_encrypt(\$buffer_containing_pub_key, $message); | |
313 | #or | |
314 | my $ct = dh_encrypt($pub_key_filename, $message, $hash_name); | |
315 | ||
316 | #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
317 | ||
318 | Encryption works similar to the L<Crypt::PK::ECC> encryption whereas shared DH key is computed, and | |
319 | the hash of the shared key XOR'ed against the plaintext forms the ciphertext. | |
320 | ||
321 | =head2 dh_decrypt | |
322 | ||
323 | DH based decryption as implemented by libtomcrypt. See method L</decrypt> below. | |
324 | ||
325 | my $pt = dh_decrypt($priv_key_filename, $ciphertext); | |
326 | #or | |
327 | my $pt = dh_decrypt(\$buffer_containing_priv_key, $ciphertext); | |
328 | ||
329 | =head2 dh_sign_message | |
330 | ||
331 | Generate DH signature as implemented by libtomcrypt. See method L</sign_message> below. | |
332 | ||
333 | my $sig = dh_sign_message($priv_key_filename, $message); | |
334 | #or | |
335 | my $sig = dh_sign_message(\$buffer_containing_priv_key, $message); | |
336 | #or | |
337 | my $sig = dh_sign_message($priv_key, $message, $hash_name); | |
338 | ||
339 | =head2 dh_verify_message | |
340 | ||
341 | Verify DH signature as implemented by libtomcrypt. See method L</verify_message> below. | |
342 | ||
343 | dh_verify_message($pub_key_filename, $signature, $message) or die "ERROR"; | |
344 | #or | |
345 | dh_verify_message(\$buffer_containing_pub_key, $signature, $message) or die "ERROR"; | |
346 | #or | |
347 | dh_verify_message($pub_key, $signature, $message, $hash_name) or die "ERROR"; | |
348 | ||
349 | =head2 dh_sign_hash | |
350 | ||
351 | Generate DH signature as implemented by libtomcrypt. See method L</sign_hash> below. | |
352 | ||
353 | my $sig = dh_sign_hash($priv_key_filename, $message_hash); | |
354 | #or | |
355 | my $sig = dh_sign_hash(\$buffer_containing_priv_key, $message_hash); | |
356 | ||
357 | =head2 dh_verify_hash | |
358 | ||
359 | Verify DH signature as implemented by libtomcrypt. See method L</verify_hash> below. | |
360 | ||
361 | dh_verify_hash($pub_key_filename, $signature, $message_hash) or die "ERROR"; | |
362 | #or | |
363 | dh_verify_hash(\$buffer_containing_pub_key, $signature, $message_hash) or die "ERROR"; | |
364 | ||
365 | =head2 dh_shared_secret | |
366 | ||
367 | DH based shared secret generation. See method L</shared_secret> below. | |
368 | ||
369 | #on Alice side | |
370 | my $shared_secret = dh_shared_secret('Alice_priv_dh1.key', 'Bob_pub_dh1.key'); | |
371 | ||
372 | #on Bob side | |
373 | my $shared_secret = dh_shared_secret('Bob_priv_dh1.key', 'Alice_pub_dh1.key'); | |
374 | ||
375 | 375 | =head1 SEE ALSO |
376 | 376 | |
377 | 377 | =over |
187 | 187 | #Signature: Bob (received $message + $sig) |
188 | 188 | dsa_verify_message('Alice_pub_dsa1.der', $sig, $message) or die "ERROR"; |
189 | 189 | |
190 | =head1 FUNCTIONS | |
191 | ||
192 | =head2 dsa_encrypt | |
193 | ||
194 | DSA based encryption as implemented by libtomcrypt. See method L</encrypt> below. | |
195 | ||
196 | my $ct = dsa_encrypt($pub_key_filename, $message); | |
197 | #or | |
198 | my $ct = dsa_encrypt(\$buffer_containing_pub_key, $message); | |
199 | #or | |
200 | my $ct = dsa_encrypt($pub_key_filename, $message, $hash_name); | |
201 | ||
202 | #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
203 | ||
204 | Encryption works similar to the L<Crypt::PK::ECC> encryption whereas shared DSA key is computed, and | |
205 | the hash of the shared key XOR'ed against the plaintext forms the ciphertext. | |
206 | ||
207 | =head2 dsa_decrypt | |
208 | ||
209 | DSA based decryption as implemented by libtomcrypt. See method L</decrypt> below. | |
210 | ||
211 | my $pt = dsa_decrypt($priv_key_filename, $ciphertext); | |
212 | #or | |
213 | my $pt = dsa_decrypt(\$buffer_containing_priv_key, $ciphertext); | |
214 | ||
215 | =head2 dsa_sign_message | |
216 | ||
217 | Generate DSA signature. See method L</sign_message> below. | |
218 | ||
219 | my $sig = dsa_sign_message($priv_key_filename, $message); | |
220 | #or | |
221 | my $sig = dsa_sign_message(\$buffer_containing_priv_key, $message); | |
222 | #or | |
223 | my $sig = dsa_sign_message($priv_key, $message, $hash_name); | |
224 | ||
225 | =head2 dsa_verify_message | |
226 | ||
227 | Verify DSA signature. See method L</verify_message> below. | |
228 | ||
229 | dsa_verify_message($pub_key_filename, $signature, $message) or die "ERROR"; | |
230 | #or | |
231 | dsa_verify_message(\$buffer_containing_pub_key, $signature, $message) or die "ERROR"; | |
232 | #or | |
233 | dsa_verify_message($pub_key, $signature, $message, $hash_name) or die "ERROR"; | |
234 | ||
235 | =head2 dsa_sign_hash | |
236 | ||
237 | Generate DSA signature. See method L</sign_hash> below. | |
238 | ||
239 | my $sig = dsa_sign_hash($priv_key_filename, $message_hash); | |
240 | #or | |
241 | my $sig = dsa_sign_hash(\$buffer_containing_priv_key, $message_hash); | |
242 | ||
243 | =head2 dsa_verify_hash | |
244 | ||
245 | Verify DSA signature. See method L</verify_hash> below. | |
246 | ||
247 | dsa_verify_hash($pub_key_filename, $signature, $message_hash) or die "ERROR"; | |
248 | #or | |
249 | dsa_verify_hash(\$buffer_containing_pub_key, $signature, $message_hash) or die "ERROR"; | |
250 | ||
251 | 190 | =head1 METHODS |
252 | 191 | |
253 | 192 | =head2 new |
398 | 337 | y => "8F7604D77FA62C7539562458A63C7611B7...", #public key, where y = g^x mod p |
399 | 338 | } |
400 | 339 | |
340 | =head1 FUNCTIONS | |
341 | ||
342 | =head2 dsa_encrypt | |
343 | ||
344 | DSA based encryption as implemented by libtomcrypt. See method L</encrypt> below. | |
345 | ||
346 | my $ct = dsa_encrypt($pub_key_filename, $message); | |
347 | #or | |
348 | my $ct = dsa_encrypt(\$buffer_containing_pub_key, $message); | |
349 | #or | |
350 | my $ct = dsa_encrypt($pub_key_filename, $message, $hash_name); | |
351 | ||
352 | #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
353 | ||
354 | Encryption works similar to the L<Crypt::PK::ECC> encryption whereas shared DSA key is computed, and | |
355 | the hash of the shared key XOR'ed against the plaintext forms the ciphertext. | |
356 | ||
357 | =head2 dsa_decrypt | |
358 | ||
359 | DSA based decryption as implemented by libtomcrypt. See method L</decrypt> below. | |
360 | ||
361 | my $pt = dsa_decrypt($priv_key_filename, $ciphertext); | |
362 | #or | |
363 | my $pt = dsa_decrypt(\$buffer_containing_priv_key, $ciphertext); | |
364 | ||
365 | =head2 dsa_sign_message | |
366 | ||
367 | Generate DSA signature. See method L</sign_message> below. | |
368 | ||
369 | my $sig = dsa_sign_message($priv_key_filename, $message); | |
370 | #or | |
371 | my $sig = dsa_sign_message(\$buffer_containing_priv_key, $message); | |
372 | #or | |
373 | my $sig = dsa_sign_message($priv_key, $message, $hash_name); | |
374 | ||
375 | =head2 dsa_verify_message | |
376 | ||
377 | Verify DSA signature. See method L</verify_message> below. | |
378 | ||
379 | dsa_verify_message($pub_key_filename, $signature, $message) or die "ERROR"; | |
380 | #or | |
381 | dsa_verify_message(\$buffer_containing_pub_key, $signature, $message) or die "ERROR"; | |
382 | #or | |
383 | dsa_verify_message($pub_key, $signature, $message, $hash_name) or die "ERROR"; | |
384 | ||
385 | =head2 dsa_sign_hash | |
386 | ||
387 | Generate DSA signature. See method L</sign_hash> below. | |
388 | ||
389 | my $sig = dsa_sign_hash($priv_key_filename, $message_hash); | |
390 | #or | |
391 | my $sig = dsa_sign_hash(\$buffer_containing_priv_key, $message_hash); | |
392 | ||
393 | =head2 dsa_verify_hash | |
394 | ||
395 | Verify DSA signature. See method L</verify_hash> below. | |
396 | ||
397 | dsa_verify_hash($pub_key_filename, $signature, $message_hash) or die "ERROR"; | |
398 | #or | |
399 | dsa_verify_hash(\$buffer_containing_pub_key, $signature, $message_hash) or die "ERROR"; | |
400 | ||
401 | 401 | =head1 SEE ALSO |
402 | 402 | |
403 | 403 | =over |
510 | 510 | |
511 | 511 | =head1 DESCRIPTION |
512 | 512 | |
513 | The module provides a set of core ECC functions as well that are designed to be the Elliptic Curve analogy of | |
514 | all of the Diffie-Hellman routines (ECDH). | |
515 | ||
516 | =head1 FUNCTIONS | |
517 | ||
518 | =head2 ecc_encrypt | |
519 | ||
520 | Elliptic Curve Diffie-Hellman (ECDH) encryption as implemented by libtomcrypt. See method L</encrypt> below. | |
521 | ||
522 | my $ct = ecc_encrypt($pub_key_filename, $message); | |
523 | #or | |
524 | my $ct = ecc_encrypt(\$buffer_containing_pub_key, $message); | |
525 | #or | |
526 | my $ct = ecc_encrypt($pub_key_filename, $message, $hash_name); | |
527 | ||
528 | #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
529 | ||
530 | ECCDH Encryption is performed by producing a random key, hashing it, and XOR'ing the digest against the plaintext. | |
531 | ||
532 | =head2 ecc_decrypt | |
533 | ||
534 | Elliptic Curve Diffie-Hellman (ECDH) decryption as implemented by libtomcrypt. See method L</decrypt> below. | |
535 | ||
536 | my $pt = ecc_decrypt($priv_key_filename, $ciphertext); | |
537 | #or | |
538 | my $pt = ecc_decrypt(\$buffer_containing_priv_key, $ciphertext); | |
539 | ||
540 | =head2 ecc_sign_message | |
541 | ||
542 | Elliptic Curve Digital Signature Algorithm (ECDSA) - signature generation. See method L</sign_message> below. | |
543 | ||
544 | my $sig = ecc_sign_message($priv_key_filename, $message); | |
545 | #or | |
546 | my $sig = ecc_sign_message(\$buffer_containing_priv_key, $message); | |
547 | #or | |
548 | my $sig = ecc_sign_message($priv_key, $message, $hash_name); | |
549 | ||
550 | =head2 ecc_verify_message | |
551 | ||
552 | Elliptic Curve Digital Signature Algorithm (ECDSA) - signature verification. See method L</verify_message> below. | |
553 | ||
554 | ecc_verify_message($pub_key_filename, $signature, $message) or die "ERROR"; | |
555 | #or | |
556 | ecc_verify_message(\$buffer_containing_pub_key, $signature, $message) or die "ERROR"; | |
557 | #or | |
558 | ecc_verify_message($pub_key, $signature, $message, $hash_name) or die "ERROR"; | |
559 | ||
560 | =head2 ecc_sign_hash | |
561 | ||
562 | Elliptic Curve Digital Signature Algorithm (ECDSA) - signature generation. See method L</sign_hash> below. | |
563 | ||
564 | my $sig = ecc_sign_hash($priv_key_filename, $message_hash); | |
565 | #or | |
566 | my $sig = ecc_sign_hash(\$buffer_containing_priv_key, $message_hash); | |
567 | ||
568 | =head2 ecc_verify_hash | |
569 | ||
570 | Elliptic Curve Digital Signature Algorithm (ECDSA) - signature verification. See method L</verify_hash> below. | |
571 | ||
572 | ecc_verify_hash($pub_key_filename, $signature, $message_hash) or die "ERROR"; | |
573 | #or | |
574 | ecc_verify_hash(\$buffer_containing_pub_key, $signature, $message_hash) or die "ERROR"; | |
575 | ||
576 | =head2 ecc_shared_secret | |
577 | ||
578 | Elliptic curve Diffie-Hellman (ECDH) - construct a Diffie-Hellman shared secret with a private and public ECC key. See method L</shared_secret> below. | |
579 | ||
580 | #on Alice side | |
581 | my $shared_secret = ecc_shared_secret('Alice_priv_ecc1.der', 'Bob_pub_ecc1.der'); | |
582 | ||
583 | #on Bob side | |
584 | my $shared_secret = ecc_shared_secret('Bob_priv_ecc1.der', 'Alice_pub_ecc1.der'); | |
513 | The module provides a set of core ECC functions as well as implementation of ECDSA and ECDH. | |
514 | ||
515 | Supports elliptic curves C<y^2 = x^3 + a*x + b> over prime fields C<Fp = Z/pZ> (binary fields not supported). | |
585 | 516 | |
586 | 517 | =head1 METHODS |
587 | 518 | |
592 | 523 | my $pk = Crypt::PK::ECC->new($priv_or_pub_key_filename); |
593 | 524 | #or |
594 | 525 | my $pk = Crypt::PK::ECC->new(\$buffer_containing_priv_or_pub_key); |
526 | ||
527 | Support for password protected PEM keys | |
528 | ||
529 | my $pk = Crypt::PK::ECC->new($priv_pem_key_filename, $password); | |
530 | #or | |
531 | my $pk = Crypt::PK::ECC->new(\$buffer_containing_priv_pem_key, $password); | |
595 | 532 | |
596 | 533 | =head2 generate_key |
597 | 534 | |
624 | 561 | 'secp192r1' |
625 | 562 | 'secp224k1' |
626 | 563 | 'secp224r1' |
627 | 'secp256k1' | |
564 | 'secp256k1' ... used by Bitcoin | |
628 | 565 | 'secp256r1' |
629 | 566 | 'secp384r1' |
630 | 567 | 'secp521r1' |
808 | 745 | pub_y => "895D57E992D0A15F88D6680B27B701F615FCDC0F", |
809 | 746 | } |
810 | 747 | |
748 | =head1 FUNCTIONS | |
749 | ||
750 | =head2 ecc_encrypt | |
751 | ||
752 | Elliptic Curve Diffie-Hellman (ECDH) encryption as implemented by libtomcrypt. See method L</encrypt> below. | |
753 | ||
754 | my $ct = ecc_encrypt($pub_key_filename, $message); | |
755 | #or | |
756 | my $ct = ecc_encrypt(\$buffer_containing_pub_key, $message); | |
757 | #or | |
758 | my $ct = ecc_encrypt($pub_key_filename, $message, $hash_name); | |
759 | ||
760 | #NOTE: $hash_name can be 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
761 | ||
762 | ECCDH Encryption is performed by producing a random key, hashing it, and XOR'ing the digest against the plaintext. | |
763 | ||
764 | =head2 ecc_decrypt | |
765 | ||
766 | Elliptic Curve Diffie-Hellman (ECDH) decryption as implemented by libtomcrypt. See method L</decrypt> below. | |
767 | ||
768 | my $pt = ecc_decrypt($priv_key_filename, $ciphertext); | |
769 | #or | |
770 | my $pt = ecc_decrypt(\$buffer_containing_priv_key, $ciphertext); | |
771 | ||
772 | =head2 ecc_sign_message | |
773 | ||
774 | Elliptic Curve Digital Signature Algorithm (ECDSA) - signature generation. See method L</sign_message> below. | |
775 | ||
776 | my $sig = ecc_sign_message($priv_key_filename, $message); | |
777 | #or | |
778 | my $sig = ecc_sign_message(\$buffer_containing_priv_key, $message); | |
779 | #or | |
780 | my $sig = ecc_sign_message($priv_key, $message, $hash_name); | |
781 | ||
782 | =head2 ecc_verify_message | |
783 | ||
784 | Elliptic Curve Digital Signature Algorithm (ECDSA) - signature verification. See method L</verify_message> below. | |
785 | ||
786 | ecc_verify_message($pub_key_filename, $signature, $message) or die "ERROR"; | |
787 | #or | |
788 | ecc_verify_message(\$buffer_containing_pub_key, $signature, $message) or die "ERROR"; | |
789 | #or | |
790 | ecc_verify_message($pub_key, $signature, $message, $hash_name) or die "ERROR"; | |
791 | ||
792 | =head2 ecc_sign_hash | |
793 | ||
794 | Elliptic Curve Digital Signature Algorithm (ECDSA) - signature generation. See method L</sign_hash> below. | |
795 | ||
796 | my $sig = ecc_sign_hash($priv_key_filename, $message_hash); | |
797 | #or | |
798 | my $sig = ecc_sign_hash(\$buffer_containing_priv_key, $message_hash); | |
799 | ||
800 | =head2 ecc_verify_hash | |
801 | ||
802 | Elliptic Curve Digital Signature Algorithm (ECDSA) - signature verification. See method L</verify_hash> below. | |
803 | ||
804 | ecc_verify_hash($pub_key_filename, $signature, $message_hash) or die "ERROR"; | |
805 | #or | |
806 | ecc_verify_hash(\$buffer_containing_pub_key, $signature, $message_hash) or die "ERROR"; | |
807 | ||
808 | =head2 ecc_shared_secret | |
809 | ||
810 | Elliptic curve Diffie-Hellman (ECDH) - construct a Diffie-Hellman shared secret with a private and public ECC key. See method L</shared_secret> below. | |
811 | ||
812 | #on Alice side | |
813 | my $shared_secret = ecc_shared_secret('Alice_priv_ecc1.der', 'Bob_pub_ecc1.der'); | |
814 | ||
815 | #on Bob side | |
816 | my $shared_secret = ecc_shared_secret('Bob_priv_ecc1.der', 'Alice_pub_ecc1.der'); | |
817 | ||
811 | 818 | =head1 SEE ALSO |
812 | 819 | |
813 | 820 | =over |
204 | 204 | #Signature: Bob (received $message + $sig) |
205 | 205 | rsa_verify_message('Alice_pub_rsa1.der', $sig, $message) or die "ERROR"; |
206 | 206 | |
207 | =head1 FUNCTIONS | |
208 | ||
209 | =head2 rsa_encrypt | |
210 | ||
211 | RSA based encryption. See method L</encrypt> below. | |
212 | ||
213 | my $ct = rsa_encrypt($pub_key_filename, $message); | |
214 | #or | |
215 | my $ct = rsa_encrypt(\$buffer_containing_pub_key, $message); | |
216 | #or | |
217 | my $ct = rsa_encrypt($pub_key, $message, $padding); | |
218 | #or | |
219 | my $ct = rsa_encrypt($pub_key, $message, 'oaep', $hash_name, $lparam); | |
220 | ||
221 | # $padding .................... 'oaep' (DEFAULT), 'v1.5' or 'none' | |
222 | # $hash_name (only for oaep) .. 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
223 | # $lparam (only for oaep) ..... DEFAULT is empty string | |
224 | ||
225 | =head2 rsa_decrypt | |
226 | ||
227 | RSA based decryption. See method L</decrypt> below. | |
228 | ||
229 | my $pt = rsa_decrypt($priv_key_filename, $ciphertext); | |
230 | #or | |
231 | my $pt = rsa_decrypt(\$buffer_containing_priv_key, $ciphertext); | |
232 | #or | |
233 | my $pt = rsa_decrypt($priv_key, $ciphertext, $padding); | |
234 | #or | |
235 | my $pt = rsa_decrypt($priv_key, $ciphertext, 'oaep', $hash_name, $lparam); | |
236 | ||
237 | # $padding .................... 'oaep' (DEFAULT), 'v1.5' or 'none' | |
238 | # $hash_name (only for oaep) .. 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
239 | # $lparam (only for oaep) ..... DEFAULT is empty string | |
240 | ||
241 | =head2 rsa_sign_message | |
242 | ||
243 | Generate RSA signature. See method L</sign_message> below. | |
244 | ||
245 | my $sig = rsa_sign_message($priv_key_filename, $message); | |
246 | #or | |
247 | my $sig = rsa_sign_message(\$buffer_containing_priv_key, $message); | |
248 | #or | |
249 | my $sig = rsa_sign_message($priv_key, $message, $hash_name); | |
250 | #or | |
251 | my $sig = rsa_sign_message($priv_key, $message, $hash_name, $padding); | |
252 | #or | |
253 | my $sig = rsa_sign_message($priv_key, $message, $hash_name, 'pss', $saltlen); | |
254 | ||
255 | # $hash_name ............... 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
256 | # $padding ................. 'pss' (DEFAULT) or 'v1.5' | |
257 | # $saltlen (only for pss) .. DEFAULT is 12 | |
258 | ||
259 | =head2 rsa_verify_message | |
260 | ||
261 | Verify RSA signature. See method L</verify_message> below. | |
262 | ||
263 | rsa_verify_message($pub_key_filename, $signature, $message) or die "ERROR"; | |
264 | #or | |
265 | rsa_verify_message(\$buffer_containing_pub_key, $signature, $message) or die "ERROR"; | |
266 | #or | |
267 | rsa_verify_message($pub_key, $signature, $message, $hash_name) or die "ERROR"; | |
268 | #or | |
269 | rsa_verify_message($pub_key, $signature, $message, $hash_name, $padding) or die "ERROR"; | |
270 | #or | |
271 | rsa_verify_message($pub_key, $signature, $message, $hash_name, 'pss', $saltlen) or die "ERROR"; | |
272 | ||
273 | # $hash_name ............... 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
274 | # $padding ................. 'pss' (DEFAULT) or 'v1.5' | |
275 | # $saltlen (only for pss) .. DEFAULT is 12 | |
276 | ||
277 | =head2 rsa_sign_hash | |
278 | ||
279 | Generate RSA signature. See method L</sign_hash> below. | |
280 | ||
281 | my $sig = rsa_sign_hash($priv_key_filename, $message_hash); | |
282 | #or | |
283 | my $sig = rsa_sign_hash(\$buffer_containing_priv_key, $message_hash); | |
284 | #or | |
285 | my $sig = rsa_sign_hash($priv_key, $message_hash, $hash_name); | |
286 | #or | |
287 | my $sig = rsa_sign_hash($priv_key, $message_hash, $hash_name, $padding); | |
288 | #or | |
289 | my $sig = rsa_sign_hash($priv_key, $message_hash, $hash_name, 'pss', $saltlen); | |
290 | ||
291 | # $hash_name ............... 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
292 | # $padding ................. 'pss' (DEFAULT) or 'v1.5' | |
293 | # $saltlen (only for pss) .. DEFAULT is 12 | |
294 | ||
295 | =head2 rsa_verify_hash | |
296 | ||
297 | Verify RSA signature. See method L</verify_hash> below. | |
298 | ||
299 | rsa_verify_hash($pub_key_filename, $signature, $message_hash) or die "ERROR"; | |
300 | #or | |
301 | rsa_verify_hash(\$buffer_containing_pub_key, $signature, $message_hash) or die "ERROR"; | |
302 | #or | |
303 | rsa_verify_hash($pub_key, $signature, $message_hash, $hash_name) or die "ERROR"; | |
304 | #or | |
305 | rsa_verify_hash($pub_key, $signature, $message_hash, $hash_name, $padding) or die "ERROR"; | |
306 | #or | |
307 | rsa_verify_hash($pub_key, $signature, $message_hash, $hash_name, 'pss', $saltlen) or die "ERROR"; | |
308 | ||
309 | # $hash_name ............... 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
310 | # $padding ................. 'pss' (DEFAULT) or 'v1.5' | |
311 | # $saltlen (only for pss) .. DEFAULT is 12 | |
207 | =head1 DESCRIPTION | |
208 | ||
209 | The module provides a full featured RSA implementation. | |
312 | 210 | |
313 | 211 | =head1 METHODS |
314 | 212 | |
506 | 404 | dQ => "4597284B2968B72C4212DB7E8F24360B987B80514DA9...", #d mod (q - 1) CRT param |
507 | 405 | } |
508 | 406 | |
407 | =head1 FUNCTIONS | |
408 | ||
409 | =head2 rsa_encrypt | |
410 | ||
411 | RSA based encryption. See method L</encrypt> below. | |
412 | ||
413 | my $ct = rsa_encrypt($pub_key_filename, $message); | |
414 | #or | |
415 | my $ct = rsa_encrypt(\$buffer_containing_pub_key, $message); | |
416 | #or | |
417 | my $ct = rsa_encrypt($pub_key, $message, $padding); | |
418 | #or | |
419 | my $ct = rsa_encrypt($pub_key, $message, 'oaep', $hash_name, $lparam); | |
420 | ||
421 | # $padding .................... 'oaep' (DEFAULT), 'v1.5' or 'none' | |
422 | # $hash_name (only for oaep) .. 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
423 | # $lparam (only for oaep) ..... DEFAULT is empty string | |
424 | ||
425 | =head2 rsa_decrypt | |
426 | ||
427 | RSA based decryption. See method L</decrypt> below. | |
428 | ||
429 | my $pt = rsa_decrypt($priv_key_filename, $ciphertext); | |
430 | #or | |
431 | my $pt = rsa_decrypt(\$buffer_containing_priv_key, $ciphertext); | |
432 | #or | |
433 | my $pt = rsa_decrypt($priv_key, $ciphertext, $padding); | |
434 | #or | |
435 | my $pt = rsa_decrypt($priv_key, $ciphertext, 'oaep', $hash_name, $lparam); | |
436 | ||
437 | # $padding .................... 'oaep' (DEFAULT), 'v1.5' or 'none' | |
438 | # $hash_name (only for oaep) .. 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
439 | # $lparam (only for oaep) ..... DEFAULT is empty string | |
440 | ||
441 | =head2 rsa_sign_message | |
442 | ||
443 | Generate RSA signature. See method L</sign_message> below. | |
444 | ||
445 | my $sig = rsa_sign_message($priv_key_filename, $message); | |
446 | #or | |
447 | my $sig = rsa_sign_message(\$buffer_containing_priv_key, $message); | |
448 | #or | |
449 | my $sig = rsa_sign_message($priv_key, $message, $hash_name); | |
450 | #or | |
451 | my $sig = rsa_sign_message($priv_key, $message, $hash_name, $padding); | |
452 | #or | |
453 | my $sig = rsa_sign_message($priv_key, $message, $hash_name, 'pss', $saltlen); | |
454 | ||
455 | # $hash_name ............... 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
456 | # $padding ................. 'pss' (DEFAULT) or 'v1.5' | |
457 | # $saltlen (only for pss) .. DEFAULT is 12 | |
458 | ||
459 | =head2 rsa_verify_message | |
460 | ||
461 | Verify RSA signature. See method L</verify_message> below. | |
462 | ||
463 | rsa_verify_message($pub_key_filename, $signature, $message) or die "ERROR"; | |
464 | #or | |
465 | rsa_verify_message(\$buffer_containing_pub_key, $signature, $message) or die "ERROR"; | |
466 | #or | |
467 | rsa_verify_message($pub_key, $signature, $message, $hash_name) or die "ERROR"; | |
468 | #or | |
469 | rsa_verify_message($pub_key, $signature, $message, $hash_name, $padding) or die "ERROR"; | |
470 | #or | |
471 | rsa_verify_message($pub_key, $signature, $message, $hash_name, 'pss', $saltlen) or die "ERROR"; | |
472 | ||
473 | # $hash_name ............... 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
474 | # $padding ................. 'pss' (DEFAULT) or 'v1.5' | |
475 | # $saltlen (only for pss) .. DEFAULT is 12 | |
476 | ||
477 | =head2 rsa_sign_hash | |
478 | ||
479 | Generate RSA signature. See method L</sign_hash> below. | |
480 | ||
481 | my $sig = rsa_sign_hash($priv_key_filename, $message_hash); | |
482 | #or | |
483 | my $sig = rsa_sign_hash(\$buffer_containing_priv_key, $message_hash); | |
484 | #or | |
485 | my $sig = rsa_sign_hash($priv_key, $message_hash, $hash_name); | |
486 | #or | |
487 | my $sig = rsa_sign_hash($priv_key, $message_hash, $hash_name, $padding); | |
488 | #or | |
489 | my $sig = rsa_sign_hash($priv_key, $message_hash, $hash_name, 'pss', $saltlen); | |
490 | ||
491 | # $hash_name ............... 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
492 | # $padding ................. 'pss' (DEFAULT) or 'v1.5' | |
493 | # $saltlen (only for pss) .. DEFAULT is 12 | |
494 | ||
495 | =head2 rsa_verify_hash | |
496 | ||
497 | Verify RSA signature. See method L</verify_hash> below. | |
498 | ||
499 | rsa_verify_hash($pub_key_filename, $signature, $message_hash) or die "ERROR"; | |
500 | #or | |
501 | rsa_verify_hash(\$buffer_containing_pub_key, $signature, $message_hash) or die "ERROR"; | |
502 | #or | |
503 | rsa_verify_hash($pub_key, $signature, $message_hash, $hash_name) or die "ERROR"; | |
504 | #or | |
505 | rsa_verify_hash($pub_key, $signature, $message_hash, $hash_name, $padding) or die "ERROR"; | |
506 | #or | |
507 | rsa_verify_hash($pub_key, $signature, $message_hash, $hash_name, 'pss', $saltlen) or die "ERROR"; | |
508 | ||
509 | # $hash_name ............... 'SHA1' (DEFAULT), 'SHA256' or any other hash supported by Crypt::Digest | |
510 | # $padding ................. 'pss' (DEFAULT) or 'v1.5' | |
511 | # $saltlen (only for pss) .. DEFAULT is 12 | |
512 | ||
509 | 513 | =head1 OpenSSL interoperability |
510 | 514 | |
511 | 515 | ### let's have: |