Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/random/other_algorithm.c
/*- | /*- | ||||
* Copyright (c) 2015 Mark R V Murray | * Copyright (c) 2015-2018 Mark R V Murray | ||||
* All rights reserved. | * All rights reserved. | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
* are met: | * are met: | ||||
* 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | ||||
* notice, this list of conditions and the following disclaimer | * notice, this list of conditions and the following disclaimer | ||||
* in this position and unchanged. | * in this position and unchanged. | ||||
Show All 14 Lines | |||||
* | * | ||||
*/ | */ | ||||
/*- | /*- | ||||
* This is a skeleton for folks who wish to build a loadable module | * This is a skeleton for folks who wish to build a loadable module | ||||
* containing an alternative entropy-processing algorithm for random(4). | * containing an alternative entropy-processing algorithm for random(4). | ||||
* | * | ||||
* The functions below should be completed with the appropriate code, | * The functions below should be completed with the appropriate code, | ||||
* and the nearby yarrow.c and fortuna.c may be consulted for examples | * and the nearby fortuna.c may be consulted for examples of working code. | ||||
* of working code. | |||||
* | * | ||||
* The author is willing to provide reasonable help to those wishing to | * The author is willing to provide reasonable help to those wishing to | ||||
* write such a module for themselves. Please use the markm@ FreeBSD | * write such a module for themselves. Please use the markm@ FreeBSD | ||||
* email address, and ensure that you are developing this on a suitably | * email address, and ensure that you are developing this on a suitably | ||||
* supported branch (This is currently 11-CURRENT, and will be no | * supported branch (This is currently 12-CURRENT, and may be no | ||||
* older than 11-STABLE in the future). | * older than 12-STABLE in the future). | ||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/limits.h> | |||||
#ifdef _KERNEL | |||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/lock.h> | #include <sys/lock.h> | ||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
#include <sys/mutex.h> | #include <sys/mutex.h> | ||||
#include <sys/random.h> | #include <sys/random.h> | ||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#include <machine/cpu.h> | #include <machine/cpu.h> | ||||
#include <crypto/rijndael/rijndael-api-fst.h> | #include <crypto/rijndael/rijndael-api-fst.h> | ||||
#include <crypto/sha2/sha256.h> | #include <crypto/sha2/sha256.h> | ||||
#include <dev/random/hash.h> | #include <dev/random/hash.h> | ||||
#include <dev/random/randomdev.h> | #include <dev/random/randomdev.h> | ||||
#include <dev/random/random_harvestq.h> | #include <dev/random/random_harvestq.h> | ||||
#include <dev/random/uint128.h> | #include <dev/random/uint128.h> | ||||
#include <dev/random/other_algorithm.h> | #include <dev/random/other_algorithm.h> | ||||
#else /* !_KERNEL */ | |||||
#include <inttypes.h> | |||||
#include <stdbool.h> | |||||
#include <stdio.h> | |||||
#include <stdlib.h> | |||||
#include <string.h> | |||||
#include <threads.h> | |||||
#include "unit_test.h" | |||||
#include <crypto/rijndael/rijndael-api-fst.h> | |||||
#include <crypto/sha2/sha256.h> | |||||
#include <dev/random/hash.h> | |||||
#include <dev/random/randomdev.h> | |||||
#include <dev/random/uint128.h> | |||||
#include <dev/random/other_algorithm.h> | |||||
#endif /* _KERNEL */ | |||||
static void random_other_pre_read(void); | static void random_other_pre_read(void); | ||||
static void random_other_read(uint8_t *, u_int); | static void random_other_read(uint8_t *, u_int); | ||||
static bool random_other_seeded(void); | static bool random_other_seeded(void); | ||||
static void random_other_process_event(struct harvest_event *); | static void random_other_process_event(struct harvest_event *); | ||||
static void random_other_init_alg(void *); | static void random_other_init_alg(void *); | ||||
static void random_other_deinit_alg(void *); | static void random_other_deinit_alg(void *); | ||||
/* | /* | ||||
* RANDOM_OTHER_NPOOLS is used when reading hardware random | * RANDOM_OTHER_NPOOLS is used when reading hardware random | ||||
* number sources to ensure that each pool gets one read sample | * number sources to ensure that each pool gets one read sample | ||||
* per loop iteration. Yarrow has 2 such pools (FAST and SLOW), | * per loop iteration. Fortuna has 32 (0-31). | ||||
* and fortuna has 32 (0-31). The RNG used prior to Yarrow and | |||||
* ported from Linux had just 1 pool. | |||||
*/ | */ | ||||
#define RANDOM_OTHER_NPOOLS 1 | #define RANDOM_OTHER_NPOOLS 1 | ||||
struct random_algorithm random_alg_context = { | struct random_algorithm random_alg_context = { | ||||
.ra_ident = "other", | .ra_ident = "other", | ||||
.ra_init_alg = random_other_init_alg, | .ra_init_alg = random_other_init_alg, | ||||
.ra_deinit_alg = random_other_deinit_alg, | .ra_deinit_alg = random_other_deinit_alg, | ||||
.ra_pre_read = random_other_pre_read, | .ra_pre_read = random_other_pre_read, | ||||
▲ Show 20 Lines • Show All 123 Lines • Show Last 20 Lines |