]>
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_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
29 Contains: Private typedefs and #defines for Counterpane Yarrow PRNG.
31 Written by: Counterpane, Inc.
33 Copyright: (c) 2000 by Apple Computer, Inc., all rights reserved.
35 Change History (most recent first):
37 02/10/99 dpm Created, based on Counterpane source.
43 Completely private header for the Counterpane PRNG. Should only be included by prng.c
46 #ifndef __YARROW_PRNG_PRIV_H__
47 #define __YARROW_PRNG_PRIV_H__
49 #include "userdefines.h"
50 #include "dev/random/YarrowCoreLib/include/yarrow.h"
51 #include "entropysources.h"
56 #define TOTAL_SOURCES ENTROPY_SOURCES+USER_SOURCES
59 #define COMP_SOURCES TOTAL_SOURCES
61 #define COMP_SOURCES ENTROPY_SOURCES
65 typedef enum prng_ready_status
{
66 PRNG_READY
= 33, /* Compiler will initialize to either 0 or random if allowed to */
70 /* Top level output state */
74 UINT index
; /* current byte to output */
75 UINT numout
; /* bytes since last prng_make_new_state */
78 /* PRNG state structure */
83 /* Entropy Pools (somewhat unlike a gene pool) */
85 UINT poolSize
[TOTAL_SOURCES
]; /* Note that size is in bytes and est in bits */
86 UINT poolEstBits
[TOTAL_SOURCES
];
87 COMP_CTX comp_state
[COMP_SOURCES
];
90 prng_ready_status ready
;
94 * Clients see an opaque PrngRef; internal code uses the
97 typedef struct PRNG PRNG
;
101 #define CHECKSTATE(p) \
102 if(p==NULL) {return PRNG_ERR_NOT_READY;} /* Does the state exist? */ \
103 if(p->ready != PRNG_READY) {return PRNG_ERR_NOT_READY;} /* Set error state and return */
104 /* To make sure that a pointer isn't NULL */
105 #define PCHECK(ptr) if(ptr==NULL) {return PRNG_ERR_NULL_POINTER;}
106 /* To make sure that malloc returned a valid value */
107 #define MCHECK(ptr) if(ptr==NULL) {return PRNG_ERR_LOW_MEMORY;}
108 /* To make sure that a given value is non-negative */
109 #if defined(macintosh) || defined(__APPLE__)
110 /* original looks like a bogon */
111 #define ZCHECK(val) if(val<0) {return PRNG_ERR_OUT_OF_BOUNDS;}
113 #define ZCHECK(val) if(p<0) {return PRNG_ERR_OUT_OF_BOUNDS;}
114 #endif /* macintosh */
115 /* To make sure that the generator state is valid */
116 #define GENCHECK(p) if(p->outstate.index>20) {return PRNG_ERR_OUT_OF_BOUNDS;} /* index is unsigned */
117 /* To make sure that the entropy pool is valid */
118 #define POOLCHECK(p) /* */