NAME

Crypt::NaCl::Tweet - XS bindings for TweetNaCl

SYNOPSIS

use Crypt::NaCl::Tweet ":all"

# TODO for now. sorry. see below.

DESCRIPTION

TweetNaCl is an implementation of NaCl which fits into 100 tweets. Cute trick, but it also makes for a more digestable/auditable self-contained library. Crypt::NaCl::Tweet includes, and provides perl bindings to, that library.

See the documentation available on the NaCl website for more information about the purpose and design of the available functions. Note that the crypto_ prefixes (and _tweet suffixes) are stripped from function names for ease of use.

Functions and constants documented below are sorted into their high-level primitives.

box

FUNCTIONS

box
my $ciphertext = box($msg, $nonce, $their_public_key, $my_secret_key);
box_afternm
my $ciphertext = box_afternm($msg, $nonce, $key);
box_beforenm
my $key = box_beforenm($their_public_key, $my_secret_key);
box_keypair
my ($public_key, $secret_key) = box_keypair();
box_open
my $plaintext = box_open($ciphertext, $nonce, $their_public_key, $my_secret_key);
box_open_afternm
my $plaintext = box_open_afternm($ciphertext, $nonce, $key);

CONSTANTS

box_PRIMITIVE
box_PUBLICKEYBYTES
box_SECRETKEYBYTES
box_BEFORENMBYTES
box_NONCEBYTES
box_ZEROBYTES
box_BOXZEROBYTES

hash

FUNCTIONS

hash
my $binary_hash = hash($msg);

CONSTANTS

hash_BYTES
hash_PRIMITIVE

onetimeauth

FUNCTIONS

onetimeauth
my $authenticator = onetimeauth($msg, $key);
onetimeauth_keygen
my $auth_key = onetimeauth_keygen();
onetimeauth_verify
my $is_valid = onetimeauth_verify($authenticator, $msg, $key);

CONSTANTS

onetimeauth_BYTES
onetimeauth_KEYBYTES
onetimeauth_PRIMITIVE

scalarmult

FUNCTIONS

scalarmult
my $q = scalarmult($n, $p);

Low-level function.

scalarmult_base
my $q = scalarmult_base($n);

Low-level function.

CONSTANTS

scalarmult_BYTES
scalarmult_PRIMITIVE
scalarmult_SCALARBYTES

secretbox

FUNCTIONS

secretbox
my $ciphertext = secretbox($msg, $nonce, $key);
secretbox_open
my $plaintext = secretbox_open($ciphertext, $nonce, $key);

CONSTANTS

secretbox_KEYBYTES
secretbox_NONCEBYTES
secretbox_PRIMITIVE
secretbox_ZEROBYTES
secretbox_BOXZEROBYTES

sign

FUNCTIONS

sign
my $signed_msg = sign($msg, $secret_key);
sign_keypair
my ($public_key, $secret_key) = sign_keypair();
sign_open
my $msg = sign_open($signed_msg, $public_key);

returns undef if signature is not valid.

CONSTANTS

sign_BYTES
sign_PRIMITIVE
sign_PUBLICKEYBYTES
sign_SECRETKEYBYTES

stream

FUNCTIONS

stream
my $stream_bytes = stream($nbytes, $nonce, $key);
stream_keygen
my $stream_key = stream_keygen();
stream_xor
my $ciphertext = stream_xor($msg, $nonce, $key);

CONSTANTS

stream_KEYBYTES
stream_NONCEBYTES
stream_PRIMITIVE

verify

FUNCTIONS

verify, verify_16
my $is_equal = verify($x, $y);
my $is_equal = verify_16($x, $y);

Constant-time. $x and $y must be 16 bytes.

verify_32
my $is_equal = verify_32($x, $y);

Constant-time. $x and $y must be 32 bytes.

CONSTANTS

verify_BYTES

Sixteen.

verify_16_BYTES

Sixteen.

verify_32_BYTES

Thirty-two.

BUGS/KNOWN LIMITATIONS

TweetNaCl is a very minimal library, and this is (at time of writing) a new distribution. Docs and tests are lacking. Patches welcome!

FEEDBACK

For reporting bugs, giving feedback, submitting patches, etc. please use the following:

AUTHOR

Brad Barden <perlmodules@5c30.org>

COPYRIGHT & LICENSE

Copyright (c) 2025 Brad Barden. All rights reserved.

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