]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/random/YarrowCoreLib/src/prngpriv.h
xnu-344.49.tar.gz
[apple/xnu.git] / bsd / dev / random / YarrowCoreLib / src / prngpriv.h
1 /*
2 * Copyright (c) 1999, 2000-2001 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
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
13 * file.
14 *
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.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25
26 /*
27 File: prngpriv.h
28
29 Contains: Private typedefs and #defines for Counterpane Yarrow PRNG.
30
31 Written by: Counterpane, Inc.
32
33 Copyright: (c) 2000 by Apple Computer, Inc., all rights reserved.
34
35 Change History (most recent first):
36
37 02/10/99 dpm Created, based on Counterpane source.
38
39 */
40 /*
41 prngpriv.h
42
43 Completely private header for the Counterpane PRNG. Should only be included by prng.c
44 */
45
46 #ifndef __YARROW_PRNG_PRIV_H__
47 #define __YARROW_PRNG_PRIV_H__
48
49 #include "userdefines.h"
50 #include "dev/random/YarrowCoreLib/include/yarrow.h"
51 #include "entropysources.h"
52 #include "comp.h"
53 #include "sha1mod.h"
54 #include "smf.h"
55
56 #define TOTAL_SOURCES ENTROPY_SOURCES+USER_SOURCES
57
58 #ifdef COMPRESSION_ON
59 #define COMP_SOURCES TOTAL_SOURCES
60 #else
61 #define COMP_SOURCES ENTROPY_SOURCES
62 #endif
63
64 /* Error numbers */
65 typedef enum prng_ready_status {
66 PRNG_READY = 33, /* Compiler will initialize to either 0 or random if allowed to */
67 PRNG_NOT_READY = 0
68 } prng_ready_status;
69
70 /* Top level output state */
71 typedef struct{
72 BYTE IV[20];
73 BYTE out[20];
74 UINT index; /* current byte to output */
75 UINT numout; /* bytes since last prng_make_new_state */
76 } GEN_CTX;
77
78 /* PRNG state structure */
79 struct PRNG {
80 /* Output State */
81 GEN_CTX outstate;
82
83 /* Entropy Pools (somewhat unlike a gene pool) */
84 SHA1_CTX 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];
88
89 /* Status Flags */
90 prng_ready_status ready;
91 };
92
93 /*
94 * Clients see an opaque PrngRef; internal code uses the
95 * following typedef.
96 */
97 typedef struct PRNG PRNG;
98
99
100 /* Test Macros */
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;}
112 #else
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) /* */
119
120
121 #endif