mirror of
https://github.com/serai-dex/serai.git
synced 2025-03-12 09:26:51 +00:00
Have the C++ RNG apply a DST
This commit is contained in:
parent
30529038f2
commit
0eb2386ef0
1 changed files with 8 additions and 4 deletions
|
@ -5,11 +5,15 @@
|
||||||
#include "ringct/bulletproofs.h"
|
#include "ringct/bulletproofs.h"
|
||||||
#include "ringct/rctSigs.h"
|
#include "ringct/rctSigs.h"
|
||||||
|
|
||||||
|
typedef std::lock_guard<std::mutex> lock;
|
||||||
std::mutex rng_mutex;
|
std::mutex rng_mutex;
|
||||||
char rng_entropy[64];
|
|
||||||
|
uint8_t rng_entropy[64];
|
||||||
void rng(uint8_t* seed) {
|
void rng(uint8_t* seed) {
|
||||||
|
// Set the first half to the seed
|
||||||
memcpy(rng_entropy, seed, 32);
|
memcpy(rng_entropy, seed, 32);
|
||||||
memset(&rng_entropy[32], 0, 32);
|
// Set the second half to the hash of a DST to ensure a lack of collisions
|
||||||
|
crypto::cn_fast_hash("RNG_entropy_seed", 16, (char*) &rng_entropy[32]);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -41,7 +45,7 @@ extern "C" {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* c_generate_bp(uint8_t* seed, uint8_t len, uint64_t* a, uint8_t* m) {
|
uint8_t* c_generate_bp(uint8_t* seed, uint8_t len, uint64_t* a, uint8_t* m) {
|
||||||
std::lock_guard<std::mutex> guard(rng_mutex);
|
lock guard(rng_mutex);
|
||||||
rng(seed);
|
rng(seed);
|
||||||
|
|
||||||
rct::keyV masks;
|
rct::keyV masks;
|
||||||
|
@ -70,7 +74,7 @@ extern "C" {
|
||||||
// That's why this must also have control over RNG, to prevent interrupting multisig signing
|
// That's why this must also have control over RNG, to prevent interrupting multisig signing
|
||||||
// while not using known seeds. Considering this doesn't actually define a batch,
|
// while not using known seeds. Considering this doesn't actually define a batch,
|
||||||
// and it's only verifying a single BP, it'd probably be fine, but...
|
// and it's only verifying a single BP, it'd probably be fine, but...
|
||||||
std::lock_guard<std::mutex> guard(rng_mutex);
|
lock guard(rng_mutex);
|
||||||
rng(seed);
|
rng(seed);
|
||||||
|
|
||||||
rct::Bulletproof bp;
|
rct::Bulletproof bp;
|
||||||
|
|
Loading…
Reference in a new issue