Skip to content

Commit

Permalink
xnu-7195.60.75
Browse files Browse the repository at this point in the history
  • Loading branch information
Darwin authored and das committed Feb 2, 2021
1 parent d4061fb commit 33eb983
Show file tree
Hide file tree
Showing 183 changed files with 3,855 additions and 2,508 deletions.
27 changes: 0 additions & 27 deletions .gitignore

This file was deleted.

15 changes: 15 additions & 0 deletions EXTERNAL_HEADERS/corecrypto/cc.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,19 @@ int cc_cmp_safe (size_t num, const void * ptr1, const void * ptr2);
/* Return the minimum value between S and T. */
#define CC_MIN(S, T) ({__typeof__(S) _cc_min_s = S; __typeof__(T) _cc_min_t = T; _cc_min_s <= _cc_min_t ? _cc_min_s : _cc_min_t;})

/*
When building with "-nostdinc" (i.e. iboot), ptrauth.h is in a non-standard location.
This requires a new flag to be used when building iboot: -ibuiltininc.
This flag doesn't seem present at the moment in clang. For now lets not
diversify in iBoot.
*/
#if __has_feature(ptrauth_calls) && (CC_KERNEL || CC_USE_L4 || CC_USE_SEPROM)
#include <ptrauth.h>
#define CC_SPTR(_sn_, _n_) \
__ptrauth(ptrauth_key_process_independent_code, 1, ptrauth_string_discriminator("cc_" #_sn_ #_n_)) _n_
#else
#define CC_SPTR(_sn_, _n_) _n_
#endif

#endif /* _CORECRYPTO_CC_H_ */
4 changes: 2 additions & 2 deletions EXTERNAL_HEADERS/corecrypto/ccdigest.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ struct ccdigest_info {
size_t oid_size;
const unsigned char *oid;
const void *initial_state;
void(*compress)(ccdigest_state_t state, size_t nblocks,
void(* CC_SPTR(ccdigest_info, compress))(ccdigest_state_t state, size_t nblocks,
const void *data);
void(*final)(const struct ccdigest_info *di, ccdigest_ctx_t ctx,
void(* CC_SPTR(ccdigest_info, final))(const struct ccdigest_info *di, ccdigest_ctx_t ctx,
unsigned char *digest);
};

Expand Down
8 changes: 4 additions & 4 deletions EXTERNAL_HEADERS/corecrypto/ccdrbg_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct ccdrbg_info {
@param in Additional input bytes
@return 0 if successful
*/
int (*init)(const struct ccdrbg_info *info, struct ccdrbg_state *drbg,
int (*CC_SPTR(ccdrbg_info, init))(const struct ccdrbg_info *info, struct ccdrbg_state *drbg,
size_t entropyLength, const void* entropy,
size_t nonceLength, const void* nonce,
size_t psLength, const void* ps);
Expand All @@ -40,7 +40,7 @@ struct ccdrbg_info {
@param in Additional input bytes
@return 0 if successful
*/
int (*reseed)(struct ccdrbg_state *prng,
int (*CC_SPTR(ccdrbg_info, reseed))(struct ccdrbg_state *prng,
size_t entropylen, const void *entropy,
size_t inlen, const void *in);

Expand All @@ -52,14 +52,14 @@ struct ccdrbg_info {
@param in Additional input bytes
@return 0 if successfull
*/
int (*generate)(struct ccdrbg_state *prng,
int (*CC_SPTR(ccdrbg_info, generate))(struct ccdrbg_state *prng,
size_t outlen, void *out,
size_t inlen, const void *in);

/*! Terminate a PRNG state
@param prng The PRNG state to terminate
*/
void (*done)(struct ccdrbg_state *prng);
void (*CC_SPTR(ccdrbg_info, done))(struct ccdrbg_state *prng);

/** private parameters */
const void *custom;
Expand Down
78 changes: 65 additions & 13 deletions EXTERNAL_HEADERS/corecrypto/cckprng.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,20 @@ struct cckprng_sched_ctx {
unsigned pool_idx;
};

// A function pointer to fill an entropy buffer. It should return some
// estimate of entropy (e.g. the number of timing samples resident in
// the buffer). The implementation may return zero if no entropy is
// available. The implementation should return negative in case of an
// error (e.g. a failure in continuous health tests).
//
// The caller should set entropy_nbytes to the maximum size of the
// input buffer, and the implementation should set it to the number of
// bytes it has initialized. The third argument is arbitrary state the
// implementation provides and receives back on each call.
typedef int32_t (*cckprng_getentropy)(size_t *entropy_nbytes,
void *entropy,
void *arg);

struct cckprng_ctx {
// The master secret of the PRNG
struct cckprng_key_ctx key;
Expand Down Expand Up @@ -250,24 +264,38 @@ struct cckprng_ctx {

// Diagnostics for the PRNG
struct cckprng_diag diag;

// A function pointer to get entropy
cckprng_getentropy getentropy;

// An arbitrary piece of state to be provided to the entropy function
void *getentropy_arg;
};

// This collection of function pointers is just a convenience for
// registering the PRNG with xnu
struct cckprng_funcs {
void (*init)(struct cckprng_ctx *ctx,
unsigned max_ngens,
size_t entropybuf_nbytes,
const void *entropybuf,
const uint32_t *entropybuf_nsamples,
size_t seed_nbytes,
const void *seed,
size_t nonce_nbytes,
const void *nonce);
void (*initgen)(struct cckprng_ctx *ctx, unsigned gen_idx);
void (*reseed)(struct cckprng_ctx *ctx, size_t nbytes, const void *seed);
void (*refresh)(struct cckprng_ctx *ctx);
void (*generate)(struct cckprng_ctx *ctx, unsigned gen_idx, size_t nbytes, void *out);
void (*CC_SPTR(cckprng_funcs, init))(struct cckprng_ctx *ctx,
unsigned max_ngens,
size_t entropybuf_nbytes,
const void *entropybuf,
const uint32_t *entropybuf_nsamples,
size_t seed_nbytes,
const void *seed,
size_t nonce_nbytes,
const void *nonce);
void (*CC_SPTR(cckprng_funcs, initgen))(struct cckprng_ctx *ctx, unsigned gen_idx);
void (*CC_SPTR(cckprng_funcs, reseed))(struct cckprng_ctx *ctx, size_t nbytes, const void *seed);
void (*CC_SPTR(cckprng_funcs, refresh))(struct cckprng_ctx *ctx);
void (*CC_SPTR(cckprng_funcs, generate))(struct cckprng_ctx *ctx, unsigned gen_idx, size_t nbytes, void *out);
void (*CC_SPTR(cckprng_funcs, init_with_getentropy))(struct cckprng_ctx *ctx,
unsigned max_ngens,
size_t seed_nbytes,
const void *seed,
size_t nonce_nbytes,
const void *nonce,
cckprng_getentropy getentropy,
void *getentropy_arg);
};

/*
Expand Down Expand Up @@ -296,6 +324,30 @@ void cckprng_init(struct cckprng_ctx *ctx,
size_t nonce_nbytes,
const void *nonce);

/*
@function cckprng_init_with_getentropy
@abstract Initialize a kernel PRNG context.
@param ctx Context for this instance
@param max_ngens Maximum count of generators that may be allocated
@param seed_nbytes Length of the seed in bytes
@param seed Pointer to a high-entropy seed
@param nonce_nbytes Length of the nonce in bytes
@param seed Pointer to a single-use nonce
@param getentropy A function pointer to fill an entropy buffer
@param getentropy_arg State provided to the entropy function
@discussion @p max_ngens should be set based on an upper bound of CPUs available on the device. See the @p cckprng_getentropy type definition for discussion on its semantics.
*/
void cckprng_init_with_getentropy(struct cckprng_ctx *ctx,
unsigned max_ngens,
size_t seed_nbytes,
const void *seed,
size_t nonce_nbytes,
const void *nonce,
cckprng_getentropy getentropy,
void *getentropy_arg);

/*
@function cckprng_initgen
@abstract Initialize an output generator.
Expand Down
Loading

0 comments on commit 33eb983

Please sign in to comment.