aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2021-04-24 03:04:55 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2021-04-24 03:04:55 +0000
commit04689b034404630340221b98e2a5378a853cbc39 (patch)
treee2e393cd7adb04f018f30c8a34836270d7421276
parent635497d5ffde54c2f067b5f053ee8961cbc9d03d (diff)
parent23714ed84501f0b908d036bb428ff1406dbbe29d (diff)
downloadahash-android12-s1-release.tar.gz
Snap for 7310088 from 23714ed84501f0b908d036bb428ff1406dbbe29d to sc-releaseandroid-vts-12.0_r9android-vts-12.0_r8android-vts-12.0_r7android-vts-12.0_r6android-vts-12.0_r5android-vts-12.0_r4android-vts-12.0_r3android-vts-12.0_r2android-vts-12.0_r12android-vts-12.0_r11android-vts-12.0_r10android-vts-12.0_r1android-security-12.0.0_r59android-security-12.0.0_r58android-security-12.0.0_r57android-security-12.0.0_r56android-security-12.0.0_r55android-security-12.0.0_r54android-security-12.0.0_r53android-security-12.0.0_r52android-security-12.0.0_r51android-security-12.0.0_r50android-security-12.0.0_r49android-security-12.0.0_r48android-security-12.0.0_r47android-security-12.0.0_r46android-security-12.0.0_r45android-security-12.0.0_r44android-security-12.0.0_r43android-security-12.0.0_r42android-security-12.0.0_r41android-security-12.0.0_r40android-security-12.0.0_r39android-security-12.0.0_r38android-security-12.0.0_r37android-security-12.0.0_r36android-security-12.0.0_r35android-security-12.0.0_r34android-security-11.0.0_r71android-platform-12.0.0_r9android-platform-12.0.0_r8android-platform-12.0.0_r7android-platform-12.0.0_r6android-platform-12.0.0_r5android-platform-12.0.0_r4android-platform-12.0.0_r31android-platform-12.0.0_r30android-platform-12.0.0_r3android-platform-12.0.0_r29android-platform-12.0.0_r28android-platform-12.0.0_r27android-platform-12.0.0_r26android-platform-12.0.0_r25android-platform-12.0.0_r24android-platform-12.0.0_r23android-platform-12.0.0_r22android-platform-12.0.0_r21android-platform-12.0.0_r20android-platform-12.0.0_r2android-platform-12.0.0_r19android-platform-12.0.0_r18android-platform-12.0.0_r17android-platform-12.0.0_r16android-platform-12.0.0_r15android-platform-12.0.0_r14android-platform-12.0.0_r13android-platform-12.0.0_r12android-platform-12.0.0_r11android-platform-12.0.0_r10android-platform-12.0.0_r1android-cts-12.0_r9android-cts-12.0_r8android-cts-12.0_r7android-cts-12.0_r6android-cts-12.0_r5android-cts-12.0_r4android-cts-12.0_r3android-cts-12.0_r2android-cts-12.0_r12android-cts-12.0_r11android-cts-12.0_r10android-cts-12.0_r1android-12.0.0_r9android-12.0.0_r8android-12.0.0_r34android-12.0.0_r33android-12.0.0_r31android-12.0.0_r30android-12.0.0_r3android-12.0.0_r25android-12.0.0_r2android-12.0.0_r11android-12.0.0_r10android-12.0.0_r1android12-tests-releaseandroid12-security-releaseandroid12-s5-releaseandroid12-s4-releaseandroid12-s3-releaseandroid12-s2-releaseandroid12-s1-releaseandroid12-releaseandroid12-platform-release
Change-Id: Ia414ff9c7d20242a3d689bcc8c07bc2786a2d983
-rw-r--r--patches/0001-Use-dev-urandom-instead-of-getrandom.patch49
-rw-r--r--src/random_state.rs13
2 files changed, 61 insertions, 1 deletions
diff --git a/patches/0001-Use-dev-urandom-instead-of-getrandom.patch b/patches/0001-Use-dev-urandom-instead-of-getrandom.patch
new file mode 100644
index 0000000..d5adff0
--- /dev/null
+++ b/patches/0001-Use-dev-urandom-instead-of-getrandom.patch
@@ -0,0 +1,49 @@
+From 5bce943cdb8fc81525257413f174844d644d63c8 Mon Sep 17 00:00:00 2001
+From: Eric Biggers <ebiggers@google.com>
+Date: Tue, 20 Apr 2021 16:48:07 -0700
+Subject: [PATCH] Use /dev/urandom instead of getrandom()
+
+To generate the ahash crate's default hash keys, use /dev/urandom
+instead of getrandom() to avoid blocking boot on systems where the
+entropy pool isn't initialized in time and where the use case of this
+crate doesn't actually require cryptographic randomness.
+
+If opening or reading from /dev/urandom fails, fall back to getrandom().
+
+Note that std::collections::HashMap doesn't block for randomness either,
+for the same reason. So this change just makes ahash work like HashMap.
+
+Bug: 185934601
+Change-Id: Ie81a1f3a893d578348db11aee114d1a8f2d9fac5
+---
+diff --git a/src/random_state.rs b/src/random_state.rs
+index 501e3eb..9b3b3d0 100644
+--- a/src/random_state.rs
++++ b/src/random_state.rs
+@@ -10,11 +10,22 @@ use core::hash::Hasher;
+ use lazy_static::*;
+ use core::sync::atomic::{AtomicUsize, Ordering};
+
++#[cfg(all(feature = "runtime-rng", not(all(feature = "compile-time-rng", test))))]
++fn read_urandom(dest: &mut [u8]) -> Result<(), std::io::Error> {
++ use std::fs::File;
++ use std::io::Read;
++
++ let mut f = File::open("/dev/urandom")?;
++ f.read_exact(dest)
++}
++
+ #[cfg(all(feature = "runtime-rng", not(all(feature = "compile-time-rng", test))))]
+ lazy_static! {
+ static ref SEEDS: [[u64; 4]; 2] = {
+ let mut result: [u8; 64] = [0; 64];
+- getrandom::getrandom(&mut result).expect("getrandom::getrandom() failed.");
++ if read_urandom(&mut result).is_err() {
++ getrandom::getrandom(&mut result).expect("getrandom::getrandom() failed.")
++ }
+ result.convert()
+ };
+ }
+--
+2.31.1.498.g6c1eba8ee3d-goog
+
diff --git a/src/random_state.rs b/src/random_state.rs
index 501e3eb..9b3b3d0 100644
--- a/src/random_state.rs
+++ b/src/random_state.rs
@@ -11,10 +11,21 @@ use lazy_static::*;
use core::sync::atomic::{AtomicUsize, Ordering};
#[cfg(all(feature = "runtime-rng", not(all(feature = "compile-time-rng", test))))]
+fn read_urandom(dest: &mut [u8]) -> Result<(), std::io::Error> {
+ use std::fs::File;
+ use std::io::Read;
+
+ let mut f = File::open("/dev/urandom")?;
+ f.read_exact(dest)
+}
+
+#[cfg(all(feature = "runtime-rng", not(all(feature = "compile-time-rng", test))))]
lazy_static! {
static ref SEEDS: [[u64; 4]; 2] = {
let mut result: [u8; 64] = [0; 64];
- getrandom::getrandom(&mut result).expect("getrandom::getrandom() failed.");
+ if read_urandom(&mut result).is_err() {
+ getrandom::getrandom(&mut result).expect("getrandom::getrandom() failed.")
+ }
result.convert()
};
}