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