1 | /* Copyright (c) (2022,2023) 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 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
12 | * |
13 | * This file contains Original Code and/or Modifications of Original Code |
14 | * as defined in and that are subject to the Apple Public Source License |
15 | * Version 2.0 (the 'License'). You may not use this file except in |
16 | * compliance with the License. The rights granted to you under the License |
17 | * may not be used to create, or enable the creation or redistribution of, |
18 | * unlawful or unlicensed copies of an Apple operating system, or to |
19 | * circumvent, violate, or enable the circumvention or violation of, any |
20 | * terms of an Apple operating system software license agreement. |
21 | * |
22 | * Please obtain a copy of the License at |
23 | * http://www.opensource.apple.com/apsl/ and read it before using this file. |
24 | * |
25 | * The Original Code and all software distributed under the License are |
26 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER |
27 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
28 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, |
29 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
30 | * Please see the License for the specific language governing rights and |
31 | * limitations under the License. |
32 | * |
33 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
34 | */ |
35 | |
36 | #include "cc_internal.h" |
37 | #include "ccdrbg.h" |
38 | #include "ccdrbg_internal.h" |
39 | |
40 | bool |
41 | ccdrbg_must_reseed(const struct ccdrbg_info *info, |
42 | const struct ccdrbg_state *drbg) |
43 | { |
44 | CC_ENSURE_DIT_ENABLED |
45 | |
46 | return info->must_reseed(drbg); |
47 | } |
48 | |
49 | int |
50 | ccdrbg_init(const struct ccdrbg_info *info, |
51 | struct ccdrbg_state *drbg, |
52 | size_t entropyLength, const void* entropy, |
53 | size_t nonceLength, const void* nonce, |
54 | size_t psLength, const void* ps) |
55 | { |
56 | CC_ENSURE_DIT_ENABLED |
57 | |
58 | return info->init(info, drbg, entropyLength, entropy, nonceLength, nonce, psLength, ps); |
59 | } |
60 | |
61 | int |
62 | ccdrbg_reseed(const struct ccdrbg_info *info, |
63 | struct ccdrbg_state *drbg, |
64 | size_t entropyLength, const void *entropy, |
65 | size_t additionalLength, const void *additional) |
66 | { |
67 | CC_ENSURE_DIT_ENABLED |
68 | |
69 | return info->reseed(drbg, entropyLength, entropy, additionalLength, additional); |
70 | } |
71 | |
72 | |
73 | int |
74 | ccdrbg_generate(const struct ccdrbg_info *info, |
75 | struct ccdrbg_state *drbg, |
76 | size_t dataOutLength, void *dataOut, |
77 | size_t additionalLength, const void *additional) |
78 | { |
79 | CC_ENSURE_DIT_ENABLED |
80 | |
81 | return info->generate(drbg, dataOutLength, dataOut, additionalLength, additional); |
82 | } |
83 | |
84 | void |
85 | ccdrbg_done(const struct ccdrbg_info *info, struct ccdrbg_state *drbg) |
86 | { |
87 | info->done(drbg); |
88 | } |
89 | |
90 | size_t |
91 | ccdrbg_context_size(const struct ccdrbg_info *info) |
92 | { |
93 | return info->size; |
94 | } |
95 | |