]>
Commit | Line | Data |
---|---|---|
0b4e3aa0 | 1 | /* |
5d5c5d0d A |
2 | * Copyright (c) 1999, 2000-2001 Apple Computer, Inc. All rights reserved. |
3 | * | |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
0b4e3aa0 | 5 | * |
2d21ac55 A |
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. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
0b4e3aa0 A |
27 | */ |
28 | ||
29 | /* | |
30 | File: prngpriv.h | |
31 | ||
32 | Contains: Private typedefs and #defines for Counterpane Yarrow PRNG. | |
33 | ||
34 | Written by: Counterpane, Inc. | |
35 | ||
36 | Copyright: (c) 2000 by Apple Computer, Inc., all rights reserved. | |
37 | ||
38 | Change History (most recent first): | |
39 | ||
40 | 02/10/99 dpm Created, based on Counterpane source. | |
41 | ||
42 | */ | |
43 | /* | |
44 | prngpriv.h | |
45 | ||
46 | Completely private header for the Counterpane PRNG. Should only be included by prng.c | |
47 | */ | |
48 | ||
49 | #ifndef __YARROW_PRNG_PRIV_H__ | |
50 | #define __YARROW_PRNG_PRIV_H__ | |
51 | ||
52 | #include "userdefines.h" | |
53 | #include "dev/random/YarrowCoreLib/include/yarrow.h" | |
54 | #include "entropysources.h" | |
55 | #include "comp.h" | |
56 | #include "sha1mod.h" | |
57 | #include "smf.h" | |
58 | ||
59 | #define TOTAL_SOURCES ENTROPY_SOURCES+USER_SOURCES | |
60 | ||
61 | #ifdef COMPRESSION_ON | |
62 | #define COMP_SOURCES TOTAL_SOURCES | |
63 | #else | |
64 | #define COMP_SOURCES ENTROPY_SOURCES | |
65 | #endif | |
66 | ||
67 | /* Error numbers */ | |
68 | typedef enum prng_ready_status { | |
69 | PRNG_READY = 33, /* Compiler will initialize to either 0 or random if allowed to */ | |
70 | PRNG_NOT_READY = 0 | |
71 | } prng_ready_status; | |
72 | ||
73 | /* Top level output state */ | |
74 | typedef struct{ | |
75 | BYTE IV[20]; | |
76 | BYTE out[20]; | |
77 | UINT index; /* current byte to output */ | |
78 | UINT numout; /* bytes since last prng_make_new_state */ | |
79 | } GEN_CTX; | |
80 | ||
81 | /* PRNG state structure */ | |
82 | struct PRNG { | |
83 | /* Output State */ | |
84 | GEN_CTX outstate; | |
85 | ||
86 | /* Entropy Pools (somewhat unlike a gene pool) */ | |
2d21ac55 | 87 | YSHA1_CTX pool; |
0b4e3aa0 A |
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]; | |
91 | ||
92 | /* Status Flags */ | |
93 | prng_ready_status ready; | |
94 | }; | |
95 | ||
96 | /* | |
97 | * Clients see an opaque PrngRef; internal code uses the | |
98 | * following typedef. | |
99 | */ | |
100 | typedef struct PRNG PRNG; | |
101 | ||
102 | ||
103 | /* Test Macros */ | |
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;} | |
115 | #else | |
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) /* */ | |
122 | ||
123 | ||
124 | #endif |