Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
flint++
Browse files Browse the repository at this point in the history
  • Loading branch information
microshine committed Feb 4, 2016
1 parent 05950b7 commit b0357ec
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 33 deletions.
16 changes: 8 additions & 8 deletions src/aes/aes_gcm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ static Handle<std::string> AES_GCM_encrypt(
THROW_OPENSSL("EVP_CIPHER_CTX_new");

/* Initialise the encryption operation. */
if (1 != EVP_EncryptInit_ex(ctx.Get(), cipher, NULL, NULL, NULL))
if (1 != EVP_EncryptInit_ex(ctx.Get(), cipher, nullptr, nullptr, nullptr))
THROW_OPENSSL("Initialise the encryption operation");

/* Set IV length if default 12 bytes (96 bits) is not appropriate */
if (1 != EVP_CIPHER_CTX_ctrl(ctx.Get(), EVP_CTRL_GCM_SET_IVLEN, hIv->length(), NULL))
if (1 != EVP_CIPHER_CTX_ctrl(ctx.Get(), EVP_CTRL_GCM_SET_IVLEN, hIv->length(), nullptr))
THROW_OPENSSL("EVP_CIPHER_CTX_ctrl");

/* Initialise key and IV */
if (1 != EVP_EncryptInit_ex(ctx.Get(), NULL, NULL, key, iv))
if (1 != EVP_EncryptInit_ex(ctx.Get(), nullptr, nullptr, key, iv))
THROW_OPENSSL("Initialise key and IV");

/* Provide any AAD data. This can be called zero or more times as
* required
*/
if (1 != EVP_EncryptUpdate(ctx.Get(), NULL, &output_len, aad, hAad->length()))
if (1 != EVP_EncryptUpdate(ctx.Get(), nullptr, &output_len, aad, hAad->length()))
THROW_OPENSSL("Provide any AAD data");

/* Provide the message to be encrypted, and obtain the encrypted output.
Expand Down Expand Up @@ -127,21 +127,21 @@ static Handle<std::string> AES_GCM_decrypt(
THROW_OPENSSL("EVP_CIPHER_CTX_new");

/* Initialise the encryption operation. */
if (1 != EVP_DecryptInit_ex(ctx.Get(), cipher, NULL, NULL, NULL))
if (1 != EVP_DecryptInit_ex(ctx.Get(), cipher, nullptr, nullptr, nullptr))
THROW_OPENSSL("Initialise the encryption operation");

/* Set IV length if default 12 bytes (96 bits) is not appropriate */
if (1 != EVP_CIPHER_CTX_ctrl(ctx.Get(), EVP_CTRL_GCM_SET_IVLEN, hIv->length(), NULL))
if (1 != EVP_CIPHER_CTX_ctrl(ctx.Get(), EVP_CTRL_GCM_SET_IVLEN, hIv->length(), nullptr))
THROW_OPENSSL("EVP_CIPHER_CTX_ctrl");

/* Initialise key and IV */
if (1 != EVP_DecryptInit_ex(ctx.Get(), NULL, NULL, key, iv))
if (1 != EVP_DecryptInit_ex(ctx.Get(), nullptr, nullptr, key, iv))
THROW_OPENSSL("Initialise key and IV");

/* Provide any AAD data. This can be called zero or more times as
* required
*/
if (1 != EVP_DecryptUpdate(ctx.Get(), NULL, &output_len, aad, hAad->length()))
if (1 != EVP_DecryptUpdate(ctx.Get(), nullptr, &output_len, aad, hAad->length()))
THROW_OPENSSL("Provide any AAD data");


Expand Down
38 changes: 19 additions & 19 deletions src/core/excep.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#ifndef OSSL_CORE_EXCEP_H_INCLUDE
#define OSSL_CORE_EXCEP_H_INCLUDE

#include <stdexcept>
#include <openssl/err.h>

#include "logger.h"

std::string OPENSSL_get_errors();

#define LOG_ERROR(text) \
LOG_INFO("ERROR: %s\n%s", text, __FUNCTION__);

#define THROW_ERROR(text) \
{LOG_ERROR(text); throw std::runtime_error(text);}

#define THROW_OPENSSL(text) \
{LOG_ERROR(text);throw std::runtime_error(OPENSSL_get_errors().c_str());}

#ifndef OSSL_CORE_EXCEP_H_INCLUDE
#define OSSL_CORE_EXCEP_H_INCLUDE

#include <stdexcept>
#include <openssl/err.h>

#include "logger.h"

std::string OPENSSL_get_errors();

#define LOG_ERROR(text) \
LOG_INFO("ERROR: %s\n%s", text, __FUNCTION__);

#define THROW_ERROR(text) \
{LOG_ERROR(text); throw std::runtime_error(text);}

#define THROW_OPENSSL(text) \
{LOG_ERROR(text);throw std::runtime_error(OPENSSL_get_errors().c_str());}

#endif // OSSL_CORE_EXCEP_H_INCLUDE
4 changes: 1 addition & 3 deletions src/node/w_aes.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
#include "../aes/common.h"
#include "async_aes.h"

using namespace node;

class WAes: public ObjectWrap {
class WAes: public node::ObjectWrap {
public:
static v8::Local<v8::Object> NewInstance() {
v8::Local<v8::Function> cons = Nan::New(constructor());
Expand Down
4 changes: 1 addition & 3 deletions src/node/w_key.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
#include "../rsa/common.h"
#include "../ec/common.h"

using namespace node;

#define v8Object_get_BN(v8Obj, v8Param, RsaKey, RsaKeyParam) \
{unsigned char* v8Param = (unsigned char*)node::Buffer::Data(Nan::Get(v8Obj, Nan::New(#v8Param).ToLocalChecked()).ToLocalChecked()->ToObject()); \
RsaKey->RsaKeyParam = BN_bin2bn(v8Param, node::Buffer::Length(Nan::Get(v8Obj, Nan::New(#v8Param).ToLocalChecked()).ToLocalChecked()->ToObject()), nullptr);}

class WKey : public ObjectWrap {
class WKey : public node::ObjectWrap {
public:
static v8::Local<v8::Object> NewInstance() {
v8::Local<v8::Function> cons = Nan::New(constructor());
Expand Down

0 comments on commit b0357ec

Please sign in to comment.