X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/eb6b6ca394357805f2bdba989abae309f718b4d8..f427ee49d309d8fc33ebf3042c3a775f2f530ded:/EXTERNAL_HEADERS/corecrypto/cckprng.h diff --git a/EXTERNAL_HEADERS/corecrypto/cckprng.h b/EXTERNAL_HEADERS/corecrypto/cckprng.h index edcff9a61..0c97177ff 100644 --- a/EXTERNAL_HEADERS/corecrypto/cckprng.h +++ b/EXTERNAL_HEADERS/corecrypto/cckprng.h @@ -1,11 +1,12 @@ -/* - * cckprng.h - * corecrypto - * - * Created on 12/7/2017 - * - * Copyright (c) 2017 Apple Inc. All rights reserved. +/* Copyright (c) (2018,2019) Apple Inc. All rights reserved. * + * corecrypto is licensed under Apple Inc.’s Internal Use License Agreement (which + * is contained in the License.txt file distributed with corecrypto) and only to + * people who accept that license. IMPORTANT: Any license rights granted to you by + * Apple Inc. (if any) are limited to internal use within your organization only on + * devices and computers you own or control, for the sole purpose of verifying the + * security characteristics and correct functioning of the Apple Software. You may + * not, directly or indirectly, redistribute the Apple Software or any portions thereof. */ #ifndef _CORECRYPTO_CCKPRNG_H_ @@ -15,25 +16,6 @@ #include -#define CCKPRNG_YARROW 0 - -#if CCKPRNG_YARROW - -typedef struct PRNG *PrngRef; - -struct cckprng_ctx { - PrngRef prng; - uint64_t bytes_since_entropy; - uint64_t bytes_generated; -}; - -#define CCKPRNG_ENTROPY_INTERVAL (1 << 14) -#define CCKPRNG_RESEED_NTICKS 50 - -typedef struct cckprng_ctx *cckprng_ctx_t; - -#else - // This is a Fortuna-inspired PRNG. While it differs from Fortuna in // many minor details, the biggest difference is its support for // multiple independent output generators. This is to make it suitable @@ -138,7 +120,7 @@ struct cckprng_diag { // Diagnostics corresponding to individual output generators unsigned ngens; - struct cckprng_gen_diag *gens; + CC_ALIGNED(8) struct cckprng_gen_diag *gens; // Diagnostics corresponding to internal entropy pools struct cckprng_pool_diag pools[CCKPRNG_NPOOLS]; @@ -156,6 +138,16 @@ struct cckprng_lock_ctx { cckprng_lock_mutex mutex; }; +#elif CC_ANDROID || CC_LINUX + +#include + +typedef pthread_mutex_t cckprng_lock_mutex; + +struct cckprng_lock_ctx { + cckprng_lock_mutex mutex; +}; + #else #include @@ -224,17 +216,16 @@ struct cckprng_sched_ctx { // A counter governing the set of entropy pools to drain uint64_t reseed_sched; - // A timestamp from the last reseed - uint64_t reseed_last; - // An index used to add entropy to pools in a round-robin style unsigned pool_idx; }; struct cckprng_ctx { - // The master secret of the PRNG - uint8_t seed[CCKPRNG_SEED_NBYTES]; + struct cckprng_key_ctx key; + + // A counter used in CTR mode (with the master secret) + uint8_t ctr[16]; // State used to schedule entropy consumption and reseeds struct cckprng_sched_ctx sched; @@ -245,6 +236,9 @@ struct cckprng_ctx { // The maximum number of generators that may be allocated unsigned max_ngens; + // The actual number of generators that have been initialized + unsigned ngens; + // An array of output generators (allocated dynamically) of length max_ngens struct cckprng_gen_ctx *gens; @@ -276,8 +270,6 @@ struct cckprng_funcs { void (*generate)(struct cckprng_ctx *ctx, unsigned gen_idx, size_t nbytes, void *out); }; -#endif - /* @function cckprng_init @abstract Initialize a kernel PRNG context.