| 1 | /* Copyright (c) (2012,2015,2016,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_IMPL_H_ |
| 13 | #define _CORECRYPTO_CCDRBG_IMPL_H_ |
| 14 | |
| 15 | #include <corecrypto/cc.h> |
| 16 | |
| 17 | /* opaque drbg structure */ |
| 18 | struct ccdrbg_state; |
| 19 | |
| 20 | struct ccdrbg_info { |
| 21 | /*! Size of the DRBG state in bytes **/ |
| 22 | size_t size; |
| 23 | |
| 24 | /*! Instantiate the DRBG |
| 25 | @param drbg The DRBG state |
| 26 | @param entropylen Length of entropy |
| 27 | @param entropy Entropy bytes |
| 28 | @param inlen Length of additional input |
| 29 | @param in Additional input bytes |
| 30 | @return 0 if successful |
| 31 | */ |
| 32 | int (*CC_SPTR(ccdrbg_info, init))(const struct ccdrbg_info *info, struct ccdrbg_state *drbg, |
| 33 | size_t entropyLength, const void* entropy, |
| 34 | size_t nonceLength, const void* nonce, |
| 35 | size_t psLength, const void* ps); |
| 36 | |
| 37 | /*! Add entropy to the DRBG |
| 38 | @param drbg The DRBG state |
| 39 | @param entropylen Length of entropy |
| 40 | @param entropy Entropy bytes |
| 41 | @param inlen Length of additional input |
| 42 | @param in Additional input bytes |
| 43 | @return 0 if successful |
| 44 | */ |
| 45 | int (*CC_SPTR(ccdrbg_info, reseed))(struct ccdrbg_state *drbg, |
| 46 | size_t entropylen, const void *entropy, |
| 47 | size_t inlen, const void *in); |
| 48 | |
| 49 | /*! Read from the DRBG in a FIPS Testing compliant manor |
| 50 | @param drbg The DRBG state to read from |
| 51 | @param out [out] Where to store the data |
| 52 | @param outlen Length of data desired (octets) |
| 53 | @param inlen Length of additional input |
| 54 | @param in Additional input bytes |
| 55 | @return 0 if successfull |
| 56 | */ |
| 57 | int (*CC_SPTR(ccdrbg_info, generate))(struct ccdrbg_state *drbg, |
| 58 | size_t outlen, void *out, |
| 59 | size_t inlen, const void *in); |
| 60 | |
| 61 | /*! Terminate a DRBG state |
| 62 | @param drbg The DRBG state to terminate |
| 63 | */ |
| 64 | void (*CC_SPTR(ccdrbg_info, done))(struct ccdrbg_state *drbg); |
| 65 | |
| 66 | /** private parameters */ |
| 67 | const void *custom; |
| 68 | |
| 69 | /*! Whether the DRBG requires a reseed to continue generation |
| 70 | @param drbg The DRBG state |
| 71 | @return true if the DRBG requires reseed; false otherwise |
| 72 | */ |
| 73 | bool (*CC_SPTR(ccdrbg_info, must_reseed))(const struct ccdrbg_state *drbg); |
| 74 | }; |
| 75 | |
| 76 | |
| 77 | |
| 78 | #endif // _CORECRYPTO_CCDRBG_IMPL_H_ |
| 79 | |