summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hbbp_keygen.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/hbbp_keygen.c b/hbbp_keygen.c
index 6bcde5c..f464441 100644
--- a/hbbp_keygen.c
+++ b/hbbp_keygen.c
@@ -2,9 +2,9 @@
#include <sys/stat.h>
#include <fcntl.h>
+#include "common.h"
#include "crypto.h"
-
#define pub_len crypto_box_PUBLICKEYBYTES
#define priv_len crypto_box_SECRETKEYBYTES
@@ -16,6 +16,27 @@ void error_cleanup(int num) {
exit(1);
}
+// used by nacl's crypto_box_keypair
+void randombytes(byte *buf, unsigned long long len)
+ __attribute__ ((externally_visible));
+
+void randombytes(byte *buf, unsigned long long len) {
+ int fd = open("/dev/urandom", O_RDONLY);
+ if (fd == -1) goto error;
+
+ while (len > 0) {
+ int sz = read(fd, buf, len);
+ if (sz < 1) goto error;
+ buf += sz;
+ len -= sz;
+ }
+ return;
+
+ error:
+ perror("failed accessing /dev/urandom");
+ error_cleanup(4);
+}
+
int main() {
int fd[4], i;
byte key_pub [2][pub_len],
contact: Jan Huwald // Impressum