diff options
| author | Pierre Bourdon <delroth@gmail.com> | 2018-06-08 00:41:08 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-06-08 00:41:08 +0900 |
| commit | de0fe0e210ad72b6ef10afa5e092d486de578557 (patch) | |
| tree | 5e59440206a80f70d310a129ac05171900e21b42 /Source/Core/Common/Crypto/ec.cpp | |
| parent | b51fbaa5b084edc638b66ebd3be8093f4887ee14 (diff) | |
| parent | fff1db973096a893475f3ec96ee6f28e35c4a67c (diff) | |
Merge pull request #6928 from leoetlino/random
Common: Add Random utilities
Diffstat (limited to 'Source/Core/Common/Crypto/ec.cpp')
| -rw-r--r-- | Source/Core/Common/Crypto/ec.cpp | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/Source/Core/Common/Crypto/ec.cpp b/Source/Core/Common/Crypto/ec.cpp index 9a57300f89..78cd346ebd 100644 --- a/Source/Core/Common/Crypto/ec.cpp +++ b/Source/Core/Common/Crypto/ec.cpp @@ -15,6 +15,8 @@ #include "Common/Common.h" #include "Common/Crypto/bn.h" #include "Common/Crypto/ec.h" +#include "Common/Random.h" +#include "Common/StringUtil.h" #ifdef _MSC_VER #pragma warning(push) @@ -230,30 +232,18 @@ static Point operator*(const u8* a, const Point& b) return d; } -static void silly_random(u8* rndArea, u8 count) -{ - u16 i; - srand((unsigned)(time(nullptr))); - - for (i = 0; i < count; i++) - { - rndArea[i] = rand(); - } -} - Signature Sign(const u8* key, const u8* hash) { u8 e[30]{}; memcpy(e + 10, hash, 20); - // Changing random number generator to a lame one... u8 m[30]; - silly_random(m, sizeof(m)); - // fp = fopen("/dev/random", "rb"); - // if (fread(m, sizeof m, 1, fp) != 1) - // fatal("reading random"); - // fclose(fp); - m[0] = 0; + do + { + // Generate 240 bits and keep 233. + Common::Random::Generate(m, sizeof(m)); + m[0] &= 1; + } while (bn_compare(m, ec_N, sizeof(m)) >= 0); Elt r = (m * ec_G).X(); if (bn_compare(r.data.data(), ec_N, 30) >= 0) |
