Header file fixupUse <erl_nif.h> since it is a system header.Also rearrange headers to be consistent.
This commit is contained in:
parent
460c5bddfd
commit
fe478ea253
@ -1,8 +1,9 @@
|
|||||||
|
#include <sodium.h>
|
||||||
|
|
||||||
|
#include <erl_nif.h>
|
||||||
|
|
||||||
#include "aead.h"
|
#include "aead.h"
|
||||||
#include "enacl.h"
|
#include "enacl.h"
|
||||||
#include "erl_nif.h"
|
|
||||||
|
|
||||||
#include <sodium.h>
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* AEAD ChaCha20 Poly1305
|
* AEAD ChaCha20 Poly1305
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef ENACL_AEAD_H
|
#ifndef ENACL_AEAD_H
|
||||||
#define ENACL_AEAD_H
|
#define ENACL_AEAD_H
|
||||||
|
|
||||||
#include "erl_nif.h"
|
#include <erl_nif.h>
|
||||||
|
|
||||||
/* AEAD ChaCha20 Poly1305 */
|
/* AEAD ChaCha20 Poly1305 */
|
||||||
ERL_NIF_TERM
|
ERL_NIF_TERM
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
|
#include <erl_nif.h>
|
||||||
|
|
||||||
#include "enacl.h"
|
#include "enacl.h"
|
||||||
#include "erl_nif.h"
|
|
||||||
|
|
||||||
ERL_NIF_TERM nacl_error_tuple(ErlNifEnv *env, char *error_atom) {
|
ERL_NIF_TERM nacl_error_tuple(ErlNifEnv *env, char *error_atom) {
|
||||||
return enif_make_tuple2(env, enif_make_atom(env, "error"),
|
return enif_make_tuple2(env, enif_make_atom(env, "error"),
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef ENACL_H
|
#ifndef ENACL_H
|
||||||
#define ENACL_H
|
#define ENACL_H
|
||||||
|
|
||||||
#include "erl_nif.h"
|
#include <erl_nif.h>
|
||||||
|
|
||||||
#define ATOM_OK "ok"
|
#define ATOM_OK "ok"
|
||||||
#define ATOM_ERROR "error"
|
#define ATOM_ERROR "error"
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
#include <sodium.h>
|
#include <sodium.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "erl_nif.h"
|
#include <erl_nif.h>
|
||||||
|
|
||||||
#include "aead.h"
|
#include "aead.h"
|
||||||
#include "enacl.h"
|
#include "enacl.h"
|
||||||
#include "generichash.h"
|
#include "generichash.h"
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
#include "pwhash.h"
|
#include "pwhash.h"
|
||||||
|
#include "randombytes.h"
|
||||||
#include "sign.h"
|
#include "sign.h"
|
||||||
|
|
||||||
#define CRYPTO_SIGN_STATE_RESOURCE "crypto_sign_state"
|
#define CRYPTO_SIGN_STATE_RESOURCE "crypto_sign_state"
|
||||||
@ -757,49 +758,6 @@ static ERL_NIF_TERM enacl_crypto_onetimeauth_verify(ErlNifEnv *env, int argc,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static ERL_NIF_TERM enif_randombytes(ErlNifEnv *env, int argc,
|
|
||||||
ERL_NIF_TERM const argv[]) {
|
|
||||||
unsigned req_size;
|
|
||||||
ErlNifBinary result;
|
|
||||||
|
|
||||||
if ((argc != 1) || (!enif_get_uint(env, argv[0], &req_size))) {
|
|
||||||
return enif_make_badarg(env);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!enif_alloc_binary(req_size, &result)) {
|
|
||||||
return nacl_error_tuple(env, "alloc_failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
randombytes(result.data, result.size);
|
|
||||||
|
|
||||||
return enif_make_binary(env, &result);
|
|
||||||
}
|
|
||||||
|
|
||||||
static ERL_NIF_TERM enif_randombytes_uint32(ErlNifEnv *env, int argc,
|
|
||||||
ERL_NIF_TERM const argv[]) {
|
|
||||||
ErlNifUInt64 result;
|
|
||||||
|
|
||||||
if (argc != 0) {
|
|
||||||
return enif_make_badarg(env);
|
|
||||||
}
|
|
||||||
|
|
||||||
result = randombytes_random();
|
|
||||||
return enif_make_uint64(env, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
static ERL_NIF_TERM enif_randombytes_uniform(ErlNifEnv *env, int argc,
|
|
||||||
ERL_NIF_TERM const argv[]) {
|
|
||||||
unsigned upper_bound;
|
|
||||||
ErlNifUInt64 result;
|
|
||||||
|
|
||||||
if ((argc != 1) || (!enif_get_uint(env, argv[0], &upper_bound))) {
|
|
||||||
return enif_make_badarg(env);
|
|
||||||
}
|
|
||||||
|
|
||||||
result = randombytes_uniform(upper_bound);
|
|
||||||
return enif_make_uint64(env, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Key exchange */
|
/* Key exchange */
|
||||||
|
|
||||||
static ERL_NIF_TERM enacl_crypto_kx_SECRETKEYBYTES(ErlNifEnv *env, int argc,
|
static ERL_NIF_TERM enacl_crypto_kx_SECRETKEYBYTES(ErlNifEnv *env, int argc,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "erl_nif.h"
|
|
||||||
|
|
||||||
#include <sodium.h>
|
#include <sodium.h>
|
||||||
|
|
||||||
|
#include <erl_nif.h>
|
||||||
|
|
||||||
#include "enacl.h"
|
#include "enacl.h"
|
||||||
#include "generichash.h"
|
#include "generichash.h"
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef ENACL_GENERICHASH_H
|
#ifndef ENACL_GENERICHASH_H
|
||||||
#define ENACL_GENERICHASH_H
|
#define ENACL_GENERICHASH_H
|
||||||
|
|
||||||
|
#include <erl_nif.h>
|
||||||
|
|
||||||
int enacl_init_generic_hash_ctx(ErlNifEnv *env);
|
int enacl_init_generic_hash_ctx(ErlNifEnv *env);
|
||||||
|
|
||||||
ERL_NIF_TERM enacl_crypto_generichash_BYTES(ErlNifEnv *env, int argc,
|
ERL_NIF_TERM enacl_crypto_generichash_BYTES(ErlNifEnv *env, int argc,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "erl_nif.h"
|
|
||||||
|
|
||||||
#include <sodium.h>
|
#include <sodium.h>
|
||||||
|
|
||||||
|
#include <erl_nif.h>
|
||||||
|
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
|
|
||||||
ERL_NIF_TERM enacl_crypto_hash(ErlNifEnv *env, int argc,
|
ERL_NIF_TERM enacl_crypto_hash(ErlNifEnv *env, int argc,
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef ENACL_HASH_H
|
#ifndef ENACL_HASH_H
|
||||||
#define ENACL_HASH_H
|
#define ENACL_HASH_H
|
||||||
|
|
||||||
|
#include <erl_nif.h>
|
||||||
|
|
||||||
ERL_NIF_TERM enacl_crypto_hash(ErlNifEnv *env, int argc,
|
ERL_NIF_TERM enacl_crypto_hash(ErlNifEnv *env, int argc,
|
||||||
const ERL_NIF_TERM argv[]);
|
const ERL_NIF_TERM argv[]);
|
||||||
#endif
|
#endif
|
@ -1,7 +1,8 @@
|
|||||||
#include <sodium.h>
|
#include <sodium.h>
|
||||||
|
|
||||||
|
#include <erl_nif.h>
|
||||||
|
|
||||||
#include "enacl.h"
|
#include "enacl.h"
|
||||||
#include "erl_nif.h"
|
|
||||||
#include "pwhash.h"
|
#include "pwhash.h"
|
||||||
|
|
||||||
static size_t enacl_pwhash_opslimit(ErlNifEnv *env, ERL_NIF_TERM arg) {
|
static size_t enacl_pwhash_opslimit(ErlNifEnv *env, ERL_NIF_TERM arg) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef ENACL_PWHASH_H
|
#ifndef ENACL_PWHASH_H
|
||||||
#define ENACL_PWHASH_H
|
#define ENACL_PWHASH_H
|
||||||
|
|
||||||
#include "erl_nif.h"
|
#include <erl_nif.h>
|
||||||
|
|
||||||
ERL_NIF_TERM enacl_crypto_pwhash(ErlNifEnv *env, int argc,
|
ERL_NIF_TERM enacl_crypto_pwhash(ErlNifEnv *env, int argc,
|
||||||
ERL_NIF_TERM const argv[]);
|
ERL_NIF_TERM const argv[]);
|
||||||
|
49
c_src/randombytes.c
Normal file
49
c_src/randombytes.c
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#include <sodium.h>
|
||||||
|
|
||||||
|
#include <erl_nif.h>
|
||||||
|
|
||||||
|
#include "enacl.h"
|
||||||
|
#include "randombytes.h"
|
||||||
|
|
||||||
|
ERL_NIF_TERM enif_randombytes(ErlNifEnv *env, int argc,
|
||||||
|
ERL_NIF_TERM const argv[]) {
|
||||||
|
unsigned req_size;
|
||||||
|
ErlNifBinary result;
|
||||||
|
|
||||||
|
if ((argc != 1) || (!enif_get_uint(env, argv[0], &req_size))) {
|
||||||
|
return enif_make_badarg(env);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!enif_alloc_binary(req_size, &result)) {
|
||||||
|
return nacl_error_tuple(env, "alloc_failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
randombytes(result.data, result.size);
|
||||||
|
|
||||||
|
return enif_make_binary(env, &result);
|
||||||
|
}
|
||||||
|
|
||||||
|
ERL_NIF_TERM enif_randombytes_uint32(ErlNifEnv *env, int argc,
|
||||||
|
ERL_NIF_TERM const argv[]) {
|
||||||
|
ErlNifUInt64 result;
|
||||||
|
|
||||||
|
if (argc != 0) {
|
||||||
|
return enif_make_badarg(env);
|
||||||
|
}
|
||||||
|
|
||||||
|
result = randombytes_random();
|
||||||
|
return enif_make_uint64(env, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
ERL_NIF_TERM enif_randombytes_uniform(ErlNifEnv *env, int argc,
|
||||||
|
ERL_NIF_TERM const argv[]) {
|
||||||
|
unsigned upper_bound;
|
||||||
|
ErlNifUInt64 result;
|
||||||
|
|
||||||
|
if ((argc != 1) || (!enif_get_uint(env, argv[0], &upper_bound))) {
|
||||||
|
return enif_make_badarg(env);
|
||||||
|
}
|
||||||
|
|
||||||
|
result = randombytes_uniform(upper_bound);
|
||||||
|
return enif_make_uint64(env, result);
|
||||||
|
}
|
15
c_src/randombytes.h
Normal file
15
c_src/randombytes.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#ifndef ENACL_RANDOMBYTES_H
|
||||||
|
#define ENACL_RANDOMBYTES_H
|
||||||
|
|
||||||
|
#include <erl_nif.h>
|
||||||
|
|
||||||
|
ERL_NIF_TERM enif_randombytes(ErlNifEnv *env, int argc,
|
||||||
|
ERL_NIF_TERM const argv[]);
|
||||||
|
|
||||||
|
ERL_NIF_TERM enif_randombytes_uint32(ErlNifEnv *env, int argc,
|
||||||
|
ERL_NIF_TERM const argv[]);
|
||||||
|
|
||||||
|
ERL_NIF_TERM enif_randombytes_uniform(ErlNifEnv *env, int argc,
|
||||||
|
ERL_NIF_TERM const argv[]);
|
||||||
|
|
||||||
|
#endif
|
@ -1,7 +1,7 @@
|
|||||||
#include "erl_nif.h"
|
|
||||||
|
|
||||||
#include <sodium.h>
|
#include <sodium.h>
|
||||||
|
|
||||||
|
#include <erl_nif.h>
|
||||||
|
|
||||||
#include "enacl.h"
|
#include "enacl.h"
|
||||||
#include "sign.h"
|
#include "sign.h"
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef ENACL_SIGN_H
|
#ifndef ENACL_SIGN_H
|
||||||
#define ENACL_SIGN_H
|
#define ENACL_SIGN_H
|
||||||
|
|
||||||
#include "erl_nif.h"
|
#include <erl_nif.h>
|
||||||
|
|
||||||
int enacl_init_sign_ctx(ErlNifEnv *env);
|
int enacl_init_sign_ctx(ErlNifEnv *env);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user