NAME

HEAT::Crypto - HEAT cryptographic routines

SYNOPSIS

 use HEAT::Crypto qw(keygen shared_key sign verify encrypt decrypt);

 # generate public-private key pairs
 my $alice = keygen($seed);
 my $bob = keygen($seed);

 # compute shared secret
 my $secret = shared_key($alice->{k}, $bob->{p});
 shared_key($bob->{k}, $alice->{p}) eq $secret or die;

 # message signing and verifying
 my $signature = sign($alice->{k}, $message);
 verify($signature, $message, $alice->{p}) or die;

 # message encryption and decryption
 my $encrypted = encrypt($message, $secret);
 decrypt($encrypted, $secret) eq $message or die;

DESCRIPTION

This module provides HEAT compatible ECDH key agreement, signing and encryption ported to perl from the HEAT SDK.

The functions below are not exported by default and need to be imported explicitly:

keygen()
keygen( $seed );

Generate a new key pair. It returns a hash with 3 values:

{
  p => <public key bytes>,
  k => <private key bytes>,
  s => <signing key bytes>,
}
shared_key( $private_key, $public_key );

Compute shared secret.

Returns the key as a hexadecimal string.

sign( $private_key, $message );

Sign message with the private key.

Returns the signature as a hexadecimal string.

verify( $signature, $message, $public_key );

Verifies the message signature against the public key.

Returns 1 on success.

encrypt( $data, $key );

Encrypts data with the given key.

In array context it returns the encryption nonce, initialization vector and cypher text. In scalar context it concatenates them.

decrypt( $data, $key );

Decrypts data with the given key. Data is expected to be returned by encrypt();

It returns the decrypted data on success. This function might die in case of errors.

priv_to_pub_key( $private_key )

Derives the public key from the private key.

Returns the public key as a hexadecimal string.

account_id( $public_key )

Derives the account ID from the public key.

Returns an integer.

AUTHOR

Toma Mazilu

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself

SEE ALSO