Skip to content

Commit

Permalink
start implementing aead
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 194729e commit 36595ed
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/crypto_aead.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Node Native Module for Lib Sodium
*
* @Author Pedro Paixao
* @email paixaop at gmail dot com
* @License MIT
*/
#include "node_sodium.h"


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

}
52 changes: 52 additions & 0 deletions src/include/crypto_aead.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Node Native Module for Lib Sodium
*
* @Author Pedro Paixao
* @email paixaop at gmail dot com
* @License MIT
*/
#ifndef __CRYPTO_AEAD_H__
#define __CRYPTO_AEAD_H__

/*
int crypto_aead_aes256gcm_decrypt(unsigned char *m,
unsigned long long *mlen_p,
unsigned char *nsec,
const unsigned char *c,
unsigned long long clen,
const unsigned char *ad,
unsigned long long adlen,
const unsigned char *npub,
const unsigned char *k)
*/

#define CRYPTO_AEAD_DEF(ALGO) \
NAN_METHOD(bind_crypto_aead_ ## ALGO ## _decrypt) { \
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 ## _decrypt (token_ptr, msg, msg_size, key) == 0 ) { \
return info.GetReturnValue().Set(token); \
} \
return info.GetReturnValue().Set(Nan::Null()); \
}\

#define METHOD_AND_PROPS(ALGO) \
NEW_METHOD(crypto_aead_ ## ALGO ## _decrypt); \
NEW_METHOD(crypto_aead_ ## ALGO ## _decrypt_detached); \
NEW_METHOD(crypto_aead_ ## ALGO ## _encrypt); \
NEW_METHOD(crypto_aead_ ## ALGO ## _encrypt_detached); \
NEW_INT_PROP(crypto_aead_ ## ALGO ## _ABYTES); \
NEW_INT_PROP(crypto_aead_ ## ALGO ## _KEYBYTES); \
NEW_INT_PROP(crypto_aead_ ## ALGO ## _NPUBBYTES); \
NEW_INT_PROP(crypto_aead_ ## ALGO ## _NSECBYTES); \
NEW_INT_PROP(crypto_aead_ ## ALGO ## _STATEBYTES);

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


#endif
1 change: 1 addition & 0 deletions src/include/node_sodium.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ using namespace v8;
#define ARG_TO_VOID_BUFFER(NAME) GET_ARG_AS_VOID(_arg, NAME); _arg++
#define ARG_TO_UCHAR_BUFFER(NAME) GET_ARG_AS_UCHAR(_arg, NAME); _arg++
#define ARG_TO_UCHAR_BUFFER_LEN(NAME, MAXLEN) GET_ARG_AS_UCHAR_LEN(_arg, NAME, MAXLEN); _arg++

#define ARG_TO_UCHAR_BUFFER_LEN_OR_NULL(NAME, MAXLEN) \
GET_ARG_AS_OR_NULL(_arg, NAME, unsigned char*); \
if( NAME ## _size != 0 && NAME ## _size != MAXLEN ) { \
Expand Down
1 change: 1 addition & 0 deletions src/include/node_sodium_register.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ 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);
void register_crypto_aead(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 @@ -39,6 +39,7 @@ void RegisterModule(Handle<Object> target) {
register_crypto_scalarmult(target);
register_crypto_scalarmult_curve25519(target);
register_crypto_core(target);
//register_crypto_aead(target);
}

NODE_MODULE(sodium, RegisterModule);

0 comments on commit 36595ed

Please sign in to comment.