1 /* $NetBSD: cprng.h,v 1.17 2020/04/30 03:28:19 riastradh Exp $ */ 2 3 /*- 4 * Copyright (c) 2011-2013 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Thor Lancelot Simon and Taylor R. Campbell. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 /* 33 * XXX Don't change this to _SYS_CPRNG_H or anything -- code outside 34 * this file relies on its name... (I'm looking at you, ipf!) 35 */ 36 #ifndef _CPRNG_H 37 #define _CPRNG_H 38 39 #include <sys/types.h> 40 41 #include <crypto/nist_hash_drbg/nist_hash_drbg.h> 42 #include <crypto/cprng_fast/cprng_fast.h> 43 44 #define CPRNG_MAX_LEN NIST_HASH_DRBG_MAX_REQUEST_BYTES 45 46 typedef struct cprng_strong cprng_strong_t; 47 48 void cprng_init(void); 49 50 #define CPRNG_INIT_ANY 0x00000001 51 #define CPRNG_REKEY_ANY 0x00000002 52 #define CPRNG_USE_CV 0x00000004 53 #define CPRNG_HARD 0x00000008 54 #define CPRNG_FMT "\177\020\ 55 b\0INIT_ANY\0\ 56 b\1REKEY_ANY\0\ 57 b\2USE_CV\0\ 58 b\3HARD\0" 59 60 cprng_strong_t * 61 cprng_strong_create(const char *, int, int); 62 void cprng_strong_destroy(cprng_strong_t *); 63 size_t cprng_strong(cprng_strong_t *, void *, size_t, int); 64 65 extern cprng_strong_t *kern_cprng; /* IPL_VM */ 66 extern cprng_strong_t *user_cprng; /* IPL_NONE, thread context only */ 67 68 uint32_t cprng_strong32(void); 69 uint64_t cprng_strong64(void); 70 71 #endif /* _CPRNG_H */ 72