/* * VMS_RANDOM.H * * VMS-specific definitions for the FreeBSD random number support via * Fortuna. * * The major purpose of this module is to bridge the set of bits defined * in RNDBITDEF.SDL (which are the useful bits controlling the collectors * in VMS terms) and the enum random_entropy_source which the FreeBSD C * code expects. * * Author: Doug Gordon * * Edit History: * * X-1 DAG Doug Gordon 1-Feb-2022 * Original. */ #ifndef _VMS_RANDOM_H_ #define _VMS_RANDOM_H_ /* * We want the __NEW_STARLET flavors of our VMS include files but don't * want to chance disrupting code that includes this header. */ #ifndef __NEW_STARLET #define __NEW_STARLET #define __UNDEF_NEW_STARLET #endif #include #include extern volatile uint64 EXE$GL_ACTIVE_RANDOM_SOURCES; /* * Time between entropy roll-ups from the harvesters * One tenth of a second as delta time, in decimal */ #define ONE_TENTH_SEC 1000000LL /* * Fix a stupid problem in RNDBITDEF.H which can be adjusted at a later time */ #ifdef RNDBIT$M_PURE_RDRND #define RNDBIT$M_PURE_RDRAND RNDBIT$M_PURE_RDRND #define rndbit$v_pure_rdrand rndbit$v_pure_rdrnd #define RANDOM$K_PURE_RDRAND RANDOM$K_PURE_RDRND #endif /* * enum of the various source. Some symbols are retained from the FreeBSD * flavor for things that *might* get support. NI indicates Not Implemented * at this point. */ enum random_entropy_source { RANDOM_START = 0, RANDOM_CACHED = RANDOM$K_CACHED, /* Environmental sources */ RANDOM_ATTACH = RANDOM$K_ATTACH, /* Device attachment - NI */ RANDOM_PERCPU = RANDOM$K_PERCPU, /* Per-CPU counters */ RANDOM_LCKMGR = RANDOM$K_LCKMGR, /* Lock Manager */ RANDOM_CLUSTER = RANDOM$K_CLUSTER, /* Cluster hooks */ RANDOM_NET_TUN = RANDOM$K_NET_TUN, /* Write to tunnel - NI */ RANDOM_NET_ETHER = RANDOM$K_NET_ETHER, /* Write ethernet packet */ RANDOM_INTERRUPT = RANDOM$K_INTERRUPT, /* Device Interrupts */ RANDOM_SWI = RANDOM$K_SWI, /* Software Interrupts */ RANDOM_FS_ATIME = RANDOM$K_FS_ATIME, /* File System */ RANDOM_NPP = RANDOM$K_NPP, /* Pool Packet deallocation */ RANDOM_UMA = RANDOM_NPP, /* Special!! UMA/SLAB Allocator */ RANDOM_ENVIRONMENTAL_END = RANDOM_UMA, /* Fast hardware random-number sources from here on. */ RANDOM_PURE_START = RANDOM$K_RANDOM_PURE_START, RANDOM_PURE_RDRAND = RANDOM$K_PURE_RDRND, /* X86 RDRAND instruction */ RANDOM_PURE_VIRTIO = RANDOM$K_PURE_VIRTIO, /* VIRTIO Entropy driver - NI */ ENTROPYSOURCE }; #define RANDOM_HARVEST_EVERYTHING_MASK ((1 << (RANDOM_ENVIRONMENTAL_END + 1)) - 1) #define RANDOM_HARVEST_PURE_MASK (((1 << ENTROPYSOURCE) - 1) & (-1UL << RANDOM_PURE_START)) /* * Random harvest routine prototypes */ /* Queued entropy - most common routine */ void exe$random_harvest_queue(const void *entropy, u_int size, enum random_entropy_source origin); /* Fast harvest - high data rate sources */ void exe$random_harvest_fast(const void *entropy, u_int size); /* Direct entropy harvesting - copy straight to Fortuna */ void exe$random_harvest_direct(const void *entropy, u_int size, enum random_entropy_source origin); /* * Macros to ease some of the common calls */ #define RANDOM_SOURCE(BIT) ((EXE$GL_ACTIVE_RANDOM_SOURCES & RNDBIT$M_##BIT) != 0) #define NPP_ENTROPY_HARVEST(packet, size) if (RANDOM_SOURCE(NPP)) exe$random_harvest_fast(packet, size) #ifdef __UNDEF_NEW_STARLET #undef __NEW_STARLET #undef __UNDEF_NEW_STARLET #endif #endif /* _VMS_RANDOM_H_ */