1/* Copyright (c) (2017-2019,2022) Apple Inc. All rights reserved.
2 *
3 * corecrypto is licensed under Apple Inc.’s Internal Use License Agreement (which
4 * is contained in the License.txt file distributed with corecrypto) and only to
5 * people who accept that license. IMPORTANT: Any license rights granted to you by
6 * Apple Inc. (if any) are limited to internal use within your organization only on
7 * devices and computers you own or control, for the sole purpose of verifying the
8 * security characteristics and correct functioning of the Apple Software. You may
9 * not, directly or indirectly, redistribute the Apple Software or any portions thereof.
10 */
11
12#ifndef _CORECRYPTO_CCDRBG_INTERNAL_H_
13#define _CORECRYPTO_CCDRBG_INTERNAL_H_
14
15#include <corecrypto/cc.h>
16#include <corecrypto/ccdrbg_impl.h>
17#include <corecrypto/ccdrbg.h>
18#include <corecrypto/ccaes.h>
19
20#define DRBG_CTR_KEYLEN(drbg) ((drbg)->custom.keylen)
21#define DRBG_CTR_CTRLEN (8)
22#define DRBG_CTR_BLOCKLEN(drbg) (CCAES_BLOCK_SIZE)
23#define DRBG_CTR_SEEDLEN(drbg) (DRBG_CTR_KEYLEN(drbg) + DRBG_CTR_BLOCKLEN(drbg))
24
25#define DRBG_CTR_MAX_KEYLEN (CCAES_KEY_SIZE_256)
26#define DRBG_CTR_MAX_BLOCKLEN (CCAES_BLOCK_SIZE)
27#define DRBG_CTR_MAX_SEEDLEN (DRBG_CTR_MAX_KEYLEN + DRBG_CTR_MAX_BLOCKLEN)
28
29struct ccdrbg_nistctr_state {
30 uint8_t Key[DRBG_CTR_MAX_KEYLEN];
31 uint8_t V[DRBG_CTR_MAX_BLOCKLEN];
32 uint64_t reseed_counter; // Fits max NIST requirement of 2^48.
33 struct ccdrbg_nistctr_custom custom;
34};
35
36/*
37 * NIST SP 800-90 TRNG DRBG
38 *
39 * Call into the SEP DRBG and perform a SP 800-90 test operation.
40 */
41void ccdrbg_factory_trng(struct ccdrbg_info *info);
42
43/* Required length of the various TRNG entropy and personalization inputs. */
44#define CCDRBG_TRNG_VECTOR_LEN 48
45
46#endif /* _CORECRYPTO_CCDRBG_INTERNAL_H_ */
47