NAME

Crypt::PK::ECC - Public key cryptography based on EC

SYNOPSIS

### OO interface

#Encryption: Alice
my $pub = Crypt::PK::ECC->new('Bob_pub_ecc1.der'); 
my $ct = $pub->encrypt("secret message");
#
#Encryption: Bob (received ciphertext $ct)
my $priv = Crypt::PK::ECC->new('Bob_priv_ecc1.der');
my $pt = $priv->decrypt($ct);
 
#Signature: Alice
my $priv = Crypt::PK::ECC->new('Alice_priv_ecc1.der');
my $sig = $priv->sign($message);
#
#Signature: Bob (received $message + $sig)
my $pub = Crypt::PK::ECC->new('Alice_pub_ecc1.der');
$pub->verify($sig, $message) or die "ERROR";

#Shared secret
my $priv = Crypt::PK::ECC->new('Alice_priv_ecc1.der');
my $pub = Crypt::PK::ECC->new('Bob_pub_ecc1.der'); 
my $shared_secret = $priv->shared_secret($pub);

#Key generation
my $pk = Crypt::PK::ECC->new();
$pk->generate_key(24);
my $private_der = $pk->export_key_der('private');
my $public_der = $pk->export_key_der('public');
my $public_ansi_x963 = $pk->export_key_x963();

### Functional interface

#Encryption: Alice
my $ct = ecc_encrypt('Bob_pub_ecc1.der', "secret message");
#Encryption: Bob (received ciphertext $ct)
my $pt = ecc_decrypt('Bob_priv_ecc1.der', $ct);
 
#Signature: Alice
my $sig = ecc_sign('Alice_priv_ecc1.der', $message);
#Signature: Bob (received $message + $sig)
ecc_verify('Alice_pub_ecc1.der', $sig, $message) or die "ERROR";

#Shared secret
my $shared_secret = ecc_shared_secret('Alice_priv_ecc1.der', 'Bob_pub_ecc1.der');

DESCRIPTION

The module provides a set of core ECC functions as well that are designed to be the Elliptic Curve analogy of all of the Diffie-Hellman routines (ECDH).

FUNCTIONS

ecc_encrypt

Elliptic Curve Diffie-Hellman (ECDH) encryption.

ECCDH Encryption is performed by producing a random key, hashing it, and XOR'ing the digest against the plaintext.

ecc_decrypt

Elliptic Curve Diffie-Hellman (ECDH) decryption

ecc_sign

Elliptic Curve Digital Signature Algorithm (ECDSA) - signature generation

ecc_verify

Elliptic Curve Digital Signature Algorithm (ECDSA) - signature verification

ecc_shared_secret

Elliptic curve Diffie-Hellman (ECDH) - construct a Diffie-Hellman shared secret with a private and public ECC key.

METHODS

new

my $pk = Crypt::PK::ECC->new();
#or
my $pk = Crypt::PK::ECC->new($priv_or_pub_key_filename);
#or
my $pk = Crypt::PK::ECC->new(\$buffer_containing_priv_or_pub_key);

generate_key

Uses Yarrow-based cryptographically strong random number generator seeded with random data taken from /dev/random (UNIX) or CryptGenRandom (Win32).

$pk->generate_key($keysize);
# $keysize .. key size in bytes: 14, 16, 20, 24, 28, 32, 48 or 65
#   14 => use curve SECP112R1
#   16 => use curve SECP128R1
#   20 => use curve SECP160R1
#   24 => use curve P-192 recommended by FIPS 186-3
#   28 => use curve P-224 recommended by FIPS 186-3
#   32 => use curve P-256 recommended by FIPS 186-3
#   48 => use curve P-384 recommended by FIPS 186-3
#   65 => use curve P-521 recommended by FIPS 186-3

See http://csrc.nist.gov/publications/fips/fips186-3/fips_186-3.pdf and http://www.secg.org/collateral/sec2_final.pdf

import_key

$pk->import_key($filename);
#or
$pk->import_key(\$buffer_containing_key);

import_key_x963

ANSI X9.63 Import (public key only) - can load data exported by export_key_x963

$pk->import_key(\$buffer_containing_pub_key_ansi_x963);

export_key_der

my $private_der = $pk->export_key_der('private');
#or
my $public_der = $pk->export_key_der('public');

export_key_x963

ANSI X9.63 Export (public key only)

my $public_ansi_x963 = $pk->export_key_x963();

encrypt

decrypt

sign

verify

shared_secret

# Alice having her priv key $pk and Bob's public key $pkb
my $pk  = Crypt::PK::ECC->new($priv_key_filename);
my $pkb = Crypt::PK::ECC->new($pub_key_filename);
my $shared_secret = $pk->shared_secret($pkb);

# Bob having his priv key $pk and Alice's public key $pka
my $pk = Crypt::PK::ECC->new($priv_key_filename);
my $pka = Crypt::PK::ECC->new($pub_key_filename);
my $shared_secret = $pk->shared_secret($pka);  # same value as computed by Alice

is_private

size