Skip to content

Commit

Permalink
implement all crypto_auth algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Paixao authored and Pedro Paixao committed Apr 13, 2016
1 parent da942fd commit dd94379
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 47 deletions.
3 changes: 2 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
{
'target_name': 'sodium',
'sources': [
'./src/crypto_auth.cc',
'./src/crypto_auth_algos.cc',
'./src/crypto_core.cc',
'./src/crypto_scalarmult_curve25519.cc',
'./src/crypto_scalarmult.cc',
Expand All @@ -26,7 +28,6 @@
'./src/crypto_shorthash_siphash24.cc',
'./src/crypto_generichash.cc',
'./src/crypto_generichash_blake2b.cc',
'./src/crypto_auth.cc',
'./src/crypto_onetimeauth.cc',
'./src/crypto_onetimeauth_poly1305.cc'
],
Expand Down
73 changes: 30 additions & 43 deletions docs/not implemented.md
Original file line number Diff line number Diff line change
@@ -1,74 +1,57 @@
* crypto_aead_aes256gcm_ABYTES
* crypto_aead_aes256gcm_beforenm

* crypto_aead_aes256gcm_decrypt
* crypto_aead_aes256gcm_decrypt_afternm
* crypto_aead_aes256gcm_decrypt_detached
* crypto_aead_aes256gcm_decrypt_detached_afternm
* crypto_aead_aes256gcm_encrypt
* crypto_aead_aes256gcm_encrypt_afternm
* crypto_aead_aes256gcm_encrypt_detached

* crypto_aead_aes256gcm_beforenm
* crypto_aead_aes256gcm_decrypt_afternm
* crypto_aead_aes256gcm_decrypt_detached_afternm
* crypto_aead_aes256gcm_encrypt_afternm
* crypto_aead_aes256gcm_encrypt_detached_afternm
* crypto_aead_aes256gcm_is_available

* crypto_aead_aes256gcm_ABYTES
* crypto_aead_aes256gcm_KEYBYTES
* crypto_aead_aes256gcm_NPUBBYTES
* crypto_aead_aes256gcm_NSECBYTES
* crypto_aead_aes256gcm_STATEBYTES
* crypto_aead_chacha20poly1305_ABYTES

* crypto_aead_chacha20poly1305_decrypt
* crypto_aead_chacha20poly1305_decrypt_detached
* crypto_aead_chacha20poly1305_encrypt
* crypto_aead_chacha20poly1305_encrypt_detached
* crypto_aead_chacha20poly1305_ietf_ABYTES
* crypto_aead_chacha20poly1305_ABYTES
* crypto_aead_chacha20poly1305_KEYBYTES
* crypto_aead_chacha20poly1305_NPUBBYTES
* crypto_aead_chacha20poly1305_NSECBYTES

* crypto_aead_chacha20poly1305_ietf_decrypt
* crypto_aead_chacha20poly1305_ietf_decrypt_detached
* crypto_aead_chacha20poly1305_ietf_encrypt
* crypto_aead_chacha20poly1305_ietf_encrypt_detached
* crypto_aead_chacha20poly1305_ietf_ABYTES
* crypto_aead_chacha20poly1305_ietf_KEYBYTES
* crypto_aead_chacha20poly1305_ietf_NPUBBYTES
* crypto_aead_chacha20poly1305_ietf_NSECBYTES
* crypto_aead_chacha20poly1305_KEYBYTES
* crypto_aead_chacha20poly1305_NPUBBYTES
* crypto_aead_chacha20poly1305_NSECBYTES
* crypto_auth_hmacsha256
* crypto_auth_hmacsha256_BYTES
* crypto_auth_hmacsha256_final
* crypto_auth_hmacsha256_init
* crypto_auth_hmacsha256_KEYBYTES
* crypto_auth_hmacsha256_STATEBYTES
* crypto_auth_hmacsha256_update
* crypto_auth_hmacsha256_verify
* crypto_auth_hmacsha512
* crypto_auth_hmacsha512256
* crypto_auth_hmacsha512256_BYTES
* crypto_auth_hmacsha512256_final
* crypto_auth_hmacsha512256_init
* crypto_auth_hmacsha512256_KEYBYTES
* crypto_auth_hmacsha512256_STATEBYTES
* crypto_auth_hmacsha512256_update
* crypto_auth_hmacsha512256_verify
* crypto_auth_hmacsha512_BYTES
* crypto_auth_hmacsha512_final
* crypto_auth_hmacsha512_init
* crypto_auth_hmacsha512_KEYBYTES
* crypto_auth_hmacsha512_STATEBYTES
* crypto_auth_hmacsha512_update
* crypto_auth_hmacsha512_verify

* crypto_box_curve25519xsalsa20poly1305
* crypto_box_curve25519xsalsa20poly1305_afternm
* crypto_box_curve25519xsalsa20poly1305_beforenm
* crypto_box_curve25519xsalsa20poly1305_keypair
* crypto_box_curve25519xsalsa20poly1305_open
* crypto_box_curve25519xsalsa20poly1305_open_afternm
* crypto_box_curve25519xsalsa20poly1305_seed_keypair

* crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES
* crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES
* crypto_box_curve25519xsalsa20poly1305_keypair
* crypto_box_curve25519xsalsa20poly1305_MACBYTES
* crypto_box_curve25519xsalsa20poly1305_NONCEBYTES
* crypto_box_curve25519xsalsa20poly1305_open
* crypto_box_curve25519xsalsa20poly1305_open_afternm
* crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES
* crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES
* crypto_box_curve25519xsalsa20poly1305_seed_keypair
* crypto_box_curve25519xsalsa20poly1305_SEEDBYTES
* crypto_box_curve25519xsalsa20poly1305_ZEROBYTES

* crypto_box_detached
* crypto_box_detached_afternm
* crypto_box_easy_afternm
Expand All @@ -77,21 +60,25 @@
* crypto_box_seal
* crypto_box_seal_open
* crypto_box_seed_keypair

* crypto_sign_ed25519
* crypto_sign_ed25519_BYTES
* crypto_sign_ed25519_open
* crypto_sign_ed25519_detached
* crypto_sign_ed25519_keypair
* crypto_sign_ed25519_open
* crypto_sign_ed25519_PUBLICKEYBYTES
* crypto_sign_ed25519_SECRETKEYBYTES
* crypto_sign_ed25519_seed_keypair
* crypto_sign_ed25519_SEEDBYTES
* crypto_sign_ed25519_sk_to_pk
* crypto_sign_ed25519_sk_to_seed
* crypto_sign_ed25519_verify_detached

* crypto_sign_ed25519_BYTES
* crypto_sign_ed25519_PUBLICKEYBYTES
* crypto_sign_ed25519_SECRETKEYBYTES
* crypto_sign_ed25519_SEEDBYTES

* crypto_sign_edwards25519sha512batch
* crypto_sign_edwards25519sha512batch_keypair
* crypto_sign_edwards25519sha512batch_open

* randombytes_implementation_name
* randombytes_set_implementation
* sodium_allocarray
Expand Down
7 changes: 4 additions & 3 deletions src/crypto_auth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @License MIT
*/
#include "node_sodium.h"

#include "crypto_auth_algos.h"
/**
* int crypto_auth(
* unsigned char* tok,
Expand Down Expand Up @@ -67,8 +67,9 @@ NAN_METHOD(bind_crypto_auth_verify) {
*/
void register_crypto_auth(Handle<Object> target) {
// Auth
NEW_METHOD(crypto_auth);
NEW_METHOD(crypto_auth_verify);
NEW_METHOD_ALIAS(crypto_auth, crypto_auth_hmacsha512256);
NEW_METHOD_ALIAS(crypto_auth_verify, crypto_auth_hmacsha512256_verify);

NEW_INT_PROP(crypto_auth_BYTES);
NEW_INT_PROP(crypto_auth_KEYBYTES);
NEW_STRING_PROP(crypto_auth_PRIMITIVE);
Expand Down
23 changes: 23 additions & 0 deletions src/crypto_auth_algos.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Node Native Module for Lib Sodium
*
* @Author Pedro Paixao
* @email paixaop at gmail dot com
* @License MIT
*/
#include "node_sodium.h"
#include "crypto_auth_algos.h"

CRYPTO_AUTH_DEF(hmacsha256)
CRYPTO_AUTH_DEF(hmacsha512)
CRYPTO_AUTH_DEF(hmacsha512256)

/**
* Register function calls in node binding
*/
void register_crypto_auth_algos(Handle<Object> target) {

METHOD_AND_PROPS(hmacsha256)
METHOD_AND_PROPS(hmacsha512)
METHOD_AND_PROPS(hmacsha512256)
}
79 changes: 79 additions & 0 deletions src/include/crypto_auth_algos.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* Node Native Module for Lib Sodium
*
* @Author Pedro Paixao
* @email paixaop at gmail dot com
* @License MIT
*/
#ifndef __CRYPTO_AUTH_ALGOS_H__
#define __CRYPTO_AUTH_ALGOS_H__

#define CRYPTO_AUTH_DEF(ALGO) \
NAN_METHOD(bind_crypto_auth_ ## ALGO) { \
Nan::EscapableHandleScope scope; \
ARGS(2,"arguments message, and key must be buffers"); \
ARG_TO_UCHAR_BUFFER(msg);\
ARG_TO_UCHAR_BUFFER_LEN(key, crypto_auth_ ## ALGO ## _KEYBYTES); \
NEW_BUFFER_AND_PTR(token, crypto_auth_ ## ALGO ## _BYTES); \
if( crypto_auth_ ## ALGO (token_ptr, msg, msg_size, key) == 0 ) { \
return info.GetReturnValue().Set(token); \
} \
return info.GetReturnValue().Set(Nan::Null()); \
}\
NAN_METHOD(bind_crypto_auth_ ## ALGO ## _verify) { \
Nan::EscapableHandleScope scope; \
ARGS(3,"arguments token, message, and key must be buffers"); \
ARG_TO_UCHAR_BUFFER_LEN(token, crypto_auth_ ## ALGO ## _BYTES); \
ARG_TO_UCHAR_BUFFER(message); \
ARG_TO_UCHAR_BUFFER_LEN(key, crypto_auth_ ## ALGO ## _KEYBYTES); \
return info.GetReturnValue().Set( \
Nan::New<Integer>(crypto_auth_ ## ALGO ## _verify(token, message, message_size, key))\
);\
}\
NAN_METHOD(bind_crypto_auth_ ## ALGO ## _init) { \
Nan::EscapableHandleScope scope; \
ARGS(1,"argument key must a buffer"); \
ARG_TO_UCHAR_BUFFER(key); \
NEW_BUFFER_AND_PTR(state, crypto_auth_ ## ALGO ## _statebytes()); \
if( crypto_auth_ ## ALGO ## _init((crypto_auth_ ## ALGO ## _state*) state_ptr, key, key_size) == 0 ) { \
return info.GetReturnValue().Set(state); \
} \
return info.GetReturnValue().Set(Nan::Null()); \
} \
NAN_METHOD(bind_crypto_auth_ ## ALGO ## _update) { \
Nan::EscapableHandleScope scope; \
ARGS(2,"arguments must be two buffers: hash state, message part"); \
ARG_TO_VOID_BUFFER(state); \
ARG_TO_UCHAR_BUFFER(msg); \
if( crypto_auth_ ## ALGO ## _update((crypto_auth_ ## ALGO ## _state*)state, msg, msg_size) == 0 ) { \
return info.GetReturnValue().Set(Nan::True()); \
} \
return info.GetReturnValue().Set(Nan::False()); \
} \
NAN_METHOD(bind_crypto_auth_ ## ALGO ## _final) { \
Nan::EscapableHandleScope scope; \
ARGS(1,"arguments must be a hash state buffer"); \
ARG_TO_VOID_BUFFER(state); \
NEW_BUFFER_AND_PTR(hash, crypto_auth_ ## ALGO ## _BYTES); \
if( crypto_auth_ ## ALGO ## _final((crypto_auth_ ## ALGO ## _state*)state, hash_ptr) == 0 ) { \
return info.GetReturnValue().Set(hash); \
} \
return info.GetReturnValue().Set(Nan::False()); \
} \


#define METHOD_AND_PROPS(ALGO) \
NEW_METHOD(crypto_auth_ ## ALGO); \
NEW_METHOD(crypto_auth_ ## ALGO ## _verify); \
NEW_INT_PROP(crypto_auth_ ## ALGO ## _BYTES); \
NEW_INT_PROP(crypto_auth_ ## ALGO ## _KEYBYTES);

#define NAN_METHODS(ALGO) \
NAN_METHOD(bind_crypto_auth_ ## ALGO); \
NAN_METHOD(bind_crypto_auth_ ## ALGO ## _verify); \

NAN_METHODS(hmacsha256);
NAN_METHODS(hmacsha512);
NAN_METHODS(hmacsha512256);

#endif
1 change: 1 addition & 0 deletions src/include/node_sodium_register.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ void register_crypto_box(Handle<Object> target);
void register_crypto_scalarmult(Handle<Object> target);
void register_crypto_scalarmult_curve25519(Handle<Object> target);
void register_crypto_core(Handle<Object> target);
void register_crypto_auth_algos(Handle<Object> target);

#endif
1 change: 1 addition & 0 deletions src/sodium.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void RegisterModule(Handle<Object> target) {
register_crypto_shorthash_siphash24(target);
register_crypto_generichash(target);
register_crypto_generichash_blake2b(target);
register_crypto_auth_algos(target);
register_crypto_auth(target);
register_crypto_onetimeauth(target);
register_crypto_onetimeauth_poly1305(target);
Expand Down

0 comments on commit dd94379

Please sign in to comment.