]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/random/YarrowCoreLib/src/prngpriv.h
xnu-792.6.56.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 * 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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /*
25 File: prngpriv.h
26
27 Contains: Private typedefs and #defines for Counterpane Yarrow PRNG.
28
29 Written by: Counterpane, Inc.
30
31 Copyright: (c) 2000 by Apple Computer, Inc., all rights reserved.
32
33 Change History (most recent first):
34
35 02/10/99 dpm Created, based on Counterpane source.
36
37 */
38 /*
39 prngpriv.h
40
41 Completely private header for the Counterpane PRNG. Should only be included by prng.c
42 */
43
44 #ifndef __YARROW_PRNG_PRIV_H__
45 #define __YARROW_PRNG_PRIV_H__
46
47 #include "userdefines.h"
48 #include "dev/random/YarrowCoreLib/include/yarrow.h"
49 #include "entropysources.h"
50 #include "comp.h"
51 #include "sha1mod.h"
52 #include "smf.h"
53
54 #define TOTAL_SOURCES ENTROPY_SOURCES+USER_SOURCES
55
56 #ifdef COMPRESSION_ON
57 #define COMP_SOURCES TOTAL_SOURCES
58 #else
59 #define COMP_SOURCES ENTROPY_SOURCES
60 #endif
61
62 /* Error numbers */
63 typedef enum prng_ready_status {
64 PRNG_READY = 33, /* Compiler will initialize to either 0 or random if allowed to */
65 PRNG_NOT_READY = 0
66 } prng_ready_status;
67
68 /* Top level output state */
69 typedef struct{
70 BYTE IV[20];
71 BYTE out[20];
72 UINT index; /* current byte to output */
73 UINT numout; /* bytes since last prng_make_new_state */
74 } GEN_CTX;
75
76 /* PRNG state structure */
77 struct PRNG {
78 /* Output State */
79 GEN_CTX outstate;
80
81 /* Entropy Pools (somewhat unlike a gene pool) */
82 SHA1_CTX pool;
83 UINT poolSize[TOTAL_SOURCES]; /* Note that size is in bytes and est in bits */
84 UINT poolEstBits[TOTAL_SOURCES];
85 COMP_CTX comp_state[COMP_SOURCES];
86
87 /* Status Flags */
88 prng_ready_status ready;
89 };
90
91 /*
92 * Clients see an opaque PrngRef; internal code uses the
93 * following typedef.
94 */
95 typedef struct PRNG PRNG;
96
97
98 /* Test Macros */
99 #define CHECKSTATE(p) \
100 if(p==NULL) {return PRNG_ERR_NOT_READY;} /* Does the state exist? */ \
101 if(p->ready != PRNG_READY) {return PRNG_ERR_NOT_READY;} /* Set error state and return */
102 /* To make sure that a pointer isn't NULL */
103 #define PCHECK(ptr) if(ptr==NULL) {return PRNG_ERR_NULL_POINTER;}
104 /* To make sure that malloc returned a valid value */
105 #define MCHECK(ptr) if(ptr==NULL) {return PRNG_ERR_LOW_MEMORY;}
106 /* To make sure that a given value is non-negative */
107 #if defined(macintosh) || defined(__APPLE__)
108 /* original looks like a bogon */
109 #define ZCHECK(val) if(val<0) {return PRNG_ERR_OUT_OF_BOUNDS;}
110 #else
111 #define ZCHECK(val) if(p<0) {return PRNG_ERR_OUT_OF_BOUNDS;}
112 #endif /* macintosh */
113 /* To make sure that the generator state is valid */
114 #define GENCHECK(p) if(p->outstate.index>20) {return PRNG_ERR_OUT_OF_BOUNDS;} /* index is unsigned */
115 /* To make sure that the entropy pool is valid */
116 #define POOLCHECK(p) /* */
117
118
119 #endif