]> mj.ucw.cz Git - libucw.git/commitdiff
Added a library module for generation of cryptographically secure
authorMartin Mares <mj@ucw.cz>
Fri, 29 Mar 2002 16:34:20 +0000 (16:34 +0000)
committerMartin Mares <mj@ucw.cz>
Fri, 29 Mar 2002 16:34:20 +0000 (16:34 +0000)
random numbers.

lib/Makefile
lib/lib.h
lib/randomkey.c [new file with mode: 0644]

index 9cf5c53b1bb8ff05419633fb3c84cc5998baeb31..2ccb3d0ae3e0518eb44a2d96dd4a178a61a1eaa3 100644 (file)
@@ -7,7 +7,7 @@ SHLIB_OBJS=alloc.o alloc_str.o ctmatch.o db.o fastbuf.o fb-file.o fb-mem.o lists
        log.o log2.o md5.o md5hex.o mmap.o pagecache.o patimatch.o patmatch.o pool.o \
        prime.o random.o realloc.o regex.o timer.o url.o wildmatch.o \
        wordsplit.o str_ctype.o str_upper.o bucket.o conf.o object.o sorter.o \
-       finger.o proctitle.o ipaccess.o profile.o bitsig.o
+       finger.o proctitle.o ipaccess.o profile.o bitsig.o randomkey.o
 
 obj/lib/libsh.a: $(addprefix obj/lib/,$(SHLIB_OBJS))
 
index 22169423260926312e91fe588ac85b6e0bc162e0..dea7c10c8929fa7fe923d24f69bbb78d12204e0a 100644 (file)
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -176,4 +176,8 @@ void munmap_file(void *start, unsigned len);
 void setproctitle_init(int argc, char **argv);
 void setproctitle(char *msg, ...) __attribute__((format(printf,1,2)));
 
+/* randomkey.c */
+
+void randomkey(byte *buf, uns size);
+
 #endif
diff --git a/lib/randomkey.c b/lib/randomkey.c
new file mode 100644 (file)
index 0000000..03cba19
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ *     Sherlock Library -- Cryptographically Safe Random Key Generator
+ *
+ *     (c) 2002 Martin Mares <mj@ucw.cz>
+ */
+
+#include "lib/lib.h"
+
+#include <fcntl.h>
+#include <unistd.h>
+
+void
+randomkey(byte *buf, uns size)
+{
+  int fd;
+
+  if ((fd = open("/dev/urandom", O_RDONLY, 0)) < 0)
+    die("Unable to open /dev/urandom: %m");
+  if (read(fd, buf, size) != (int) size)
+    die("Error reading /dev/urandom: %m");
+  close(fd);
+}