Skip to content

Commit

Permalink
Merge pull request #9 from jpbland1/add-rng
Browse files Browse the repository at this point in the history
add rng to the bindings
  • Loading branch information
dgarske authored Nov 12, 2024
2 parents cc5a33f + 2c78a09 commit 65f5756
Show file tree
Hide file tree
Showing 41 changed files with 268 additions and 38 deletions.
2 changes: 1 addition & 1 deletion addon/wolfcrypt/ecc.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ecc.cpp
*
* Copyright (C) 2006-2022 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down
2 changes: 1 addition & 1 deletion addon/wolfcrypt/evp.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* evp.cpp
*
* Copyright (C) 2006-2022 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down
2 changes: 1 addition & 1 deletion addon/wolfcrypt/h/ecc.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ecc.h
*
* Copyright (C) 2006-2022 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down
2 changes: 1 addition & 1 deletion addon/wolfcrypt/h/evp.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* evp.h
*
* Copyright (C) 2006-2022 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down
2 changes: 1 addition & 1 deletion addon/wolfcrypt/h/hmac.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* hmac.h
*
* Copyright (C) 2006-2022 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down
2 changes: 1 addition & 1 deletion addon/wolfcrypt/h/pbkdf2.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* pbkdf2.h
*
* Copyright (C) 2006-2022 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down
2 changes: 1 addition & 1 deletion addon/wolfcrypt/h/pkcs12.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* pkcs12.h
*
* Copyright (C) 2006-2022 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down
2 changes: 1 addition & 1 deletion addon/wolfcrypt/h/pkcs7.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* pkcs7.h
*
* Copyright (C) 2006-2022 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down
32 changes: 32 additions & 0 deletions addon/wolfcrypt/h/random.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* random.h
*
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
* wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#include <napi.h>
#ifndef WOLFSSL_USER_SETTINGS
#include "wolfssl/options.h"
#endif
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/wolfcrypt/types.h>
#include <wolfssl/wolfcrypt/random.h>

Napi::Number sizeof_WC_RNG(const Napi::CallbackInfo& info);
Napi::Number bind_wc_InitRng(const Napi::CallbackInfo& info);
Napi::Number bind_wc_RNG_GenerateBlock(const Napi::CallbackInfo& info);
Napi::Number bind_wc_FreeRng(const Napi::CallbackInfo& info);
2 changes: 1 addition & 1 deletion addon/wolfcrypt/h/rsa.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* rsa.h
*
* Copyright (C) 2006-2022 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down
2 changes: 1 addition & 1 deletion addon/wolfcrypt/h/sha.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* sha.h
*
* Copyright (C) 2006-2022 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down
2 changes: 1 addition & 1 deletion addon/wolfcrypt/hmac.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* hmac.cpp
*
* Copyright (C) 2006-2022 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down
8 changes: 7 additions & 1 deletion addon/wolfcrypt/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* main.cpp
*
* Copyright (C) 2006-2022 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down Expand Up @@ -29,6 +29,7 @@
#include "./h/pbkdf2.h"
#include "./h/pkcs7.h"
#include "./h/pkcs12.h"
#include "./h/random.h"

using namespace Napi;

Expand Down Expand Up @@ -175,6 +176,11 @@ Napi::Object Init(Napi::Env env, Napi::Object exports)
exports.Set(Napi::String::New(env, "nodejsPKCS12InternalToDer"), Napi::Function::New(env, nodejsPKCS12InternalToDer));
exports.Set(Napi::String::New(env, "wc_PKCS12_free"), Napi::Function::New(env, bind_wc_PKCS12_free));

exports.Set(Napi::String::New(env, "sizeof_WC_RNG"), Napi::Function::New(env, sizeof_WC_RNG));
exports.Set(Napi::String::New(env, "wc_InitRng"), Napi::Function::New(env, bind_wc_InitRng));
exports.Set(Napi::String::New(env, "wc_RNG_GenerateBlock"), Napi::Function::New(env, bind_wc_RNG_GenerateBlock));
exports.Set(Napi::String::New(env, "wc_FreeRng"), Napi::Function::New(env, bind_wc_FreeRng));

return exports;
}

