]>
git.saurik.com Git - apple/xnu.git/blob - EXTERNAL_HEADERS/corecrypto/cckprng.h
7 * Copyright (c) 2017 Apple Inc. All rights reserved.
11 #ifndef _CORECRYPTO_CCKPRNG_H_
12 #define _CORECRYPTO_CCKPRNG_H_
14 #include <corecrypto/cc.h>
16 typedef struct PRNG
*PrngRef
;
17 typedef struct cckprng_ctx
*cckprng_ctx_t
;
21 uint64_t bytes_since_entropy
;
22 uint64_t bytes_generated
;
25 #define CCKPRNG_ENTROPY_INTERVAL (1 << 14)
26 #define CCKPRNG_RESEED_NTICKS 50
29 @function cckprng_init
30 @abstract Initialize a kernel PRNG context.
32 @param ctx Context for this instance
33 @param nbytes Length of the seed in bytes
34 @param seed Pointer to a high-entropy seed
36 @result @p CCKPRNG_OK iff successful. Panic on @p CCKPRNG_ABORT.
38 int cckprng_init(cckprng_ctx_t ctx
, size_t nbytes
, const void *seed
);
41 @function cckprng_reseed
42 @abstract Reseed a kernel PRNG context immediately.
44 @param ctx Context for this instance
45 @param nbytes Length of the seed in bytes
46 @param seed Pointer to a high-entropy seed
48 @result @p CCKPRNG_OK iff successful. Panic on @p CCKPRNG_ABORT.
50 int cckprng_reseed(cckprng_ctx_t ctx
, size_t nbytes
, const void *seed
);
53 @function cckprng_addentropy
54 @abstract Add entropy to a kernel PRNG context.
56 @param ctx Context for this instance
57 @param nbytes Length of the input entropy in bytes
58 @param seed Pointer to input entropy
60 @result @p CCKPRNG_OK iff successful. Panic on @p CCKPRNG_ABORT.
62 @discussion Input entropy is stored internally and consumed at the
63 opportune moment. This will not necessarily be before the next call
64 to @p cckprng_generate. To force an immediate reseed, call @p
67 int cckprng_addentropy(cckprng_ctx_t ctx
, size_t nbytes
, const void *entropy
);
70 @function cckprng_generate
71 @abstract Generate random values for use in applications.
73 @param ctx Context for this instance
74 @param nbytes Length of the desired output in bytes
75 @param seed Pointer to the output buffer
77 @result @p CCKPRNG_OK iff successful. Panic on @p
78 CCKPRNG_ABORT. Provide input to @p cckprng_addentropy on @p
81 int cckprng_generate(cckprng_ctx_t ctx
, size_t nbytes
, void *out
);
83 #endif /* _CORECRYPTO_CCKPRNG_H_ */