Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/majn/tgl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Wiederhake <BenWiederhake.GitHub@gmx>2015-09-29 15:24:59 +0300
committerBen Wiederhake <BenWiederhake.GitHub@gmx>2015-10-01 21:59:54 +0300
commit6b602adf384ab0447c6b6b20a218800ab2a119a3 (patch)
tree25f9c3b6c1789a15a1d86875424107d6f264364c
parentb954098d6e938e1539293b4cbef7d46bbfbf2ea8 (diff)
Implement rand_altern.c using gcrypt.
-rw-r--r--crypto/rand_altern.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/crypto/rand_altern.c b/crypto/rand_altern.c
index f5b015e..477fa6b 100644
--- a/crypto/rand_altern.c
+++ b/crypto/rand_altern.c
@@ -22,12 +22,30 @@
#ifdef TGL_AVOID_OPENSSL_RAND
-// #include <gcrypt/rand.h>
-// Or similar
+/* Marginally speed up compilation */
+#define GCRYPT_NO_MPI_MACROS
+/* Fail-fast when something becomes deprecated. */
+#define GCRYPT_NO_DEPRECATED
+
+#include <assert.h>
+#include <gcrypt.h>
#include "rand.h"
-/* FIXME */
-#error Not yet implemented: OpenSSL-independent defines for rand
+void TGLC_rand_add (const void *buf, int num, double entropy) {
+ (void) entropy;
+ // TODO: Translate half-broken "entropy" into gcry's "quality".
+ gcry_random_add_bytes (buf, num, 50);
+}
+
+int TGLC_rand_bytes (unsigned char *buf, int num) {
+ gcry_randomize (buf, num, GCRY_STRONG_RANDOM);
+ return 1; // Don't ask why.
+}
+
+int TGLC_rand_pseudo_bytes (unsigned char *buf, int num) {
+ gcry_create_nonce (buf, num);
+ return 0; // Don't ask why.
+}
#endif