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