]>
git.saurik.com Git - apple/xnu.git/blob - bsd/dev/random/YarrowCoreLib/src/prngpriv.h
2 * Copyright (c) 1999, 2000-2001 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 Contains: Private typedefs and #defines for Counterpane Yarrow PRNG.
34 Written by: Counterpane, Inc.
36 Copyright: (c) 2000 by Apple Computer, Inc., all rights reserved.
38 Change History (most recent first):
40 02/10/99 dpm Created, based on Counterpane source.
46 Completely private header for the Counterpane PRNG. Should only be included by prng.c
49 #ifndef __YARROW_PRNG_PRIV_H__
50 #define __YARROW_PRNG_PRIV_H__
52 #include "userdefines.h"
53 #include "dev/random/YarrowCoreLib/include/yarrow.h"
54 #include "entropysources.h"
59 #define TOTAL_SOURCES ENTROPY_SOURCES+USER_SOURCES
62 #define COMP_SOURCES TOTAL_SOURCES
64 #define COMP_SOURCES ENTROPY_SOURCES
68 typedef enum prng_ready_status
{
69 PRNG_READY
= 33, /* Compiler will initialize to either 0 or random if allowed to */
73 /* Top level output state */
77 UINT index
; /* current byte to output */
78 UINT numout
; /* bytes since last prng_make_new_state */
81 /* PRNG state structure */
86 /* Entropy Pools (somewhat unlike a gene pool) */
88 UINT poolSize
[TOTAL_SOURCES
]; /* Note that size is in bytes and est in bits */
89 UINT poolEstBits
[TOTAL_SOURCES
];
90 COMP_CTX comp_state
[COMP_SOURCES
];
93 prng_ready_status ready
;
97 * Clients see an opaque PrngRef; internal code uses the
100 typedef struct PRNG PRNG
;
104 #define CHECKSTATE(p) \
105 if(p==NULL) {return PRNG_ERR_NOT_READY;} /* Does the state exist? */ \
106 if(p->ready != PRNG_READY) {return PRNG_ERR_NOT_READY;} /* Set error state and return */
107 /* To make sure that a pointer isn't NULL */
108 #define PCHECK(ptr) if(ptr==NULL) {return PRNG_ERR_NULL_POINTER;}
109 /* To make sure that malloc returned a valid value */
110 #define MCHECK(ptr) if(ptr==NULL) {return PRNG_ERR_LOW_MEMORY;}
111 /* To make sure that a given value is non-negative */
112 #if defined(macintosh) || defined(__APPLE__)
113 /* original looks like a bogon */
114 #define ZCHECK(val) if(val<0) {return PRNG_ERR_OUT_OF_BOUNDS;}
116 #define ZCHECK(val) if(p<0) {return PRNG_ERR_OUT_OF_BOUNDS;}
117 #endif /* macintosh */
118 /* To make sure that the generator state is valid */
119 #define GENCHECK(p) if(p->outstate.index>20) {return PRNG_ERR_OUT_OF_BOUNDS;} /* index is unsigned */
120 /* To make sure that the entropy pool is valid */
121 #define POOLCHECK(p) /* */