diff --git a/addon/wolfcrypt/ecc.cpp b/addon/wolfcrypt/ecc.cpp index 047a7a4..46a1293 100644 --- a/addon/wolfcrypt/ecc.cpp +++ b/addon/wolfcrypt/ecc.cpp @@ -1,6 +1,6 @@ /* ecc.cpp * - * Copyright (C) 2006-2022 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/addon/wolfcrypt/evp.cpp b/addon/wolfcrypt/evp.cpp index 2991dd8..280c553 100644 --- a/addon/wolfcrypt/evp.cpp +++ b/addon/wolfcrypt/evp.cpp @@ -1,6 +1,6 @@ /* evp.cpp * - * Copyright (C) 2006-2022 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/addon/wolfcrypt/h/ecc.h b/addon/wolfcrypt/h/ecc.h index 7f87d5f..89eddae 100644 --- a/addon/wolfcrypt/h/ecc.h +++ b/addon/wolfcrypt/h/ecc.h @@ -1,6 +1,6 @@ /* ecc.h * - * Copyright (C) 2006-2022 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/addon/wolfcrypt/h/evp.h b/addon/wolfcrypt/h/evp.h index 730daf3..ab62719 100644 --- a/addon/wolfcrypt/h/evp.h +++ b/addon/wolfcrypt/h/evp.h @@ -1,6 +1,6 @@ /* evp.h * - * Copyright (C) 2006-2022 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/addon/wolfcrypt/h/hmac.h b/addon/wolfcrypt/h/hmac.h index df96fd6..cbf493b 100644 --- a/addon/wolfcrypt/h/hmac.h +++ b/addon/wolfcrypt/h/hmac.h @@ -1,6 +1,6 @@ /* hmac.h * - * Copyright (C) 2006-2022 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/addon/wolfcrypt/h/pbkdf2.h b/addon/wolfcrypt/h/pbkdf2.h index 9e30645..2891d15 100644 --- a/addon/wolfcrypt/h/pbkdf2.h +++ b/addon/wolfcrypt/h/pbkdf2.h @@ -1,6 +1,6 @@ /* pbkdf2.h * - * Copyright (C) 2006-2022 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/addon/wolfcrypt/h/pkcs12.h b/addon/wolfcrypt/h/pkcs12.h index 853c8ec..e82912d 100644 --- a/addon/wolfcrypt/h/pkcs12.h +++ b/addon/wolfcrypt/h/pkcs12.h @@ -1,6 +1,6 @@ /* pkcs12.h * - * Copyright (C) 2006-2022 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/addon/wolfcrypt/h/pkcs7.h b/addon/wolfcrypt/h/pkcs7.h index 8c5e5cc..7e4f931 100644 --- a/addon/wolfcrypt/h/pkcs7.h +++ b/addon/wolfcrypt/h/pkcs7.h @@ -1,6 +1,6 @@ /* pkcs7.h * - * Copyright (C) 2006-2022 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/addon/wolfcrypt/h/random.h b/addon/wolfcrypt/h/random.h new file mode 100644 index 0000000..e7a5786 --- /dev/null +++ b/addon/wolfcrypt/h/random.h @@ -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 +#ifndef WOLFSSL_USER_SETTINGS +#include "wolfssl/options.h" +#endif +#include +#include +#include + +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); diff --git a/addon/wolfcrypt/h/rsa.h b/addon/wolfcrypt/h/rsa.h index 962a090..b02dd3e 100644 --- a/addon/wolfcrypt/h/rsa.h +++ b/addon/wolfcrypt/h/rsa.h @@ -1,6 +1,6 @@ /* rsa.h * - * Copyright (C) 2006-2022 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/addon/wolfcrypt/h/sha.h b/addon/wolfcrypt/h/sha.h index d8ab1b0..f730931 100644 --- a/addon/wolfcrypt/h/sha.h +++ b/addon/wolfcrypt/h/sha.h @@ -1,6 +1,6 @@ /* sha.h * - * Copyright (C) 2006-2022 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/addon/wolfcrypt/hmac.cpp b/addon/wolfcrypt/hmac.cpp index ef414e4..3d69123 100644 --- a/addon/wolfcrypt/hmac.cpp +++ b/addon/wolfcrypt/hmac.cpp @@ -1,6 +1,6 @@ /* hmac.cpp * - * Copyright (C) 2006-2022 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/addon/wolfcrypt/main.cpp b/addon/wolfcrypt/main.cpp index 5f84450..21beaa6 100644 --- a/addon/wolfcrypt/main.cpp +++ b/addon/wolfcrypt/main.cpp @@ -1,6 +1,6 @@ /* main.cpp * - * Copyright (C) 2006-2022 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * @@ -29,6 +29,7 @@ #include "./h/pbkdf2.h" #include "./h/pkcs7.h" #include "./h/pkcs12.h" +#include "./h/random.h" using namespace Napi; @@ -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; } diff --git a/addon/wolfcrypt/pbkdf2.cpp b/addon/wolfcrypt/pbkdf2.cpp index a30bda6..25d0a9d 100644 --- a/addon/wolfcrypt/pbkdf2.cpp +++ b/addon/wolfcrypt/pbkdf2.cpp @@ -1,6 +1,6 @@ /* pbkdf2.cpp * - * Copyright (C) 2006-2022 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/addon/wolfcrypt/pkcs12.cpp b/addon/wolfcrypt/pkcs12.cpp index 76e15a7..df7db8a 100644 --- a/addon/wolfcrypt/pkcs12.cpp +++ b/addon/wolfcrypt/pkcs12.cpp @@ -1,6 +1,6 @@ /* pkcs12.cpp * - * Copyright (C) 2006-2022 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/addon/wolfcrypt/pkcs7.cpp b/addon/wolfcrypt/pkcs7.cpp index 11c4aff..da242aa 100644 --- a/addon/wolfcrypt/pkcs7.cpp +++ b/addon/wolfcrypt/pkcs7.cpp @@ -1,6 +1,6 @@ /* pkcs7.cpp * - * Copyright (C) 2006-2022 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/addon/wolfcrypt/random.cpp b/addon/wolfcrypt/random.cpp new file mode 100644 index 0000000..3e8a06d --- /dev/null +++ b/addon/wolfcrypt/random.cpp @@ -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().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().Data()); + uint8_t* out = (uint8_t*)(info[1].As().Data()); + word32 outLen = (word32)(info[2].As().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().Data()); + + ret = wc_FreeRng(rng); + + return Napi::Number::New(env, ret); +} diff --git a/addon/wolfcrypt/rsa.cpp b/addon/wolfcrypt/rsa.cpp index 1d38da3..16e1493 100644 --- a/addon/wolfcrypt/rsa.cpp +++ b/addon/wolfcrypt/rsa.cpp @@ -1,6 +1,6 @@ /* rsa.cpp * - * Copyright (C) 2006-2022 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/addon/wolfcrypt/sha.cpp b/addon/wolfcrypt/sha.cpp index 500d5ef..502af8b 100644 --- a/addon/wolfcrypt/sha.cpp +++ b/addon/wolfcrypt/sha.cpp @@ -1,6 +1,6 @@ /* sha.cpp * - * Copyright (C) 2006-2022 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/binding.gyp b/binding.gyp index 20ac163..e9068f9 100644 --- a/binding.gyp +++ b/binding.gyp @@ -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': [ "= rngOne.length) { + console.log('FAIL RNG generateBlock') + } + else { + console.log('PASS RNG generateBlock') + } + } + } +} + +module.exports = rng_tests diff --git a/tests/rsa.js b/tests/rsa.js index 412eea6..b73f75c 100644 --- a/tests/rsa.js +++ b/tests/rsa.js @@ -1,6 +1,6 @@ /* rsa.js * - * Copyright (C) 2006-2022 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. * diff --git a/tests/sha.js b/tests/sha.js index fbdd75b..5f11da2 100644 --- a/tests/sha.js +++ b/tests/sha.js @@ -1,6 +1,6 @@ /* sha.js * - * Copyright (C) 2006-2022 wolfSSL Inc. + * Copyright (C) 2006-2024 wolfSSL Inc. * * This file is part of wolfSSL. *