xref: /xnu-12377.41.6/EXTERNAL_HEADERS/corecrypto/ccdrbg_df.h (revision bbb1b6f9e71b8cdde6e5cd6f4841f207dee3d828)
1 /* Copyright (c) (2021,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_DF_H_
13 #define _CORECRYPTO_CCDRBG_DF_H_
14 
15 #include <corecrypto/cc.h>
16 #include <corecrypto/ccmode_impl.h>
17 
18 // This is an interface for derivation functions for DRBGs to convert
19 // high-entropy inputs into key material. Because this interface is
20 // intended for internal usage, we declare only the type names and
21 // initialization functions here.
22 
23 typedef struct ccdrbg_df_ctx ccdrbg_df_ctx_t;
24 
25 struct ccdrbg_df_ctx {
26     int (*derive_keys)(const ccdrbg_df_ctx_t *ctx,
27                        size_t inputs_count,
28                        const cc_iovec_t *inputs,
29                        size_t keys_nbytes,
30                        void *keys);
31 };
32 
33 // This is a block-cipher-based instantiation of the derivation
34 // function for use in the CTR-DRBG.
35 
36 typedef struct ccdrbg_df_bc_ctx ccdrbg_df_bc_ctx_t;
37 
38 struct ccdrbg_df_bc_ctx {
39     ccdrbg_df_ctx_t df_ctx;
40     const struct ccmode_cbc *cbc_info;
41     size_t key_nbytes;
42 
43     // See ccmode_impl.h.
44     cc_ctx_decl_field(cccbc_ctx, CCCBC_MAX_CTX_SIZE, cbc_ctx);
45 };
46 
47 /*!
48   @function ccdrbg_df_bc_init
49   @abstract Initialize a block-cipher-based derivation function
50   @param ctx The derivation function context
51   @param cbc_info A descriptor for a CBC mode of a block cipher
52   @param key_nbytes The length of the key to use in the derivation function
53 
54   @discussion Note that a fixed key is used internally, so only the
55   key length needs to be specified.
56   @return 0 if successful; negative otherwise
57 */
58 CC_WARN_RESULT
59 CC_NONNULL_ALL
60 int ccdrbg_df_bc_init(ccdrbg_df_bc_ctx_t *ctx,
61                       const struct ccmode_cbc *cbc_info,
62                       size_t key_nbytes);
63 
64 #endif /* _CORECRYPTO_CCDRBG_DF_H_ */
65