Crypt::OpenSSL::Base::Func - Base Functions, using the OpenSSL libraries
use Crypt::OpenSSL::Base::Func;
RFC4493: aes_cmac
my $mac = aes_cmac($cipher_name, $key, $plaintext)
my $cipher_name = 'aes-128-cbc';
my $key = pack("H*", '2b7e151628aed2a6abf7158809cf4f3c');
my $msg_1 = pack("H*", '6bc1bee22e409f96e93d7e117393172a');
my $mac_1 = aes_cmac($cipher_name, $key, $msg_1);
print unpack("H*", $mac_1), "\n";
#$ echo -n '6bc1bee22e409f96e93d7e117393172a' | xxd -r -p | openssl dgst -mac cmac -macopt cipher:aes-128-cbc -macopt hexkey:2b7e151628aed2a6abf7158809cf4f3c
#(stdin)= 070a16b46b4d4144f79bdd9dd04a287c
my $r = aead_encrypt($cipher_name, $plaintext, $aad, $key, $iv, $tag_len);
# $r = [ $ciphertext, $tag ];
my $plaintext = aead_decrypt($cipher_name, $ciphertext, $aad, $tag, $key, $iv);
RFC7292 : PKCS12_key_gen
see also openssl/crypto/pkcs12/p12_key.c
pkcs12_key_gen($password, $salt, $id, $iteration, $digest_name)
my $macdata_key = pkcs12_key_gen('123456', pack("H*", 'e241f01650dbeae4'), 3, 2048, 'sha256');
print unpack("H*", $macdata_key), "\n";
RFC2898 : PBKDF2
see also openssl/crypto/evp/p5_crpt2.c
my $k = pkcs5_pbkdf2_hmac($password, $salt, $iteration, $digest_name)
my $pbkdf2_key = pkcs5_pbkdf2_hmac('123456', pack("H*", 'b698314b0d68bcbd'), 2048, 'sha256');
print unpack("H*", $pbkdf2_key), "\n";
my $random_bn = random_bn($Nn);
my $Nn = 16;
my $random_bn = random_bn($Nn);
print $random_bn->to_hex, "\n";
my $dgst = digest($digest_name, $msg);
my $priv_pkey = gen_ec_key(group_name, $priv_hex);
my $pub_pkey = gen_ec_pubkey(group_name, $pub_hex);
my $pub_pkey = export_ec_pubkey($priv_pkey);
my $pub_hex = read_ec_pubkey($pub_pkey, $want_compressed);
my $z_bin = ecdh($local_priv_pkey, $peer_pub_pkey);
my $z_bin = ecdh_pem($local_priv_pem_file, $peer_pub_pem_file);
my $priv_hex = read_key($priv_pkey);
my $pub_hex = read_pubkey($pub_pkey);
my $priv_pkey = read_key_from_pem($priv_pem_filename);
my $pub_pkey = read_pubkey_from_pem($pub_pem_filename);
my $priv_pkey = read_key_from_der($priv_der_filename);
my $pub_pkey = read_pubkey_from_der($pub_der_filename);
write_key_to_pem($dst_fname, $priv_pkey);
write_key_to_pem($dst_fname, $pub_pkey);
write_key_to_der($dst_fname, $priv_pkey);
write_key_to_der($dst_fname, $pub_pkey);
my $x_bn = get_pkey_bn_param($pkey, $param_name);
my $x_hex = get_pkey_octet_string_param($pkey, $param_name);
my $s = get_pkey_utf8_string_param($pkey, $param_name);