-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85a8f63
commit 30422b6
Showing
14 changed files
with
330 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//================================================================================== | ||
// © 2024 Duality Technologies, Inc. All rights reserved. | ||
// This is a proprietary software product of Duality Technologies, Inc. | ||
// protected under copyright laws and international copyright treaties, patent | ||
// law, trade secret law and other intellectual property rights of general | ||
// applicability. Any use of this software is strictly prohibited absent a | ||
// written agreement executed by Duality Technologies, Inc., which provides | ||
// certain limited rights to use this software. You may not copy, distribute, | ||
// make publicly available, publicly perform, disassemble, de-compile or reverse | ||
// engineer any part of this software, breach its security, or circumvent, | ||
// manipulate, impair or disrupt its operation. | ||
//================================================================================== | ||
#include "blake2engine.h" | ||
|
||
Blake2Engine* createEngineInstance() { | ||
// initialization of PRNGs | ||
constexpr size_t maxGens = Blake2Engine::MAX_SEED_GENS; | ||
#pragma omp critical | ||
std::array<uint32_t, maxGens> initKey{}; | ||
initKey[0] = std::chrono::high_resolution_clock::now().time_since_epoch().count(); | ||
initKey[1] = std::hash<std::thread::id>{}(std::this_thread::get_id()); | ||
#if !defined(__arm__) && !defined(__EMSCRIPTEN__) | ||
if (sizeof(size_t) == 8) | ||
initKey[2] = (std::hash<std::thread::id>{}(std::this_thread::get_id()) >> 32); | ||
#endif | ||
void* mem = malloc(1); | ||
uint32_t counter = reinterpret_cast<long long>(mem); // NOLINT | ||
free(mem); | ||
|
||
Blake2Engine gen(initKey, counter); | ||
|
||
std::uniform_int_distribution<uint32_t> distribution(0); | ||
std::array<uint32_t, maxGens> seed{}; | ||
for (uint32_t i = 0; i < maxGens; i++) { | ||
seed[i] = distribution(gen); | ||
} | ||
|
||
std::array<uint32_t, maxGens> rdseed{}; | ||
size_t attempts = 3; | ||
bool rdGenPassed = false; | ||
for(size_t i = 0; i < attempts && !rdGenPassed; ++i) { | ||
try { | ||
std::random_device genR; | ||
for (uint32_t i = 0; i < maxGens; i++) { | ||
rdseed[i] = distribution(genR); | ||
} | ||
rdGenPassed = true; | ||
} | ||
catch (std::exception& e) { | ||
} | ||
} | ||
for (uint32_t i = 0; i < maxGens; i++) { | ||
seed[i] += rdseed[i]; | ||
} | ||
|
||
return new Blake2Engine(seed); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/sh | ||
|
||
# set -x | ||
|
||
g++ -fPIC -shared -o libblake2.so -I./include -I../ ./lib/*.c ./lib/*.cpp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//================================================================================== | ||
// © 2024 Duality Technologies, Inc. All rights reserved. | ||
// This is a proprietary software product of Duality Technologies, Inc. | ||
// protected under copyright laws and international copyright treaties, patent | ||
// law, trade secret law and other intellectual property rights of general | ||
// applicability. Any use of this software is strictly prohibited absent a | ||
// written agreement executed by Duality Technologies, Inc., which provides | ||
// certain limited rights to use this software. You may not copy, distribute, | ||
// make publicly available, publicly perform, disassemble, de-compile or reverse | ||
// engineer any part of this software, breach its security, or circumvent, | ||
// manipulate, impair or disrupt its operation. | ||
//================================================================================== | ||
#ifndef __PRNG_H__ | ||
#define __PRNG_H__ | ||
|
||
#include <cstdint> | ||
#include <limits> | ||
|
||
|
||
class PRNG { | ||
public: | ||
// all C++11 distributions used in OpenFHE work by default with uint32_t | ||
// a different data type can be specified if needed for a particular | ||
// architecture | ||
using result_type = uint32_t; | ||
|
||
PRNG(result_type seed) {} | ||
/** | ||
* @brief minimum value used by C+11 distribution generators when no lower | ||
* bound is explicitly specified by the user | ||
*/ | ||
static constexpr result_type min() { | ||
return std::numeric_limits<result_type>::min(); | ||
} | ||
|
||
/** | ||
* @brief maximum value used by C+11 distribution generators when no upper | ||
* bound is explicitly specified by the user | ||
*/ | ||
static constexpr result_type max() { | ||
return std::numeric_limits<result_type>::max(); | ||
} | ||
|
||
virtual result_type operator()() = 0; | ||
virtual ~PRNG() = default; | ||
}; | ||
|
||
#endif // __PRNG_H__ | ||
|
Oops, something went wrong.