static u64 chacha20(void)
{
- static u8 in [SIZE]; p_random(in , SIZE);
- static u8 key [ 32]; p_random(key , 32);
- static u8 nonce[ 8]; p_random(nonce, 8);
- static u8 out [SIZE];
+ u8 out[SIZE];
+ RANDOM_INPUT(in , SIZE);
+ RANDOM_INPUT(key , 32);
+ RANDOM_INPUT(nonce, 8);
TIMING_START {
crypto_stream_chacha20_xor(out, in, SIZE, nonce, key);
static u64 poly1305(void)
{
- static u8 in [SIZE]; p_random(in , SIZE);
- static u8 key[ 32]; p_random(key , 32);
- static u8 out[ 16];
+ u8 out[16];
+ RANDOM_INPUT(in , SIZE);
+ RANDOM_INPUT(key, 32);
TIMING_START {
crypto_onetimeauth(out, in, SIZE, key);
static u64 authenticated(void)
{
- static u8 in [SIZE]; p_random(in , SIZE);
- static u8 key [ 32]; p_random(key , 32);
- static u8 nonce[ 8]; p_random(nonce, 8);
- static u8 out [SIZE];
- static u8 mac [crypto_aead_xchacha20poly1305_ietf_ABYTES];
+ u8 out[SIZE];
+ u8 mac[crypto_aead_xchacha20poly1305_ietf_ABYTES];
+ RANDOM_INPUT(in , SIZE);
+ RANDOM_INPUT(key , 32);
+ RANDOM_INPUT(nonce, 8);
+
TIMING_START {
crypto_aead_xchacha20poly1305_ietf_encrypt_detached(
out, mac, 0, in, SIZE, 0, 0, 0, nonce, key);
static u64 blake2b(void)
{
- static u8 in [SIZE]; p_random(in , SIZE);
- static u8 key [ 32]; p_random(key, 32);
- static u8 hash[ 64];
+ u8 hash[64];
+ RANDOM_INPUT(in , SIZE);
+ RANDOM_INPUT(key, 32);
TIMING_START {
crypto_generichash(hash, 64, in, SIZE, key, 32);
static u64 sha512(void)
{
- static u8 in [SIZE]; p_random(in , SIZE);
- static u8 hash[ 64];
+ u8 hash[64];
+ RANDOM_INPUT(in, SIZE);
TIMING_START {
crypto_hash_sha512(hash, in, SIZE);
static u64 argon2i(void)
{
- static u8 password [ 16]; p_random(password, 16);
- static u8 salt [ 16]; p_random(salt , 16);
- static u8 hash [ 32];
+ u8 hash [32];
+ RANDOM_INPUT(password, 16);
+ RANDOM_INPUT(salt , 16);
TIMING_START {
if (crypto_pwhash(hash, 32, (char*)password, 16, salt,
static u64 edDSA_sign(void)
{
- u8 sk [64]; p_random(sk, 32);
- u8 pk [32]; crypto_sign_keypair(pk, sk);
- u8 message [64]; p_random(message, 64);
+ u8 sk [64];
+ u8 pk [32];
u8 signature[64];
+ RANDOM_INPUT(message, 64);
+ crypto_sign_keypair(pk, sk);
TIMING_START {
crypto_sign_detached(signature, 0, message, 64, sk);
static u64 edDSA_check(void)
{
- u8 sk [64]; p_random(sk, 32);
- u8 pk [32]; crypto_sign_keypair(pk, sk);
- u8 message [64]; p_random(message, 64);
+ u8 sk [64];
+ u8 pk [32];
u8 signature[64];
-
+ RANDOM_INPUT(message, 64);
+ crypto_sign_keypair(pk, sk);
crypto_sign_detached(signature, 0, message, 64, sk);
TIMING_START {
static u64 salsa20(void)
{
- static u8 in [SIZE]; p_random(in , SIZE);
- static u8 key [ 32]; p_random(key , 32);
- static u8 nonce[ 8]; p_random(nonce, 8);
- static u8 out [SIZE];
+ u8 out[SIZE];
+ RANDOM_INPUT(in , SIZE);
+ RANDOM_INPUT(key , 32);
+ RANDOM_INPUT(nonce, 8);
TIMING_START {
crypto_stream_salsa20_xor(out, in, SIZE, nonce, key);
static u64 poly1305(void)
{
- static u8 in [SIZE]; p_random(in , SIZE);
- static u8 key[ 32]; p_random(key , 32);
- static u8 out[ 16];
+ u8 out[16];
+ RANDOM_INPUT(in , SIZE);
+ RANDOM_INPUT(key, 32);
TIMING_START {
crypto_onetimeauth(out, in, SIZE, key);
static u64 authenticated(void)
{
- static u8 in [SIZE + 32]; p_random(in , SIZE);
- static u8 key [ 32]; p_random(key , 32);
- static u8 nonce[ 8]; p_random(nonce, 8);
- static u8 out [SIZE + 32];
+ u8 out[SIZE + 32];
+ RANDOM_INPUT(in , SIZE + 32);
+ RANDOM_INPUT(key , 32);
+ RANDOM_INPUT(nonce, 8);
TIMING_START {
crypto_secretbox(out, in, SIZE + 32, nonce, key);
static u64 sha512(void)
{
- static u8 in [SIZE]; p_random(in , SIZE);
- static u8 hash[ 64];
+ u8 hash[64];
+ RANDOM_INPUT(in, SIZE);
TIMING_START {
crypto_hash(hash, in, SIZE);
{
u8 sk [ 64];
u8 pk [ 32];
- u8 message [ 64]; p_random(message, 64);
u8 signed_msg[128];
unsigned long long sig_size;
-
+ RANDOM_INPUT(message, 64);
crypto_sign_keypair(pk, sk);
TIMING_START {
{
u8 sk [ 64];
u8 pk [ 32];
- u8 message [ 64]; p_random(message, 64);
u8 signed_msg[128];
u8 out_msg [128];
unsigned long long sig_size;
unsigned long long msg_size;
-
+ RANDOM_INPUT(message, 64);
crypto_sign_keypair(pk, sk);
crypto_sign(signed_msg, &sig_size, message, 64, sk);
static u64 chacha20(void)
{
- static u8 in [SIZE]; p_random(in , SIZE);
- static u8 key [ 32]; p_random(key , 32);
- static u8 nonce[ 8]; p_random(nonce, 8);
- static u8 out [SIZE];
+ u8 out[SIZE];
+ RANDOM_INPUT(in , SIZE);
+ RANDOM_INPUT(key , 32);
+ RANDOM_INPUT(nonce, 8);
TIMING_START {
crypto_chacha_ctx ctx;
static u64 poly1305(void)
{
- static u8 in [SIZE]; p_random(in , SIZE);
- static u8 key[ 32]; p_random(key , 32);
- static u8 out[ 16];
+ u8 out[16];
+ RANDOM_INPUT(in , SIZE);
+ RANDOM_INPUT(key, 32);
TIMING_START {
crypto_poly1305(out, in, SIZE, key);
static u64 authenticated(void)
{
- static u8 in [SIZE]; p_random(in , SIZE);
- static u8 key [ 32]; p_random(key , 32);
- static u8 nonce[ 8]; p_random(nonce, 8);
- static u8 out [SIZE];
- static u8 mac [ 16];
+ u8 out[SIZE];
+ u8 mac[ 16];
+ RANDOM_INPUT(in , SIZE);
+ RANDOM_INPUT(key , 32);
+ RANDOM_INPUT(nonce, 8);
TIMING_START {
crypto_lock(mac, out, key, nonce, in, SIZE);
static u64 blake2b(void)
{
- static u8 in [SIZE]; p_random(in , SIZE);
- static u8 key [ 32]; p_random(key, 32);
- static u8 hash[ 64];
+ u8 hash[64];
+ RANDOM_INPUT(in , SIZE);
+ RANDOM_INPUT(key, 32);
TIMING_START {
crypto_blake2b_general(hash, 64, key, 32, in, SIZE);
static u64 sha512(void)
{
- static u8 in [SIZE]; p_random(in , SIZE);
- static u8 hash[ 64];
+ u8 hash[64];
+ RANDOM_INPUT(in, SIZE);
TIMING_START {
crypto_sha512(hash, in, SIZE);
static u64 argon2i(void)
{
- size_t nb_blocks = SIZE / 1024;
- static u8 work_area[SIZE];
- static u8 password [ 16]; p_random(password, 16);
- static u8 salt [ 16]; p_random(salt , 16);
- static u8 hash [ 32];
+ u64 work_area[SIZE / 8];
+ u8 hash [32];
+ size_t nb_blocks = SIZE / 1024;
+ RANDOM_INPUT(password, 16);
+ RANDOM_INPUT(salt , 16);
TIMING_START {
crypto_argon2i(hash, 32, work_area, nb_blocks, 3,
static u64 edDSA_sign(void)
{
- u8 sk [32]; p_random(sk, 32);
- u8 pk [32]; crypto_sign_public_key(pk, sk);
- u8 message [64]; p_random(message, 64);
+ u8 pk [32];
u8 signature[64];
+ RANDOM_INPUT(sk , 32);
+ RANDOM_INPUT(message, 64);
+ crypto_sign_public_key(pk, sk);
TIMING_START {
crypto_sign(signature, sk, pk, message, 64);
static u64 edDSA_check(void)
{
- u8 sk [32]; p_random(sk, 32);
- u8 pk [32]; crypto_sign_public_key(pk, sk);
- u8 message [64]; p_random(message, 64);
+ u8 pk [32];
u8 signature[64];
-
+ RANDOM_INPUT(sk , 32);
+ RANDOM_INPUT(message, 64);
+ crypto_sign_public_key(pk, sk);
crypto_sign(signature, sk, pk, message, 64);
TIMING_START {
u8 output_chunk[INPUT_SIZE];
u8 output_whole[INPUT_SIZE];
// inputs
- u8 input [INPUT_SIZE]; p_random(input, INPUT_SIZE);
- u8 key [32]; p_random(key , 32);
- u8 nonce [8]; p_random(nonce, 8);
+ RANDOM_INPUT(input, INPUT_SIZE);
+ RANDOM_INPUT(key , 32);
+ RANDOM_INPUT(nonce, 8);
// Encrypt in chunks
crypto_chacha_ctx ctx;
static int p_chacha20_same_ptr()
{
int status = 0;
- u8 input [INPUT_SIZE]; p_random(input, INPUT_SIZE);
- u8 key [32]; p_random(key , 32);
- u8 nonce [8]; p_random(nonce, 8);
- u8 output [INPUT_SIZE];
+ u8 output[INPUT_SIZE];
+ RANDOM_INPUT(input, INPUT_SIZE);
+ RANDOM_INPUT(key , 32);
+ RANDOM_INPUT(nonce, 8);
crypto_chacha_ctx ctx;
crypto_chacha20_init (&ctx, key, nonce);
crypto_chacha20_encrypt(&ctx, output, input, INPUT_SIZE);
u8 output_part[STREAM_SIZE ];
u8 output_all [STREAM_SIZE ];
u8 output_more[STREAM_SIZE * 2];
- u8 key [32]; p_random(key , 32);
- u8 nonce [8]; p_random(nonce, 8 );
+ RANDOM_INPUT(key , 32);
+ RANDOM_INPUT(nonce, 8);
u64 ctr = rand64() % CHACHA_NB_BLOCKS;
size_t limit = ctr * CHACHA_BLOCK_SIZE;
// Encrypt all at once
u8 mac_chunk[16];
u8 mac_whole[16];
// inputs
- u8 input[INPUT_SIZE]; p_random(input, INPUT_SIZE);
- u8 key [32]; p_random(key , 32);
+ RANDOM_INPUT(input, INPUT_SIZE);
+ RANDOM_INPUT(key , 32);
// Authenticate bit by bit
crypto_poly1305_ctx ctx;
#define INPUT_SIZE (POLY1305_BLOCK_SIZE + (2 * 16)) // total input size
int status = 0;
FOR (i, 0, POLY1305_BLOCK_SIZE + 16) {
- u8 input[INPUT_SIZE]; p_random(input, INPUT_SIZE);
- u8 key [32]; p_random(key , 32);
+ RANDOM_INPUT(input, INPUT_SIZE);
+ RANDOM_INPUT(key , 32);
u8 mac [16];
crypto_poly1305(mac , input + 16, POLY1305_BLOCK_SIZE, key);
crypto_poly1305(input+i, input + 16, POLY1305_BLOCK_SIZE, key);
u8 hash_chunk[64];
u8 hash_whole[64];
// inputs
- u8 input[INPUT_SIZE]; p_random(input, INPUT_SIZE);
+ RANDOM_INPUT(input, INPUT_SIZE);
// Authenticate bit by bit
crypto_blake2b_ctx ctx;
#define INPUT_SIZE (BLAKE2B_BLOCK_SIZE + (2 * 64)) // total input size
int status = 0;
FOR (i, 0, BLAKE2B_BLOCK_SIZE + 64) {
- u8 input[INPUT_SIZE]; p_random(input, INPUT_SIZE);
u8 hash [64];
+ RANDOM_INPUT(input, INPUT_SIZE);
crypto_blake2b(hash , input + 64, BLAKE2B_BLOCK_SIZE);
crypto_blake2b(input+i, input + 64, BLAKE2B_BLOCK_SIZE);
status |= memcmp(hash, input + i, 64);
u8 hash_chunk[64];
u8 hash_whole[64];
// inputs
- u8 input[INPUT_SIZE]; p_random(input, INPUT_SIZE);
+ RANDOM_INPUT(input, INPUT_SIZE);
// Authenticate bit by bit
crypto_sha512_ctx ctx;
#define INPUT_SIZE (SHA_512_BLOCK_SIZE + (2 * 64)) // total input size
int status = 0;
FOR (i, 0, SHA_512_BLOCK_SIZE + 64) {
- u8 input[INPUT_SIZE]; p_random(input, INPUT_SIZE);
u8 hash [64];
+ RANDOM_INPUT(input, INPUT_SIZE);
crypto_sha512(hash , input + 64, SHA_512_BLOCK_SIZE);
crypto_sha512(input+i, input + 64, SHA_512_BLOCK_SIZE);
status |= memcmp(hash, input + i, 64);
static int p_eddsa_random()
{
int status = 0;
- u8 message[MESSAGE_SIZE]; p_random(message, 32);
+ RANDOM_INPUT(message, MESSAGE_SIZE);
FOR (i, 0, 1000) {
RANDOM_INPUT(pk, 32);
RANDOM_INPUT(signature , 64);
static int p_eddsa_incremental()
{
int status = 0;
- u8 message[MESSAGE_SIZE]; p_random(message, 32);
FOR (i, 0, MESSAGE_SIZE) {
RANDOM_INPUT(message, MESSAGE_SIZE);
RANDOM_INPUT(sk, 32);
{
int status = 0;
FOR (i, 0, 1000) {
- u8 key [32]; p_random(key , 32);
- u8 nonce [24]; p_random(nonce , 24);
- u8 ad [ 4]; p_random(ad , 4);
- u8 plaintext[ 8]; p_random(plaintext, 8);
+ RANDOM_INPUT(key , 32);
+ RANDOM_INPUT(nonce , 24);
+ RANDOM_INPUT(ad , 4);
+ RANDOM_INPUT(plaintext, 8);
u8 box[24], box2[24];
u8 out[8];
// AEAD roundtrip
{
int status = 0;
FOR (i, 0, 128) {
- u8 key [ 32]; p_random(key , 32);
- u8 nonce [ 24]; p_random(nonce , 24);
- u8 ad [128]; p_random(ad , i);
+ RANDOM_INPUT(key , 32);
+ RANDOM_INPUT(nonce , 24);
+ RANDOM_INPUT(ad , 128);
u8 mac1[16];
u8 mac2[16];
// roundtrip