32ef372
From 5d38da6d4eb29bf87e98a5cb4577b870dbf405ed Mon Sep 17 00:00:00 2001
32ef372
From: Robbie Harwood <rharwood@redhat.com>
32ef372
Date: Wed, 14 Sep 2016 16:12:57 -0400
32ef372
Subject: [PATCH] Add OS prng intended for use with getrandom()
32ef372
32ef372
Add the prng_os.c module, using the name previously occupied by what
32ef372
is now prng_device.c.  Unlike prng_device.c, this PRNG module
32ef372
maintains no file descriptor and just uses k5_os_random(), which is
32ef372
most efficient on platforms which have a getrandom() system call.
32ef372
32ef372
[ghudson@mit.edu: expanded on commit message]
32ef372
32ef372
ticket: 8499
32ef372
(cherry picked from commit 0be7642b2b6f7b9e0acebb2c3d60aa6c3f7543aa)
32ef372
---
32ef372
 src/lib/crypto/krb/prng_os.c | 72 ++++++++++++++++++++++++++++++++++++++++++++
32ef372
 1 file changed, 72 insertions(+)
32ef372
 create mode 100644 src/lib/crypto/krb/prng_os.c
32ef372
32ef372
diff --git a/src/lib/crypto/krb/prng_os.c b/src/lib/crypto/krb/prng_os.c
32ef372
new file mode 100644
32ef372
index 0000000..8ea13e7
32ef372
--- /dev/null
32ef372
+++ b/src/lib/crypto/krb/prng_os.c
32ef372
@@ -0,0 +1,72 @@
32ef372
+/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
32ef372
+/* lib/crypto/krb/prng_os.c - OS PRNG implementation */
32ef372
+/*
32ef372
+ * Copyright (C) 2016 by the Massachusetts Institute of Technology.
32ef372
+ * All rights reserved.
32ef372
+ *
32ef372
+ * Redistribution and use in source and binary forms, with or without
32ef372
+ * modification, are permitted provided that the following conditions
32ef372
+ * are met:
32ef372
+ *
32ef372
+ * * Redistributions of source code must retain the above copyright
32ef372
+ *   notice, this list of conditions and the following disclaimer.
32ef372
+ *
32ef372
+ * * Redistributions in binary form must reproduce the above copyright
32ef372
+ *   notice, this list of conditions and the following disclaimer in
32ef372
+ *   the documentation and/or other materials provided with the
32ef372
+ *   distribution.
32ef372
+ *
32ef372
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32ef372
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32ef372
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
32ef372
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32ef372
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
32ef372
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
32ef372
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32ef372
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32ef372
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32ef372
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32ef372
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
32ef372
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
32ef372
+ */
32ef372
+
32ef372
+/*
32ef372
+ * This file implements a PRNG module which relies on the system's PRNG.  An
32ef372
+ * OS packager can select this module given sufficient confidence in the
32ef372
+ * operating system's native PRNG quality.
32ef372
+ */
32ef372
+
32ef372
+#include "crypto_int.h"
32ef372
+
32ef372
+int
32ef372
+k5_prng_init(void)
32ef372
+{
32ef372
+    return 0;
32ef372
+}
32ef372
+
32ef372
+void
32ef372
+k5_prng_cleanup(void)
32ef372
+{
32ef372
+}
32ef372
+
32ef372
+krb5_error_code KRB5_CALLCONV
32ef372
+krb5_c_random_add_entropy(krb5_context context, unsigned int randsource,
32ef372
+                          const krb5_data *indata)
32ef372
+{
32ef372
+    return 0;
32ef372
+}
32ef372
+
32ef372
+krb5_error_code KRB5_CALLCONV
32ef372
+krb5_c_random_make_octets(krb5_context context, krb5_data *outdata)
32ef372
+{
32ef372
+    krb5_boolean res;
32ef372
+
32ef372
+    res = k5_get_os_entropy((uint8_t *)outdata->data, outdata->length, 0);
32ef372
+    return res ? 0 : KRB5_CRYPTO_INTERNAL;
32ef372
+}
32ef372
+
32ef372
+krb5_error_code KRB5_CALLCONV
32ef372
+krb5_c_random_os_entropy(krb5_context context, int strong, int *success)
32ef372
+{
32ef372
+    return 0;
32ef372
+}
32ef372
-- 
32ef372
2.9.3
32ef372