Expand Down
2 changes: 1 addition & 1 deletion addon/wolfcrypt/pbkdf2.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* pbkdf2.cpp
*
* Copyright (C) 2006-2022 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down
2 changes: 1 addition & 1 deletion addon/wolfcrypt/pkcs12.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* pkcs12.cpp
*
* Copyright (C) 2006-2022 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down
2 changes: 1 addition & 1 deletion addon/wolfcrypt/pkcs7.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* pkcs7.cpp
*
* Copyright (C) 2006-2022 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down
63 changes: 63 additions & 0 deletions addon/wolfcrypt/random.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* random.cpp
*
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
* wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
#include "./h/random.h"

Napi::Number sizeof_WC_RNG(const Napi::CallbackInfo& info)
{
Napi::Env env = info.Env();

return Napi::Number::New(env, sizeof(WC_RNG));
}

Napi::Number bind_wc_InitRng(const Napi::CallbackInfo& info)
{
Napi::Env env = info.Env();
int ret;
WC_RNG* rng = (WC_RNG*)(info[0].As<Napi::Uint8Array>().Data());

ret = wc_InitRng(rng);

return Napi::Number::New(env, ret);
}

Napi::Number bind_wc_RNG_GenerateBlock(const Napi::CallbackInfo& info)
{
Napi::Env env = info.Env();
int ret;
WC_RNG* rng = (WC_RNG*)(info[0].As<Napi::Uint8Array>().Data());
uint8_t* out = (uint8_t*)(info[1].As<Napi::Uint8Array>().Data());
word32 outLen = (word32)(info[2].As<Napi::Number>().Int32Value());

ret = wc_RNG_GenerateBlock(rng, out, outLen);

return Napi::Number::New(env, ret);
}

Napi::Number bind_wc_FreeRng(const Napi::CallbackInfo& info)
{
Napi::Env env = info.Env();
int ret;
WC_RNG* rng = (WC_RNG*)(info[0].As<Napi::Uint8Array>().Data());

ret = wc_FreeRng(rng);

return Napi::Number::New(env, ret);
}
2 changes: 1 addition & 1 deletion addon/wolfcrypt/rsa.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* rsa.cpp
*
* Copyright (C) 2006-2022 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down
2 changes: 1 addition & 1 deletion addon/wolfcrypt/sha.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* sha.cpp
*
* Copyright (C) 2006-2022 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down
5 changes: 3 additions & 2 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"addon/wolfcrypt/ecc.cpp",
"addon/wolfcrypt/pbkdf2.cpp",
"addon/wolfcrypt/pkcs7.cpp",
"addon/wolfcrypt/pkcs12.cpp"
"addon/wolfcrypt/pkcs12.cpp",
"addon/wolfcrypt/random.cpp"
],
'include_dirs': [
"<!@(node -p \"require('node-addon-api').include\")"
Expand All @@ -23,7 +24,7 @@
'dependencies': [
"<!(node -p \"require('node-addon-api').gyp\")",
],
'defines': [ 'NAPI_DISABLE_C_EXCEPTIONS' ],
'defines': ['NAPI_DISABLE_C_EXCEPTIONS'],
'msvs_settings': {
'VCCLCompilerTool': {
'ExceptionHandling': '1',
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* index.js
*
* Copyright (C) 2006-2022 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down
2 changes: 1 addition & 1 deletion interfaces/ecc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ecc.js
*
* Copyright (C) 2006-2022 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down
2 changes: 1 addition & 1 deletion interfaces/evp.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* evp.js
*
* Copyright (C) 2006-2022 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down
2 changes: 1 addition & 1 deletion interfaces/hmac.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* hmac.js
*
* Copyright (C) 2006-2022 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down
2 changes: 1 addition & 1 deletion interfaces/pbkdf2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* pbkdf2.js
*
* Copyright (C) 2006-2022 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down
2 changes: 1 addition & 1 deletion interfaces/pkcs12.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* pkcs12.js
*
* Copyright (C) 2006-2022 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down
2 changes: 1 addition & 1 deletion interfaces/pkcs7.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* pkcs7.js
*
* Copyright (C) 2006-2022 wolfSSL Inc.
* Copyright (C) 2006-2024 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
Expand Down
Loading

0 comments on commit 65f5756

Please sign in to comment.