]>
git.saurik.com Git - apple/xnu.git/blob - bsd/dev/random/YarrowCoreLib/src/prngpriv.h
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
34 Contains: Private typedefs and #defines for Counterpane Yarrow PRNG.
36 Written by: Counterpane, Inc.
38 Copyright: (c) 2000 by Apple Computer, Inc., all rights reserved.
40 Change History (most recent first):
42 02/10/99 dpm Created, based on Counterpane source.
48 Completely private header for the Counterpane PRNG. Should only be included by prng.c
51 #ifndef __YARROW_PRNG_PRIV_H__
52 #define __YARROW_PRNG_PRIV_H__
54 #include "userdefines.h"
55 #include "dev/random/YarrowCoreLib/include/yarrow.h"
56 #include "entropysources.h"
61 #define TOTAL_SOURCES ENTROPY_SOURCES+USER_SOURCES
64 #define COMP_SOURCES TOTAL_SOURCES
66 #define COMP_SOURCES ENTROPY_SOURCES
70 typedef enum prng_ready_status
{
71 PRNG_READY
= 33, /* Compiler will initialize to either 0 or random if allowed to */
75 /* Top level output state */
79 UINT index
; /* current byte to output */
80 UINT numout
; /* bytes since last prng_make_new_state */
83 /* PRNG state structure */
88 /* Entropy Pools (somewhat unlike a gene pool) */
90 UINT poolSize
[TOTAL_SOURCES
]; /* Note that size is in bytes and est in bits */
91 UINT poolEstBits
[TOTAL_SOURCES
];
92 COMP_CTX comp_state
[COMP_SOURCES
];
95 prng_ready_status ready
;
99 * Clients see an opaque PrngRef; internal code uses the
102 typedef struct PRNG PRNG
;
106 #define CHECKSTATE(p) \
107 if(p==NULL) {return PRNG_ERR_NOT_READY;} /* Does the state exist? */ \
108 if(p->ready != PRNG_READY) {return PRNG_ERR_NOT_READY;} /* Set error state and return */
109 /* To make sure that a pointer isn't NULL */
110 #define PCHECK(ptr) if(ptr==NULL) {return PRNG_ERR_NULL_POINTER;}
111 /* To make sure that malloc returned a valid value */
112 #define MCHECK(ptr) if(ptr==NULL) {return PRNG_ERR_LOW_MEMORY;}
113 /* To make sure that a given value is non-negative */
114 #if defined(macintosh) || defined(__APPLE__)
115 /* original looks like a bogon */
116 #define ZCHECK(val) if(val<0) {return PRNG_ERR_OUT_OF_BOUNDS;}
118 #define ZCHECK(val) if(p<0) {return PRNG_ERR_OUT_OF_BOUNDS;}
119 #endif /* macintosh */
120 /* To make sure that the generator state is valid */
121 #define GENCHECK(p) if(p->outstate.index>20) {return PRNG_ERR_OUT_OF_BOUNDS;} /* index is unsigned */
122 /* To make sure that the entropy pool is valid */
123 #define POOLCHECK(p) /* */