aboutsummaryrefslogtreecommitdiff
path: root/src/crypto
diff options
context:
space:
mode:
Diffstat (limited to 'src/crypto')
-rw-r--r--src/crypto/crypto.cpp2
-rw-r--r--src/crypto/crypto.h9
-rw-r--r--src/crypto/random.c4
-rw-r--r--src/crypto/random.h2
-rw-r--r--src/crypto/slow-hash.c7
5 files changed, 17 insertions, 7 deletions
diff --git a/src/crypto/crypto.cpp b/src/crypto/crypto.cpp
index e47aab0f7..e251d0ec2 100644
--- a/src/crypto/crypto.cpp
+++ b/src/crypto/crypto.cpp
@@ -83,7 +83,7 @@ namespace crypto {
/* generate a random 32-byte (256-bit) integer and copy it to res */
static inline void random_scalar(ec_scalar &res) {
unsigned char tmp[64];
- generate_random_bytes(64, tmp);
+ generate_random_bytes_not_thread_safe(64, tmp);
sc_reduce(tmp);
memcpy(&res, tmp, 32);
}
diff --git a/src/crypto/crypto.h b/src/crypto/crypto.h
index 883aa521a..fa55c2aab 100644
--- a/src/crypto/crypto.h
+++ b/src/crypto/crypto.h
@@ -117,13 +117,20 @@ namespace crypto {
const public_key *const *, std::size_t, const signature *);
};
+ /* Generate N random bytes
+ */
+ inline void rand(size_t N, uint8_t *bytes) {
+ boost::lock_guard<boost::mutex> lock(random_lock);
+ generate_random_bytes_not_thread_safe(N, bytes);
+ }
+
/* Generate a value filled with random bytes.
*/
template<typename T>
typename std::enable_if<std::is_pod<T>::value, T>::type rand() {
typename std::remove_cv<T>::type res;
boost::lock_guard<boost::mutex> lock(random_lock);
- generate_random_bytes(sizeof(T), &res);
+ generate_random_bytes_not_thread_safe(sizeof(T), &res);
return res;
}
diff --git a/src/crypto/random.c b/src/crypto/random.c
index d7fcb7e65..6a9f63c12 100644
--- a/src/crypto/random.c
+++ b/src/crypto/random.c
@@ -45,7 +45,7 @@ static void generate_system_random_bytes(size_t n, void *result);
static void generate_system_random_bytes(size_t n, void *result) {
HCRYPTPROV prov;
-#define must_succeed(x) do if (!(x)) assert(0); while (0)
+#define must_succeed(x) do if (!(x)) abort(); while (0)
must_succeed(CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT));
must_succeed(CryptGenRandom(prov, (DWORD)n, result));
must_succeed(CryptReleaseContext(prov, 0));
@@ -113,7 +113,7 @@ INITIALIZER(init_random) {
#endif
}
-void generate_random_bytes(size_t n, void *result) {
+void generate_random_bytes_not_thread_safe(size_t n, void *result) {
#if !defined(NDEBUG)
assert(curstate == 1);
curstate = 2;
diff --git a/src/crypto/random.h b/src/crypto/random.h
index 322b5bad1..b0d2303b6 100644
--- a/src/crypto/random.h
+++ b/src/crypto/random.h
@@ -32,4 +32,4 @@
#include <stddef.h>
-void generate_random_bytes(size_t n, void *result);
+void generate_random_bytes_not_thread_safe(size_t n, void *result);
diff --git a/src/crypto/slow-hash.c b/src/crypto/slow-hash.c
index 4efa8af6c..6e03be4d4 100644
--- a/src/crypto/slow-hash.c
+++ b/src/crypto/slow-hash.c
@@ -683,7 +683,8 @@ static void (*const extra_hashes[4])(const void *, size_t, char *) = {
#include "aesb.c"
-/* The asm corresponds to this C code
+#ifndef ARM_MUL_IMPL_ASM
+/* The asm corresponds to this C code */
#define SHORT uint32_t
#define LONG uint64_t
@@ -714,7 +715,8 @@ void mul(const uint8_t *ca, const uint8_t *cb, uint8_t *cres) {
res[3] = t.tmp[2];
res[0] = t.tmp[6];
res[1] = t.tmp[7];
-} */
+}
+#else // ARM_MUL_IMPL_ASM (TODO: this fails hash-slow test with GCC 6.1.1)
/* Can work as inline, but actually runs slower. Keep it separate */
#define mul(a, b, c) cn_mul128(a, b, c)
@@ -749,6 +751,7 @@ __asm__ __volatile__(
: [A]"r"(aa[1]), [a]"r"(aa[0]), [B]"r"(bb[1]), [b]"r"(bb[0]), [r]"r"(r)
: "cc", "memory");
}
+#endif // ARM_MUL_IMPL_ASM
STATIC INLINE void sum_half_blocks(uint8_t* a, const uint8_t* b)
{