Crypt::Sodium - Perl bindings for libsodium https://github.com/jedisct1/libsodium


NAME

Crypt::Sodium - Perl bindings for libsodium (NaCL) https://github.com/jedisct1/libsodium


SYNOPSIS

  use Crypt::Sodium;
  my $k = crypto_stream_key();
  my $n = crypto_stream_nonce();
  my $ciphertext = crypto_stream_xor("Hello World!", $n, $k);
  my $cleartext = crypto_stream_xor($ciphertext, $n, $k);


DESCRIPTION

  Simple wrapper around NaCL functions as provided by libsodium.  crypto_box, crypto_stream, crypto_hash,
  and crypto_sign are all present and accounted for.  None of the specific implementations are exposed, 
  only the default implementations are.
  I'm releasing this, though I don't feel I have any business writing a Crypt:: namespace'd module.  SO, 
  if you use it, please use it with caution, and supply me with patches when you notice any security holes.  I
  will do my best to apply them and release new versions promptly.


EXPORTED FUNCTIONS

box_keypair()
   Usage: my ($public_key, $secret_key) = box_keypair();
sign_keypair()

   Usage: my ($public_key, $secret_key) = sign_keypair();
crypto_sign($message, $secret_key)

   Usage: my $signed_message = crypto_sign($m, $sk);
crypto_sign_open($signed_message, $public_key)

   Usage: my $message = crypto_sign_open($sm, $pk);
crypto_box($message, $nonce, $public_key, $secret_key)

   Usage: my $ciphertext = crypto_box($m, $n, $pk, $sk);
   Note: $nonce must be at least crypto_box_NONCEBYTES long.
crypto_box_open($ciphertext, $nonce, $public_key, $secret_key)

   Usage: my $cleartext = crypto_box_open($c, $n, $pk, $sk);
crypto_secretbox($message, $nonce, $key);

   Usage: my $ciphertext = crypto_secretbox($m, $n, $k);
   Note: $nonce must be at least crypto_box_NONCEBYTES long,
         $key must be at least crypto_box_SECRETKEYBYTES long.
crypto_secretbox_open($ciphertext, $nonce, $key);

   Usage: my $message = crypto_secretbox($c, $n, $k);
crypto_hash($to_hash)

   Usage: my $hash = crypto_hash($to_hash);
crypto_stream($length, $nonce, $key)

   Usage: my $stream = crypto_stream($length, $nonce, $key);
   Note: $nonce must be at least crypto_stream_NONCEBYTES long, 
         $key must be at least crypto_stream_KEYBYTES long.
crypto_stream_xor($message, $nonce, $key)

   Usage: my $ciphertext = crypto_stream_xor($message, $nonce, $key);
          my $cleartext = crypto_stream_xor($ciphertext, $nonce, $key);
   Note: $nonce must be at least crypto_stream_NONCEBYTES long, 
         $key must be at least crypto_stream_KEYBYTES long.
randombytes_buf($length)

   Usage: my $bytes = randombytes(24);
crypto_box_nonce()

   Usage: my $nonce = crypto_box_nonce();
crypto_stream_nonce()

   Usage: my $nonce = crypto_stream_nonce();
crypto_stream_key()
   Usage: my $key = crypto_stream_key();
crypto_pwhash_salt()

   Usage: my $salt = crypto_pwhash_salt();
crypto_pwhash_scrypt($password, $salt, $keylen, $opslimit, $memlimit)

   Usage: my $derivedkey = crypto_pwhash_scrypt($password, $salt, $keylen, $opslimit, $memlimit);
   Note: $salt must be crypto_pwhash_SALTBYTES long, use crypto_pwhash_salt() to generate
         $keylen maybe omitted, the default is crypto_box_SEEDBYTES
         $opslimit maybe omitted, the default is crypto_pwhash_OPSLIMIT
         $memlimit maybe omitted, the default is crypto_pwhash_MEMLIMIT
         See L<http://doc.libsodium.org/password_hashing/README.html>; for details>.
crypto_pwhash_scrypt_str($password, $salt, $opslimit, $memlimit) Usage: my $hash_string = crypto_pwhash_scrypt_str($password, $salt); Note: like the crypto_pwhash_scrypt function, this function can also take an opslimit and memlimit value. The default opslimit is exported into your namespace as crypto_pwhash_OPSLIMIT and the default memlimit is exported as crypto_pwhash_MEMLIMIT, if you have a really important password to hash and don't mind using 1GB of ram and 10s+ of CPU time on an i7-class CPU, you can use crypto_pwhash_OPSLIMIT_SENSITIVE and crypto_pwhash_MEMLIMIT_SENSITIVE instead.


EXPORTED CONSTANTS

 crypto_stream_KEYBYTES
 crypto_stream_NONCEBYTES
 crypto_box_NONCEBYTES
 crypto_box_PUBLICKEYBYTES
 crypto_box_SECRETKEYBYTES
 crypto_box_MACBYTES
 crypto_box_SEEDBYTES
 crypto_secretbox_MACBYTES
 crypto_sign_PUBLICKEYBYTES
 crypto_sign_SECRETKEYBYTES
 crypto_pwhash_SALTBYTES
 crypto_pwhash_OPSLIMIT
 crypto_pwhash_MEMLIMIT
 crypto_pwhash_STRBYTES


SEE ALSO

 https://github.com/jedisct1/libsodium
 http://nacl.cr.yp.to/


DEPENDENCIES

 libsodium 1.0.0 or higher


AUTHOR

Michael Gregorowicz, <mike@mg2.org>


COPYRIGHT AND LICENSE

Copyright (C) 2015 Michael Gregorowicz

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.18 or, at your option, any later version of Perl 5 you may have available.

 Crypt::Sodium - Perl bindings for libsodium https://github.com/jedisct1/libsodium