Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F110626944
D22455.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D22455.diff
View Options
Index: head/sys/dev/random/ivy.c
===================================================================
--- head/sys/dev/random/ivy.c
+++ head/sys/dev/random/ivy.c
@@ -40,6 +40,7 @@
#include <sys/malloc.h>
#include <sys/module.h>
#include <sys/random.h>
+#include <sys/sysctl.h>
#include <sys/systm.h>
#include <machine/md_var.h>
@@ -59,23 +60,46 @@
.rs_read = random_ivy_read
};
+SYSCTL_NODE(_kern_random, OID_AUTO, rdrand, CTLFLAG_RW, 0,
+ "rdrand (ivy) entropy source");
+static bool acquire_independent_seed_samples = false;
+SYSCTL_BOOL(_kern_random_rdrand, OID_AUTO, rdrand_independent_seed,
+ CTLFLAG_RWTUN, &acquire_independent_seed_samples, 0,
+ "If non-zero, use more expensive and slow, but safer, seeded samples "
+ "where RDSEED is not present.");
+
static bool
x86_rdrand_store(u_long *buf)
{
- u_long rndval;
+ u_long rndval, seed_iterations, i;
int retry;
- retry = RETRY_COUNT;
- __asm __volatile(
- "1:\n\t"
- "rdrand %1\n\t" /* read randomness into rndval */
- "jc 2f\n\t" /* CF is set on success, exit retry loop */
- "dec %0\n\t" /* otherwise, retry-- */
- "jne 1b\n\t" /* and loop if retries are not exhausted */
- "2:"
- : "+r" (retry), "=r" (rndval) : : "cc");
+ /* Per [1], "§ 5.2.6 Generating Seeds from RDRAND,"
+ * machines lacking RDSEED will guarantee RDRAND is reseeded every 8kB
+ * of generated output.
+ *
+ * [1]: https://software.intel.com/en-us/articles/intel-digital-random-number-generator-drng-software-implementation-guide#inpage-nav-6-8
+ */
+ if (acquire_independent_seed_samples)
+ seed_iterations = 8 * 1024 / sizeof(*buf);
+ else
+ seed_iterations = 1;
+
+ for (i = 0; i < seed_iterations; i++) {
+ retry = RETRY_COUNT;
+ __asm __volatile(
+ "1:\n\t"
+ "rdrand %1\n\t" /* read randomness into rndval */
+ "jc 2f\n\t" /* CF is set on success, exit retry loop */
+ "dec %0\n\t" /* otherwise, retry-- */
+ "jne 1b\n\t" /* and loop if retries are not exhausted */
+ "2:"
+ : "+r" (retry), "=r" (rndval) : : "cc");
+ if (retry == 0)
+ return (false);
+ }
*buf = rndval;
- return (retry != 0);
+ return (true);
}
static bool
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Feb 22, 2:53 AM (3 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16764882
Default Alt Text
D22455.diff (2 KB)
Attached To
Mode
D22455: random/ivy: Provide mechanism to read independent seed values from rdrand
Attached
Detach File
Event Timeline
Log In to Comment