Changeset View
Standalone View
sys/sys/random.h
Show First 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | enum random_entropy_source { | ||||
RANDOM_PURE_RNDTEST, | RANDOM_PURE_RNDTEST, | ||||
RANDOM_PURE_VIRTIO, | RANDOM_PURE_VIRTIO, | ||||
RANDOM_PURE_BROADCOM, | RANDOM_PURE_BROADCOM, | ||||
RANDOM_PURE_CCP, | RANDOM_PURE_CCP, | ||||
ENTROPYSOURCE | ENTROPYSOURCE | ||||
}; | }; | ||||
#define RANDOM_HARVEST_EVERYTHING_MASK ((1 << (RANDOM_ENVIRONMENTAL_END + 1)) - 1) | #define RANDOM_HARVEST_EVERYTHING_MASK ((1 << (RANDOM_ENVIRONMENTAL_END + 1)) - 1) | ||||
#define RANDOM_HARVEST_PURE_MASK (((1 << ENTROPYSOURCE) - 1) & (-1UL << RANDOM_PURE_START)) | #define RANDOM_HARVEST_PURE_MASK (((1 << ENTROPYSOURCE) - 1) & (-1UL << RANDOM_PURE_START)) | ||||
#define RANDOM_LEGACY_BOOT_ENTROPY_MODULE "/boot/entropy" | #define RANDOM_LEGACY_BOOT_ENTROPY_MODULE "/boot/entropy" | ||||
#define RANDOM_CACHED_BOOT_ENTROPY_MODULE "boot_entropy_cache" | #define RANDOM_CACHED_BOOT_ENTROPY_MODULE "boot_entropy_cache" | ||||
cem: This special casing is a little dubious — e.g., PPC64 has TRNG since POWER7 and is more than… | |||||
#define RANDOM_CACHED_SKIP_START 256 | #define RANDOM_CACHED_SKIP_START 256 | ||||
#if defined(DEV_RANDOM) | #if defined(DEV_RANDOM) | ||||
void random_harvest_queue(const void *, u_int, u_int, enum random_entropy_source); | extern u_int hc_source_mask; | ||||
void random_harvest_fast(const void *, u_int, u_int, enum random_entropy_source); | void random_harvest_queue_(const void *, u_int, u_int, enum random_entropy_source); | ||||
void random_harvest_direct(const void *, u_int, u_int, enum random_entropy_source); | void random_harvest_fast_(const void *, u_int, u_int); | ||||
void random_harvest_direct_(const void *, u_int, u_int, enum random_entropy_source); | |||||
static __inline void | |||||
random_harvest_queue(const void *entropy, u_int size, u_int bits, | |||||
enum random_entropy_source origin) | |||||
{ | |||||
if (hc_source_mask & (1 << origin)) | |||||
Not Done Inline ActionsI don't think the predict_false's make sense here. cem: I don't think the predict_false's make sense here. | |||||
Not Done Inline Actionswhy do you think it does not make sense? it helps the compiler *avoid* a forward jump in the common case of the feature not being enabled - instead it will be more likely to insert a jmp to a section which calls random_harvest_queue_ and then jumps back. a case which arguably is already heavily pessimized. so i would argue it makes excellent sense. mjg: why do you think it does not make sense? it helps the compiler *avoid* a forward jump in the… | |||||
Not Done Inline ActionsWhy do you think that features being disabled is the common case? E.g., I would expect pure sources to be both enabled and sampled reasonably often. The __predict_false will mispredict those. Additionally, CPU branch predictors have been smart enough to predict the branch correctly for disabled sources since the 90s. I think predict_false/true should only be used when we're actually going to be smarter than the runtime branch predictor. cem: Why do you think that features being disabled is the common case? E.g., I would expect pure… | |||||
random_harvest_queue_(entropy, size, bits, origin); | |||||
} | |||||
static __inline void | |||||
random_harvest_fast(const void *entropy, u_int size, u_int bits, | |||||
enum random_entropy_source origin) | |||||
{ | |||||
if (hc_source_mask & (1 << origin)) | |||||
random_harvest_fast_(entropy, size, bits); | |||||
} | |||||
static __inline void | |||||
random_harvest_direct(const void *entropy, u_int size, u_int bits, | |||||
enum random_entropy_source origin) | |||||
{ | |||||
if (hc_source_mask & (1 << origin)) | |||||
random_harvest_direct_(entropy, size, bits, origin); | |||||
} | |||||
void random_harvest_register_source(enum random_entropy_source); | void random_harvest_register_source(enum random_entropy_source); | ||||
void random_harvest_deregister_source(enum random_entropy_source); | void random_harvest_deregister_source(enum random_entropy_source); | ||||
#else | #else | ||||
#define random_harvest_queue(a, b, c, d) do {} while (0) | #define random_harvest_queue(a, b, c, d) do {} while (0) | ||||
#define random_harvest_fast(a, b, c, d) do {} while (0) | #define random_harvest_fast(a, b, c, d) do {} while (0) | ||||
#define random_harvest_direct(a, b, c, d) do {} while (0) | #define random_harvest_direct(a, b, c, d) do {} while (0) | ||||
#define random_harvest_register_source(a) do {} while (0) | #define random_harvest_register_source(a) do {} while (0) | ||||
#define random_harvest_deregister_source(a) do {} while (0) | #define random_harvest_deregister_source(a) do {} while (0) | ||||
#endif | #endif | ||||
#if defined(RANDOM_ENABLE_UMA) | #if defined(RANDOM_ENABLE_UMA) | ||||
#define random_harvest_fast_uma(a, b, c, d) random_harvest_fast(a, b, c, d) | #define random_harvest_fast_uma(a, b, c, d) random_harvest_fast(a, b, c, d) | ||||
#else /* !defined(RANDOM_ENABLE_UMA) */ | #else /* !defined(RANDOM_ENABLE_UMA) */ | ||||
#define random_harvest_fast_uma(a, b, c, d) do {} while (0) | #define random_harvest_fast_uma(a, b, c, d) do {} while (0) | ||||
#endif /* defined(RANDOM_ENABLE_UMA) */ | #endif /* defined(RANDOM_ENABLE_UMA) */ | ||||
#if defined(RANDOM_ENABLE_ETHER) | |||||
#define random_harvest_queue_ether(a, b, c) random_harvest_queue(a, b, c, RANDOM_NET_ETHER) | |||||
Not Done Inline Actionscomment mismatch cem: comment mismatch | |||||
#else /* !defined(RANDOM_ENABLE_ETHER) */ | |||||
Not Done Inline Actionscomment mismatch cropped up again cem: comment mismatch cropped up again | |||||
#define random_harvest_queue_ether(a, b, c) do {} while (0) | |||||
#endif /* defined(RANDOM_ENABLE_ETHER) */ | |||||
#endif /* _KERNEL */ | #endif /* _KERNEL */ | ||||
#define GRND_NONBLOCK 0x1 | #define GRND_NONBLOCK 0x1 | ||||
#define GRND_RANDOM 0x2 | #define GRND_RANDOM 0x2 | ||||
ssize_t getrandom(void *buf, size_t buflen, unsigned int flags); | ssize_t getrandom(void *buf, size_t buflen, unsigned int flags); | ||||
#endif /* _SYS_RANDOM_H_ */ | #endif /* _SYS_RANDOM_H_ */ |
This special casing is a little dubious — e.g., PPC64 has TRNG since POWER7 and is more than capable of driving the same high-throughput NICs as amd64.
I'm leaning towards just disable it for all arch. *Maybe* add a runtime test to detect other sources of entropy and enable it if there's nothing else. Then again, the data is not very random (or not at all random for non-jumbo frames? Not sure we ever determined that), so maybe it's useless there too.