workaround for the MoarVM problem with MP_GEN_RAND et al.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
diff --git a/bn_mp_rand.c b/bn_mp_rand.c
index b66d1b0..c165946 100644
--- a/bn_mp_rand.c
+++ b/bn_mp_rand.c
@@ -179,6 +179,16 @@ static int s_gen_random(mp_digit *r)
return ret;
}
+/*
+ Public for legacy reasons only, do not use elsewhere!
+ There is a good reason it is not officially documented!
+ */
+mp_digit gen_random_mp_digit(void) {
+ mp_digit p;
+ MP_UNUSED_VARIABLE s_gen_random(&p);
+ return p;
+}
+
int mp_rand(mp_int *a, int digits)
{
int res;
diff --git a/tommath.h b/tommath.h
index 555b4e3..1f71c20 100644
--- a/tommath.h
+++ b/tommath.h
@@ -600,6 +600,19 @@ int mp_fwrite(const mp_int *a, int radix, FILE *stream);
#define mp_todecimal(M, S) mp_toradix((M), (S), 10)
#define mp_tohex(M, S) mp_toradix((M), (S), 16)
+#if ( (defined __GCC__) || (defined __clang__) )
+# define MP_UNUSED_VARIABLE __attribute__((unused))
+#else
+# define MP_UNUSED_VARIABLE (void)
+#endif
+/*
+ Public for legacy reasons only, do not use elsewhere!
+ There is a good reason it is not officially documented!
+ */
+mp_digit gen_random_mp_digit(void);
+#define MP_GEN_RANDOM_MAX MP_MASK
+#define MP_GEN_RANDOM() gen_random_mp_digit(void)
+
#ifdef __cplusplus
}
#endif