-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Library Support * ECDH * `libdecaf:decaf_x25519_base_scalarmul/1` * `libdecaf:decaf_x25519_direct_scalarmul/2` * `libdecaf:decaf_x448_base_scalarmul/1` * `libdecaf:decaf_x448_direct_scalarmul/2` * EdDSA * `libdecaf:decaf_255_eddsa_derive_public_key/1` * `libdecaf:decaf_255_eddsa_sign/4` * `libdecaf:decaf_255_eddsa_verify/4` * `libdecaf:decaf_448_eddsa_derive_public_key/1` * `libdecaf:decaf_448_eddsa_sign/5` * `libdecaf:decaf_448_eddsa_verify/5` * SHA-2 * `libdecaf:sha2_512/2` * Streaming support * `libdecaf:sha2_512_init/0`, `libdecaf:sha2_512_update/2`, `libdecaf:sha2_512_final/2` * SHA-3 * `libdecaf:sha3_224/1` * `libdecaf:sha3_256/1` * `libdecaf:sha3_384/1` * `libdecaf:sha3_512/1` * `libdecaf:shake128/2` * `libdecaf:shake256/2` * Streaming support * `libdecaf:sha3_224_init/0`, `libdecaf:sha3_224_update/2`, `libdecaf:sha3_224_final/1` * `libdecaf:sha3_256_init/0`, `libdecaf:sha3_256_update/2`, `libdecaf:sha3_256_final/1` * `libdecaf:sha3_384_init/0`, `libdecaf:sha3_384_update/2`, `libdecaf:sha3_384_final/1` * `libdecaf:sha3_512_init/0`, `libdecaf:sha3_512_update/2`, `libdecaf:sha3_512_final/1` * `libdecaf:shake128_init/0`, `libdecaf:shake128_update/2`, `libdecaf:shake128_final/2` * `libdecaf:shake256_init/0`, `libdecaf:shake256_update/2`, `libdecaf:shake256_final/2`
- Loading branch information
1 parent
03b0d6d
commit 4d38fff
Showing
21 changed files
with
959 additions
and
359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
language: erlang | ||
|
||
sudo: required | ||
dist: trusty | ||
sudo: false | ||
|
||
otp_release: | ||
- 17.5 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Changelog | ||
|
||
## 0.0.1 (2016-03-01) | ||
|
||
* Initial Release | ||
|
||
* Publish to [hex.pm](https://hex.pm/packages/libdecaf). | ||
|
||
* Library Support | ||
* ECDH | ||
* `libdecaf:decaf_x25519_base_scalarmul/1` | ||
* `libdecaf:decaf_x25519_direct_scalarmul/2` | ||
* `libdecaf:decaf_x448_base_scalarmul/1` | ||
* `libdecaf:decaf_x448_direct_scalarmul/2` | ||
* EdDSA | ||
* `libdecaf:decaf_255_eddsa_derive_public_key/1` | ||
* `libdecaf:decaf_255_eddsa_sign/4` | ||
* `libdecaf:decaf_255_eddsa_verify/4` | ||
* `libdecaf:decaf_448_eddsa_derive_public_key/1` | ||
* `libdecaf:decaf_448_eddsa_sign/5` | ||
* `libdecaf:decaf_448_eddsa_verify/5` | ||
* SHA-2 | ||
* `libdecaf:sha2_512/2` | ||
* Streaming support | ||
* `libdecaf:sha2_512_init/0`, `libdecaf:sha2_512_update/2`, `libdecaf:sha2_512_final/2` | ||
* SHA-3 | ||
* `libdecaf:sha3_224/1` | ||
* `libdecaf:sha3_256/1` | ||
* `libdecaf:sha3_384/1` | ||
* `libdecaf:sha3_512/1` | ||
* `libdecaf:shake128/2` | ||
* `libdecaf:shake256/2` | ||
* Streaming support | ||
* `libdecaf:sha3_224_init/0`, `libdecaf:sha3_224_update/2`, `libdecaf:sha3_224_final/1` | ||
* `libdecaf:sha3_256_init/0`, `libdecaf:sha3_256_update/2`, `libdecaf:sha3_256_final/1` | ||
* `libdecaf:sha3_384_init/0`, `libdecaf:sha3_384_update/2`, `libdecaf:sha3_384_final/1` | ||
* `libdecaf:sha3_512_init/0`, `libdecaf:sha3_512_update/2`, `libdecaf:sha3_512_final/1` | ||
* `libdecaf:shake128_init/0`, `libdecaf:shake128_update/2`, `libdecaf:shake128_final/2` | ||
* `libdecaf:shake256_init/0`, `libdecaf:shake256_update/2`, `libdecaf:shake256_final/2` | ||
|
||
* Basic Tests based on the [draft-irtf-cfrg-eddsa](https://tools.ietf.org/html/draft-irtf-cfrg-eddsa), [FIPS 180-4](http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf), [FIPS 202](http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf), and [RFC 7748](https://tools.ietf.org/html/rfc7748) test vectors. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// -*- mode: c; tab-width: 8; indent-tabs-mode: 1; st-rulers: [70] -*- | ||
// vim: ts=8 sw=8 ft=c noet | ||
|
||
#include <decaf/decaf_255.h> | ||
|
||
/* | ||
* Erlang NIF functions | ||
*/ | ||
|
||
/* decaf/decaf_255.h */ | ||
|
||
static ERL_NIF_TERM | ||
libdecaf_decaf_x25519_base_scalarmul_1(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) | ||
{ | ||
ErlNifBinary scalar; | ||
|
||
if (argc != 1 || !enif_inspect_binary(env, argv[0], &scalar) | ||
|| scalar.size != X25519_PRIVATE_BYTES) { | ||
return enif_make_badarg(env); | ||
} | ||
|
||
ERL_NIF_TERM out; | ||
uint8_t *u = (uint8_t *)(enif_make_new_binary(env, X25519_PUBLIC_BYTES, &out)); | ||
|
||
(void) decaf_x25519_base_scalarmul(u, scalar.data); | ||
|
||
return out; | ||
} | ||
|
||
static ERL_NIF_TERM | ||
libdecaf_decaf_x25519_direct_scalarmul_2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) | ||
{ | ||
ErlNifBinary base; | ||
ErlNifBinary scalar; | ||
|
||
if (argc != 2 || !enif_inspect_binary(env, argv[0], &base) | ||
|| base.size != X25519_PUBLIC_BYTES | ||
|| !enif_inspect_binary(env, argv[1], &scalar) | ||
|| scalar.size != X25519_PRIVATE_BYTES) { | ||
return enif_make_badarg(env); | ||
} | ||
|
||
ERL_NIF_TERM out; | ||
uint8_t *u = (uint8_t *)(enif_make_new_binary(env, X25519_PUBLIC_BYTES, &out)); | ||
|
||
if (decaf_x25519_direct_scalarmul(u, base.data, scalar.data) == DECAF_SUCCESS) { | ||
return out; | ||
} else { | ||
return ATOM_error; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// -*- mode: c; tab-width: 8; indent-tabs-mode: 1; st-rulers: [70] -*- | ||
// vim: ts=8 sw=8 ft=c noet | ||
|
||
#include <decaf/decaf_448.h> | ||
|
||
/* | ||
* Erlang NIF functions | ||
*/ | ||
|
||
/* decaf/decaf_448.h */ | ||
|
||
static ERL_NIF_TERM | ||
libdecaf_decaf_x448_base_scalarmul_1(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) | ||
{ | ||
ErlNifBinary scalar; | ||
|
||
if (argc != 1 || !enif_inspect_binary(env, argv[0], &scalar) | ||
|| scalar.size != X448_PRIVATE_BYTES) { | ||
return enif_make_badarg(env); | ||
} | ||
|
||
ERL_NIF_TERM out; | ||
uint8_t *u = (uint8_t *)(enif_make_new_binary(env, X448_PUBLIC_BYTES, &out)); | ||
|
||
(void) decaf_x448_base_scalarmul(u, scalar.data); | ||
|
||
return out; | ||
} | ||
|
||
static ERL_NIF_TERM | ||
libdecaf_decaf_x448_direct_scalarmul_2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) | ||
{ | ||
ErlNifBinary base; | ||
ErlNifBinary scalar; | ||
|
||
if (argc != 2 || !enif_inspect_binary(env, argv[0], &base) | ||
|| base.size != X448_PUBLIC_BYTES | ||
|| !enif_inspect_binary(env, argv[1], &scalar) | ||
|| scalar.size != X448_PRIVATE_BYTES) { | ||
return enif_make_badarg(env); | ||
} | ||
|
||
ERL_NIF_TERM out; | ||
uint8_t *u = (uint8_t *)(enif_make_new_binary(env, X448_PUBLIC_BYTES, &out)); | ||
|
||
if (decaf_x448_direct_scalarmul(u, base.data, scalar.data) == DECAF_SUCCESS) { | ||
return out; | ||
} else { | ||
return ATOM_error; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// -*- mode: c; tab-width: 8; indent-tabs-mode: 1; st-rulers: [70] -*- | ||
// vim: ts=8 sw=8 ft=c noet | ||
|
||
#include <decaf/eddsa_255.h> | ||
|
||
/* | ||
* Erlang NIF functions | ||
*/ | ||
|
||
/* decaf/eddsa_255.h */ | ||
|
||
static ERL_NIF_TERM | ||
libdecaf_decaf_255_eddsa_derive_public_key_1(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) | ||
{ | ||
ErlNifBinary privkey; | ||
|
||
if (argc != 1 || !enif_inspect_binary(env, argv[0], &privkey) | ||
|| privkey.size != DECAF_255_EDDSA_PRIVATE_BYTES) { | ||
return enif_make_badarg(env); | ||
} | ||
|
||
ERL_NIF_TERM out; | ||
uint8_t *pubkey = (uint8_t *)(enif_make_new_binary(env, DECAF_255_EDDSA_PUBLIC_BYTES, &out)); | ||
|
||
(void) decaf_255_eddsa_derive_public_key(pubkey, privkey.data); | ||
|
||
return out; | ||
} | ||
|
||
static ERL_NIF_TERM | ||
libdecaf_decaf_255_eddsa_sign_4(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) | ||
{ | ||
ErlNifBinary privkey; | ||
ErlNifBinary pubkey; | ||
ErlNifBinary message; | ||
unsigned int prehashed; | ||
|
||
if (argc != 4 || !enif_inspect_binary(env, argv[0], &privkey) | ||
|| privkey.size != DECAF_255_EDDSA_PRIVATE_BYTES | ||
|| !enif_inspect_binary(env, argv[1], &pubkey) | ||
|| pubkey.size != DECAF_255_EDDSA_PUBLIC_BYTES | ||
|| !enif_inspect_binary(env, argv[2], &message) | ||
|| !enif_get_uint(env, argv[3], &prehashed) | ||
|| (prehashed != 0 && prehashed != 1)) { | ||
return enif_make_badarg(env); | ||
} | ||
|
||
ERL_NIF_TERM out; | ||
uint8_t *signature = (uint8_t *)(enif_make_new_binary(env, DECAF_255_EDDSA_SIGNATURE_BYTES, &out)); | ||
|
||
(void) decaf_255_eddsa_sign(signature, privkey.data, pubkey.data, message.data, message.size, prehashed); | ||
|
||
return out; | ||
} | ||
|
||
static ERL_NIF_TERM | ||
libdecaf_decaf_255_eddsa_verify_4(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) | ||
{ | ||
ErlNifBinary signature; | ||
ErlNifBinary pubkey; | ||
ErlNifBinary message; | ||
unsigned int prehashed; | ||
|
||
if (argc != 4 || !enif_inspect_binary(env, argv[0], &signature) | ||
|| signature.size != DECAF_255_EDDSA_SIGNATURE_BYTES | ||
|| !enif_inspect_binary(env, argv[1], &pubkey) | ||
|| pubkey.size != DECAF_255_EDDSA_PUBLIC_BYTES | ||
|| !enif_inspect_binary(env, argv[2], &message) | ||
|| !enif_get_uint(env, argv[3], &prehashed) | ||
|| (prehashed != 0 && prehashed != 1)) { | ||
return enif_make_badarg(env); | ||
} | ||
|
||
if (decaf_255_eddsa_verify(signature.data, pubkey.data, message.data, message.size, prehashed) == DECAF_SUCCESS) { | ||
return ATOM_true; | ||
} else { | ||
return ATOM_false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// -*- mode: c; tab-width: 8; indent-tabs-mode: 1; st-rulers: [70] -*- | ||
// vim: ts=8 sw=8 ft=c noet | ||
|
||
#include <decaf/eddsa_448.h> | ||
|
||
/* | ||
* Erlang NIF functions | ||
*/ | ||
|
||
/* decaf/eddsa_448.h */ | ||
|
||
static ERL_NIF_TERM | ||
libdecaf_decaf_448_eddsa_derive_public_key_1(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) | ||
{ | ||
ErlNifBinary privkey; | ||
|
||
if (argc != 1 || !enif_inspect_binary(env, argv[0], &privkey) | ||
|| (privkey.size != DECAF_448_EDDSA_PRIVATE_BYTES && privkey.size != 32)) { | ||
return enif_make_badarg(env); | ||
} | ||
|
||
ERL_NIF_TERM out; | ||
uint8_t *pubkey = (uint8_t *)(enif_make_new_binary(env, DECAF_448_EDDSA_PUBLIC_BYTES, &out)); | ||
|
||
(void) decaf_448_eddsa_derive_public_key(pubkey, privkey.data, (privkey.size == 32) ? 1 : 0); | ||
|
||
return out; | ||
} | ||
|
||
static ERL_NIF_TERM | ||
libdecaf_decaf_448_eddsa_sign_5(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) | ||
{ | ||
ErlNifBinary privkey; | ||
ErlNifBinary pubkey; | ||
ErlNifBinary message; | ||
unsigned int prehashed; | ||
ErlNifBinary context; | ||
|
||
if (argc != 5 || !enif_inspect_binary(env, argv[0], &privkey) | ||
|| (privkey.size != DECAF_448_EDDSA_PRIVATE_BYTES && privkey.size != 32) | ||
|| !enif_inspect_binary(env, argv[1], &pubkey) | ||
|| pubkey.size != DECAF_448_EDDSA_PUBLIC_BYTES | ||
|| !enif_inspect_binary(env, argv[2], &message) | ||
|| !enif_get_uint(env, argv[3], &prehashed) | ||
|| (prehashed != 0 && prehashed != 1) | ||
|| !enif_inspect_binary(env, argv[4], &context) | ||
|| context.size > 255) { | ||
return enif_make_badarg(env); | ||
} | ||
|
||
ERL_NIF_TERM out; | ||
uint8_t *signature = (uint8_t *)(enif_make_new_binary(env, DECAF_448_EDDSA_SIGNATURE_BYTES, &out)); | ||
|
||
(void) decaf_448_eddsa_sign(signature, privkey.data, pubkey.data, message.data, message.size, prehashed, context.data, context.size, (privkey.size == 32) ? 1 : 0); | ||
|
||
return out; | ||
} | ||
|
||
static ERL_NIF_TERM | ||
libdecaf_decaf_448_eddsa_verify_5(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) | ||
{ | ||
ErlNifBinary signature; | ||
ErlNifBinary pubkey; | ||
ErlNifBinary message; | ||
unsigned int prehashed; | ||
ErlNifBinary context; | ||
|
||
if (argc != 5 || !enif_inspect_binary(env, argv[0], &signature) | ||
|| signature.size != DECAF_448_EDDSA_SIGNATURE_BYTES | ||
|| !enif_inspect_binary(env, argv[1], &pubkey) | ||
|| pubkey.size != DECAF_448_EDDSA_PUBLIC_BYTES | ||
|| !enif_inspect_binary(env, argv[2], &message) | ||
|| !enif_get_uint(env, argv[3], &prehashed) | ||
|| (prehashed != 0 && prehashed != 1) | ||
|| !enif_inspect_binary(env, argv[4], &context) | ||
|| context.size > 255) { | ||
return enif_make_badarg(env); | ||
} | ||
|
||
if (decaf_448_eddsa_verify(signature.data, pubkey.data, message.data, message.size, prehashed, context.data, context.size) == DECAF_SUCCESS) { | ||
return ATOM_true; | ||
} else { | ||
return ATOM_false; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.