|
|
6d61af |
diff -up ntp-4.2.6p5/include/ntp_random.h.orig ntp-4.2.6p5/include/ntp_random.h
|
|
|
6d61af |
--- ntp-4.2.6p5/include/ntp_random.h.orig 2009-12-09 08:36:35.000000000 +0100
|
|
|
6d61af |
+++ ntp-4.2.6p5/include/ntp_random.h 2014-12-19 16:01:32.450628801 +0100
|
|
|
6d61af |
@@ -1,6 +1,9 @@
|
|
|
6d61af |
|
|
|
6d61af |
#include <ntp_types.h>
|
|
|
6d61af |
|
|
|
6d61af |
+void ntp_crypto_srandom(void);
|
|
|
6d61af |
+int ntp_crypto_random_buf(void *buf, size_t nbytes);
|
|
|
6d61af |
+
|
|
|
6d61af |
long ntp_random (void);
|
|
|
6d61af |
void ntp_srandom (unsigned long);
|
|
|
6d61af |
void ntp_srandomdev (void);
|
|
|
6d61af |
diff -up ntp-4.2.6p5/libntp/ntp_random.c.orig ntp-4.2.6p5/libntp/ntp_random.c
|
|
|
6d61af |
--- ntp-4.2.6p5/libntp/ntp_random.c.orig 2009-12-09 08:36:36.000000000 +0100
|
|
|
6d61af |
+++ ntp-4.2.6p5/libntp/ntp_random.c 2014-12-19 16:04:32.069016676 +0100
|
|
|
6d61af |
@@ -481,3 +481,63 @@ ntp_random( void )
|
|
|
6d61af |
}
|
|
|
6d61af |
return(i);
|
|
|
6d61af |
}
|
|
|
6d61af |
+
|
|
|
6d61af |
+/*
|
|
|
6d61af |
+ * Crypto-quality random number functions
|
|
|
6d61af |
+ *
|
|
|
6d61af |
+ * Author: Harlan Stenn, 2014
|
|
|
6d61af |
+ *
|
|
|
6d61af |
+ * This file is Copyright (c) 2014 by Network Time Foundation.
|
|
|
6d61af |
+ * BSD terms apply: see the file COPYRIGHT in the distribution root for details.
|
|
|
6d61af |
+ */
|
|
|
6d61af |
+
|
|
|
6d61af |
+#include <openssl/err.h>
|
|
|
6d61af |
+#include <openssl/rand.h>
|
|
|
6d61af |
+
|
|
|
6d61af |
+int crypto_rand_init = 0;
|
|
|
6d61af |
+
|
|
|
6d61af |
+/*
|
|
|
6d61af |
+ * ntp_crypto_srandom:
|
|
|
6d61af |
+ *
|
|
|
6d61af |
+ * Initialize the random number generator, if needed by the underlying
|
|
|
6d61af |
+ * crypto random number generation mechanism.
|
|
|
6d61af |
+ */
|
|
|
6d61af |
+
|
|
|
6d61af |
+void
|
|
|
6d61af |
+ntp_crypto_srandom(
|
|
|
6d61af |
+ void
|
|
|
6d61af |
+ )
|
|
|
6d61af |
+{
|
|
|
6d61af |
+ if (!crypto_rand_init) {
|
|
|
6d61af |
+ RAND_poll();
|
|
|
6d61af |
+ crypto_rand_init = 1;
|
|
|
6d61af |
+ }
|
|
|
6d61af |
+}
|
|
|
6d61af |
+
|
|
|
6d61af |
+/*
|
|
|
6d61af |
+ * ntp_crypto_random_buf:
|
|
|
6d61af |
+ *
|
|
|
6d61af |
+ * Returns 0 on success, -1 on error.
|
|
|
6d61af |
+ */
|
|
|
6d61af |
+int
|
|
|
6d61af |
+ntp_crypto_random_buf(
|
|
|
6d61af |
+ void *buf,
|
|
|
6d61af |
+ size_t nbytes
|
|
|
6d61af |
+ )
|
|
|
6d61af |
+{
|
|
|
6d61af |
+ int rc;
|
|
|
6d61af |
+
|
|
|
6d61af |
+ rc = RAND_bytes(buf, nbytes);
|
|
|
6d61af |
+ if (1 != rc) {
|
|
|
6d61af |
+ unsigned long err;
|
|
|
6d61af |
+ char *err_str;
|
|
|
6d61af |
+
|
|
|
6d61af |
+ err = ERR_get_error();
|
|
|
6d61af |
+ err_str = ERR_error_string(err, NULL);
|
|
|
6d61af |
+ /* XXX: Log the error */
|
|
|
6d61af |
+
|
|
|
6d61af |
+ return -1;
|
|
|
6d61af |
+ }
|
|
|
6d61af |
+ return 0;
|
|
|
6d61af |
+}
|
|
|
6d61af |
+
|
|
|
6d61af |
diff -up ntp-4.2.6p5/util/ntp-keygen.c.orig ntp-4.2.6p5/util/ntp-keygen.c
|
|
|
6d61af |
--- ntp-4.2.6p5/util/ntp-keygen.c.orig 2014-12-19 15:27:38.375236349 +0100
|
|
|
6d61af |
+++ ntp-4.2.6p5/util/ntp-keygen.c 2014-12-19 15:58:00.006170042 +0100
|
|
|
6d61af |
@@ -263,6 +263,8 @@ main(
|
|
|
6d61af |
ssl_check_version();
|
|
|
6d61af |
#endif /* OPENSSL */
|
|
|
6d61af |
|
|
|
6d61af |
+ ntp_crypto_srandom();
|
|
|
6d61af |
+
|
|
|
6d61af |
/*
|
|
|
6d61af |
* Process options, initialize host name and timestamp.
|
|
|
6d61af |
*/
|
|
|
6d61af |
@@ -743,7 +745,14 @@ gen_md5(
|
|
|
6d61af |
int temp;
|
|
|
6d61af |
|
|
|
6d61af |
while (1) {
|
|
|
6d61af |
- temp = ntp_random() & 0xff;
|
|
|
6d61af |
+ int rc;
|
|
|
6d61af |
+
|
|
|
6d61af |
+ rc = ntp_crypto_random_buf(&temp, 1);
|
|
|
6d61af |
+ if (-1 == rc) {
|
|
|
6d61af |
+ fprintf(stderr, "ntp_crypto_random_buf() failed.\n");
|
|
|
6d61af |
+ exit (-1);
|
|
|
6d61af |
+ }
|
|
|
6d61af |
+ temp &= 0xff;
|
|
|
6d61af |
if (temp == '#')
|
|
|
6d61af |
continue;
|
|
|
6d61af |
|