/src/cryptofuzz/modules/wolfcrypt/module.cpp
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | #include "module.h"  | 
2  |  | #include <cryptofuzz/util.h>  | 
3  |  | #include <cryptofuzz/repository.h>  | 
4  |  | #include <fuzzing/datasource/id.hpp>  | 
5  |  | #include <iostream>  | 
6  |  |  | 
7  |  | #if defined(CRYPTOFUZZ_WOLFCRYPT_MMAP_FIXED)  | 
8  |  |  #if UINTPTR_MAX != 0xFFFFFFFF  | 
9  |  |   #error "CRYPTOFUZZ_WOLFCRYPT_MMAP_FIXED only supported on 32 bit"  | 
10  |  |  #endif  | 
11  |  | #endif  | 
12  |  |  | 
13  |  | #if defined(CRYPTOFUZZ_WOLFCRYPT_MMAP_FIXED)  | 
14  |  | #include <sys/mman.h>  | 
15  |  | #endif  | 
16  |  |  | 
17  |  | extern "C" { | 
18  |  | #include <wolfssl/options.h>  | 
19  |  | #include <wolfssl/wolfcrypt/md2.h>  | 
20  |  | #include <wolfssl/wolfcrypt/md4.h>  | 
21  |  | #include <wolfssl/wolfcrypt/md5.h>  | 
22  |  | #include <wolfssl/wolfcrypt/ripemd.h>  | 
23  |  | #include <wolfssl/wolfcrypt/sha.h>  | 
24  |  | #include <wolfssl/wolfcrypt/sha256.h>  | 
25  |  | #include <wolfssl/wolfcrypt/sha512.h>  | 
26  |  | #include <wolfssl/wolfcrypt/sha3.h>  | 
27  |  | #include <wolfssl/wolfcrypt/blake2.h>  | 
28  |  | #include <wolfssl/wolfcrypt/siphash.h>  | 
29  |  |  | 
30  |  | #include <wolfssl/wolfcrypt/aes.h>  | 
31  |  | #include <wolfssl/wolfcrypt/arc4.h>  | 
32  |  | #include <wolfssl/wolfcrypt/camellia.h>  | 
33  |  | #include <wolfssl/wolfcrypt/chacha.h>  | 
34  |  | #include <wolfssl/wolfcrypt/chacha20_poly1305.h>  | 
35  |  | #include <wolfssl/wolfcrypt/des3.h>  | 
36  |  |  | 
37  |  | #include <wolfssl/wolfcrypt/hmac.h>  | 
38  |  |  | 
39  |  | #include <wolfssl/wolfcrypt/cmac.h>  | 
40  |  |  | 
41  |  | #include <wolfssl/wolfcrypt/kdf.h>  | 
42  |  |  | 
43  |  | #include <wolfssl/wolfcrypt/pwdbased.h>  | 
44  |  | #include <wolfssl/wolfcrypt/ecc.h>  | 
45  |  | #include <wolfssl/wolfcrypt/curve25519.h>  | 
46  |  | #include <wolfssl/wolfcrypt/curve448.h>  | 
47  |  | #include <wolfssl/wolfcrypt/ed448.h>  | 
48  |  | #include <wolfssl/wolfcrypt/ed25519.h>  | 
49  |  |  | 
50  |  | #include <wolfssl/wolfcrypt/dh.h>  | 
51  |  | #include <wolfssl/wolfcrypt/asn.h>  | 
52  |  | #include <wolfssl/wolfcrypt/cryptocb.h>  | 
53  |  | #include <wolfssl/wolfcrypt/error-crypt.h>  | 
54  |  | }  | 
55  |  |  | 
56  |  | #include "module_internal.h"  | 
57  |  | #include "bn_ops.h"  | 
58  |  | #include "ecdsa_generic.h"  | 
59  |  | #include "ecdsa_448.h"  | 
60  |  | #include "ecdsa_25519.h"  | 
61  |  |  | 
62  |  | namespace cryptofuzz { | 
63  |  | namespace module { | 
64  |  |  | 
65  |  | namespace wolfCrypt_detail { | 
66  | 11.3k  |     int wc_Check(const int ret) { | 
67  | 11.3k  |         CF_ASSERT(ret <= 0, "Unexpected return value");  | 
68  | 11.3k  |         return ret;  | 
69  | 11.3k  |     }  | 
70  |  | }  | 
71  |  |  | 
72  |  | namespace wolfCrypt_detail { | 
73  |  |     WC_RNG rng;  | 
74  |  | #if defined(WOLF_CRYPTO_CB)  | 
75  |  |     WC_RNG rng_deterministic;  | 
76  |  | #endif /* WOLF_CRYPTO_CB */  | 
77  |  |  | 
78  |  |  | 
79  |  | #if defined(CRYPTOFUZZ_WOLFCRYPT_ALLOCATION_FAILURES) || defined(CRYPTOFUZZ_WOLFCRYPT_MMAP_FIXED)  | 
80  |  |     Datasource* ds;  | 
81  |  | #endif  | 
82  |  |  | 
83  |  | #if defined(WOLF_CRYPTO_CB)  | 
84  | 212  |     int CryptoCB(int devId, wc_CryptoInfo* info, void* ctx) { | 
85  | 212  |         (void)devId;  | 
86  | 212  |         (void)ctx;  | 
87  |  |  | 
88  | 212  |         if (info->algo_type == WC_ALGO_TYPE_RNG) { | 
89  | 13  |             try { | 
90  | 13  |                 if ( info->rng.sz ) { | 
91  | 13  |                     const auto data = ds->GetData(0, info->rng.sz, info->rng.sz);  | 
92  |  |  | 
93  | 13  |                     memcpy(info->rng.out, data.data(), info->rng.sz);  | 
94  | 13  |                 }  | 
95  | 13  |             } catch ( ... ) { | 
96  | 1  |                 return -1;  | 
97  | 1  |             }  | 
98  |  |  | 
99  | 12  |             return 0;  | 
100  | 199  |         } else if (info->algo_type == WC_ALGO_TYPE_SEED) { | 
101  |  |             /* Taken from wolfcrypt/test/test.c */  | 
102  |  |  | 
103  | 2  |             static byte seed[sizeof(word32)] = { 0x00, 0x00, 0x00, 0x01 }; | 
104  | 2  |             word32* seedWord32 = (word32*)seed;  | 
105  | 2  |             word32 len;  | 
106  |  |  | 
107  |  |             /* wc_GenerateSeed is a local symbol so we need to fake the entropy. */  | 
108  | 28  |             while (info->seed.sz > 0) { | 
109  | 26  |                 len = (word32)sizeof(seed);  | 
110  | 26  |                 if (info->seed.sz < len)  | 
111  | 0  |                     len = info->seed.sz;  | 
112  | 26  |                 XMEMCPY(info->seed.seed, seed, sizeof(seed));  | 
113  | 26  |                 info->seed.seed += len;  | 
114  | 26  |                 info->seed.sz -= len;  | 
115  | 26  |                 (*seedWord32)++;  | 
116  | 26  |             }  | 
117  | 2  |             return 0;  | 
118  | 2  |         }  | 
119  | 197  |         return NOT_COMPILED_IN;  | 
120  | 212  |     }  | 
121  |  | #endif /* WOLF_CRYPTO_CB */  | 
122  |  |  | 
123  |  | #if defined(CRYPTOFUZZ_WOLFCRYPT_ALLOCATION_FAILURES)  | 
124  |  |     bool disableAllocationFailures;  | 
125  |  |     bool haveAllocFailure;  | 
126  |  | #endif  | 
127  |  |  | 
128  | 6  |     void InitializeSystemRNG(void) { | 
129  | 6  |         const auto cached_disableAllocationFailures = disableAllocationFailures;  | 
130  | 6  |         disableAllocationFailures = true;  | 
131  | 6  |         CF_ASSERT(wc_InitRng(&wolfCrypt_detail::rng) == 0, "Cannot initialize wolfCrypt RNG");  | 
132  | 6  |         disableAllocationFailures = cached_disableAllocationFailures;  | 
133  | 6  |     }  | 
134  |  |  | 
135  | 306  |     WC_RNG* GetSystemRNG(void) { | 
136  | 306  |         if ( rng.status != 1 ) { | 
137  | 4  |             /* ignore ret */ wc_FreeRng(&rng);  | 
138  | 4  |             CF_NORET(InitializeSystemRNG());  | 
139  | 4  |             CF_ASSERT(rng.status == 1, "System RNG broken after re-initialization");  | 
140  | 4  |         }  | 
141  |  |  | 
142  | 306  |         return &rng;  | 
143  | 306  |     }  | 
144  | 312  |     WC_RNG* GetRNG(void) { | 
145  | 312  | #if defined(WOLF_CRYPTO_CB)  | 
146  | 312  |         if ( ds == nullptr ) { | 
147  | 0  |             return GetSystemRNG();  | 
148  | 0  |         }  | 
149  |  |  | 
150  | 312  |         bool which = false; try { which = ds->Get<bool>(); } catch ( ... ) { } | 
151  |  |  | 
152  | 312  |         return which ? &rng_deterministic : GetSystemRNG();  | 
153  |  | #else  | 
154  |  |         return &rng;  | 
155  |  | #endif  | 
156  | 312  |     }  | 
157  |  |  | 
158  |  |     std::vector<std::pair<void*, size_t>> fixed_allocs;  | 
159  |  |  | 
160  | 7.59k  |     void SetGlobalDs(Datasource* ds) { | 
161  | 7.59k  | #if defined(CRYPTOFUZZ_WOLFCRYPT_ALLOCATION_FAILURES) || defined(CRYPTOFUZZ_WOLFCRYPT_MMAP_FIXED)  | 
162  |  | #if defined(CRYPTOFUZZ_WOLFCRYPT_MMAP_FIXED)  | 
163  |  |         fixed_allocs.clear();  | 
164  |  | #endif  | 
165  | 7.59k  |         wolfCrypt_detail::ds = ds;  | 
166  |  | #else  | 
167  |  |         (void)ds;  | 
168  |  | #endif  | 
169  | 7.59k  |     }  | 
170  |  |  | 
171  | 7.59k  |     void UnsetGlobalDs(void) { | 
172  | 7.59k  | #if defined(CRYPTOFUZZ_WOLFCRYPT_ALLOCATION_FAILURES) || defined(CRYPTOFUZZ_WOLFCRYPT_MMAP_FIXED)  | 
173  | 7.59k  |         wolfCrypt_detail::ds = nullptr;  | 
174  | 7.59k  | #endif  | 
175  | 7.59k  |     }  | 
176  |  |  | 
177  | 12.0M  |     inline bool AllocationFailure(void) { | 
178  | 12.0M  | #if defined(CRYPTOFUZZ_WOLFCRYPT_ALLOCATION_FAILURES)  | 
179  | 12.0M  |         if ( disableAllocationFailures == true ) { | 
180  | 260  |             return false;  | 
181  | 260  |         }  | 
182  |  |  | 
183  | 12.0M  |         bool fail = false;  | 
184  | 12.0M  |         if ( ds == nullptr ) { | 
185  | 0  |             if ( fail ) { | 
186  |  | #if defined(CRYPTOFUZZ_WOLFCRYPT_DEBUG)  | 
187  |  |                 std::cout << "Have allocation failure" << std::endl;  | 
188  |  | #endif  | 
189  | 0  |                 haveAllocFailure = true;  | 
190  | 0  |             }  | 
191  | 0  |             return fail;  | 
192  | 0  |         }  | 
193  | 12.0M  |         try { | 
194  | 12.0M  |             fail = ds->Get<bool>();  | 
195  | 12.0M  |         } catch ( ... ) { } | 
196  |  |  | 
197  | 12.0M  |         if ( fail ) { | 
198  |  | #if defined(CRYPTOFUZZ_WOLFCRYPT_DEBUG)  | 
199  |  |             std::cout << "Have allocation failure" << std::endl;  | 
200  |  | #endif  | 
201  | 1.30k  |             haveAllocFailure = true;  | 
202  | 1.30k  |         }  | 
203  | 12.0M  |         return fail;  | 
204  |  | #else  | 
205  |  |         return false;  | 
206  |  | #endif  | 
207  | 12.0M  |     }  | 
208  |  |  | 
209  |  | #if defined(CRYPTOFUZZ_WOLFCRYPT_MMAP_FIXED)  | 
210  |  |     bool isFixedAlloc(const void* ptr) { | 
211  |  |         for (const auto& p : fixed_allocs) { | 
212  |  |             if ( p.first == ptr ) { | 
213  |  |                 return true;  | 
214  |  |             }  | 
215  |  |         }  | 
216  |  |         return false;  | 
217  |  |     }  | 
218  |  |  | 
219  |  |     void* fixed_alloc(const size_t n) { | 
220  |  |         constexpr uint32_t top = 0xFFFFE000;  | 
221  |  |         const uint32_t preferred = (top - n) & 0xFFFFF000;  | 
222  |  |  | 
223  |  |         for (const auto& p : fixed_allocs) { | 
224  |  |             const size_t a_start = (size_t)preferred;  | 
225  |  |             const size_t a_end = a_start + n;  | 
226  |  |             const size_t b_start = (size_t)p.first;  | 
227  |  |             const size_t b_end = b_start + p.second;  | 
228  |  |  | 
229  |  |             /* If an existing pointer overlaps with the preferred pointer, revert to normal malloc */  | 
230  |  |             if ( a_start <= b_end && b_start <= a_end ) { | 
231  |  |                 return util::malloc(n);  | 
232  |  |             }  | 
233  |  |         }  | 
234  |  |  | 
235  |  |         void* p = mmap(  | 
236  |  |                 (void*)preferred,  | 
237  |  |                 n,  | 
238  |  |                 PROT_READ | PROT_WRITE,  | 
239  |  |                 MAP_SHARED | MAP_FIXED | MAP_ANONYMOUS,  | 
240  |  |                 -1,  | 
241  |  |                 0);  | 
242  |  |  | 
243  |  |         if ( p == (void*)0xFFFFFFFF ) { | 
244  |  |             /* mmap failed, revert to normal malloc */  | 
245  |  |             return util::malloc(n);  | 
246  |  |         }  | 
247  |  |  | 
248  |  |         fixed_allocs.push_back({p, n}); | 
249  |  |  | 
250  |  |         return p;  | 
251  |  |     }  | 
252  |  |  | 
253  |  |     void* malloc(const size_t n) { | 
254  |  |         bool doFixedMmap = false;  | 
255  |  |         if ( ds == nullptr ) { | 
256  |  |             goto end;  | 
257  |  |         }  | 
258  |  |         try { | 
259  |  |             doFixedMmap = ds->Get<bool>();  | 
260  |  |         } catch ( ... ) { } | 
261  |  | end:  | 
262  |  |         return doFixedMmap ? fixed_alloc(n) : util::malloc(n);  | 
263  |  |     }  | 
264  |  |  | 
265  |  |     void* realloc(void* ptr, const size_t n) { | 
266  |  |         if ( isFixedAlloc(ptr) ) { | 
267  |  |             /* realloc currently not supported for mmap'ed regions */  | 
268  |  |             return nullptr;  | 
269  |  |         } else { | 
270  |  |             return util::realloc(ptr, n);  | 
271  |  |         }  | 
272  |  |     }  | 
273  |  |  | 
274  |  |     void free(void* ptr) { | 
275  |  |         /* Find pointer in list */  | 
276  |  |         for (size_t i = 0; i < fixed_allocs.size(); i++) { | 
277  |  |             if ( fixed_allocs[i].first == ptr ) { | 
278  |  |                 if ( munmap(ptr, fixed_allocs[i].second) != 0 ) { | 
279  |  |                     abort();  | 
280  |  |                 }  | 
281  |  |  | 
282  |  |                 /* Erase pointer from list */  | 
283  |  |                 fixed_allocs.erase(fixed_allocs.begin() + i);  | 
284  |  |  | 
285  |  |                 return;  | 
286  |  |             }  | 
287  |  |         }  | 
288  |  |  | 
289  |  |         util::free(ptr);  | 
290  |  |     }  | 
291  |  | #else  | 
292  | 12.0M  |     void* malloc(const size_t n) { | 
293  | 12.0M  |         return util::malloc(n);  | 
294  | 12.0M  |     }  | 
295  | 0  |     void* realloc(void* ptr, const size_t n) { | 
296  | 0  |         return util::realloc(ptr, n);  | 
297  | 0  |     }  | 
298  | 12.0M  |     void free(void* ptr) { | 
299  | 12.0M  |         util::free(ptr);  | 
300  | 12.0M  |     }  | 
301  |  | #endif  | 
302  |  | }  | 
303  |  |  | 
304  | 12.0M  | static void* wolfCrypt_custom_malloc(size_t n) { | 
305  | 12.0M  |     return wolfCrypt_detail::AllocationFailure() ?  | 
306  | 1.30k  |         nullptr :  | 
307  | 12.0M  |         wolfCrypt_detail::malloc(n);  | 
308  | 12.0M  | }  | 
309  |  |  | 
310  | 0  | static void* wolfCrypt_custom_realloc(void* ptr, size_t n) { | 
311  | 0  |     return wolfCrypt_detail::AllocationFailure() ?  | 
312  | 0  |         nullptr :  | 
313  | 0  |         wolfCrypt_detail::realloc(ptr, n);  | 
314  | 0  | }  | 
315  |  |  | 
316  | 12.0M  | static void wolfCrypt_custom_free(void* ptr) { | 
317  | 12.0M  |     wolfCrypt_detail::free(ptr);  | 
318  | 12.0M  | }  | 
319  |  |  | 
320  |  | wolfCrypt::wolfCrypt(void) :  | 
321  | 2  |     Module("wolfCrypt") { | 
322  |  |  | 
323  | 2  | #if defined(CRYPTOFUZZ_WOLFCRYPT_ALLOCATION_FAILURES)  | 
324  | 2  |     wolfCrypt_detail::disableAllocationFailures = false;  | 
325  | 2  | #endif  | 
326  |  |  | 
327  | 2  |     CF_NORET(wolfCrypt_detail::InitializeSystemRNG());  | 
328  |  |  | 
329  | 2  | #if defined(WOLF_CRYPTO_CB)  | 
330  | 2  |     CF_NORET(wc_CryptoCb_Init());  | 
331  |  |  | 
332  | 2  |     CF_ASSERT(wc_CryptoCb_RegisterDevice(0xAABBCC, wolfCrypt_detail::CryptoCB, nullptr) == 0, "Cannot initialize CryptoCB");  | 
333  | 2  |     CF_ASSERT(wc_InitRng_ex(&wolfCrypt_detail::rng_deterministic, nullptr, 0xAABBCC) == 0, "Cannot initialize deterministic wolfCrypt RNG");  | 
334  | 2  | #endif /* WOLF_CRYPTO_CB */  | 
335  |  |  | 
336  | 2  |     wolfCrypt_detail::SetGlobalDs(nullptr);  | 
337  | 2  |     CF_ASSERT(wolfSSL_SetAllocators(wolfCrypt_custom_malloc, wolfCrypt_custom_free, wolfCrypt_custom_realloc) == 0, "Cannot set allocator functions");  | 
338  | 2  | }  | 
339  |  |  | 
340  |  | namespace wolfCrypt_detail { | 
341  |  |     template <class OperationType, class ReturnType, class CTXType>  | 
342  |  |     class Operation { | 
343  |  |         protected:  | 
344  |  |             CTXType ctx;  | 
345  |  |         public:  | 
346  | 34  |             Operation(void) { }cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, Md2>::Operation() Line  | Count  | Source  |  346  | 2  |             Operation(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, Md4>::Operation() Line  | Count  | Source  |  346  | 2  |             Operation(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, wc_Md5>::Operation() Line  | Count  | Source  |  346  | 2  |             Operation(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, RipeMd>::Operation() Line  | Count  | Source  |  346  | 2  |             Operation(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, wc_Sha>::Operation() Line  | Count  | Source  |  346  | 2  |             Operation(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, wc_Sha256>::Operation() Line  | Count  | Source  |  346  | 4  |             Operation(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, wc_Sha512>::Operation() Line  | Count  | Source  |  346  | 4  |             Operation(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, wc_Sha3>::Operation() Line  | Count  | Source  |  346  | 12  |             Operation(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, Blake2b>::Operation() Line  | Count  | Source  |  346  | 2  |             Operation(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, Blake2s>::Operation() Line  | Count  | Source  |  346  | 2  |             Operation(void) { } |  
  | 
347  | 0  |             ~Operation() { }Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, Md2>::~Operation() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, Md4>::~Operation() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, wc_Md5>::~Operation() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, RipeMd>::~Operation() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, wc_Sha>::~Operation() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, wc_Sha256>::~Operation() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, wc_Sha512>::~Operation() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, wc_Sha3>::~Operation() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, Blake2b>::~Operation() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, Blake2s>::~Operation()  | 
348  |  |  | 
349  |  |             virtual bool runInit(OperationType& op) = 0;  | 
350  |  |             virtual bool runUpdate(util::Multipart& parts) = 0;  | 
351  |  |             virtual std::optional<ReturnType> runFinalize(void) = 0;  | 
352  |  |             virtual void runFree(void) = 0;  | 
353  |  |             virtual std::optional<ReturnType> runOneShot(const Buffer& in, Datasource& ds) = 0;  | 
354  |  |  | 
355  | 233  |             std::optional<ReturnType> Run(OperationType& op, Datasource& ds) { | 
356  | 233  |                 std::optional<ReturnType> ret = std::nullopt;  | 
357  | 233  |                 util::Multipart parts;  | 
358  |  |  | 
359  | 233  |                 bool doOneShot = false;  | 
360  | 233  |                 try { | 
361  | 233  |                     doOneShot = ds.Get<bool>();  | 
362  | 233  |                 } catch ( ... ) { } | 
363  |  |  | 
364  | 233  |                 if ( doOneShot == true ) { | 
365  | 28  |                     ret = runOneShot(op.cleartext, ds);  | 
366  | 205  |                 } else { | 
367  | 205  |                     if ( runInit(op) == false ) { | 
368  | 0  |                         return std::nullopt;  | 
369  | 0  |                     }  | 
370  |  |  | 
371  | 205  |                     parts = util::ToParts(ds, op.cleartext);  | 
372  |  |  | 
373  | 205  |                     CF_CHECK_EQ(runUpdate(parts), true);  | 
374  |  |  | 
375  | 192  |                     ret = runFinalize();  | 
376  | 192  |                 }  | 
377  |  |  | 
378  | 233  | end:  | 
379  | 233  |                 if ( doOneShot == false ) { | 
380  | 205  |                     runFree();  | 
381  | 205  |                 }  | 
382  | 233  |                 return ret;  | 
383  | 233  |             } Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, Md2>::Run(cryptofuzz::operation::Digest&, fuzzing::datasource::Datasource&) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, Md4>::Run(cryptofuzz::operation::Digest&, fuzzing::datasource::Datasource&) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, wc_Md5>::Run(cryptofuzz::operation::Digest&, fuzzing::datasource::Datasource&) cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, RipeMd>::Run(cryptofuzz::operation::Digest&, fuzzing::datasource::Datasource&) Line  | Count  | Source  |  355  | 52  |             std::optional<ReturnType> Run(OperationType& op, Datasource& ds) { |  356  | 52  |                 std::optional<ReturnType> ret = std::nullopt;  |  357  | 52  |                 util::Multipart parts;  |  358  |  |  |  359  | 52  |                 bool doOneShot = false;  |  360  | 52  |                 try { |  361  | 52  |                     doOneShot = ds.Get<bool>();  |  362  | 52  |                 } catch ( ... ) { } |  363  |  |  |  364  | 52  |                 if ( doOneShot == true ) { |  365  | 3  |                     ret = runOneShot(op.cleartext, ds);  |  366  | 49  |                 } else { |  367  | 49  |                     if ( runInit(op) == false ) { |  368  | 0  |                         return std::nullopt;  |  369  | 0  |                     }  |  370  |  |  |  371  | 49  |                     parts = util::ToParts(ds, op.cleartext);  |  372  |  |  |  373  | 49  |                     CF_CHECK_EQ(runUpdate(parts), true);  |  374  |  |  |  375  | 49  |                     ret = runFinalize();  |  376  | 49  |                 }  |  377  |  |  |  378  | 52  | end:  |  379  | 52  |                 if ( doOneShot == false ) { |  380  | 49  |                     runFree();  |  381  | 49  |                 }  |  382  | 52  |                 return ret;  |  383  | 52  |             }  |  
 Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, wc_Sha>::Run(cryptofuzz::operation::Digest&, fuzzing::datasource::Datasource&) cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, wc_Sha256>::Run(cryptofuzz::operation::Digest&, fuzzing::datasource::Datasource&) Line  | Count  | Source  |  355  | 57  |             std::optional<ReturnType> Run(OperationType& op, Datasource& ds) { |  356  | 57  |                 std::optional<ReturnType> ret = std::nullopt;  |  357  | 57  |                 util::Multipart parts;  |  358  |  |  |  359  | 57  |                 bool doOneShot = false;  |  360  | 57  |                 try { |  361  | 57  |                     doOneShot = ds.Get<bool>();  |  362  | 57  |                 } catch ( ... ) { } |  363  |  |  |  364  | 57  |                 if ( doOneShot == true ) { |  365  | 12  |                     ret = runOneShot(op.cleartext, ds);  |  366  | 45  |                 } else { |  367  | 45  |                     if ( runInit(op) == false ) { |  368  | 0  |                         return std::nullopt;  |  369  | 0  |                     }  |  370  |  |  |  371  | 45  |                     parts = util::ToParts(ds, op.cleartext);  |  372  |  |  |  373  | 45  |                     CF_CHECK_EQ(runUpdate(parts), true);  |  374  |  |  |  375  | 40  |                     ret = runFinalize();  |  376  | 40  |                 }  |  377  |  |  |  378  | 57  | end:  |  379  | 57  |                 if ( doOneShot == false ) { |  380  | 45  |                     runFree();  |  381  | 45  |                 }  |  382  | 57  |                 return ret;  |  383  | 57  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, wc_Sha512>::Run(cryptofuzz::operation::Digest&, fuzzing::datasource::Datasource&) Line  | Count  | Source  |  355  | 54  |             std::optional<ReturnType> Run(OperationType& op, Datasource& ds) { |  356  | 54  |                 std::optional<ReturnType> ret = std::nullopt;  |  357  | 54  |                 util::Multipart parts;  |  358  |  |  |  359  | 54  |                 bool doOneShot = false;  |  360  | 54  |                 try { |  361  | 54  |                     doOneShot = ds.Get<bool>();  |  362  | 54  |                 } catch ( ... ) { } |  363  |  |  |  364  | 54  |                 if ( doOneShot == true ) { |  365  | 7  |                     ret = runOneShot(op.cleartext, ds);  |  366  | 47  |                 } else { |  367  | 47  |                     if ( runInit(op) == false ) { |  368  | 0  |                         return std::nullopt;  |  369  | 0  |                     }  |  370  |  |  |  371  | 47  |                     parts = util::ToParts(ds, op.cleartext);  |  372  |  |  |  373  | 47  |                     CF_CHECK_EQ(runUpdate(parts), true);  |  374  |  |  |  375  | 39  |                     ret = runFinalize();  |  376  | 39  |                 }  |  377  |  |  |  378  | 54  | end:  |  379  | 54  |                 if ( doOneShot == false ) { |  380  | 47  |                     runFree();  |  381  | 47  |                 }  |  382  | 54  |                 return ret;  |  383  | 54  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, wc_Sha3>::Run(cryptofuzz::operation::Digest&, fuzzing::datasource::Datasource&) Line  | Count  | Source  |  355  | 70  |             std::optional<ReturnType> Run(OperationType& op, Datasource& ds) { |  356  | 70  |                 std::optional<ReturnType> ret = std::nullopt;  |  357  | 70  |                 util::Multipart parts;  |  358  |  |  |  359  | 70  |                 bool doOneShot = false;  |  360  | 70  |                 try { |  361  | 70  |                     doOneShot = ds.Get<bool>();  |  362  | 70  |                 } catch ( ... ) { } |  363  |  |  |  364  | 70  |                 if ( doOneShot == true ) { |  365  | 6  |                     ret = runOneShot(op.cleartext, ds);  |  366  | 64  |                 } else { |  367  | 64  |                     if ( runInit(op) == false ) { |  368  | 0  |                         return std::nullopt;  |  369  | 0  |                     }  |  370  |  |  |  371  | 64  |                     parts = util::ToParts(ds, op.cleartext);  |  372  |  |  |  373  | 64  |                     CF_CHECK_EQ(runUpdate(parts), true);  |  374  |  |  |  375  | 64  |                     ret = runFinalize();  |  376  | 64  |                 }  |  377  |  |  |  378  | 70  | end:  |  379  | 70  |                 if ( doOneShot == false ) { |  380  | 64  |                     runFree();  |  381  | 64  |                 }  |  382  | 70  |                 return ret;  |  383  | 70  |             }  |  
 Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, Blake2b>::Run(cryptofuzz::operation::Digest&, fuzzing::datasource::Datasource&) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Operation<cryptofuzz::operation::Digest, cryptofuzz::Buffer, Blake2s>::Run(cryptofuzz::operation::Digest&, fuzzing::datasource::Datasource&)  | 
384  |  |     };  | 
385  |  |  | 
386  |  |     template <class CTXType>  | 
387  |  |     class Init { | 
388  |  |         public:  | 
389  |  |             virtual bool Initialize(CTXType* ctx) = 0;  | 
390  | 34  |             Init(void) { }cryptofuzz::module::wolfCrypt_detail::Init<Md2>::Init() Line  | Count  | Source  |  390  | 2  |             Init(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::Init<Md4>::Init() Line  | Count  | Source  |  390  | 2  |             Init(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::Init<wc_Md5>::Init() Line  | Count  | Source  |  390  | 2  |             Init(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::Init<RipeMd>::Init() Line  | Count  | Source  |  390  | 2  |             Init(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::Init<wc_Sha>::Init() Line  | Count  | Source  |  390  | 2  |             Init(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::Init<wc_Sha256>::Init() Line  | Count  | Source  |  390  | 4  |             Init(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::Init<wc_Sha512>::Init() Line  | Count  | Source  |  390  | 4  |             Init(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::Init<wc_Sha3>::Init() Line  | Count  | Source  |  390  | 12  |             Init(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::Init<Blake2b>::Init() Line  | Count  | Source  |  390  | 2  |             Init(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::Init<Blake2s>::Init() Line  | Count  | Source  |  390  | 2  |             Init(void) { } |  
  | 
391  | 0  |             virtual ~Init() { }Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Init<Md2>::~Init() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Init<Md4>::~Init() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Init<wc_Md5>::~Init() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Init<RipeMd>::~Init() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Init<wc_Sha>::~Init() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Init<wc_Sha256>::~Init() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Init<wc_Sha512>::~Init() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Init<wc_Sha3>::~Init() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Init<Blake2b>::~Init() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Init<Blake2s>::~Init()  | 
392  |  |     };  | 
393  |  |  | 
394  |  |     template <class CTXType>  | 
395  |  |     class Init_Void : public Init<CTXType> { | 
396  |  |         public:  | 
397  |  |             using FnType = void (*)(CTXType*);  | 
398  |  |         private:  | 
399  |  |             FnType init;  | 
400  |  |         public:  | 
401  |  |             Init_Void(FnType init) :  | 
402  |  |                 Init<CTXType>(),  | 
403  |  |                 init(init)  | 
404  | 4  |             { }cryptofuzz::module::wolfCrypt_detail::Init_Void<Md2>::Init_Void(void (*)(Md2*)) Line  | Count  | Source  |  404  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::Init_Void<Md4>::Init_Void(void (*)(Md4*)) Line  | Count  | Source  |  404  | 2  |             { } |  
  | 
405  |  |  | 
406  |  |             ~Init_Void() { } | 
407  |  |  | 
408  | 0  |             bool Initialize(CTXType* ctx) override { | 
409  | 0  |                 CF_NORET(init(ctx));  | 
410  | 0  |                 return true;  | 
411  | 0  |             } Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Init_Void<Md2>::Initialize(Md2*) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Init_Void<Md4>::Initialize(Md4*)  | 
412  |  |     };  | 
413  |  |  | 
414  |  |     template <class CTXType>  | 
415  |  |     class Init_Int : public Init<CTXType> { | 
416  |  |         public:  | 
417  |  |             using FnType = int (*)(CTXType*);  | 
418  |  |         private:  | 
419  |  |             FnType init;  | 
420  |  |         public:  | 
421  |  |             Init_Int(FnType init) :  | 
422  |  |                 Init<CTXType>(),  | 
423  |  |                 init(init)  | 
424  | 12  |             { }cryptofuzz::module::wolfCrypt_detail::Init_Int<RipeMd>::Init_Int(int (*)(RipeMd*)) Line  | Count  | Source  |  424  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha>::Init_Int(int (*)(wc_Sha*)) Line  | Count  | Source  |  424  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha256>::Init_Int(int (*)(wc_Sha256*)) Line  | Count  | Source  |  424  | 4  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha512>::Init_Int(int (*)(wc_Sha512*)) Line  | Count  | Source  |  424  | 4  |             { } |  
  | 
425  |  |  | 
426  |  |             ~Init_Int() { } | 
427  |  |  | 
428  | 141  |             bool Initialize(CTXType* ctx) override { | 
429  | 141  |                 return init(ctx) == 0;  | 
430  | 141  |             } cryptofuzz::module::wolfCrypt_detail::Init_Int<RipeMd>::Initialize(RipeMd*) Line  | Count  | Source  |  428  | 49  |             bool Initialize(CTXType* ctx) override { |  429  | 49  |                 return init(ctx) == 0;  |  430  | 49  |             }  |  
 Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha>::Initialize(wc_Sha*) cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha256>::Initialize(wc_Sha256*) Line  | Count  | Source  |  428  | 45  |             bool Initialize(CTXType* ctx) override { |  429  | 45  |                 return init(ctx) == 0;  |  430  | 45  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha512>::Initialize(wc_Sha512*) Line  | Count  | Source  |  428  | 47  |             bool Initialize(CTXType* ctx) override { |  429  | 47  |                 return init(ctx) == 0;  |  430  | 47  |             }  |  
  | 
431  |  |     };  | 
432  |  |  | 
433  |  |     template <class CTXType>  | 
434  |  |     class Init_IntParams : public Init<CTXType> { | 
435  |  |         public:  | 
436  |  |             using FnType = int (*)(CTXType*, void*, int);  | 
437  |  |         private:  | 
438  |  |             FnType init;  | 
439  |  |         public:  | 
440  |  |             Init_IntParams(FnType init) :  | 
441  |  |                 Init<CTXType>(),  | 
442  |  |                 init(init)  | 
443  | 14  |             { }cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Md5>::Init_IntParams(int (*)(wc_Md5*, void*, int)) Line  | Count  | Source  |  443  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>::Init_IntParams(int (*)(wc_Sha3*, void*, int)) Line  | Count  | Source  |  443  | 12  |             { } |  
  | 
444  |  |  | 
445  |  |             ~Init_IntParams() { } | 
446  |  |  | 
447  | 64  |             bool Initialize(CTXType* ctx) override { | 
448  | 64  |                 return init(ctx, nullptr, INVALID_DEVID) == 0;  | 
449  | 64  |             } Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Md5>::Initialize(wc_Md5*) cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>::Initialize(wc_Sha3*) Line  | Count  | Source  |  447  | 64  |             bool Initialize(CTXType* ctx) override { |  448  | 64  |                 return init(ctx, nullptr, INVALID_DEVID) == 0;  |  449  | 64  |             }  |  
  | 
450  |  |     };  | 
451  |  |  | 
452  |  |     template <class CTXType, unsigned int Param>  | 
453  |  |     class Init_IntFixedParam : public Init<CTXType> { | 
454  |  |         public:  | 
455  |  |             using FnType = int (*)(CTXType*, unsigned int);  | 
456  |  |         private:  | 
457  |  |             FnType init;  | 
458  |  |         public:  | 
459  |  |             Init_IntFixedParam(FnType init) :  | 
460  |  |                 Init<CTXType>(),  | 
461  |  |                 init(init)  | 
462  | 4  |             { }cryptofuzz::module::wolfCrypt_detail::Init_IntFixedParam<Blake2b, 64u>::Init_IntFixedParam(int (*)(Blake2b*, unsigned int)) Line  | Count  | Source  |  462  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::Init_IntFixedParam<Blake2s, 32u>::Init_IntFixedParam(int (*)(Blake2s*, unsigned int)) Line  | Count  | Source  |  462  | 2  |             { } |  
  | 
463  |  |  | 
464  |  |             ~Init_IntFixedParam() { } | 
465  |  |  | 
466  | 0  |             bool Initialize(CTXType* ctx) override { | 
467  | 0  |                 return init(ctx, Param) == 0;  | 
468  | 0  |             } Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Init_IntFixedParam<Blake2b, 64u>::Initialize(Blake2b*) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Init_IntFixedParam<Blake2s, 32u>::Initialize(Blake2s*)  | 
469  |  |     };  | 
470  |  |  | 
471  |  |     template <class CTXType>  | 
472  |  |     class DigestUpdate { | 
473  |  |         public:  | 
474  |  |             virtual bool Update(CTXType* ctx, const uint8_t* data, unsigned int size) = 0;  | 
475  | 34  |             DigestUpdate(void) { }cryptofuzz::module::wolfCrypt_detail::DigestUpdate<Md2>::DigestUpdate() Line  | Count  | Source  |  475  | 2  |             DigestUpdate(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestUpdate<Md4>::DigestUpdate() Line  | Count  | Source  |  475  | 2  |             DigestUpdate(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestUpdate<wc_Md5>::DigestUpdate() Line  | Count  | Source  |  475  | 2  |             DigestUpdate(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestUpdate<RipeMd>::DigestUpdate() Line  | Count  | Source  |  475  | 2  |             DigestUpdate(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestUpdate<wc_Sha>::DigestUpdate() Line  | Count  | Source  |  475  | 2  |             DigestUpdate(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestUpdate<wc_Sha256>::DigestUpdate() Line  | Count  | Source  |  475  | 4  |             DigestUpdate(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestUpdate<wc_Sha512>::DigestUpdate() Line  | Count  | Source  |  475  | 4  |             DigestUpdate(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestUpdate<wc_Sha3>::DigestUpdate() Line  | Count  | Source  |  475  | 12  |             DigestUpdate(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestUpdate<Blake2b>::DigestUpdate() Line  | Count  | Source  |  475  | 2  |             DigestUpdate(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestUpdate<Blake2s>::DigestUpdate() Line  | Count  | Source  |  475  | 2  |             DigestUpdate(void) { } |  
  | 
476  | 0  |             virtual ~DigestUpdate() { }Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestUpdate<Md2>::~DigestUpdate() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestUpdate<Md4>::~DigestUpdate() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestUpdate<wc_Md5>::~DigestUpdate() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestUpdate<RipeMd>::~DigestUpdate() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestUpdate<wc_Sha>::~DigestUpdate() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestUpdate<wc_Sha256>::~DigestUpdate() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestUpdate<wc_Sha512>::~DigestUpdate() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestUpdate<wc_Sha3>::~DigestUpdate() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestUpdate<Blake2b>::~DigestUpdate() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestUpdate<Blake2s>::~DigestUpdate()  | 
477  |  |     };  | 
478  |  |  | 
479  |  |     template <class CTXType>  | 
480  |  |     class DigestUpdate_Void : public DigestUpdate<CTXType> { | 
481  |  |         public:  | 
482  |  |             using FnType = void (*)(CTXType*, const uint8_t*, unsigned int);  | 
483  |  |         private:  | 
484  |  |             FnType update;  | 
485  |  |         public:  | 
486  |  |             DigestUpdate_Void(FnType update) :  | 
487  |  |                 DigestUpdate<CTXType>(),  | 
488  |  |                 update(update)  | 
489  | 4  |             { }cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Void<Md2>::DigestUpdate_Void(void (*)(Md2*, unsigned char const*, unsigned int)) Line  | Count  | Source  |  489  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Void<Md4>::DigestUpdate_Void(void (*)(Md4*, unsigned char const*, unsigned int)) Line  | Count  | Source  |  489  | 2  |             { } |  
  | 
490  |  |  | 
491  |  |             ~DigestUpdate_Void() { } | 
492  |  |  | 
493  | 0  |             bool Update(CTXType* ctx, const uint8_t* data, unsigned int size) override { | 
494  | 0  |                 CF_NORET(update(ctx, data, size));  | 
495  | 0  |                 return true;  | 
496  | 0  |             } Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Void<Md2>::Update(Md2*, unsigned char const*, unsigned int) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Void<Md4>::Update(Md4*, unsigned char const*, unsigned int)  | 
497  |  |     };  | 
498  |  |  | 
499  |  |     template <class CTXType>  | 
500  |  |     class DigestUpdate_Int : public DigestUpdate<CTXType> { | 
501  |  |         public:  | 
502  |  |             using FnType = int (*)(CTXType*, const uint8_t*, unsigned int);  | 
503  |  |         private:  | 
504  |  |             FnType update;  | 
505  |  |         public:  | 
506  |  |             DigestUpdate_Int(FnType update) :  | 
507  |  |                 DigestUpdate<CTXType>(),  | 
508  |  |                 update(update)  | 
509  | 30  |             { }cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Md5>::DigestUpdate_Int(int (*)(wc_Md5*, unsigned char const*, unsigned int)) Line  | Count  | Source  |  509  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<RipeMd>::DigestUpdate_Int(int (*)(RipeMd*, unsigned char const*, unsigned int)) Line  | Count  | Source  |  509  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha>::DigestUpdate_Int(int (*)(wc_Sha*, unsigned char const*, unsigned int)) Line  | Count  | Source  |  509  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha256>::DigestUpdate_Int(int (*)(wc_Sha256*, unsigned char const*, unsigned int)) Line  | Count  | Source  |  509  | 4  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha512>::DigestUpdate_Int(int (*)(wc_Sha512*, unsigned char const*, unsigned int)) Line  | Count  | Source  |  509  | 4  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>::DigestUpdate_Int(int (*)(wc_Sha3*, unsigned char const*, unsigned int)) Line  | Count  | Source  |  509  | 12  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<Blake2b>::DigestUpdate_Int(int (*)(Blake2b*, unsigned char const*, unsigned int)) Line  | Count  | Source  |  509  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<Blake2s>::DigestUpdate_Int(int (*)(Blake2s*, unsigned char const*, unsigned int)) Line  | Count  | Source  |  509  | 2  |             { } |  
  | 
510  |  |  | 
511  |  |             ~DigestUpdate_Int() { } | 
512  |  |  | 
513  | 3.76k  |             bool Update(CTXType* ctx, const uint8_t* data, unsigned int size) override { | 
514  | 3.76k  |                 return update(ctx, data, size) == 0;  | 
515  | 3.76k  |             } Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Md5>::Update(wc_Md5*, unsigned char const*, unsigned int) cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<RipeMd>::Update(RipeMd*, unsigned char const*, unsigned int) Line  | Count  | Source  |  513  | 417  |             bool Update(CTXType* ctx, const uint8_t* data, unsigned int size) override { |  514  | 417  |                 return update(ctx, data, size) == 0;  |  515  | 417  |             }  |  
 Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha>::Update(wc_Sha*, unsigned char const*, unsigned int) cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha256>::Update(wc_Sha256*, unsigned char const*, unsigned int) Line  | Count  | Source  |  513  | 553  |             bool Update(CTXType* ctx, const uint8_t* data, unsigned int size) override { |  514  | 553  |                 return update(ctx, data, size) == 0;  |  515  | 553  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha512>::Update(wc_Sha512*, unsigned char const*, unsigned int) Line  | Count  | Source  |  513  | 980  |             bool Update(CTXType* ctx, const uint8_t* data, unsigned int size) override { |  514  | 980  |                 return update(ctx, data, size) == 0;  |  515  | 980  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>::Update(wc_Sha3*, unsigned char const*, unsigned int) Line  | Count  | Source  |  513  | 1.81k  |             bool Update(CTXType* ctx, const uint8_t* data, unsigned int size) override { |  514  | 1.81k  |                 return update(ctx, data, size) == 0;  |  515  | 1.81k  |             }  |  
 Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<Blake2b>::Update(Blake2b*, unsigned char const*, unsigned int) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<Blake2s>::Update(Blake2s*, unsigned char const*, unsigned int)  | 
516  |  |     };  | 
517  |  |  | 
518  |  |     template <class CTXType>  | 
519  |  |     class DigestFinalize { | 
520  |  |         public:  | 
521  |  |             virtual bool Finalize(CTXType* ctx, uint8_t* data) = 0;  | 
522  | 34  |             DigestFinalize(void) { }cryptofuzz::module::wolfCrypt_detail::DigestFinalize<Md2>::DigestFinalize() Line  | Count  | Source  |  522  | 2  |             DigestFinalize(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestFinalize<Md4>::DigestFinalize() Line  | Count  | Source  |  522  | 2  |             DigestFinalize(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestFinalize<wc_Md5>::DigestFinalize() Line  | Count  | Source  |  522  | 2  |             DigestFinalize(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestFinalize<RipeMd>::DigestFinalize() Line  | Count  | Source  |  522  | 2  |             DigestFinalize(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestFinalize<wc_Sha>::DigestFinalize() Line  | Count  | Source  |  522  | 2  |             DigestFinalize(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestFinalize<wc_Sha256>::DigestFinalize() Line  | Count  | Source  |  522  | 4  |             DigestFinalize(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestFinalize<wc_Sha512>::DigestFinalize() Line  | Count  | Source  |  522  | 4  |             DigestFinalize(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestFinalize<wc_Sha3>::DigestFinalize() Line  | Count  | Source  |  522  | 12  |             DigestFinalize(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestFinalize<Blake2b>::DigestFinalize() Line  | Count  | Source  |  522  | 2  |             DigestFinalize(void) { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestFinalize<Blake2s>::DigestFinalize() Line  | Count  | Source  |  522  | 2  |             DigestFinalize(void) { } |  
  | 
523  | 0  |             virtual ~DigestFinalize() { }Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestFinalize<Md2>::~DigestFinalize() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestFinalize<Md4>::~DigestFinalize() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestFinalize<wc_Md5>::~DigestFinalize() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestFinalize<RipeMd>::~DigestFinalize() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestFinalize<wc_Sha>::~DigestFinalize() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestFinalize<wc_Sha256>::~DigestFinalize() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestFinalize<wc_Sha512>::~DigestFinalize() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestFinalize<wc_Sha3>::~DigestFinalize() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestFinalize<Blake2b>::~DigestFinalize() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestFinalize<Blake2s>::~DigestFinalize()  | 
524  |  |     };  | 
525  |  |  | 
526  |  |     template <class CTXType>  | 
527  |  |     class DigestFinalize_Void : public DigestFinalize<CTXType> { | 
528  |  |         public:  | 
529  |  |             using FnType = void (*)(CTXType*, uint8_t*);  | 
530  |  |         private:  | 
531  |  |             FnType finalize;  | 
532  |  |         public:  | 
533  |  |             DigestFinalize_Void(FnType finalize) :  | 
534  |  |                 DigestFinalize<CTXType>(),  | 
535  |  |                 finalize(finalize)  | 
536  | 4  |             { }cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Void<Md2>::DigestFinalize_Void(void (*)(Md2*, unsigned char*)) Line  | Count  | Source  |  536  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Void<Md4>::DigestFinalize_Void(void (*)(Md4*, unsigned char*)) Line  | Count  | Source  |  536  | 2  |             { } |  
  | 
537  |  |  | 
538  |  |             ~DigestFinalize_Void() { } | 
539  |  |  | 
540  | 0  |             bool Finalize(CTXType* ctx, uint8_t* data) override { | 
541  | 0  |                 CF_NORET(finalize(ctx, data));  | 
542  | 0  |                 return true;  | 
543  | 0  |             } Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Void<Md2>::Finalize(Md2*, unsigned char*) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Void<Md4>::Finalize(Md4*, unsigned char*)  | 
544  |  |     };  | 
545  |  |  | 
546  |  |     template <class CTXType>  | 
547  |  |     class DigestFinalize_Int : public DigestFinalize<CTXType> { | 
548  |  |         public:  | 
549  |  |             using FnType = int (*)(CTXType*, uint8_t*);  | 
550  |  |         private:  | 
551  |  |             FnType finalize;  | 
552  |  |         public:  | 
553  |  |             DigestFinalize_Int(FnType finalize) :  | 
554  |  |                 DigestFinalize<CTXType>(),  | 
555  |  |                 finalize(finalize)  | 
556  | 22  |             { }cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Md5>::DigestFinalize_Int(int (*)(wc_Md5*, unsigned char*)) Line  | Count  | Source  |  556  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<RipeMd>::DigestFinalize_Int(int (*)(RipeMd*, unsigned char*)) Line  | Count  | Source  |  556  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha>::DigestFinalize_Int(int (*)(wc_Sha*, unsigned char*)) Line  | Count  | Source  |  556  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha256>::DigestFinalize_Int(int (*)(wc_Sha256*, unsigned char*)) Line  | Count  | Source  |  556  | 4  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha512>::DigestFinalize_Int(int (*)(wc_Sha512*, unsigned char*)) Line  | Count  | Source  |  556  | 4  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3>::DigestFinalize_Int(int (*)(wc_Sha3*, unsigned char*)) Line  | Count  | Source  |  556  | 8  |             { } |  
  | 
557  |  |  | 
558  |  |             ~DigestFinalize_Int() { } | 
559  |  |  | 
560  | 192  |             bool Finalize(CTXType* ctx, uint8_t* data) override { | 
561  | 192  |                 return finalize(ctx, data) == 0;  | 
562  | 192  |             } Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Md5>::Finalize(wc_Md5*, unsigned char*) cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<RipeMd>::Finalize(RipeMd*, unsigned char*) Line  | Count  | Source  |  560  | 49  |             bool Finalize(CTXType* ctx, uint8_t* data) override { |  561  | 49  |                 return finalize(ctx, data) == 0;  |  562  | 49  |             }  |  
 Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha>::Finalize(wc_Sha*, unsigned char*) cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha256>::Finalize(wc_Sha256*, unsigned char*) Line  | Count  | Source  |  560  | 40  |             bool Finalize(CTXType* ctx, uint8_t* data) override { |  561  | 40  |                 return finalize(ctx, data) == 0;  |  562  | 40  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha512>::Finalize(wc_Sha512*, unsigned char*) Line  | Count  | Source  |  560  | 39  |             bool Finalize(CTXType* ctx, uint8_t* data) override { |  561  | 39  |                 return finalize(ctx, data) == 0;  |  562  | 39  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3>::Finalize(wc_Sha3*, unsigned char*) Line  | Count  | Source  |  560  | 64  |             bool Finalize(CTXType* ctx, uint8_t* data) override { |  561  | 64  |                 return finalize(ctx, data) == 0;  |  562  | 64  |             }  |  
  | 
563  |  |     };  | 
564  |  |  | 
565  |  |     template <class CTXType, unsigned int Param>  | 
566  |  |     class DigestFinalize_IntFixedParam : public DigestFinalize<CTXType> { | 
567  |  |         public:  | 
568  |  |             using FnType = int (*)(CTXType*, uint8_t*, unsigned int);  | 
569  |  |         private:  | 
570  |  |             FnType finalize;  | 
571  |  |         public:  | 
572  |  |             DigestFinalize_IntFixedParam(FnType finalize) :  | 
573  |  |                 DigestFinalize<CTXType>(),  | 
574  |  |                 finalize(finalize)  | 
575  | 8  |             { }cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<Blake2b, 64u>::DigestFinalize_IntFixedParam(int (*)(Blake2b*, unsigned char*, unsigned int)) Line  | Count  | Source  |  575  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<Blake2s, 32u>::DigestFinalize_IntFixedParam(int (*)(Blake2s*, unsigned char*, unsigned int)) Line  | Count  | Source  |  575  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<wc_Sha3, 16u>::DigestFinalize_IntFixedParam(int (*)(wc_Sha3*, unsigned char*, unsigned int)) Line  | Count  | Source  |  575  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<wc_Sha3, 32u>::DigestFinalize_IntFixedParam(int (*)(wc_Sha3*, unsigned char*, unsigned int)) Line  | Count  | Source  |  575  | 2  |             { } |  
  | 
576  |  |  | 
577  |  |             ~DigestFinalize_IntFixedParam() { } | 
578  |  |  | 
579  | 0  |             bool Finalize(CTXType* ctx, uint8_t* data) override { | 
580  | 0  |                 return finalize(ctx, data, Param) == 0;  | 
581  | 0  |             } Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<Blake2b, 64u>::Finalize(Blake2b*, unsigned char*) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<Blake2s, 32u>::Finalize(Blake2s*, unsigned char*) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<wc_Sha3, 16u>::Finalize(wc_Sha3*, unsigned char*) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<wc_Sha3, 32u>::Finalize(wc_Sha3*, unsigned char*)  | 
582  |  |     };  | 
583  |  |  | 
584  |  |     template <class CTXType, size_t DigestSize, class InitType, class UpdateType, class FinalizeType>  | 
585  |  |     class Digest : public Operation<operation::Digest, component::Digest, CTXType> { | 
586  |  |         private:  | 
587  |  |             InitType init;  | 
588  |  |             UpdateType update;  | 
589  |  |             FinalizeType finalize;  | 
590  |  |             void (*freeCTX)(CTXType*);  | 
591  |  |             int (*copy)(CTXType*, CTXType*);  | 
592  |  |             int (*oneShot)(const byte*, word32, byte*);  | 
593  | 3.95k  |             CTXType* getCtx(void) { | 
594  | 3.95k  |                 bool doCopy = false;  | 
595  | 3.95k  |                 try { | 
596  | 3.95k  |                     doCopy = ds->Get<bool>();  | 
597  | 3.95k  |                 } catch ( ... ) { } | 
598  | 3.95k  |                 if ( doCopy ) { | 
599  | 1.29k  |                     if ( copy != nullptr ) { | 
600  | 1.07k  |                         CTXType dest;  | 
601  | 1.07k  |                         if ( copy(&this->ctx, &dest) == 0 ) { | 
602  | 1.07k  |                             memcpy(&this->ctx, &dest, sizeof(CTXType));  | 
603  | 1.07k  |                         }  | 
604  | 1.07k  |                     }  | 
605  | 1.29k  |                 }  | 
606  | 3.95k  |                 return &this->ctx;  | 
607  | 3.95k  |             } Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<Md2, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_Void<Md2>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Void<Md2>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Void<Md2> >::getCtx() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<Md4, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_Void<Md4>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Void<Md4>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Void<Md4> >::getCtx() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Md5, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Md5>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Md5>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Md5> >::getCtx() cryptofuzz::module::wolfCrypt_detail::Digest<RipeMd, 20ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<RipeMd>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<RipeMd>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<RipeMd> >::getCtx() Line  | Count  | Source  |  593  | 466  |             CTXType* getCtx(void) { |  594  | 466  |                 bool doCopy = false;  |  595  | 466  |                 try { |  596  | 466  |                     doCopy = ds->Get<bool>();  |  597  | 466  |                 } catch ( ... ) { } |  598  | 466  |                 if ( doCopy ) { |  599  | 223  |                     if ( copy != nullptr ) { |  600  | 0  |                         CTXType dest;  |  601  | 0  |                         if ( copy(&this->ctx, &dest) == 0 ) { |  602  | 0  |                             memcpy(&this->ctx, &dest, sizeof(CTXType));  |  603  | 0  |                         }  |  604  | 0  |                     }  |  605  | 223  |                 }  |  606  | 466  |                 return &this->ctx;  |  607  | 466  |             }  |  
 Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha, 20ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha> >::getCtx() cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha256, 28ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha256> >::getCtx() Line  | Count  | Source  |  593  | 240  |             CTXType* getCtx(void) { |  594  | 240  |                 bool doCopy = false;  |  595  | 240  |                 try { |  596  | 240  |                     doCopy = ds->Get<bool>();  |  597  | 240  |                 } catch ( ... ) { } |  598  | 240  |                 if ( doCopy ) { |  599  | 147  |                     if ( copy != nullptr ) { |  600  | 147  |                         CTXType dest;  |  601  | 147  |                         if ( copy(&this->ctx, &dest) == 0 ) { |  602  | 147  |                             memcpy(&this->ctx, &dest, sizeof(CTXType));  |  603  | 147  |                         }  |  604  | 147  |                     }  |  605  | 147  |                 }  |  606  | 240  |                 return &this->ctx;  |  607  | 240  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha256, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha256> >::getCtx() Line  | Count  | Source  |  593  | 353  |             CTXType* getCtx(void) { |  594  | 353  |                 bool doCopy = false;  |  595  | 353  |                 try { |  596  | 353  |                     doCopy = ds->Get<bool>();  |  597  | 353  |                 } catch ( ... ) { } |  598  | 353  |                 if ( doCopy ) { |  599  | 93  |                     if ( copy != nullptr ) { |  600  | 93  |                         CTXType dest;  |  601  | 93  |                         if ( copy(&this->ctx, &dest) == 0 ) { |  602  | 93  |                             memcpy(&this->ctx, &dest, sizeof(CTXType));  |  603  | 93  |                         }  |  604  | 93  |                     }  |  605  | 93  |                 }  |  606  | 353  |                 return &this->ctx;  |  607  | 353  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha512, 48ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha512> >::getCtx() Line  | Count  | Source  |  593  | 494  |             CTXType* getCtx(void) { |  594  | 494  |                 bool doCopy = false;  |  595  | 494  |                 try { |  596  | 494  |                     doCopy = ds->Get<bool>();  |  597  | 494  |                 } catch ( ... ) { } |  598  | 494  |                 if ( doCopy ) { |  599  | 102  |                     if ( copy != nullptr ) { |  600  | 102  |                         CTXType dest;  |  601  | 102  |                         if ( copy(&this->ctx, &dest) == 0 ) { |  602  | 102  |                             memcpy(&this->ctx, &dest, sizeof(CTXType));  |  603  | 102  |                         }  |  604  | 102  |                     }  |  605  | 102  |                 }  |  606  | 494  |                 return &this->ctx;  |  607  | 494  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha512, 64ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha512> >::getCtx() Line  | Count  | Source  |  593  | 525  |             CTXType* getCtx(void) { |  594  | 525  |                 bool doCopy = false;  |  595  | 525  |                 try { |  596  | 525  |                     doCopy = ds->Get<bool>();  |  597  | 525  |                 } catch ( ... ) { } |  598  | 525  |                 if ( doCopy ) { |  599  | 220  |                     if ( copy != nullptr ) { |  600  | 220  |                         CTXType dest;  |  601  | 220  |                         if ( copy(&this->ctx, &dest) == 0 ) { |  602  | 220  |                             memcpy(&this->ctx, &dest, sizeof(CTXType));  |  603  | 220  |                         }  |  604  | 220  |                     }  |  605  | 220  |                 }  |  606  | 525  |                 return &this->ctx;  |  607  | 525  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 28ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::getCtx() Line  | Count  | Source  |  593  | 497  |             CTXType* getCtx(void) { |  594  | 497  |                 bool doCopy = false;  |  595  | 497  |                 try { |  596  | 497  |                     doCopy = ds->Get<bool>();  |  597  | 497  |                 } catch ( ... ) { } |  598  | 497  |                 if ( doCopy ) { |  599  | 73  |                     if ( copy != nullptr ) { |  600  | 73  |                         CTXType dest;  |  601  | 73  |                         if ( copy(&this->ctx, &dest) == 0 ) { |  602  | 73  |                             memcpy(&this->ctx, &dest, sizeof(CTXType));  |  603  | 73  |                         }  |  604  | 73  |                     }  |  605  | 73  |                 }  |  606  | 497  |                 return &this->ctx;  |  607  | 497  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::getCtx() Line  | Count  | Source  |  593  | 404  |             CTXType* getCtx(void) { |  594  | 404  |                 bool doCopy = false;  |  595  | 404  |                 try { |  596  | 404  |                     doCopy = ds->Get<bool>();  |  597  | 404  |                 } catch ( ... ) { } |  598  | 404  |                 if ( doCopy ) { |  599  | 62  |                     if ( copy != nullptr ) { |  600  | 62  |                         CTXType dest;  |  601  | 62  |                         if ( copy(&this->ctx, &dest) == 0 ) { |  602  | 62  |                             memcpy(&this->ctx, &dest, sizeof(CTXType));  |  603  | 62  |                         }  |  604  | 62  |                     }  |  605  | 62  |                 }  |  606  | 404  |                 return &this->ctx;  |  607  | 404  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 48ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::getCtx() Line  | Count  | Source  |  593  | 450  |             CTXType* getCtx(void) { |  594  | 450  |                 bool doCopy = false;  |  595  | 450  |                 try { |  596  | 450  |                     doCopy = ds->Get<bool>();  |  597  | 450  |                 } catch ( ... ) { } |  598  | 450  |                 if ( doCopy ) { |  599  | 244  |                     if ( copy != nullptr ) { |  600  | 244  |                         CTXType dest;  |  601  | 244  |                         if ( copy(&this->ctx, &dest) == 0 ) { |  602  | 244  |                             memcpy(&this->ctx, &dest, sizeof(CTXType));  |  603  | 244  |                         }  |  604  | 244  |                     }  |  605  | 244  |                 }  |  606  | 450  |                 return &this->ctx;  |  607  | 450  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 64ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::getCtx() Line  | Count  | Source  |  593  | 526  |             CTXType* getCtx(void) { |  594  | 526  |                 bool doCopy = false;  |  595  | 526  |                 try { |  596  | 526  |                     doCopy = ds->Get<bool>();  |  597  | 526  |                 } catch ( ... ) { } |  598  | 526  |                 if ( doCopy ) { |  599  | 134  |                     if ( copy != nullptr ) { |  600  | 134  |                         CTXType dest;  |  601  | 134  |                         if ( copy(&this->ctx, &dest) == 0 ) { |  602  | 134  |                             memcpy(&this->ctx, &dest, sizeof(CTXType));  |  603  | 134  |                         }  |  604  | 134  |                     }  |  605  | 134  |                 }  |  606  | 526  |                 return &this->ctx;  |  607  | 526  |             }  |  
 Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<Blake2b, 64ul, cryptofuzz::module::wolfCrypt_detail::Init_IntFixedParam<Blake2b, 64u>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<Blake2b>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<Blake2b, 64u> >::getCtx() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<Blake2s, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_IntFixedParam<Blake2s, 32u>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<Blake2s>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<Blake2s, 32u> >::getCtx() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<wc_Sha3, 16u> >::getCtx() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<wc_Sha3, 32u> >::getCtx()  | 
608  |  |         public:  | 
609  |  |             Digest(  | 
610  |  |                 typename InitType::FnType initFn,  | 
611  |  |                 typename UpdateType::FnType updateFn,  | 
612  |  |                 typename FinalizeType::FnType finalizeFn,  | 
613  |  |                 void (*freeCTX)(CTXType*) = nullptr,  | 
614  |  |                 int (*copy)(CTXType*, CTXType*) = nullptr,  | 
615  |  |                 int (*oneShot)(const byte*, word32, byte*) = nullptr  | 
616  |  |             ) :  | 
617  |  |                 Operation<operation::Digest, component::Digest, CTXType>(),  | 
618  |  |                 init(initFn),  | 
619  |  |                 update(updateFn),  | 
620  |  |                 finalize(finalizeFn),  | 
621  |  |                 freeCTX(freeCTX),  | 
622  |  |                 copy(copy),  | 
623  |  |                 oneShot(oneShot)  | 
624  | 34  |             { }cryptofuzz::module::wolfCrypt_detail::Digest<Md2, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_Void<Md2>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Void<Md2>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Void<Md2> >::Digest(void (*)(Md2*), void (*)(Md2*, unsigned char const*, unsigned int), void (*)(Md2*, unsigned char*), void (*)(Md2*), int (*)(Md2*, Md2*), int (*)(unsigned char const*, unsigned int, unsigned char*)) Line  | Count  | Source  |  624  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::Digest<Md4, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_Void<Md4>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Void<Md4>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Void<Md4> >::Digest(void (*)(Md4*), void (*)(Md4*, unsigned char const*, unsigned int), void (*)(Md4*, unsigned char*), void (*)(Md4*), int (*)(Md4*, Md4*), int (*)(unsigned char const*, unsigned int, unsigned char*)) Line  | Count  | Source  |  624  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Md5, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Md5>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Md5>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Md5> >::Digest(int (*)(wc_Md5*, void*, int), int (*)(wc_Md5*, unsigned char const*, unsigned int), int (*)(wc_Md5*, unsigned char*), void (*)(wc_Md5*), int (*)(wc_Md5*, wc_Md5*), int (*)(unsigned char const*, unsigned int, unsigned char*)) Line  | Count  | Source  |  624  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::Digest<RipeMd, 20ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<RipeMd>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<RipeMd>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<RipeMd> >::Digest(int (*)(RipeMd*), int (*)(RipeMd*, unsigned char const*, unsigned int), int (*)(RipeMd*, unsigned char*), void (*)(RipeMd*), int (*)(RipeMd*, RipeMd*), int (*)(unsigned char const*, unsigned int, unsigned char*)) Line  | Count  | Source  |  624  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha, 20ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha> >::Digest(int (*)(wc_Sha*), int (*)(wc_Sha*, unsigned char const*, unsigned int), int (*)(wc_Sha*, unsigned char*), void (*)(wc_Sha*), int (*)(wc_Sha*, wc_Sha*), int (*)(unsigned char const*, unsigned int, unsigned char*)) Line  | Count  | Source  |  624  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha256, 28ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha256> >::Digest(int (*)(wc_Sha256*), int (*)(wc_Sha256*, unsigned char const*, unsigned int), int (*)(wc_Sha256*, unsigned char*), void (*)(wc_Sha256*), int (*)(wc_Sha256*, wc_Sha256*), int (*)(unsigned char const*, unsigned int, unsigned char*)) Line  | Count  | Source  |  624  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha256, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha256> >::Digest(int (*)(wc_Sha256*), int (*)(wc_Sha256*, unsigned char const*, unsigned int), int (*)(wc_Sha256*, unsigned char*), void (*)(wc_Sha256*), int (*)(wc_Sha256*, wc_Sha256*), int (*)(unsigned char const*, unsigned int, unsigned char*)) Line  | Count  | Source  |  624  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha512, 48ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha512> >::Digest(int (*)(wc_Sha512*), int (*)(wc_Sha512*, unsigned char const*, unsigned int), int (*)(wc_Sha512*, unsigned char*), void (*)(wc_Sha512*), int (*)(wc_Sha512*, wc_Sha512*), int (*)(unsigned char const*, unsigned int, unsigned char*)) Line  | Count  | Source  |  624  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha512, 64ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha512> >::Digest(int (*)(wc_Sha512*), int (*)(wc_Sha512*, unsigned char const*, unsigned int), int (*)(wc_Sha512*, unsigned char*), void (*)(wc_Sha512*), int (*)(wc_Sha512*, wc_Sha512*), int (*)(unsigned char const*, unsigned int, unsigned char*)) Line  | Count  | Source  |  624  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 28ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::Digest(int (*)(wc_Sha3*, void*, int), int (*)(wc_Sha3*, unsigned char const*, unsigned int), int (*)(wc_Sha3*, unsigned char*), void (*)(wc_Sha3*), int (*)(wc_Sha3*, wc_Sha3*), int (*)(unsigned char const*, unsigned int, unsigned char*)) Line  | Count  | Source  |  624  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::Digest(int (*)(wc_Sha3*, void*, int), int (*)(wc_Sha3*, unsigned char const*, unsigned int), int (*)(wc_Sha3*, unsigned char*), void (*)(wc_Sha3*), int (*)(wc_Sha3*, wc_Sha3*), int (*)(unsigned char const*, unsigned int, unsigned char*)) Line  | Count  | Source  |  624  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 48ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::Digest(int (*)(wc_Sha3*, void*, int), int (*)(wc_Sha3*, unsigned char const*, unsigned int), int (*)(wc_Sha3*, unsigned char*), void (*)(wc_Sha3*), int (*)(wc_Sha3*, wc_Sha3*), int (*)(unsigned char const*, unsigned int, unsigned char*)) Line  | Count  | Source  |  624  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 64ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::Digest(int (*)(wc_Sha3*, void*, int), int (*)(wc_Sha3*, unsigned char const*, unsigned int), int (*)(wc_Sha3*, unsigned char*), void (*)(wc_Sha3*), int (*)(wc_Sha3*, wc_Sha3*), int (*)(unsigned char const*, unsigned int, unsigned char*)) Line  | Count  | Source  |  624  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::Digest<Blake2b, 64ul, cryptofuzz::module::wolfCrypt_detail::Init_IntFixedParam<Blake2b, 64u>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<Blake2b>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<Blake2b, 64u> >::Digest(int (*)(Blake2b*, unsigned int), int (*)(Blake2b*, unsigned char const*, unsigned int), int (*)(Blake2b*, unsigned char*, unsigned int), void (*)(Blake2b*), int (*)(Blake2b*, Blake2b*), int (*)(unsigned char const*, unsigned int, unsigned char*)) Line  | Count  | Source  |  624  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::Digest<Blake2s, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_IntFixedParam<Blake2s, 32u>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<Blake2s>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<Blake2s, 32u> >::Digest(int (*)(Blake2s*, unsigned int), int (*)(Blake2s*, unsigned char const*, unsigned int), int (*)(Blake2s*, unsigned char*, unsigned int), void (*)(Blake2s*), int (*)(Blake2s*, Blake2s*), int (*)(unsigned char const*, unsigned int, unsigned char*)) Line  | Count  | Source  |  624  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<wc_Sha3, 16u> >::Digest(int (*)(wc_Sha3*, void*, int), int (*)(wc_Sha3*, unsigned char const*, unsigned int), int (*)(wc_Sha3*, unsigned char*, unsigned int), void (*)(wc_Sha3*), int (*)(wc_Sha3*, wc_Sha3*), int (*)(unsigned char const*, unsigned int, unsigned char*)) Line  | Count  | Source  |  624  | 2  |             { } |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<wc_Sha3, 32u> >::Digest(int (*)(wc_Sha3*, void*, int), int (*)(wc_Sha3*, unsigned char const*, unsigned int), int (*)(wc_Sha3*, unsigned char*, unsigned int), void (*)(wc_Sha3*), int (*)(wc_Sha3*, wc_Sha3*), int (*)(unsigned char const*, unsigned int, unsigned char*)) Line  | Count  | Source  |  624  | 2  |             { } |  
  | 
625  |  |  | 
626  | 205  |             bool runInit(operation::Digest& op) override { | 
627  | 205  |                 (void)op;  | 
628  | 205  |                 return init.Initialize(&this->ctx);  | 
629  | 205  |             } Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<Md2, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_Void<Md2>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Void<Md2>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Void<Md2> >::runInit(cryptofuzz::operation::Digest&) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<Md4, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_Void<Md4>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Void<Md4>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Void<Md4> >::runInit(cryptofuzz::operation::Digest&) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Md5, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Md5>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Md5>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Md5> >::runInit(cryptofuzz::operation::Digest&) cryptofuzz::module::wolfCrypt_detail::Digest<RipeMd, 20ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<RipeMd>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<RipeMd>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<RipeMd> >::runInit(cryptofuzz::operation::Digest&) Line  | Count  | Source  |  626  | 49  |             bool runInit(operation::Digest& op) override { |  627  | 49  |                 (void)op;  |  628  | 49  |                 return init.Initialize(&this->ctx);  |  629  | 49  |             }  |  
 Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha, 20ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha> >::runInit(cryptofuzz::operation::Digest&) cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha256, 28ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha256> >::runInit(cryptofuzz::operation::Digest&) Line  | Count  | Source  |  626  | 21  |             bool runInit(operation::Digest& op) override { |  627  | 21  |                 (void)op;  |  628  | 21  |                 return init.Initialize(&this->ctx);  |  629  | 21  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha256, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha256> >::runInit(cryptofuzz::operation::Digest&) Line  | Count  | Source  |  626  | 24  |             bool runInit(operation::Digest& op) override { |  627  | 24  |                 (void)op;  |  628  | 24  |                 return init.Initialize(&this->ctx);  |  629  | 24  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha512, 48ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha512> >::runInit(cryptofuzz::operation::Digest&) Line  | Count  | Source  |  626  | 26  |             bool runInit(operation::Digest& op) override { |  627  | 26  |                 (void)op;  |  628  | 26  |                 return init.Initialize(&this->ctx);  |  629  | 26  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha512, 64ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha512> >::runInit(cryptofuzz::operation::Digest&) Line  | Count  | Source  |  626  | 21  |             bool runInit(operation::Digest& op) override { |  627  | 21  |                 (void)op;  |  628  | 21  |                 return init.Initialize(&this->ctx);  |  629  | 21  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 28ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::runInit(cryptofuzz::operation::Digest&) Line  | Count  | Source  |  626  | 23  |             bool runInit(operation::Digest& op) override { |  627  | 23  |                 (void)op;  |  628  | 23  |                 return init.Initialize(&this->ctx);  |  629  | 23  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::runInit(cryptofuzz::operation::Digest&) Line  | Count  | Source  |  626  | 14  |             bool runInit(operation::Digest& op) override { |  627  | 14  |                 (void)op;  |  628  | 14  |                 return init.Initialize(&this->ctx);  |  629  | 14  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 48ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::runInit(cryptofuzz::operation::Digest&) Line  | Count  | Source  |  626  | 11  |             bool runInit(operation::Digest& op) override { |  627  | 11  |                 (void)op;  |  628  | 11  |                 return init.Initialize(&this->ctx);  |  629  | 11  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 64ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::runInit(cryptofuzz::operation::Digest&) Line  | Count  | Source  |  626  | 16  |             bool runInit(operation::Digest& op) override { |  627  | 16  |                 (void)op;  |  628  | 16  |                 return init.Initialize(&this->ctx);  |  629  | 16  |             }  |  
 Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<Blake2b, 64ul, cryptofuzz::module::wolfCrypt_detail::Init_IntFixedParam<Blake2b, 64u>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<Blake2b>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<Blake2b, 64u> >::runInit(cryptofuzz::operation::Digest&) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<Blake2s, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_IntFixedParam<Blake2s, 32u>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<Blake2s>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<Blake2s, 32u> >::runInit(cryptofuzz::operation::Digest&) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<wc_Sha3, 16u> >::runInit(cryptofuzz::operation::Digest&) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<wc_Sha3, 32u> >::runInit(cryptofuzz::operation::Digest&)  | 
630  |  |  | 
631  | 205  |             bool runUpdate(util::Multipart& parts) override { | 
632  | 3.76k  |                 for (const auto& part : parts) { | 
633  | 3.76k  |                     if ( update.Update(getCtx(), part.first, part.second) == false ) { | 
634  | 13  |                         return false;  | 
635  | 13  |                     }  | 
636  | 3.76k  |                 }  | 
637  |  |  | 
638  | 192  |                 return true;  | 
639  | 205  |             } Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<Md2, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_Void<Md2>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Void<Md2>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Void<Md2> >::runUpdate(std::__1::vector<std::__1::pair<unsigned char const*, unsigned long>, std::__1::allocator<std::__1::pair<unsigned char const*, unsigned long> > >&) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<Md4, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_Void<Md4>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Void<Md4>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Void<Md4> >::runUpdate(std::__1::vector<std::__1::pair<unsigned char const*, unsigned long>, std::__1::allocator<std::__1::pair<unsigned char const*, unsigned long> > >&) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Md5, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Md5>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Md5>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Md5> >::runUpdate(std::__1::vector<std::__1::pair<unsigned char const*, unsigned long>, std::__1::allocator<std::__1::pair<unsigned char const*, unsigned long> > >&) cryptofuzz::module::wolfCrypt_detail::Digest<RipeMd, 20ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<RipeMd>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<RipeMd>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<RipeMd> >::runUpdate(std::__1::vector<std::__1::pair<unsigned char const*, unsigned long>, std::__1::allocator<std::__1::pair<unsigned char const*, unsigned long> > >&) Line  | Count  | Source  |  631  | 49  |             bool runUpdate(util::Multipart& parts) override { |  632  | 417  |                 for (const auto& part : parts) { |  633  | 417  |                     if ( update.Update(getCtx(), part.first, part.second) == false ) { |  634  | 0  |                         return false;  |  635  | 0  |                     }  |  636  | 417  |                 }  |  637  |  |  |  638  | 49  |                 return true;  |  639  | 49  |             }  |  
 Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha, 20ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha> >::runUpdate(std::__1::vector<std::__1::pair<unsigned char const*, unsigned long>, std::__1::allocator<std::__1::pair<unsigned char const*, unsigned long> > >&) cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha256, 28ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha256> >::runUpdate(std::__1::vector<std::__1::pair<unsigned char const*, unsigned long>, std::__1::allocator<std::__1::pair<unsigned char const*, unsigned long> > >&) Line  | Count  | Source  |  631  | 21  |             bool runUpdate(util::Multipart& parts) override { |  632  | 222  |                 for (const auto& part : parts) { |  633  | 222  |                     if ( update.Update(getCtx(), part.first, part.second) == false ) { |  634  | 3  |                         return false;  |  635  | 3  |                     }  |  636  | 222  |                 }  |  637  |  |  |  638  | 18  |                 return true;  |  639  | 21  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha256, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha256> >::runUpdate(std::__1::vector<std::__1::pair<unsigned char const*, unsigned long>, std::__1::allocator<std::__1::pair<unsigned char const*, unsigned long> > >&) Line  | Count  | Source  |  631  | 24  |             bool runUpdate(util::Multipart& parts) override { |  632  | 331  |                 for (const auto& part : parts) { |  633  | 331  |                     if ( update.Update(getCtx(), part.first, part.second) == false ) { |  634  | 2  |                         return false;  |  635  | 2  |                     }  |  636  | 331  |                 }  |  637  |  |  |  638  | 22  |                 return true;  |  639  | 24  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha512, 48ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha512> >::runUpdate(std::__1::vector<std::__1::pair<unsigned char const*, unsigned long>, std::__1::allocator<std::__1::pair<unsigned char const*, unsigned long> > >&) Line  | Count  | Source  |  631  | 26  |             bool runUpdate(util::Multipart& parts) override { |  632  | 471  |                 for (const auto& part : parts) { |  633  | 471  |                     if ( update.Update(getCtx(), part.first, part.second) == false ) { |  634  | 3  |                         return false;  |  635  | 3  |                     }  |  636  | 471  |                 }  |  637  |  |  |  638  | 23  |                 return true;  |  639  | 26  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha512, 64ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha512> >::runUpdate(std::__1::vector<std::__1::pair<unsigned char const*, unsigned long>, std::__1::allocator<std::__1::pair<unsigned char const*, unsigned long> > >&) Line  | Count  | Source  |  631  | 21  |             bool runUpdate(util::Multipart& parts) override { |  632  | 509  |                 for (const auto& part : parts) { |  633  | 509  |                     if ( update.Update(getCtx(), part.first, part.second) == false ) { |  634  | 5  |                         return false;  |  635  | 5  |                     }  |  636  | 509  |                 }  |  637  |  |  |  638  | 16  |                 return true;  |  639  | 21  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 28ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::runUpdate(std::__1::vector<std::__1::pair<unsigned char const*, unsigned long>, std::__1::allocator<std::__1::pair<unsigned char const*, unsigned long> > >&) Line  | Count  | Source  |  631  | 23  |             bool runUpdate(util::Multipart& parts) override { |  632  | 474  |                 for (const auto& part : parts) { |  633  | 474  |                     if ( update.Update(getCtx(), part.first, part.second) == false ) { |  634  | 0  |                         return false;  |  635  | 0  |                     }  |  636  | 474  |                 }  |  637  |  |  |  638  | 23  |                 return true;  |  639  | 23  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::runUpdate(std::__1::vector<std::__1::pair<unsigned char const*, unsigned long>, std::__1::allocator<std::__1::pair<unsigned char const*, unsigned long> > >&) Line  | Count  | Source  |  631  | 14  |             bool runUpdate(util::Multipart& parts) override { |  632  | 390  |                 for (const auto& part : parts) { |  633  | 390  |                     if ( update.Update(getCtx(), part.first, part.second) == false ) { |  634  | 0  |                         return false;  |  635  | 0  |                     }  |  636  | 390  |                 }  |  637  |  |  |  638  | 14  |                 return true;  |  639  | 14  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 48ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::runUpdate(std::__1::vector<std::__1::pair<unsigned char const*, unsigned long>, std::__1::allocator<std::__1::pair<unsigned char const*, unsigned long> > >&) Line  | Count  | Source  |  631  | 11  |             bool runUpdate(util::Multipart& parts) override { |  632  | 439  |                 for (const auto& part : parts) { |  633  | 439  |                     if ( update.Update(getCtx(), part.first, part.second) == false ) { |  634  | 0  |                         return false;  |  635  | 0  |                     }  |  636  | 439  |                 }  |  637  |  |  |  638  | 11  |                 return true;  |  639  | 11  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 64ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::runUpdate(std::__1::vector<std::__1::pair<unsigned char const*, unsigned long>, std::__1::allocator<std::__1::pair<unsigned char const*, unsigned long> > >&) Line  | Count  | Source  |  631  | 16  |             bool runUpdate(util::Multipart& parts) override { |  632  | 510  |                 for (const auto& part : parts) { |  633  | 510  |                     if ( update.Update(getCtx(), part.first, part.second) == false ) { |  634  | 0  |                         return false;  |  635  | 0  |                     }  |  636  | 510  |                 }  |  637  |  |  |  638  | 16  |                 return true;  |  639  | 16  |             }  |  
 Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<Blake2b, 64ul, cryptofuzz::module::wolfCrypt_detail::Init_IntFixedParam<Blake2b, 64u>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<Blake2b>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<Blake2b, 64u> >::runUpdate(std::__1::vector<std::__1::pair<unsigned char const*, unsigned long>, std::__1::allocator<std::__1::pair<unsigned char const*, unsigned long> > >&) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<Blake2s, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_IntFixedParam<Blake2s, 32u>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<Blake2s>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<Blake2s, 32u> >::runUpdate(std::__1::vector<std::__1::pair<unsigned char const*, unsigned long>, std::__1::allocator<std::__1::pair<unsigned char const*, unsigned long> > >&) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<wc_Sha3, 16u> >::runUpdate(std::__1::vector<std::__1::pair<unsigned char const*, unsigned long>, std::__1::allocator<std::__1::pair<unsigned char const*, unsigned long> > >&) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<wc_Sha3, 32u> >::runUpdate(std::__1::vector<std::__1::pair<unsigned char const*, unsigned long>, std::__1::allocator<std::__1::pair<unsigned char const*, unsigned long> > >&)  | 
640  |  |  | 
641  | 192  |             std::optional<component::Digest> runFinalize(void) override { | 
642  | 192  |                 std::vector<uint8_t> ret(DigestSize);  | 
643  |  |  | 
644  | 192  |                 if ( finalize.Finalize(getCtx(), ret.data()) == false ) { | 
645  | 15  |                     return std::nullopt;  | 
646  | 15  |                 }  | 
647  |  |  | 
648  | 177  |                 return component::Digest(ret.data(), ret.size());  | 
649  | 192  |             } Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<Md2, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_Void<Md2>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Void<Md2>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Void<Md2> >::runFinalize() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<Md4, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_Void<Md4>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Void<Md4>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Void<Md4> >::runFinalize() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Md5, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Md5>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Md5>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Md5> >::runFinalize() cryptofuzz::module::wolfCrypt_detail::Digest<RipeMd, 20ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<RipeMd>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<RipeMd>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<RipeMd> >::runFinalize() Line  | Count  | Source  |  641  | 49  |             std::optional<component::Digest> runFinalize(void) override { |  642  | 49  |                 std::vector<uint8_t> ret(DigestSize);  |  643  |  |  |  644  | 49  |                 if ( finalize.Finalize(getCtx(), ret.data()) == false ) { |  645  | 0  |                     return std::nullopt;  |  646  | 0  |                 }  |  647  |  |  |  648  | 49  |                 return component::Digest(ret.data(), ret.size());  |  649  | 49  |             }  |  
 Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha, 20ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha> >::runFinalize() cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha256, 28ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha256> >::runFinalize() Line  | Count  | Source  |  641  | 18  |             std::optional<component::Digest> runFinalize(void) override { |  642  | 18  |                 std::vector<uint8_t> ret(DigestSize);  |  643  |  |  |  644  | 18  |                 if ( finalize.Finalize(getCtx(), ret.data()) == false ) { |  645  | 3  |                     return std::nullopt;  |  646  | 3  |                 }  |  647  |  |  |  648  | 15  |                 return component::Digest(ret.data(), ret.size());  |  649  | 18  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha256, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha256> >::runFinalize() Line  | Count  | Source  |  641  | 22  |             std::optional<component::Digest> runFinalize(void) override { |  642  | 22  |                 std::vector<uint8_t> ret(DigestSize);  |  643  |  |  |  644  | 22  |                 if ( finalize.Finalize(getCtx(), ret.data()) == false ) { |  645  | 4  |                     return std::nullopt;  |  646  | 4  |                 }  |  647  |  |  |  648  | 18  |                 return component::Digest(ret.data(), ret.size());  |  649  | 22  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha512, 48ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha512> >::runFinalize() Line  | Count  | Source  |  641  | 23  |             std::optional<component::Digest> runFinalize(void) override { |  642  | 23  |                 std::vector<uint8_t> ret(DigestSize);  |  643  |  |  |  644  | 23  |                 if ( finalize.Finalize(getCtx(), ret.data()) == false ) { |  645  | 3  |                     return std::nullopt;  |  646  | 3  |                 }  |  647  |  |  |  648  | 20  |                 return component::Digest(ret.data(), ret.size());  |  649  | 23  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha512, 64ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha512> >::runFinalize() Line  | Count  | Source  |  641  | 16  |             std::optional<component::Digest> runFinalize(void) override { |  642  | 16  |                 std::vector<uint8_t> ret(DigestSize);  |  643  |  |  |  644  | 16  |                 if ( finalize.Finalize(getCtx(), ret.data()) == false ) { |  645  | 5  |                     return std::nullopt;  |  646  | 5  |                 }  |  647  |  |  |  648  | 11  |                 return component::Digest(ret.data(), ret.size());  |  649  | 16  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 28ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::runFinalize() Line  | Count  | Source  |  641  | 23  |             std::optional<component::Digest> runFinalize(void) override { |  642  | 23  |                 std::vector<uint8_t> ret(DigestSize);  |  643  |  |  |  644  | 23  |                 if ( finalize.Finalize(getCtx(), ret.data()) == false ) { |  645  | 0  |                     return std::nullopt;  |  646  | 0  |                 }  |  647  |  |  |  648  | 23  |                 return component::Digest(ret.data(), ret.size());  |  649  | 23  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::runFinalize() Line  | Count  | Source  |  641  | 14  |             std::optional<component::Digest> runFinalize(void) override { |  642  | 14  |                 std::vector<uint8_t> ret(DigestSize);  |  643  |  |  |  644  | 14  |                 if ( finalize.Finalize(getCtx(), ret.data()) == false ) { |  645  | 0  |                     return std::nullopt;  |  646  | 0  |                 }  |  647  |  |  |  648  | 14  |                 return component::Digest(ret.data(), ret.size());  |  649  | 14  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 48ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::runFinalize() Line  | Count  | Source  |  641  | 11  |             std::optional<component::Digest> runFinalize(void) override { |  642  | 11  |                 std::vector<uint8_t> ret(DigestSize);  |  643  |  |  |  644  | 11  |                 if ( finalize.Finalize(getCtx(), ret.data()) == false ) { |  645  | 0  |                     return std::nullopt;  |  646  | 0  |                 }  |  647  |  |  |  648  | 11  |                 return component::Digest(ret.data(), ret.size());  |  649  | 11  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 64ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::runFinalize() Line  | Count  | Source  |  641  | 16  |             std::optional<component::Digest> runFinalize(void) override { |  642  | 16  |                 std::vector<uint8_t> ret(DigestSize);  |  643  |  |  |  644  | 16  |                 if ( finalize.Finalize(getCtx(), ret.data()) == false ) { |  645  | 0  |                     return std::nullopt;  |  646  | 0  |                 }  |  647  |  |  |  648  | 16  |                 return component::Digest(ret.data(), ret.size());  |  649  | 16  |             }  |  
 Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<Blake2b, 64ul, cryptofuzz::module::wolfCrypt_detail::Init_IntFixedParam<Blake2b, 64u>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<Blake2b>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<Blake2b, 64u> >::runFinalize() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<Blake2s, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_IntFixedParam<Blake2s, 32u>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<Blake2s>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<Blake2s, 32u> >::runFinalize() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<wc_Sha3, 16u> >::runFinalize() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<wc_Sha3, 32u> >::runFinalize()  | 
650  |  |  | 
651  | 205  |             void runFree(void) override { | 
652  | 205  |                 if ( freeCTX != nullptr ) { | 
653  | 156  |                     CF_NORET(freeCTX(&this->ctx));  | 
654  | 156  |                 }  | 
655  | 205  |             } Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<Md2, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_Void<Md2>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Void<Md2>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Void<Md2> >::runFree() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<Md4, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_Void<Md4>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Void<Md4>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Void<Md4> >::runFree() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Md5, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Md5>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Md5>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Md5> >::runFree() cryptofuzz::module::wolfCrypt_detail::Digest<RipeMd, 20ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<RipeMd>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<RipeMd>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<RipeMd> >::runFree() Line  | Count  | Source  |  651  | 49  |             void runFree(void) override { |  652  | 49  |                 if ( freeCTX != nullptr ) { |  653  | 0  |                     CF_NORET(freeCTX(&this->ctx));  |  654  | 0  |                 }  |  655  | 49  |             }  |  
 Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha, 20ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha> >::runFree() cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha256, 28ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha256> >::runFree() Line  | Count  | Source  |  651  | 21  |             void runFree(void) override { |  652  | 21  |                 if ( freeCTX != nullptr ) { |  653  | 21  |                     CF_NORET(freeCTX(&this->ctx));  |  654  | 21  |                 }  |  655  | 21  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha256, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha256> >::runFree() Line  | Count  | Source  |  651  | 24  |             void runFree(void) override { |  652  | 24  |                 if ( freeCTX != nullptr ) { |  653  | 24  |                     CF_NORET(freeCTX(&this->ctx));  |  654  | 24  |                 }  |  655  | 24  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha512, 48ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha512> >::runFree() Line  | Count  | Source  |  651  | 26  |             void runFree(void) override { |  652  | 26  |                 if ( freeCTX != nullptr ) { |  653  | 26  |                     CF_NORET(freeCTX(&this->ctx));  |  654  | 26  |                 }  |  655  | 26  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha512, 64ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha512> >::runFree() Line  | Count  | Source  |  651  | 21  |             void runFree(void) override { |  652  | 21  |                 if ( freeCTX != nullptr ) { |  653  | 21  |                     CF_NORET(freeCTX(&this->ctx));  |  654  | 21  |                 }  |  655  | 21  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 28ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::runFree() Line  | Count  | Source  |  651  | 23  |             void runFree(void) override { |  652  | 23  |                 if ( freeCTX != nullptr ) { |  653  | 23  |                     CF_NORET(freeCTX(&this->ctx));  |  654  | 23  |                 }  |  655  | 23  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::runFree() Line  | Count  | Source  |  651  | 14  |             void runFree(void) override { |  652  | 14  |                 if ( freeCTX != nullptr ) { |  653  | 14  |                     CF_NORET(freeCTX(&this->ctx));  |  654  | 14  |                 }  |  655  | 14  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 48ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::runFree() Line  | Count  | Source  |  651  | 11  |             void runFree(void) override { |  652  | 11  |                 if ( freeCTX != nullptr ) { |  653  | 11  |                     CF_NORET(freeCTX(&this->ctx));  |  654  | 11  |                 }  |  655  | 11  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 64ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::runFree() Line  | Count  | Source  |  651  | 16  |             void runFree(void) override { |  652  | 16  |                 if ( freeCTX != nullptr ) { |  653  | 16  |                     CF_NORET(freeCTX(&this->ctx));  |  654  | 16  |                 }  |  655  | 16  |             }  |  
 Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<Blake2b, 64ul, cryptofuzz::module::wolfCrypt_detail::Init_IntFixedParam<Blake2b, 64u>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<Blake2b>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<Blake2b, 64u> >::runFree() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<Blake2s, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_IntFixedParam<Blake2s, 32u>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<Blake2s>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<Blake2s, 32u> >::runFree() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<wc_Sha3, 16u> >::runFree() Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<wc_Sha3, 32u> >::runFree()  | 
656  |  |  | 
657  | 28  |             std::optional<component::Digest> runOneShot(const Buffer& in, Datasource& ds) override { | 
658  | 28  |                 std::optional<component::Digest> ret = std::nullopt;  | 
659  | 28  |                 std::vector<uint8_t> out(DigestSize);  | 
660  |  |  | 
661  | 28  |                 CF_CHECK_NE(oneShot, nullptr);  | 
662  |  |  | 
663  | 25  |                 CF_CHECK_EQ(oneShot(in.GetPtr(&ds), in.GetSize(), out.data()), 0);  | 
664  |  |  | 
665  | 11  |                 ret = component::Digest(out.data(), out.size());  | 
666  | 28  | end:  | 
667  | 28  |                 return ret;  | 
668  | 11  |             } Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<Md2, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_Void<Md2>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Void<Md2>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Void<Md2> >::runOneShot(cryptofuzz::Buffer const&, fuzzing::datasource::Datasource&) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<Md4, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_Void<Md4>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Void<Md4>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Void<Md4> >::runOneShot(cryptofuzz::Buffer const&, fuzzing::datasource::Datasource&) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Md5, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Md5>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Md5>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Md5> >::runOneShot(cryptofuzz::Buffer const&, fuzzing::datasource::Datasource&) cryptofuzz::module::wolfCrypt_detail::Digest<RipeMd, 20ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<RipeMd>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<RipeMd>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<RipeMd> >::runOneShot(cryptofuzz::Buffer const&, fuzzing::datasource::Datasource&) Line  | Count  | Source  |  657  | 3  |             std::optional<component::Digest> runOneShot(const Buffer& in, Datasource& ds) override { |  658  | 3  |                 std::optional<component::Digest> ret = std::nullopt;  |  659  | 3  |                 std::vector<uint8_t> out(DigestSize);  |  660  |  |  |  661  | 3  |                 CF_CHECK_NE(oneShot, nullptr);  |  662  |  | 
  |  663  | 0  |                 CF_CHECK_EQ(oneShot(in.GetPtr(&ds), in.GetSize(), out.data()), 0);  |  664  |  | 
  |  665  | 0  |                 ret = component::Digest(out.data(), out.size());  |  666  | 3  | end:  |  667  | 3  |                 return ret;  |  668  | 0  |             }  |  
 Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha, 20ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha> >::runOneShot(cryptofuzz::Buffer const&, fuzzing::datasource::Datasource&) cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha256, 28ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha256> >::runOneShot(cryptofuzz::Buffer const&, fuzzing::datasource::Datasource&) Line  | Count  | Source  |  657  | 3  |             std::optional<component::Digest> runOneShot(const Buffer& in, Datasource& ds) override { |  658  | 3  |                 std::optional<component::Digest> ret = std::nullopt;  |  659  | 3  |                 std::vector<uint8_t> out(DigestSize);  |  660  |  |  |  661  | 3  |                 CF_CHECK_NE(oneShot, nullptr);  |  662  |  |  |  663  | 3  |                 CF_CHECK_EQ(oneShot(in.GetPtr(&ds), in.GetSize(), out.data()), 0);  |  664  |  | 
  |  665  | 0  |                 ret = component::Digest(out.data(), out.size());  |  666  | 3  | end:  |  667  | 3  |                 return ret;  |  668  | 0  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha256, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha256>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha256> >::runOneShot(cryptofuzz::Buffer const&, fuzzing::datasource::Datasource&) Line  | Count  | Source  |  657  | 9  |             std::optional<component::Digest> runOneShot(const Buffer& in, Datasource& ds) override { |  658  | 9  |                 std::optional<component::Digest> ret = std::nullopt;  |  659  | 9  |                 std::vector<uint8_t> out(DigestSize);  |  660  |  |  |  661  | 9  |                 CF_CHECK_NE(oneShot, nullptr);  |  662  |  |  |  663  | 9  |                 CF_CHECK_EQ(oneShot(in.GetPtr(&ds), in.GetSize(), out.data()), 0);  |  664  |  |  |  665  | 4  |                 ret = component::Digest(out.data(), out.size());  |  666  | 9  | end:  |  667  | 9  |                 return ret;  |  668  | 4  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha512, 48ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha512> >::runOneShot(cryptofuzz::Buffer const&, fuzzing::datasource::Datasource&) Line  | Count  | Source  |  657  | 4  |             std::optional<component::Digest> runOneShot(const Buffer& in, Datasource& ds) override { |  658  | 4  |                 std::optional<component::Digest> ret = std::nullopt;  |  659  | 4  |                 std::vector<uint8_t> out(DigestSize);  |  660  |  |  |  661  | 4  |                 CF_CHECK_NE(oneShot, nullptr);  |  662  |  |  |  663  | 4  |                 CF_CHECK_EQ(oneShot(in.GetPtr(&ds), in.GetSize(), out.data()), 0);  |  664  |  |  |  665  | 3  |                 ret = component::Digest(out.data(), out.size());  |  666  | 4  | end:  |  667  | 4  |                 return ret;  |  668  | 3  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha512, 64ul, cryptofuzz::module::wolfCrypt_detail::Init_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha512>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha512> >::runOneShot(cryptofuzz::Buffer const&, fuzzing::datasource::Datasource&) Line  | Count  | Source  |  657  | 3  |             std::optional<component::Digest> runOneShot(const Buffer& in, Datasource& ds) override { |  658  | 3  |                 std::optional<component::Digest> ret = std::nullopt;  |  659  | 3  |                 std::vector<uint8_t> out(DigestSize);  |  660  |  |  |  661  | 3  |                 CF_CHECK_NE(oneShot, nullptr);  |  662  |  |  |  663  | 3  |                 CF_CHECK_EQ(oneShot(in.GetPtr(&ds), in.GetSize(), out.data()), 0);  |  664  |  | 
  |  665  | 0  |                 ret = component::Digest(out.data(), out.size());  |  666  | 3  | end:  |  667  | 3  |                 return ret;  |  668  | 0  |             }  |  
 Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 28ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::runOneShot(cryptofuzz::Buffer const&, fuzzing::datasource::Datasource&) cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::runOneShot(cryptofuzz::Buffer const&, fuzzing::datasource::Datasource&) Line  | Count  | Source  |  657  | 3  |             std::optional<component::Digest> runOneShot(const Buffer& in, Datasource& ds) override { |  658  | 3  |                 std::optional<component::Digest> ret = std::nullopt;  |  659  | 3  |                 std::vector<uint8_t> out(DigestSize);  |  660  |  |  |  661  | 3  |                 CF_CHECK_NE(oneShot, nullptr);  |  662  |  |  |  663  | 3  |                 CF_CHECK_EQ(oneShot(in.GetPtr(&ds), in.GetSize(), out.data()), 0);  |  664  |  |  |  665  | 2  |                 ret = component::Digest(out.data(), out.size());  |  666  | 3  | end:  |  667  | 3  |                 return ret;  |  668  | 2  |             }  |  
 cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 48ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::runOneShot(cryptofuzz::Buffer const&, fuzzing::datasource::Datasource&) Line  | Count  | Source  |  657  | 3  |             std::optional<component::Digest> runOneShot(const Buffer& in, Datasource& ds) override { |  658  | 3  |                 std::optional<component::Digest> ret = std::nullopt;  |  659  | 3  |                 std::vector<uint8_t> out(DigestSize);  |  660  |  |  |  661  | 3  |                 CF_CHECK_NE(oneShot, nullptr);  |  662  |  |  |  663  | 3  |                 CF_CHECK_EQ(oneShot(in.GetPtr(&ds), in.GetSize(), out.data()), 0);  |  664  |  |  |  665  | 2  |                 ret = component::Digest(out.data(), out.size());  |  666  | 3  | end:  |  667  | 3  |                 return ret;  |  668  | 2  |             }  |  
 Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 64ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_Int<wc_Sha3> >::runOneShot(cryptofuzz::Buffer const&, fuzzing::datasource::Datasource&) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<Blake2b, 64ul, cryptofuzz::module::wolfCrypt_detail::Init_IntFixedParam<Blake2b, 64u>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<Blake2b>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<Blake2b, 64u> >::runOneShot(cryptofuzz::Buffer const&, fuzzing::datasource::Datasource&) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<Blake2s, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_IntFixedParam<Blake2s, 32u>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<Blake2s>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<Blake2s, 32u> >::runOneShot(cryptofuzz::Buffer const&, fuzzing::datasource::Datasource&) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 16ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<wc_Sha3, 16u> >::runOneShot(cryptofuzz::Buffer const&, fuzzing::datasource::Datasource&) Unexecuted instantiation: cryptofuzz::module::wolfCrypt_detail::Digest<wc_Sha3, 32ul, cryptofuzz::module::wolfCrypt_detail::Init_IntParams<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestUpdate_Int<wc_Sha3>, cryptofuzz::module::wolfCrypt_detail::DigestFinalize_IntFixedParam<wc_Sha3, 32u> >::runOneShot(cryptofuzz::Buffer const&, fuzzing::datasource::Datasource&)  | 
669  |  |     };  | 
670  |  |  | 
671  |  |  | 
672  |  |     Digest<Md2, MD2_DIGEST_SIZE, Init_Void<Md2>, DigestUpdate_Void<Md2>, DigestFinalize_Void<Md2>>  | 
673  |  |         md2(wc_InitMd2, wc_Md2Update, wc_Md2Final, nullptr, nullptr, wc_Md2Hash);  | 
674  |  |  | 
675  |  |     Digest<Md4, MD4_DIGEST_SIZE, Init_Void<Md4>, DigestUpdate_Void<Md4>, DigestFinalize_Void<Md4>>  | 
676  |  |         md4(wc_InitMd4, wc_Md4Update, wc_Md4Final);  | 
677  |  |  | 
678  |  |     Digest<Md5, MD5_DIGEST_SIZE, Init_IntParams<Md5>, DigestUpdate_Int<Md5>, DigestFinalize_Int<Md5>>  | 
679  |  |         md5(wc_InitMd5_ex, wc_Md5Update, wc_Md5Final, wc_Md5Free, wc_Md5Copy, wc_Md5Hash);  | 
680  |  |  | 
681  |  |     Digest<RipeMd, RIPEMD_DIGEST_SIZE, Init_Int<RipeMd>, DigestUpdate_Int<RipeMd>, DigestFinalize_Int<RipeMd>>  | 
682  |  |         ripemd160(wc_InitRipeMd, wc_RipeMdUpdate, wc_RipeMdFinal);  | 
683  |  |  | 
684  |  |     Digest<Sha, WC_SHA_DIGEST_SIZE, Init_Int<Sha>, DigestUpdate_Int<Sha>, DigestFinalize_Int<Sha>>  | 
685  |  |         sha1(wc_InitSha, wc_ShaUpdate, wc_ShaFinal, wc_ShaFree, wc_ShaCopy, wc_ShaHash);  | 
686  |  |  | 
687  |  | #if !defined(__i386__)  | 
688  |  |     Digest<Sha224, WC_SHA224_DIGEST_SIZE, Init_Int<Sha224>, DigestUpdate_Int<Sha224>, DigestFinalize_Int<Sha224>>  | 
689  |  |         sha224(wc_InitSha224, wc_Sha224Update, wc_Sha224Final, wc_Sha224Free, wc_Sha224Copy, wc_Sha224Hash);  | 
690  |  | #endif  | 
691  |  |  | 
692  |  |     Digest<Sha256, WC_SHA256_DIGEST_SIZE, Init_Int<Sha256>, DigestUpdate_Int<Sha256>, DigestFinalize_Int<Sha256>>  | 
693  |  |         sha256(wc_InitSha256, wc_Sha256Update, wc_Sha256Final, wc_Sha256Free, wc_Sha256Copy, wc_Sha256Hash);  | 
694  |  |  | 
695  |  |     Digest<Sha384, WC_SHA384_DIGEST_SIZE, Init_Int<Sha384>, DigestUpdate_Int<Sha384>, DigestFinalize_Int<Sha384>>  | 
696  |  |         sha384(wc_InitSha384, wc_Sha384Update, wc_Sha384Final, wc_Sha384Free, wc_Sha384Copy, wc_Sha384Hash);  | 
697  |  |  | 
698  |  |     Digest<Sha512, WC_SHA512_DIGEST_SIZE, Init_Int<Sha512>, DigestUpdate_Int<Sha512>, DigestFinalize_Int<Sha512>>  | 
699  |  |         sha512(wc_InitSha512, wc_Sha512Update, wc_Sha512Final, wc_Sha512Free, wc_Sha512Copy, wc_Sha512Hash);  | 
700  |  |  | 
701  |  |     Digest<Sha3, WC_SHA3_224_DIGEST_SIZE, Init_IntParams<Sha3>, DigestUpdate_Int<Sha3>, DigestFinalize_Int<Sha3>>  | 
702  |  |         sha3_224(wc_InitSha3_224, wc_Sha3_224_Update, wc_Sha3_224_Final, wc_Sha3_224_Free, wc_Sha3_224_Copy, wc_Sha3_224Hash);  | 
703  |  |  | 
704  |  |     Digest<Sha3, WC_SHA3_256_DIGEST_SIZE, Init_IntParams<Sha3>, DigestUpdate_Int<Sha3>, DigestFinalize_Int<Sha3>>  | 
705  |  |         sha3_256(wc_InitSha3_256, wc_Sha3_256_Update, wc_Sha3_256_Final, wc_Sha3_256_Free, wc_Sha3_256_Copy, wc_Sha3_256Hash);  | 
706  |  |  | 
707  |  |     Digest<Sha3, WC_SHA3_384_DIGEST_SIZE, Init_IntParams<Sha3>, DigestUpdate_Int<Sha3>, DigestFinalize_Int<Sha3>>  | 
708  |  |         sha3_384(wc_InitSha3_384, wc_Sha3_384_Update, wc_Sha3_384_Final, wc_Sha3_384_Free, wc_Sha3_384_Copy, wc_Sha3_384Hash);  | 
709  |  |  | 
710  |  |     Digest<Sha3, WC_SHA3_512_DIGEST_SIZE, Init_IntParams<Sha3>, DigestUpdate_Int<Sha3>, DigestFinalize_Int<Sha3>>  | 
711  |  |         sha3_512(wc_InitSha3_512, wc_Sha3_512_Update, wc_Sha3_512_Final, wc_Sha3_512_Free, wc_Sha3_512_Copy, wc_Sha3_512Hash);  | 
712  |  |  | 
713  |  |     Digest<Blake2b, 64, Init_IntFixedParam<Blake2b, 64>, DigestUpdate_Int<Blake2b>, DigestFinalize_IntFixedParam<Blake2b, 64>>  | 
714  |  |         blake2b512(wc_InitBlake2b, wc_Blake2bUpdate, wc_Blake2bFinal);  | 
715  |  |  | 
716  |  |     Digest<Blake2s, 32, Init_IntFixedParam<Blake2s, 32>, DigestUpdate_Int<Blake2s>, DigestFinalize_IntFixedParam<Blake2s, 32>>  | 
717  |  |         blake2s256(wc_InitBlake2s, wc_Blake2sUpdate, wc_Blake2sFinal);  | 
718  |  |  | 
719  |  |     Digest<wc_Shake, 16, Init_IntParams<wc_Shake>, DigestUpdate_Int<wc_Shake>, DigestFinalize_IntFixedParam<wc_Shake, 16>>  | 
720  |  |         shake256(wc_InitShake128, wc_Shake128_Update, wc_Shake128_Final, wc_Shake128_Free, wc_Shake128_Copy);  | 
721  |  |     Digest<wc_Shake, 32, Init_IntParams<wc_Shake>, DigestUpdate_Int<wc_Shake>, DigestFinalize_IntFixedParam<wc_Shake, 32>>  | 
722  |  |         shake512(wc_InitShake256, wc_Shake256_Update, wc_Shake256_Final, wc_Shake256_Free, wc_Shake256_Copy);  | 
723  |  |  | 
724  | 975  |     std::optional<wc_HashType> toHashType(const component::DigestType& digestType) { | 
725  | 975  |         using fuzzing::datasource::ID;  | 
726  |  |  | 
727  | 975  |         static const std::map<uint64_t, wc_HashType> LUT = { | 
728  | 975  |             { CF_DIGEST("MD2"), WC_HASH_TYPE_MD2 }, | 
729  | 975  |             { CF_DIGEST("MD4"), WC_HASH_TYPE_MD4 }, | 
730  | 975  |             { CF_DIGEST("MD5"), WC_HASH_TYPE_MD5 }, | 
731  | 975  |             { CF_DIGEST("SHA1"), WC_HASH_TYPE_SHA }, | 
732  | 975  |             { CF_DIGEST("SHA224"), WC_HASH_TYPE_SHA224 }, | 
733  | 975  |             { CF_DIGEST("SHA256"), WC_HASH_TYPE_SHA256 }, | 
734  | 975  |             { CF_DIGEST("SHA384"), WC_HASH_TYPE_SHA384 }, | 
735  | 975  |             { CF_DIGEST("SHA512"), WC_HASH_TYPE_SHA512 }, | 
736  | 975  |             { CF_DIGEST("BLAKE2B512"), WC_HASH_TYPE_BLAKE2B }, | 
737  | 975  |             { CF_DIGEST("BLAKE2S256"), WC_HASH_TYPE_BLAKE2S }, | 
738  | 975  |             { CF_DIGEST("SHA3-224"), WC_HASH_TYPE_SHA3_224 }, | 
739  | 975  |             { CF_DIGEST("SHA3-256"), WC_HASH_TYPE_SHA3_256 }, | 
740  | 975  |             { CF_DIGEST("SHA3-384"), WC_HASH_TYPE_SHA3_384 }, | 
741  | 975  |             { CF_DIGEST("SHA3-512"), WC_HASH_TYPE_SHA3_512 }, | 
742  | 975  |             { CF_DIGEST("MD5_SHA1"), WC_HASH_TYPE_MD5_SHA }, | 
743  | 975  |         };  | 
744  |  |  | 
745  | 975  |         if ( LUT.find(digestType.Get()) == LUT.end() ) { | 
746  | 232  |             return std::nullopt;  | 
747  | 232  |         }  | 
748  |  |  | 
749  | 743  |         return LUT.at(digestType.Get());  | 
750  | 975  |     }  | 
751  |  |  | 
752  | 223  |     std::optional<size_t> toHashSize(const component::DigestType& digestType) { | 
753  | 223  |         using fuzzing::datasource::ID;  | 
754  |  |  | 
755  | 223  |         static const std::map<uint64_t, int> LUT = { | 
756  | 223  |             { CF_DIGEST("MD2"), MD2_DIGEST_SIZE }, | 
757  | 223  |             { CF_DIGEST("MD4"), MD4_DIGEST_SIZE }, | 
758  | 223  |             { CF_DIGEST("MD5"), MD5_DIGEST_SIZE }, | 
759  | 223  |             { CF_DIGEST("SHA1"), WC_SHA_DIGEST_SIZE }, | 
760  | 223  | #if !defined(__i386__)  | 
761  | 223  |             { CF_DIGEST("SHA224"), WC_SHA224_DIGEST_SIZE }, | 
762  | 223  | #endif  | 
763  | 223  |             { CF_DIGEST("SHA256"), WC_SHA256_DIGEST_SIZE }, | 
764  | 223  |             { CF_DIGEST("SHA384"), WC_SHA384_DIGEST_SIZE }, | 
765  | 223  |             { CF_DIGEST("SHA512"), WC_SHA512_DIGEST_SIZE }, | 
766  | 223  |             { CF_DIGEST("BLAKE2B512"), BLAKE2B_OUTBYTES }, | 
767  | 223  |             { CF_DIGEST("BLAKE2S256"), BLAKE2S_OUTBYTES }, | 
768  | 223  |             { CF_DIGEST("SHA3-224"), WC_SHA3_224_DIGEST_SIZE }, | 
769  | 223  |             { CF_DIGEST("SHA3-256"), WC_SHA3_256_DIGEST_SIZE }, | 
770  | 223  |             { CF_DIGEST("SHA3-384"), WC_SHA3_384_DIGEST_SIZE }, | 
771  | 223  |             { CF_DIGEST("SHA3-512"), WC_SHA3_512_DIGEST_SIZE }, | 
772  | 223  |         };  | 
773  |  |  | 
774  | 223  |         if ( LUT.find(digestType.Get()) == LUT.end() ) { | 
775  | 0  |             return std::nullopt;  | 
776  | 0  |         }  | 
777  |  |  | 
778  | 223  |         return LUT.at(digestType.Get());  | 
779  | 223  |     }  | 
780  |  |  | 
781  | 155  |     std::optional<component::Digest> DigestOneShot(operation::Digest& op, Datasource& ds) { | 
782  | 155  |         std::optional<component::Digest> ret = std::nullopt;  | 
783  |  |  | 
784  | 155  |         std::optional<wc_HashType> hashType;  | 
785  | 155  |         size_t hashSize;  | 
786  | 155  |         uint8_t* out = nullptr;  | 
787  |  |  | 
788  | 155  |         CF_CHECK_NE(hashType = wolfCrypt_detail::toHashType(op.digestType), std::nullopt);  | 
789  |  |  | 
790  | 77  |         hashSize = wc_HashGetDigestSize(*hashType);  | 
791  | 77  |         out = util::malloc(hashSize);  | 
792  |  |  | 
793  | 77  |         WC_CHECK_EQ(wc_Hash(  | 
794  | 17  |                     *hashType,  | 
795  | 17  |                     op.cleartext.GetPtr(&ds),  | 
796  | 17  |                     op.cleartext.GetSize(),  | 
797  | 17  |                     out,  | 
798  | 17  |                     hashSize), 0);  | 
799  |  |  | 
800  | 17  |         ret = component::Digest(out, hashSize);  | 
801  | 155  | end:  | 
802  | 155  |         util::free(out);  | 
803  |  |  | 
804  | 155  |         return ret;  | 
805  | 17  |     }  | 
806  |  | } /* namespace wolfCrypt_detail */  | 
807  |  |  | 
808  | 457  | std::optional<component::Digest> wolfCrypt::OpDigest(operation::Digest& op) { | 
809  | 457  |     std::optional<component::Digest> ret = std::nullopt;  | 
810  | 457  |     Datasource ds(op.modifier.GetPtr(), op.modifier.GetSize());  | 
811  | 457  |     wolfCrypt_detail::SetGlobalDs(&ds);  | 
812  |  |  | 
813  | 457  |     bool useOneShot = false;  | 
814  | 457  |     try { | 
815  | 457  |         useOneShot = ds.Get<bool>();  | 
816  | 457  |     } catch ( ... ) { } | 
817  |  |  | 
818  | 457  |     if ( useOneShot == true ) { | 
819  | 155  |         ret = wolfCrypt_detail::DigestOneShot(op, ds);  | 
820  | 302  |     } else { | 
821  | 302  |         switch ( op.digestType.Get() ) { | 
822  | 0  |             case CF_DIGEST("MD2"): | 
823  | 0  |                 ret = wolfCrypt_detail::md2.Run(op, ds);  | 
824  | 0  |                 break;  | 
825  | 0  |             case CF_DIGEST("MD4"): | 
826  | 0  |                 ret = wolfCrypt_detail::md4.Run(op, ds);  | 
827  | 0  |                 break;  | 
828  | 0  |             case CF_DIGEST("MD5"): | 
829  | 0  |                 ret = wolfCrypt_detail::md5.Run(op, ds);  | 
830  | 0  |                 break;  | 
831  | 52  |             case CF_DIGEST("RIPEMD160"): | 
832  | 52  |                 ret = wolfCrypt_detail::ripemd160.Run(op, ds);  | 
833  | 52  |                 break;  | 
834  | 0  |             case CF_DIGEST("SHA1"): | 
835  | 0  |                 ret = wolfCrypt_detail::sha1.Run(op, ds);  | 
836  | 0  |                 break;  | 
837  | 0  | #if !defined(__i386__)  | 
838  | 24  |             case CF_DIGEST("SHA224"): | 
839  | 24  |                 ret = wolfCrypt_detail::sha224.Run(op, ds);  | 
840  | 24  |                 break;  | 
841  | 0  | #endif  | 
842  | 33  |             case CF_DIGEST("SHA256"): | 
843  | 33  |                 ret = wolfCrypt_detail::sha256.Run(op, ds);  | 
844  | 33  |                 break;  | 
845  | 30  |             case CF_DIGEST("SHA384"): | 
846  | 30  |                 ret = wolfCrypt_detail::sha384.Run(op, ds);  | 
847  | 30  |                 break;  | 
848  | 24  |             case CF_DIGEST("SHA512"): | 
849  | 24  |                 ret = wolfCrypt_detail::sha512.Run(op, ds);  | 
850  | 24  |                 break;  | 
851  | 23  |             case CF_DIGEST("SHA3-224"): | 
852  | 23  |                 ret = wolfCrypt_detail::sha3_224.Run(op, ds);  | 
853  | 23  |                 break;  | 
854  | 17  |             case CF_DIGEST("SHA3-256"): | 
855  | 17  |                 ret = wolfCrypt_detail::sha3_256.Run(op, ds);  | 
856  | 17  |                 break;  | 
857  | 14  |             case CF_DIGEST("SHA3-384"): | 
858  | 14  |                 ret = wolfCrypt_detail::sha3_384.Run(op, ds);  | 
859  | 14  |                 break;  | 
860  | 16  |             case CF_DIGEST("SHA3-512"): | 
861  | 16  |                 ret = wolfCrypt_detail::sha3_512.Run(op, ds);  | 
862  | 16  |                 break;  | 
863  | 0  |             case CF_DIGEST("BLAKE2B512"): | 
864  | 0  |                 ret = wolfCrypt_detail::blake2b512.Run(op, ds);  | 
865  | 0  |                 break;  | 
866  | 0  |             case CF_DIGEST("BLAKE2S256"): | 
867  | 0  |                 ret = wolfCrypt_detail::blake2s256.Run(op, ds);  | 
868  | 0  |                 break;  | 
869  | 0  |             case CF_DIGEST("SHAKE128"): | 
870  | 0  |                 ret = wolfCrypt_detail::shake256.Run(op, ds);  | 
871  | 0  |                 break;  | 
872  | 0  |             case CF_DIGEST("SHAKE256"): | 
873  | 0  |                 ret = wolfCrypt_detail::shake512.Run(op, ds);  | 
874  | 0  |                 break;  | 
875  | 302  |         }  | 
876  | 302  |     }  | 
877  |  |  | 
878  | 457  |     wolfCrypt_detail::UnsetGlobalDs();  | 
879  |  |  | 
880  | 457  |     return ret;  | 
881  | 457  | }  | 
882  |  |  | 
883  |  | namespace wolfCrypt_detail { | 
884  | 0  |     std::optional<component::MAC> Blake2_MAC(operation::HMAC& op) { | 
885  | 0  |         std::optional<component::MAC> ret = std::nullopt;  | 
886  | 0  |         Datasource ds(op.modifier.GetPtr(), op.modifier.GetSize());  | 
887  | 0  |         wolfCrypt_detail::SetGlobalDs(&ds);  | 
888  |  | 
  | 
889  | 0  |         Blake2b blake2b;  | 
890  | 0  |         Blake2s blake2s;  | 
891  |  | 
  | 
892  | 0  |         util::Multipart parts;  | 
893  | 0  |         uint8_t out[64];  | 
894  |  | 
  | 
895  | 0  |         if ( op.digestType.Is(CF_DIGEST("BLAKE2B_MAC")) ) { | 
896  | 0  |             WC_CHECK_EQ(wc_InitBlake2b_WithKey(&blake2b, 64, op.cipher.key.GetPtr(), op.cipher.key.GetSize()), 0);  | 
897  | 0  |         } else if ( op.digestType.Is(CF_DIGEST("BLAKE2S_MAC")) ) { | 
898  | 0  |             WC_CHECK_EQ(wc_InitBlake2s_WithKey(&blake2s, 64, op.cipher.key.GetPtr(), op.cipher.key.GetSize()), 0);  | 
899  | 0  |         } else { | 
900  | 0  |             abort();  | 
901  | 0  |         }  | 
902  |  |  | 
903  | 0  |         parts = util::ToParts(ds, op.cleartext);  | 
904  |  | 
  | 
905  | 0  |         if ( op.digestType.Is(CF_DIGEST("BLAKE2B_MAC")) ) { | 
906  | 0  |             for (const auto& part : parts) { | 
907  | 0  |                 WC_CHECK_EQ(wc_Blake2bUpdate(&blake2b, part.first, part.second), 0);  | 
908  | 0  |             }  | 
909  | 0  |         } else if ( op.digestType.Is(CF_DIGEST("BLAKE2S_MAC")) ) { | 
910  | 0  |             for (const auto& part : parts) { | 
911  | 0  |                 WC_CHECK_EQ(wc_Blake2sUpdate(&blake2s, part.first, part.second), 0);  | 
912  | 0  |             }  | 
913  | 0  |         }  | 
914  |  |  | 
915  | 0  |         if ( op.digestType.Is(CF_DIGEST("BLAKE2B_MAC")) ) { | 
916  | 0  |             WC_CHECK_EQ(wc_Blake2bFinal(&blake2b, out, 64), 0);  | 
917  | 0  |         } else if ( op.digestType.Is(CF_DIGEST("BLAKE2S_MAC")) ) { | 
918  | 0  |             WC_CHECK_EQ(wc_Blake2sFinal(&blake2s, out, 64), 0);  | 
919  | 0  |         }  | 
920  |  |  | 
921  | 0  |         ret = component::MAC(out, 64);  | 
922  | 0  | end:  | 
923  | 0  |         wolfCrypt_detail::UnsetGlobalDs();  | 
924  | 0  |         return ret;  | 
925  | 0  |     }  | 
926  |  |  | 
927  | 0  |     std::optional<component::MAC> SIPHASH(operation::HMAC& op, const size_t size) { | 
928  | 0  |         std::optional<component::MAC> ret = std::nullopt;  | 
929  | 0  |         Datasource ds(op.modifier.GetPtr(), op.modifier.GetSize());  | 
930  | 0  |         wolfCrypt_detail::SetGlobalDs(&ds);  | 
931  |  | 
  | 
932  | 0  |         SipHash ctx;  | 
933  |  | 
  | 
934  | 0  |         uint8_t out[size];  | 
935  |  | 
  | 
936  | 0  |         bool stream = false;  | 
937  | 0  |         try { | 
938  | 0  |             stream = ds.Get<bool>();  | 
939  | 0  |         } catch ( ... ) { } | 
940  |  | 
  | 
941  | 0  |         CF_CHECK_EQ(op.cipher.key.GetSize(), 16);  | 
942  |  | 
  | 
943  | 0  |         if ( stream == false ) { | 
944  | 0  |             WC_CHECK_EQ(wc_SipHash(  | 
945  | 0  |                         op.cipher.key.GetPtr(&ds),  | 
946  | 0  |                         op.cleartext.GetPtr(&ds), op.cleartext.GetSize(),  | 
947  | 0  |                         out, size), 0);  | 
948  | 0  |         } else { | 
949  | 0  |             WC_CHECK_EQ(wc_InitSipHash(&ctx, op.cipher.key.GetPtr(), size), 0);  | 
950  |  | 
  | 
951  | 0  |             util::Multipart parts = util::ToParts(ds, op.cleartext);  | 
952  |  | 
  | 
953  | 0  |             for (const auto& part : parts) { | 
954  | 0  |                 WC_CHECK_EQ(wc_SipHashUpdate(&ctx, part.first, part.second), 0);  | 
955  | 0  |             }  | 
956  |  |  | 
957  | 0  |             WC_CHECK_EQ(wc_SipHashFinal(&ctx, out, size), 0);  | 
958  | 0  |         }  | 
959  |  |  | 
960  | 0  |         ret = component::MAC(out, size);  | 
961  | 0  | end:  | 
962  | 0  |         wolfCrypt_detail::UnsetGlobalDs();  | 
963  | 0  |         return ret;  | 
964  | 0  |     }  | 
965  |  | } /* namespace wolfCrypt_detail */  | 
966  |  |  | 
967  | 365  | std::optional<component::MAC> wolfCrypt::OpHMAC(operation::HMAC& op) { | 
968  | 365  |     if (  | 
969  | 365  |         op.digestType.Is(CF_DIGEST("BLAKE2B_MAC")) || | 
970  | 365  |         op.digestType.Is(CF_DIGEST("BLAKE2S_MAC")) ) { | 
971  | 0  |         return wolfCrypt_detail::Blake2_MAC(op);  | 
972  | 365  |     } else if ( op.digestType.Is(CF_DIGEST("SIPHASH64")) ) { | 
973  | 0  |         return wolfCrypt_detail::SIPHASH(op, 8);  | 
974  | 365  |     } else if ( op.digestType.Is(CF_DIGEST("SIPHASH128")) ) { | 
975  | 0  |         return wolfCrypt_detail::SIPHASH(op, 16);  | 
976  | 0  |     }  | 
977  |  |  | 
978  | 365  |     std::optional<component::MAC> ret = std::nullopt;  | 
979  | 365  |     Datasource ds(op.modifier.GetPtr(), op.modifier.GetSize());  | 
980  | 365  |     wolfCrypt_detail::SetGlobalDs(&ds);  | 
981  |  |  | 
982  | 365  |     std::optional<int> hashType;  | 
983  | 365  |     std::optional<size_t> hashSize;  | 
984  |  |  | 
985  | 365  |     Hmac ctx;  | 
986  | 365  |     bool inited = false;  | 
987  | 365  |     uint8_t* out = nullptr;  | 
988  | 365  |     util::Multipart parts;  | 
989  |  |  | 
990  |  |     /* Initialize */  | 
991  | 365  |     { | 
992  | 365  |         parts = util::ToParts(ds, op.cleartext);  | 
993  |  |  | 
994  | 365  |         CF_CHECK_NE(hashType = wolfCrypt_detail::toHashType(op.digestType), std::nullopt);  | 
995  | 223  |         CF_CHECK_NE(hashSize = wolfCrypt_detail::toHashSize(op.digestType), std::nullopt);  | 
996  | 223  |         out = util::malloc(*hashSize);  | 
997  | 223  |         WC_CHECK_EQ(wc_HmacInit(&ctx, nullptr, INVALID_DEVID), 0);  | 
998  | 223  |         inited = true;  | 
999  | 223  |         WC_CHECK_EQ(wc_HmacSetKey(&ctx, *hashType, op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize()), 0);  | 
1000  | 197  |     }  | 
1001  |  |  | 
1002  |  |     /* Process */  | 
1003  | 1.34k  |     for (const auto& part : parts) { | 
1004  | 1.34k  |         WC_CHECK_EQ(wc_HmacUpdate(&ctx, part.first, part.second), 0);  | 
1005  | 1.32k  |     }  | 
1006  |  |  | 
1007  |  |     /* Finalize */  | 
1008  | 179  |     { | 
1009  | 179  |         WC_CHECK_EQ(wc_HmacFinal(&ctx, out), 0);  | 
1010  |  |  | 
1011  | 168  |         ret = component::MAC(out, *hashSize);  | 
1012  | 168  |     }  | 
1013  |  |  | 
1014  | 365  | end:  | 
1015  | 365  |     if ( inited == true ) { | 
1016  | 223  |         CF_NORET(wc_HmacFree(&ctx));  | 
1017  | 223  |     }  | 
1018  | 365  |     util::free(out);  | 
1019  |  |  | 
1020  | 365  |     wolfCrypt_detail::UnsetGlobalDs();  | 
1021  |  |  | 
1022  | 365  |     return ret;  | 
1023  | 168  | }  | 
1024  |  |  | 
1025  |  | namespace wolfCrypt_detail { | 
1026  | 0  |     std::optional<component::Ciphertext> OpSymmetricEncrypt_AES_GCM(operation::SymmetricEncrypt& op, Datasource& ds) { | 
1027  | 0  |         std::optional<component::Ciphertext> ret = std::nullopt;  | 
1028  |  | 
  | 
1029  | 0  |         Aes ctx;  | 
1030  | 0  |         bool inited = false;  | 
1031  | 0  |         uint8_t* out = nullptr;  | 
1032  | 0  |         uint8_t* outTag = nullptr;  | 
1033  | 0  |         bool stream = false;  | 
1034  | 0  |         try { | 
1035  | 0  |             stream = ds.Get<bool>();  | 
1036  | 0  |         } catch ( ... ) { } | 
1037  |  | 
  | 
1038  |  | #if !defined(WOLFSSL_AESGCM_STREAM)  | 
1039  |  |         (void)stream;  | 
1040  |  | #endif  | 
1041  |  | 
  | 
1042  | 0  |         switch ( op.cipher.cipherType.Get() ) { | 
1043  | 0  |             case CF_CIPHER("AES_128_GCM"): | 
1044  | 0  |                 CF_CHECK_EQ(op.cipher.key.GetSize(), 16);  | 
1045  | 0  |                 break;  | 
1046  | 0  |             case CF_CIPHER("AES_192_GCM"): | 
1047  | 0  |                 CF_CHECK_EQ(op.cipher.key.GetSize(), 24);  | 
1048  | 0  |                 break;  | 
1049  | 0  |             case CF_CIPHER("AES_256_GCM"): | 
1050  | 0  |                 CF_CHECK_EQ(op.cipher.key.GetSize(), 32);  | 
1051  | 0  |                 break;  | 
1052  | 0  |         }  | 
1053  |  |  | 
1054  | 0  |         CF_CHECK_NE(op.tagSize, std::nullopt);  | 
1055  | 0  |         CF_CHECK_NE(op.aad, std::nullopt);  | 
1056  |  | 
  | 
1057  | 0  |         out = util::malloc(op.cleartext.GetSize());  | 
1058  | 0  |         outTag = util::malloc(*op.tagSize);  | 
1059  |  | 
  | 
1060  | 0  | #ifdef WOLFSSL_AESGCM_STREAM  | 
1061  | 0  |         if ( stream ) { | 
1062  | 0  |             WC_CHECK_EQ(wc_AesInit(&ctx, nullptr, INVALID_DEVID), 0);  | 
1063  | 0  |             inited = true;  | 
1064  | 0  |             WC_CHECK_EQ(wc_AesGcmInit(&ctx,  | 
1065  | 0  |                         op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize(),  | 
1066  | 0  |                         op.cipher.iv.GetPtr(&ds), op.cipher.iv.GetSize()), 0);  | 
1067  |  |  | 
1068  |  |             /* Pass AAD */  | 
1069  | 0  |             { | 
1070  | 0  |                 const auto parts = util::ToParts(ds, *op.aad);  | 
1071  | 0  |                 for (const auto& part : parts) { | 
1072  | 0  |                     WC_CHECK_EQ(wc_AesGcmEncryptUpdate(&ctx,  | 
1073  | 0  |                                 nullptr,  | 
1074  | 0  |                                 nullptr, 0,  | 
1075  | 0  |                                 part.first, part.second), 0);  | 
1076  | 0  |                 }  | 
1077  | 0  |             }  | 
1078  |  |  | 
1079  |  |             /* Pass cleartext */  | 
1080  | 0  |             { | 
1081  | 0  |                 const auto parts = util::ToParts(ds, op.cleartext);  | 
1082  | 0  |                 size_t pos = 0;  | 
1083  | 0  |                 for (const auto& part : parts) { | 
1084  | 0  |                     WC_CHECK_EQ(wc_AesGcmEncryptUpdate(&ctx,  | 
1085  | 0  |                                 out + pos,  | 
1086  | 0  |                                 part.first, part.second,  | 
1087  | 0  |                                 nullptr, 0), 0);  | 
1088  | 0  |                     pos += part.second;  | 
1089  | 0  |                 }  | 
1090  | 0  |             }  | 
1091  |  |  | 
1092  | 0  |             WC_CHECK_EQ(wc_AesGcmEncryptFinal(&ctx, outTag, *op.tagSize), 0);  | 
1093  | 0  |         } else  | 
1094  | 0  | #endif  | 
1095  | 0  |         { | 
1096  | 0  |             WC_CHECK_EQ(wc_AesInit(&ctx, nullptr, INVALID_DEVID), 0);  | 
1097  | 0  |             inited = true;  | 
1098  | 0  |             WC_CHECK_EQ(wc_AesGcmSetKey(&ctx, op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize()), 0);  | 
1099  | 0  |             WC_CHECK_EQ(wc_AesGcmEncrypt(  | 
1100  | 0  |                         &ctx,  | 
1101  | 0  |                         out,  | 
1102  | 0  |                         op.cleartext.GetPtr(&ds),  | 
1103  | 0  |                         op.cleartext.GetSize(),  | 
1104  | 0  |                         op.cipher.iv.GetPtr(&ds),  | 
1105  | 0  |                         op.cipher.iv.GetSize(),  | 
1106  | 0  |                         outTag,  | 
1107  | 0  |                         *op.tagSize,  | 
1108  | 0  |                         op.aad->GetPtr(&ds),  | 
1109  | 0  |                         op.aad->GetSize()), 0);  | 
1110  | 0  |         }  | 
1111  |  |  | 
1112  | 0  |         ret = component::Ciphertext(Buffer(out, op.cleartext.GetSize()), Buffer(outTag, *op.tagSize));  | 
1113  | 0  | end:  | 
1114  |  | 
  | 
1115  | 0  |         util::free(out);  | 
1116  | 0  |         util::free(outTag);  | 
1117  |  | 
  | 
1118  | 0  |         if ( inited == true ) { | 
1119  | 0  |             CF_NORET(wc_AesFree(&ctx));  | 
1120  | 0  |         }  | 
1121  |  | 
  | 
1122  | 0  |         return ret;  | 
1123  | 0  |     }  | 
1124  |  |  | 
1125  | 0  |     std::optional<component::Cleartext> OpSymmetricDecrypt_AES_GCM(operation::SymmetricDecrypt& op, Datasource& ds) { | 
1126  | 0  |         std::optional<component::Cleartext> ret = std::nullopt;  | 
1127  |  | 
  | 
1128  | 0  |         Aes ctx;  | 
1129  | 0  |         bool inited = false;  | 
1130  | 0  |         uint8_t* out = nullptr;  | 
1131  | 0  |         bool stream = true;  | 
1132  | 0  |         try { | 
1133  | 0  |             stream = ds.Get<bool>();  | 
1134  | 0  |         } catch ( ... ) { } | 
1135  |  | 
  | 
1136  |  | #if !defined(WOLFSSL_AESGCM_STREAM)  | 
1137  |  |         (void)stream;  | 
1138  |  | #endif  | 
1139  |  | 
  | 
1140  | 0  |         switch ( op.cipher.cipherType.Get() ) { | 
1141  | 0  |             case CF_CIPHER("AES_128_GCM"): | 
1142  | 0  |                 CF_CHECK_EQ(op.cipher.key.GetSize(), 16);  | 
1143  | 0  |                 break;  | 
1144  | 0  |             case CF_CIPHER("AES_192_GCM"): | 
1145  | 0  |                 CF_CHECK_EQ(op.cipher.key.GetSize(), 24);  | 
1146  | 0  |                 break;  | 
1147  | 0  |             case CF_CIPHER("AES_256_GCM"): | 
1148  | 0  |                 CF_CHECK_EQ(op.cipher.key.GetSize(), 32);  | 
1149  | 0  |                 break;  | 
1150  | 0  |         }  | 
1151  |  |  | 
1152  | 0  |         CF_CHECK_NE(op.aad, std::nullopt);  | 
1153  | 0  |         CF_CHECK_NE(op.tag, std::nullopt);  | 
1154  |  | 
  | 
1155  | 0  |         out = util::malloc(op.ciphertext.GetSize());  | 
1156  |  | 
  | 
1157  | 0  | #ifdef WOLFSSL_AESGCM_STREAM  | 
1158  | 0  |         if ( stream ) { | 
1159  | 0  |             WC_CHECK_EQ(wc_AesInit(&ctx, nullptr, INVALID_DEVID), 0);  | 
1160  | 0  |             inited = true;  | 
1161  | 0  |             WC_CHECK_EQ(wc_AesGcmInit(&ctx,  | 
1162  | 0  |                         op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize(),  | 
1163  | 0  |                         op.cipher.iv.GetPtr(&ds), op.cipher.iv.GetSize()), 0);  | 
1164  |  |             /* Pass AAD */  | 
1165  | 0  |             { | 
1166  | 0  |                 const auto parts = util::ToParts(ds, *op.aad);  | 
1167  | 0  |                 for (const auto& part : parts) { | 
1168  | 0  |                     WC_CHECK_EQ(wc_AesGcmDecryptUpdate(&ctx,  | 
1169  | 0  |                                 nullptr,  | 
1170  | 0  |                                 nullptr, 0,  | 
1171  | 0  |                                 part.first, part.second), 0);  | 
1172  | 0  |                 }  | 
1173  | 0  |             }  | 
1174  |  |  | 
1175  |  |             /* Pass ciphertext */  | 
1176  | 0  |             { | 
1177  | 0  |                 const auto parts = util::ToParts(ds, op.ciphertext);  | 
1178  | 0  |                 size_t pos = 0;  | 
1179  | 0  |                 for (const auto& part : parts) { | 
1180  | 0  |                     WC_CHECK_EQ(wc_AesGcmDecryptUpdate(&ctx,  | 
1181  | 0  |                                 out + pos,  | 
1182  | 0  |                                 part.first, part.second,  | 
1183  | 0  |                                 nullptr, 0), 0);  | 
1184  | 0  |                     pos += part.second;  | 
1185  | 0  |                 }  | 
1186  | 0  |             }  | 
1187  |  |  | 
1188  | 0  |             WC_CHECK_EQ(wc_AesGcmDecryptFinal(&ctx, op.tag->GetPtr(&ds), op.tag->GetSize()), 0);  | 
1189  | 0  |         } else  | 
1190  | 0  | #endif  | 
1191  | 0  |         { | 
1192  | 0  |             WC_CHECK_EQ(wc_AesInit(&ctx, nullptr, INVALID_DEVID), 0);  | 
1193  | 0  |             inited = true;  | 
1194  | 0  |             WC_CHECK_EQ(wc_AesGcmSetKey(&ctx, op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize()), 0);  | 
1195  | 0  |             WC_CHECK_EQ(wc_AesGcmDecrypt(  | 
1196  | 0  |                         &ctx,  | 
1197  | 0  |                         out,  | 
1198  | 0  |                         op.ciphertext.GetPtr(&ds),  | 
1199  | 0  |                         op.ciphertext.GetSize(),  | 
1200  | 0  |                         op.cipher.iv.GetPtr(&ds),  | 
1201  | 0  |                         op.cipher.iv.GetSize(),  | 
1202  | 0  |                         op.tag->GetPtr(&ds),  | 
1203  | 0  |                         op.tag->GetSize(),  | 
1204  | 0  |                         op.aad->GetPtr(&ds),  | 
1205  | 0  |                         op.aad->GetSize()), 0);  | 
1206  | 0  |         }  | 
1207  |  |  | 
1208  | 0  |         ret = component::Cleartext(Buffer(out, op.ciphertext.GetSize()));  | 
1209  |  | 
  | 
1210  | 0  | end:  | 
1211  | 0  |         util::free(out);  | 
1212  |  | 
  | 
1213  | 0  |         if ( inited == true ) { | 
1214  | 0  |             CF_NORET(wc_AesFree(&ctx));  | 
1215  | 0  |         }  | 
1216  |  | 
  | 
1217  | 0  |         return ret;  | 
1218  | 0  |     }  | 
1219  |  | } /* namespace wolfCrypt_detail */  | 
1220  |  |  | 
1221  | 0  | std::optional<component::Ciphertext> wolfCrypt::OpSymmetricEncrypt(operation::SymmetricEncrypt& op) { | 
1222  | 0  |     std::optional<component::Ciphertext> ret = std::nullopt;  | 
1223  | 0  |     Datasource ds(op.modifier.GetPtr(), op.modifier.GetSize());  | 
1224  | 0  |     wolfCrypt_detail::SetGlobalDs(&ds);  | 
1225  |  | 
  | 
1226  | 0  |     uint8_t* out = nullptr;  | 
1227  | 0  |     uint8_t* outTag = nullptr;  | 
1228  |  | 
  | 
1229  | 0  |     Aes aes;  | 
1230  | 0  |     bool aes_inited = false;  | 
1231  |  | 
  | 
1232  | 0  |     switch ( op.cipher.cipherType.Get() ) { | 
1233  | 0  |         case CF_CIPHER("AES_128_CBC"): | 
1234  | 0  |         case CF_CIPHER("AES_192_CBC"): | 
1235  | 0  |         case CF_CIPHER("AES_256_CBC"): | 
1236  | 0  |         { | 
1237  |  | 
  | 
1238  | 0  |             switch ( op.cipher.cipherType.Get() ) { | 
1239  | 0  |                 case CF_CIPHER("AES_128_CBC"): | 
1240  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 16);  | 
1241  | 0  |                     break;  | 
1242  | 0  |                 case CF_CIPHER("AES_192_CBC"): | 
1243  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 24);  | 
1244  | 0  |                     break;  | 
1245  | 0  |                 case CF_CIPHER("AES_256_CBC"): | 
1246  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 32);  | 
1247  | 0  |                     break;  | 
1248  | 0  |             }  | 
1249  |  |  | 
1250  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), 16);  | 
1251  |  | 
  | 
1252  | 0  |             const auto cleartext = util::Pkcs7Pad(op.cleartext.Get(), 16);  | 
1253  | 0  |             out = util::malloc(cleartext.size());  | 
1254  |  | 
  | 
1255  | 0  |             WC_CHECK_EQ(wc_AesInit(&aes, nullptr, INVALID_DEVID), 0);  | 
1256  | 0  |             aes_inited = true;  | 
1257  |  | 
  | 
1258  | 0  |             WC_CHECK_EQ(wc_AesSetKey(&aes, op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize(), op.cipher.iv.GetPtr(&ds), AES_ENCRYPTION), 0);  | 
1259  | 0  |             WC_CHECK_EQ(wc_AesCbcEncrypt(&aes, out, cleartext.data(), cleartext.size()), 0);  | 
1260  |  | 
  | 
1261  | 0  |             ret = component::Ciphertext(Buffer(out, cleartext.size()));  | 
1262  | 0  |         }  | 
1263  | 0  |         break;  | 
1264  |  |  | 
1265  | 0  |         case CF_CIPHER("CAMELLIA_128_CBC"): | 
1266  | 0  |         case CF_CIPHER("CAMELLIA_192_CBC"): | 
1267  | 0  |         case CF_CIPHER("CAMELLIA_256_CBC"): | 
1268  | 0  |         { | 
1269  | 0  |             Camellia ctx;  | 
1270  |  | 
  | 
1271  | 0  |             switch ( op.cipher.cipherType.Get() ) { | 
1272  | 0  |                 case CF_CIPHER("CAMELLIA_128_CBC"): | 
1273  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 16);  | 
1274  | 0  |                     break;  | 
1275  | 0  |                 case CF_CIPHER("CAMELLIA_192_CBC"): | 
1276  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 24);  | 
1277  | 0  |                     break;  | 
1278  | 0  |                 case CF_CIPHER("CAMELLIA_256_CBC"): | 
1279  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 32);  | 
1280  | 0  |                     break;  | 
1281  | 0  |             }  | 
1282  |  |  | 
1283  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), 16);  | 
1284  |  | 
  | 
1285  | 0  |             const auto cleartext = util::Pkcs7Pad(op.cleartext.Get(), 16);  | 
1286  | 0  |             out = util::malloc(cleartext.size());  | 
1287  |  | 
  | 
1288  | 0  |             WC_CHECK_EQ(wc_CamelliaSetKey(  | 
1289  | 0  |                         &ctx,  | 
1290  | 0  |                         op.cipher.key.GetPtr(&ds),  | 
1291  | 0  |                         op.cipher.key.GetSize(),  | 
1292  | 0  |                         op.cipher.iv.GetPtr(&ds)), 0);  | 
1293  | 0  |             WC_CHECK_EQ(wc_CamelliaCbcEncrypt(&ctx, out, cleartext.data(), cleartext.size()), 0);  | 
1294  |  | 
  | 
1295  | 0  |             ret = component::Ciphertext(Buffer(out, cleartext.size()));  | 
1296  | 0  |         }  | 
1297  | 0  |         break;  | 
1298  |  |  | 
1299  | 0  |         case CF_CIPHER("AES_128_GCM"): | 
1300  | 0  |         case CF_CIPHER("AES_192_GCM"): | 
1301  | 0  |         case CF_CIPHER("AES_256_GCM"): | 
1302  | 0  |         { | 
1303  | 0  |             ret = wolfCrypt_detail::OpSymmetricEncrypt_AES_GCM(op, ds);  | 
1304  | 0  |         }  | 
1305  | 0  |         break;  | 
1306  |  |  | 
1307  | 0  |         case CF_CIPHER("AES_128_CCM"): | 
1308  | 0  |         case CF_CIPHER("AES_192_CCM"): | 
1309  | 0  |         case CF_CIPHER("AES_256_CCM"): | 
1310  | 0  |         { | 
1311  | 0  |             switch ( op.cipher.cipherType.Get() ) { | 
1312  | 0  |                 case CF_CIPHER("AES_128_CCM"): | 
1313  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 16);  | 
1314  | 0  |                     break;  | 
1315  | 0  |                 case CF_CIPHER("AES_192_CCM"): | 
1316  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 24);  | 
1317  | 0  |                     break;  | 
1318  | 0  |                 case CF_CIPHER("AES_256_CCM"): | 
1319  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 32);  | 
1320  | 0  |                     break;  | 
1321  | 0  |             }  | 
1322  |  |  | 
1323  | 0  |             CF_CHECK_NE(op.tagSize, std::nullopt);  | 
1324  | 0  |             CF_CHECK_NE(op.aad, std::nullopt);  | 
1325  |  | 
  | 
1326  | 0  |             out = util::malloc(op.cleartext.GetSize());  | 
1327  | 0  |             outTag = util::malloc(*op.tagSize);  | 
1328  |  | 
  | 
1329  | 0  |             WC_CHECK_EQ(wc_AesInit(&aes, nullptr, INVALID_DEVID), 0);  | 
1330  | 0  |             aes_inited = true;  | 
1331  |  | 
  | 
1332  | 0  |             WC_CHECK_EQ(wc_AesCcmSetKey(&aes, op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize()), 0);  | 
1333  | 0  |             WC_CHECK_EQ(wc_AesCcmEncrypt(  | 
1334  | 0  |                         &aes,  | 
1335  | 0  |                         out,  | 
1336  | 0  |                         op.cleartext.GetPtr(&ds),  | 
1337  | 0  |                         op.cleartext.GetSize(),  | 
1338  | 0  |                         op.cipher.iv.GetPtr(&ds),  | 
1339  | 0  |                         op.cipher.iv.GetSize(),  | 
1340  | 0  |                         outTag,  | 
1341  | 0  |                         *op.tagSize,  | 
1342  | 0  |                         op.aad->GetPtr(&ds),  | 
1343  | 0  |                         op.aad->GetSize()), 0);  | 
1344  |  | 
  | 
1345  | 0  |             ret = component::Ciphertext(Buffer(out, op.cleartext.GetSize()), Buffer(outTag, *op.tagSize));  | 
1346  | 0  |         }  | 
1347  | 0  |         break;  | 
1348  |  |  | 
1349  | 0  |         case CF_CIPHER("CHACHA20_POLY1305"): | 
1350  | 0  |         { | 
1351  | 0  |             CF_CHECK_NE(op.tagSize, std::nullopt);  | 
1352  | 0  |             CF_CHECK_GTE(*op.tagSize, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE);  | 
1353  | 0  |             CF_CHECK_EQ(op.cipher.key.GetSize(), CHACHA20_POLY1305_AEAD_KEYSIZE);  | 
1354  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), CHACHA20_POLY1305_AEAD_IV_SIZE);  | 
1355  | 0  |             CF_CHECK_NE(op.aad, std::nullopt);  | 
1356  |  | 
  | 
1357  | 0  |             out = util::malloc(op.cleartext.GetSize());  | 
1358  | 0  |             outTag = util::malloc(*op.tagSize);  | 
1359  |  | 
  | 
1360  | 0  |             bool oneShot = true;  | 
1361  | 0  |             try { | 
1362  | 0  |                 oneShot = ds.Get<bool>();  | 
1363  | 0  |             } catch ( ... ) { } | 
1364  |  | 
  | 
1365  | 0  |             if ( oneShot == true ) { | 
1366  | 0  |                 WC_CHECK_EQ(wc_ChaCha20Poly1305_Encrypt(  | 
1367  | 0  |                             op.cipher.key.GetPtr(&ds),  | 
1368  | 0  |                             op.cipher.iv.GetPtr(&ds),  | 
1369  | 0  |                             op.aad->GetPtr(&ds),  | 
1370  | 0  |                             op.aad->GetSize(),  | 
1371  | 0  |                             op.cleartext.GetPtr(&ds),  | 
1372  | 0  |                             op.cleartext.GetSize(),  | 
1373  | 0  |                             out,  | 
1374  | 0  |                             outTag), 0);  | 
1375  | 0  |             } else { | 
1376  | 0  |                 ChaChaPoly_Aead aead;  | 
1377  |  | 
  | 
1378  | 0  |                 WC_CHECK_EQ(wc_ChaCha20Poly1305_Init(&aead, op.cipher.key.GetPtr(&ds), op.cipher.iv.GetPtr(&ds), 1), 0);  | 
1379  |  | 
  | 
1380  | 0  |                 { | 
1381  | 0  |                     const auto partsAAD = util::ToParts(ds, *op.aad);  | 
1382  | 0  |                     for (const auto& part : partsAAD) { | 
1383  | 0  |                         WC_CHECK_EQ(wc_ChaCha20Poly1305_UpdateAad(&aead, part.first, part.second), 0);  | 
1384  | 0  |                     }  | 
1385  | 0  |                 }  | 
1386  |  |  | 
1387  | 0  |                 { | 
1388  | 0  |                     const auto partsData = util::ToParts(ds, op.cleartext);  | 
1389  | 0  |                     size_t pos = 0;  | 
1390  | 0  |                     for (const auto& part : partsData) { | 
1391  | 0  |                         WC_CHECK_EQ(wc_ChaCha20Poly1305_UpdateData(&aead, part.first, out + pos, part.second), 0);  | 
1392  | 0  |                         pos += part.second;  | 
1393  | 0  |                     }  | 
1394  | 0  |                 }  | 
1395  |  |  | 
1396  | 0  |                 WC_CHECK_EQ(wc_ChaCha20Poly1305_Final(&aead, outTag), 0);  | 
1397  | 0  |             }  | 
1398  |  |  | 
1399  | 0  |             ret = component::Ciphertext(Buffer(out, op.cleartext.GetSize()), Buffer(outTag, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE));  | 
1400  | 0  |         }  | 
1401  | 0  |         break;  | 
1402  |  |  | 
1403  | 0  | #if defined(HAVE_XCHACHA)  | 
1404  | 0  |         case CF_CIPHER("XCHACHA20_POLY1305"): | 
1405  | 0  |         { | 
1406  | 0  |             CF_CHECK_NE(op.tagSize, std::nullopt);  | 
1407  | 0  |             CF_CHECK_GTE(*op.tagSize, CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE);  | 
1408  | 0  |             CF_CHECK_NE(op.aad, std::nullopt);  | 
1409  |  | 
  | 
1410  | 0  |             out = util::malloc(op.ciphertextSize);  | 
1411  |  | 
  | 
1412  | 0  |             WC_CHECK_EQ(wc_XChaCha20Poly1305_Encrypt(  | 
1413  | 0  |                         out, op.ciphertextSize,  | 
1414  | 0  |                         op.cleartext.GetPtr(&ds), op.cleartext.GetSize(),  | 
1415  | 0  |                         op.aad->GetPtr(&ds), op.aad->GetSize(),  | 
1416  | 0  |                         op.cipher.iv.GetPtr(&ds), op.cipher.iv.GetSize(),  | 
1417  | 0  |                         op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize()), 0);  | 
1418  | 0  |             ret = component::Ciphertext(  | 
1419  | 0  |                     Buffer(out, op.cleartext.GetSize()),  | 
1420  | 0  |                     Buffer(out + op.cleartext.GetSize(), CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE));  | 
1421  | 0  |         }  | 
1422  | 0  |         break;  | 
1423  | 0  | #endif  | 
1424  |  |  | 
1425  | 0  |         case CF_CIPHER("AES_128_CTR"): | 
1426  | 0  |         case CF_CIPHER("AES_192_CTR"): | 
1427  | 0  |         case CF_CIPHER("AES_256_CTR"): | 
1428  | 0  |         { | 
1429  | 0  |             util::Multipart parts;  | 
1430  | 0  |             size_t outIdx = 0;  | 
1431  |  | 
  | 
1432  | 0  |             switch ( op.cipher.cipherType.Get() ) { | 
1433  | 0  |                 case CF_CIPHER("AES_128_CTR"): | 
1434  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 16);  | 
1435  | 0  |                     break;  | 
1436  | 0  |                 case CF_CIPHER("AES_192_CTR"): | 
1437  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 24);  | 
1438  | 0  |                     break;  | 
1439  | 0  |                 case CF_CIPHER("AES_256_CTR"): | 
1440  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 32);  | 
1441  | 0  |                     break;  | 
1442  | 0  |             }  | 
1443  |  |  | 
1444  | 0  |             CF_CHECK_EQ(op.cleartext.GetSize() % 16, 0);  | 
1445  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), 16);  | 
1446  | 0  |             CF_CHECK_GT(op.cipher.key.GetSize(), 0);  | 
1447  |  | 
  | 
1448  | 0  |             out = util::malloc(op.cleartext.GetSize());  | 
1449  |  | 
  | 
1450  | 0  |             WC_CHECK_EQ(wc_AesInit(&aes, nullptr, INVALID_DEVID), 0);  | 
1451  | 0  |             aes_inited = true;  | 
1452  |  | 
  | 
1453  | 0  |             WC_CHECK_EQ(wc_AesSetKeyDirect(&aes, op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize(), op.cipher.iv.GetPtr(&ds), AES_ENCRYPTION), 0);  | 
1454  |  | 
  | 
1455  | 0  |             parts = util::ToParts(ds, op.cleartext);  | 
1456  | 0  |             for (const auto& part : parts) { | 
1457  | 0  |                 WC_CHECK_EQ(wc_AesCtrEncrypt(&aes, out + outIdx, part.first, part.second), 0);  | 
1458  | 0  |                 outIdx += part.second;  | 
1459  | 0  |             }  | 
1460  |  |  | 
1461  | 0  |             ret = component::Ciphertext(Buffer(out, op.cleartext.GetSize()));  | 
1462  | 0  |         }  | 
1463  | 0  |         break;  | 
1464  |  |  | 
1465  | 0  |         case CF_CIPHER("AES_128_ECB"): | 
1466  | 0  |         case CF_CIPHER("AES_192_ECB"): | 
1467  | 0  |         case CF_CIPHER("AES_256_ECB"): | 
1468  | 0  |         { | 
1469  | 0  | #if defined(HAVE_AES_ECB)  | 
1470  | 0  |             switch ( op.cipher.cipherType.Get() ) { | 
1471  | 0  |                 case CF_CIPHER("AES_128_ECB"): | 
1472  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 16);  | 
1473  | 0  |                     break;  | 
1474  | 0  |                 case CF_CIPHER("AES_192_ECB"): | 
1475  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 24);  | 
1476  | 0  |                     break;  | 
1477  | 0  |                 case CF_CIPHER("AES_256_ECB"): | 
1478  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 32);  | 
1479  | 0  |                     break;  | 
1480  | 0  |             }  | 
1481  |  |  | 
1482  | 0  |             CF_CHECK_EQ(op.cleartext.GetSize() % 16, 0);  | 
1483  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), 16);  | 
1484  | 0  |             CF_CHECK_GT(op.cipher.key.GetSize(), 0);  | 
1485  |  | 
  | 
1486  | 0  |             out = util::malloc(op.cleartext.GetSize());  | 
1487  |  | 
  | 
1488  | 0  |             WC_CHECK_EQ(wc_AesInit(&aes, nullptr, INVALID_DEVID), 0);  | 
1489  | 0  |             aes_inited = true;  | 
1490  |  | 
  | 
1491  | 0  |             WC_CHECK_EQ(wc_AesSetKeyDirect(&aes, op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize(), op.cipher.iv.GetPtr(&ds), AES_ENCRYPTION), 0);  | 
1492  |  |  | 
1493  |  |             /* Note: wc_AesEcbEncrypt does not support streaming */  | 
1494  | 0  |             WC_CHECK_EQ(wc_AesEcbEncrypt(&aes, out, op.cleartext.GetPtr(&ds), op.cleartext.GetSize()), 0);  | 
1495  |  | 
  | 
1496  | 0  |             ret = component::Ciphertext(Buffer(out, op.cleartext.GetSize()));  | 
1497  | 0  | #endif  | 
1498  | 0  |         }  | 
1499  | 0  |         break;  | 
1500  |  |  | 
1501  | 0  |         case CF_CIPHER("AES_128_XTS"): | 
1502  | 0  |         case CF_CIPHER("AES_192_XTS"): | 
1503  | 0  |         case CF_CIPHER("AES_256_XTS"): | 
1504  | 0  |         { | 
1505  | 0  |             XtsAes ctx;  | 
1506  |  | 
  | 
1507  | 0  |             switch ( op.cipher.cipherType.Get() ) { | 
1508  | 0  |                 case CF_CIPHER("AES_128_XTS"): | 
1509  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 16);  | 
1510  | 0  |                     break;  | 
1511  | 0  |                 case CF_CIPHER("AES_192_XTS"): | 
1512  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 24);  | 
1513  | 0  |                     break;  | 
1514  | 0  |                 case CF_CIPHER("AES_256_XTS"): | 
1515  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 32);  | 
1516  | 0  |                     break;  | 
1517  | 0  |             }  | 
1518  |  |  | 
1519  | 0  |             CF_CHECK_EQ(op.cleartext.GetSize() % 16, 0);  | 
1520  |  | 
  | 
1521  | 0  |             out = util::malloc(op.cleartext.GetSize());  | 
1522  |  | 
  | 
1523  | 0  |             WC_CHECK_EQ(wc_AesXtsSetKey(&ctx, op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize(), AES_ENCRYPTION, nullptr, INVALID_DEVID), 0);  | 
1524  | 0  |             WC_CHECK_EQ(wc_AesXtsEncrypt(&ctx, out, op.cleartext.GetPtr(&ds), op.cleartext.GetSize(), op.cipher.iv.GetPtr(&ds), op.cipher.iv.GetSize()), 0);  | 
1525  |  | 
  | 
1526  | 0  |             ret = component::Ciphertext(Buffer(out, op.cleartext.GetSize()));  | 
1527  | 0  |         }  | 
1528  | 0  |         break;  | 
1529  |  |  | 
1530  | 0  |         case CF_CIPHER("AES_128_CFB"): | 
1531  | 0  |         case CF_CIPHER("AES_192_CFB"): | 
1532  | 0  |         case CF_CIPHER("AES_256_CFB"): | 
1533  | 0  |         { | 
1534  | 0  |             util::Multipart parts;  | 
1535  | 0  |             size_t outIdx = 0;  | 
1536  |  | 
  | 
1537  | 0  |             switch ( op.cipher.cipherType.Get() ) { | 
1538  | 0  |                 case CF_CIPHER("AES_128_CFB"): | 
1539  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 16);  | 
1540  | 0  |                     break;  | 
1541  | 0  |                 case CF_CIPHER("AES_192_CFB"): | 
1542  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 24);  | 
1543  | 0  |                     break;  | 
1544  | 0  |                 case CF_CIPHER("AES_256_CFB"): | 
1545  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 32);  | 
1546  | 0  |                     break;  | 
1547  | 0  |             }  | 
1548  |  |  | 
1549  | 0  |             CF_CHECK_EQ(op.cleartext.GetSize() % 16, 0);  | 
1550  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), 16);  | 
1551  |  | 
  | 
1552  | 0  |             out = util::malloc(op.cleartext.GetSize());  | 
1553  |  | 
  | 
1554  | 0  |             WC_CHECK_EQ(wc_AesInit(&aes, nullptr, INVALID_DEVID), 0);  | 
1555  | 0  |             aes_inited = true;  | 
1556  |  | 
  | 
1557  | 0  |             WC_CHECK_EQ(wc_AesSetKeyDirect(&aes, op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize(), op.cipher.iv.GetPtr(&ds), AES_ENCRYPTION), 0);  | 
1558  |  | 
  | 
1559  | 0  |             parts = util::ToParts(ds, op.cleartext);  | 
1560  | 0  |             for (const auto& part : parts) { | 
1561  | 0  |                 WC_CHECK_EQ(wc_AesCfbEncrypt(&aes, out + outIdx, part.first, part.second), 0);  | 
1562  | 0  |                 outIdx += part.second;  | 
1563  | 0  |             }  | 
1564  |  |  | 
1565  | 0  |             ret = component::Ciphertext(Buffer(out, op.cleartext.GetSize()));  | 
1566  | 0  |         }  | 
1567  | 0  |         break;  | 
1568  |  |  | 
1569  | 0  |         case CF_CIPHER("AES_128_CFB1"): | 
1570  | 0  |         case CF_CIPHER("AES_192_CFB1"): | 
1571  | 0  |         case CF_CIPHER("AES_256_CFB1"): | 
1572  | 0  |         { | 
1573  | 0  |             util::Multipart parts;  | 
1574  | 0  |             size_t outIdx = 0;  | 
1575  |  | 
  | 
1576  | 0  |             switch ( op.cipher.cipherType.Get() ) { | 
1577  | 0  |                 case CF_CIPHER("AES_128_CFB1"): | 
1578  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 16);  | 
1579  | 0  |                     break;  | 
1580  | 0  |                 case CF_CIPHER("AES_192_CFB1"): | 
1581  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 24);  | 
1582  | 0  |                     break;  | 
1583  | 0  |                 case CF_CIPHER("AES_256_CFB1"): | 
1584  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 32);  | 
1585  | 0  |                     break;  | 
1586  | 0  |             }  | 
1587  |  |  | 
1588  | 0  |             CF_CHECK_EQ(op.cleartext.GetSize() % 16, 0);  | 
1589  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), 16);  | 
1590  |  | 
  | 
1591  | 0  |             out = util::malloc(op.cleartext.GetSize());  | 
1592  |  | 
  | 
1593  | 0  |             WC_CHECK_EQ(wc_AesInit(&aes, nullptr, INVALID_DEVID), 0);  | 
1594  | 0  |             aes_inited = true;  | 
1595  |  | 
  | 
1596  | 0  |             WC_CHECK_EQ(wc_AesSetKeyDirect(&aes, op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize(), op.cipher.iv.GetPtr(&ds), AES_ENCRYPTION), 0);  | 
1597  |  | 
  | 
1598  | 0  |             parts = util::ToParts(ds, op.cleartext);  | 
1599  | 0  |             for (const auto& part : parts) { | 
1600  | 0  |                 WC_CHECK_EQ(wc_AesCfb1Encrypt(&aes, out + outIdx, part.first, part.second * 8), 0);  | 
1601  | 0  |                 outIdx += part.second;  | 
1602  | 0  |             }  | 
1603  |  |  | 
1604  | 0  |             ret = component::Ciphertext(Buffer(out, op.cleartext.GetSize()));  | 
1605  | 0  |         }  | 
1606  | 0  |         break;  | 
1607  |  |  | 
1608  | 0  |         case CF_CIPHER("AES_128_CFB8"): | 
1609  | 0  |         case CF_CIPHER("AES_192_CFB8"): | 
1610  | 0  |         case CF_CIPHER("AES_256_CFB8"): | 
1611  | 0  |         { | 
1612  | 0  |             util::Multipart parts;  | 
1613  | 0  |             size_t outIdx = 0;  | 
1614  |  | 
  | 
1615  | 0  |             switch ( op.cipher.cipherType.Get() ) { | 
1616  | 0  |                 case CF_CIPHER("AES_128_CFB8"): | 
1617  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 16);  | 
1618  | 0  |                     break;  | 
1619  | 0  |                 case CF_CIPHER("AES_192_CFB8"): | 
1620  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 24);  | 
1621  | 0  |                     break;  | 
1622  | 0  |                 case CF_CIPHER("AES_256_CFB8"): | 
1623  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 32);  | 
1624  | 0  |                     break;  | 
1625  | 0  |             }  | 
1626  |  |  | 
1627  | 0  |             CF_CHECK_EQ(op.cleartext.GetSize() % 16, 0);  | 
1628  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), 16);  | 
1629  |  | 
  | 
1630  | 0  |             out = util::malloc(op.cleartext.GetSize());  | 
1631  |  | 
  | 
1632  | 0  |             WC_CHECK_EQ(wc_AesInit(&aes, nullptr, INVALID_DEVID), 0);  | 
1633  | 0  |             aes_inited = true;  | 
1634  |  | 
  | 
1635  | 0  |             WC_CHECK_EQ(wc_AesSetKeyDirect(&aes, op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize(), op.cipher.iv.GetPtr(&ds), AES_ENCRYPTION), 0);  | 
1636  |  | 
  | 
1637  | 0  |             parts = util::ToParts(ds, op.cleartext);  | 
1638  | 0  |             for (const auto& part : parts) { | 
1639  | 0  |                 WC_CHECK_EQ(wc_AesCfb8Encrypt(&aes, out + outIdx, part.first, part.second), 0);  | 
1640  | 0  |                 outIdx += part.second;  | 
1641  | 0  |             }  | 
1642  |  |  | 
1643  | 0  |             ret = component::Ciphertext(Buffer(out, op.cleartext.GetSize()));  | 
1644  | 0  |         }  | 
1645  | 0  |         break;  | 
1646  |  |  | 
1647  | 0  |         case CF_CIPHER("AES_128_OFB"): | 
1648  | 0  |         case CF_CIPHER("AES_192_OFB"): | 
1649  | 0  |         case CF_CIPHER("AES_256_OFB"): | 
1650  | 0  |         { | 
1651  | 0  |             util::Multipart parts;  | 
1652  | 0  |             size_t outIdx = 0;  | 
1653  |  | 
  | 
1654  | 0  |             switch ( op.cipher.cipherType.Get() ) { | 
1655  | 0  |                 case CF_CIPHER("AES_128_OFB"): | 
1656  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 16);  | 
1657  | 0  |                     break;  | 
1658  | 0  |                 case CF_CIPHER("AES_192_OFB"): | 
1659  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 24);  | 
1660  | 0  |                     break;  | 
1661  | 0  |                 case CF_CIPHER("AES_256_OFB"): | 
1662  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 32);  | 
1663  | 0  |                     break;  | 
1664  | 0  |             }  | 
1665  |  |  | 
1666  | 0  |             CF_CHECK_EQ(op.cleartext.GetSize() % 16, 0);  | 
1667  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), 16);  | 
1668  |  | 
  | 
1669  | 0  |             out = util::malloc(op.cleartext.GetSize());  | 
1670  |  | 
  | 
1671  | 0  |             WC_CHECK_EQ(wc_AesInit(&aes, nullptr, INVALID_DEVID), 0);  | 
1672  | 0  |             aes_inited = true;  | 
1673  |  | 
  | 
1674  | 0  |             WC_CHECK_EQ(wc_AesSetKeyDirect(&aes, op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize(), op.cipher.iv.GetPtr(&ds), AES_ENCRYPTION), 0);  | 
1675  |  | 
  | 
1676  | 0  |             parts = util::ToParts(ds, op.cleartext);  | 
1677  | 0  |             for (const auto& part : parts) { | 
1678  | 0  |                 WC_CHECK_EQ(wc_AesOfbEncrypt(&aes, out + outIdx, part.first, part.second), 0);  | 
1679  | 0  |                 outIdx += part.second;  | 
1680  | 0  |             }  | 
1681  |  |  | 
1682  | 0  |             ret = component::Ciphertext(Buffer(out, op.cleartext.GetSize()));  | 
1683  | 0  |         }  | 
1684  | 0  |         break;  | 
1685  |  |  | 
1686  | 0  |         case CF_CIPHER("RC4"): | 
1687  | 0  |         { | 
1688  | 0  |             Arc4 ctx;  | 
1689  |  | 
  | 
1690  | 0  |             out = util::malloc(op.cleartext.GetSize());  | 
1691  |  | 
  | 
1692  | 0  |             WC_CHECK_EQ(wc_Arc4Init(&ctx, NULL, INVALID_DEVID), 0);  | 
1693  | 0  |             WC_CHECK_EQ(wc_Arc4SetKey(  | 
1694  | 0  |                         &ctx,  | 
1695  | 0  |                         op.cipher.key.GetPtr(&ds),  | 
1696  | 0  |                         op.cipher.key.GetSize()), 0);  | 
1697  | 0  |             WC_CHECK_EQ(wc_Arc4Process(&ctx, out, op.cleartext.GetPtr(&ds), op.cleartext.GetSize()), 0);  | 
1698  |  | 
  | 
1699  | 0  |             ret = component::Ciphertext(Buffer(out, op.cleartext.GetSize()));  | 
1700  | 0  |         }  | 
1701  | 0  |         break;  | 
1702  |  |  | 
1703  | 0  |         case CF_CIPHER("CHACHA20"): | 
1704  | 0  |         { | 
1705  | 0  |             ChaCha ctx;  | 
1706  | 0  |             util::Multipart parts;  | 
1707  | 0  |             size_t outIdx = 0;  | 
1708  |  | 
  | 
1709  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), CHACHA_IV_BYTES);  | 
1710  |  | 
  | 
1711  | 0  |             out = util::malloc(op.cleartext.GetSize());  | 
1712  |  | 
  | 
1713  | 0  |             WC_CHECK_EQ(wc_Chacha_SetKey(&ctx, op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize()), 0);  | 
1714  | 0  |             WC_CHECK_EQ(wc_Chacha_SetIV(&ctx, op.cipher.iv.GetPtr(&ds), 0), 0);  | 
1715  |  | 
  | 
1716  | 0  |             parts = util::ToParts(ds, op.cleartext);  | 
1717  | 0  |             for (const auto& part : parts) { | 
1718  | 0  |                 WC_CHECK_EQ(wc_Chacha_Process(&ctx, out + outIdx, part.first, part.second), 0);  | 
1719  | 0  |                 outIdx += part.second;  | 
1720  | 0  |             }  | 
1721  |  |  | 
1722  | 0  |             ret = component::Ciphertext(Buffer(out, op.cleartext.GetSize()));  | 
1723  | 0  |         }  | 
1724  | 0  |         break;  | 
1725  |  |  | 
1726  | 0  |         case CF_CIPHER("DES_CBC"): | 
1727  | 0  |         { | 
1728  | 0  |             Des ctx;  | 
1729  |  | 
  | 
1730  | 0  |             CF_CHECK_EQ(op.cipher.key.GetSize(), 8);  | 
1731  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), 8);  | 
1732  |  | 
  | 
1733  | 0  |             const auto cleartext = util::Pkcs7Pad(op.cleartext.Get(), 8);  | 
1734  | 0  |             out = util::malloc(cleartext.size());  | 
1735  |  | 
  | 
1736  | 0  |             WC_CHECK_EQ(wc_Des_SetKey(&ctx, op.cipher.key.GetPtr(&ds), op.cipher.iv.GetPtr(&ds), DES_ENCRYPTION), 0);  | 
1737  | 0  |             WC_CHECK_EQ(wc_Des_CbcEncrypt(&ctx, out, cleartext.data(), cleartext.size()), 0);  | 
1738  |  | 
  | 
1739  | 0  |             ret = component::Ciphertext(Buffer(out, cleartext.size()));  | 
1740  | 0  |         }  | 
1741  | 0  |         break;  | 
1742  |  |  | 
1743  | 0  |         case CF_CIPHER("DES3_CBC"): | 
1744  | 0  |         { | 
1745  | 0  |             Des3 ctx;  | 
1746  |  | 
  | 
1747  | 0  |             CF_CHECK_EQ(op.cipher.key.GetSize(), 24);  | 
1748  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), 24);  | 
1749  |  | 
  | 
1750  | 0  |             const auto cleartext = util::Pkcs7Pad(op.cleartext.Get(), 8);  | 
1751  | 0  |             out = util::malloc(cleartext.size());  | 
1752  |  | 
  | 
1753  | 0  |             WC_CHECK_EQ(wc_Des3Init(&ctx, nullptr, -1), 0);  | 
1754  | 0  |             WC_CHECK_EQ(wc_Des3_SetKey(&ctx, op.cipher.key.GetPtr(&ds), op.cipher.iv.GetPtr(&ds), DES_ENCRYPTION), 0);  | 
1755  | 0  |             WC_CHECK_EQ(wc_Des3_CbcEncrypt(&ctx, out, cleartext.data(), cleartext.size()), 0);  | 
1756  |  | 
  | 
1757  | 0  |             ret = component::Ciphertext(Buffer(out, cleartext.size()));  | 
1758  | 0  |         }  | 
1759  | 0  |         break;  | 
1760  |  |  | 
1761  | 0  |         case CF_CIPHER("DES_ECB"): | 
1762  | 0  |         { | 
1763  | 0  | #if defined(WOLFSSL_DES_ECB)  | 
1764  | 0  |             Des ctx;  | 
1765  |  | 
  | 
1766  | 0  |             CF_CHECK_EQ(op.cipher.key.GetSize(), 8);  | 
1767  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), 8);  | 
1768  | 0  |             CF_CHECK_EQ(op.cleartext.GetSize() % 8, 0);  | 
1769  |  | 
  | 
1770  | 0  |             out = util::malloc(op.cleartext.GetSize());  | 
1771  |  | 
  | 
1772  | 0  |             WC_CHECK_EQ(wc_Des_SetKey(&ctx, op.cipher.key.GetPtr(&ds), op.cipher.iv.GetPtr(&ds), DES_ENCRYPTION), 0);  | 
1773  | 0  |             WC_CHECK_EQ(wc_Des_EcbEncrypt(&ctx, out, op.cleartext.GetPtr(&ds), op.cleartext.GetSize()), 0);  | 
1774  |  | 
  | 
1775  | 0  |             ret = component::Ciphertext(Buffer(out, op.cleartext.GetSize()));  | 
1776  | 0  | #endif  | 
1777  | 0  |         }  | 
1778  | 0  |         break;  | 
1779  |  |  | 
1780  | 0  |         case CF_CIPHER("AES_128_WRAP"): | 
1781  | 0  |         case CF_CIPHER("AES_192_WRAP"): | 
1782  | 0  |         case CF_CIPHER("AES_256_WRAP"): | 
1783  | 0  |         { | 
1784  | 0  |             int outSize;  | 
1785  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), KEYWRAP_BLOCK_SIZE);  | 
1786  |  | 
  | 
1787  | 0  |             out = util::malloc(op.ciphertextSize);  | 
1788  |  | 
  | 
1789  | 0  |             CF_CHECK_GTE(outSize = wc_AesKeyWrap(  | 
1790  | 0  |                         op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize(),  | 
1791  | 0  |                         op.cleartext.GetPtr(&ds), op.cleartext.GetSize(),  | 
1792  | 0  |                         out, op.ciphertextSize,  | 
1793  | 0  |                         op.cipher.iv.GetPtr(&ds)), 0);  | 
1794  |  | 
  | 
1795  | 0  |             ret = component::Ciphertext(Buffer(out, outSize));  | 
1796  | 0  |         }  | 
1797  | 0  |         break;  | 
1798  |  |  | 
1799  | 0  |         case CF_CIPHER("GMAC_128"): | 
1800  | 0  |         case CF_CIPHER("GMAC_192"): | 
1801  | 0  |         case CF_CIPHER("GMAC_256"): | 
1802  | 0  |         { | 
1803  |  | 
  | 
1804  | 0  |             CF_CHECK_NE(op.tagSize, std::nullopt);  | 
1805  | 0  |             CF_CHECK_NE(op.aad, std::nullopt);  | 
1806  |  | 
  | 
1807  | 0  |             outTag = util::malloc(*op.tagSize);  | 
1808  | 0  |             const auto partsAAD = util::ToParts(ds, *op.aad);  | 
1809  |  | 
  | 
1810  | 0  |             Gmac ctx;  | 
1811  | 0  |             WC_CHECK_EQ(wc_AesInit(&ctx.aes, NULL, INVALID_DEVID), 0);  | 
1812  | 0  |             WC_CHECK_EQ(wc_GmacSetKey(&ctx, op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize()), 0);  | 
1813  | 0  |             WC_CHECK_EQ(wc_GmacUpdate(&ctx,  | 
1814  | 0  |                         op.cipher.iv.GetPtr(&ds),  | 
1815  | 0  |                         op.cipher.iv.GetSize(),  | 
1816  | 0  |                         op.aad->GetPtr(&ds),  | 
1817  | 0  |                         op.aad->GetSize(),  | 
1818  | 0  |                         outTag, *op.tagSize), 0);  | 
1819  | 0  |             CF_NORET(wc_AesFree(&ctx.aes));  | 
1820  |  | 
  | 
1821  | 0  |             ret = component::Ciphertext(  | 
1822  | 0  |                     Buffer(op.cleartext.GetPtr(&ds), op.cleartext.GetSize()),  | 
1823  | 0  |                     Buffer(outTag, *op.tagSize));  | 
1824  | 0  |         }  | 
1825  | 0  |         break;  | 
1826  | 0  |         case CF_CIPHER("AES_128_SIV_CMAC"): | 
1827  | 0  |         case CF_CIPHER("AES_192_SIV_CMAC"): | 
1828  | 0  |         case CF_CIPHER("AES_256_SIV_CMAC"): | 
1829  | 0  |         { | 
1830  | 0  |             out = util::malloc(op.cleartext.GetSize());  | 
1831  |  | 
  | 
1832  | 0  |             outTag = util::malloc(AES_BLOCK_SIZE);  | 
1833  |  | 
  | 
1834  | 0  |             WC_CHECK_EQ(wc_AesSivEncrypt(  | 
1835  | 0  |                         op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize(),  | 
1836  | 0  |                         op.aad ? op.aad->GetPtr(&ds) : nullptr, op.aad ? op.aad->GetSize() : 0,  | 
1837  | 0  |                         op.cipher.iv.GetPtr(&ds), op.cipher.iv.GetSize(),  | 
1838  | 0  |                         op.cleartext.GetPtr(&ds), op.cleartext.GetSize(),  | 
1839  | 0  |                         outTag, out), 0);  | 
1840  |  | 
  | 
1841  | 0  |             ret = component::Ciphertext(  | 
1842  | 0  |                     Buffer(out, op.cleartext.GetSize()),  | 
1843  | 0  |                     Buffer(outTag, AES_BLOCK_SIZE));  | 
1844  | 0  |         }  | 
1845  | 0  |         break;  | 
1846  | 0  |     }  | 
1847  |  |  | 
1848  | 0  | end:  | 
1849  | 0  |     if ( aes_inited == true ) { | 
1850  | 0  |         CF_NORET(wc_AesFree(&aes));  | 
1851  | 0  |     }  | 
1852  | 0  |     util::free(out);  | 
1853  | 0  |     util::free(outTag);  | 
1854  |  | 
  | 
1855  | 0  |     wolfCrypt_detail::UnsetGlobalDs();  | 
1856  |  | 
  | 
1857  | 0  |     return ret;  | 
1858  | 0  | }  | 
1859  |  |  | 
1860  | 0  | std::optional<component::Cleartext> wolfCrypt::OpSymmetricDecrypt(operation::SymmetricDecrypt& op) { | 
1861  | 0  |     std::optional<component::Cleartext> ret = std::nullopt;  | 
1862  | 0  |     Datasource ds(op.modifier.GetPtr(), op.modifier.GetSize());  | 
1863  | 0  |     wolfCrypt_detail::SetGlobalDs(&ds);  | 
1864  |  | 
  | 
1865  | 0  |     uint8_t* in = nullptr;  | 
1866  | 0  |     uint8_t* out = nullptr;  | 
1867  |  | 
  | 
1868  | 0  |     Aes aes;  | 
1869  | 0  |     bool aes_inited = false;  | 
1870  |  | 
  | 
1871  | 0  |     switch ( op.cipher.cipherType.Get() ) { | 
1872  | 0  |         case CF_CIPHER("AES_128_CBC"): | 
1873  | 0  |         case CF_CIPHER("AES_192_CBC"): | 
1874  | 0  |         case CF_CIPHER("AES_256_CBC"): | 
1875  | 0  |         { | 
1876  | 0  |             switch ( op.cipher.cipherType.Get() ) { | 
1877  | 0  |                 case CF_CIPHER("AES_128_CBC"): | 
1878  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 16);  | 
1879  | 0  |                     break;  | 
1880  | 0  |                 case CF_CIPHER("AES_192_CBC"): | 
1881  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 24);  | 
1882  | 0  |                     break;  | 
1883  | 0  |                 case CF_CIPHER("AES_256_CBC"): | 
1884  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 32);  | 
1885  | 0  |                     break;  | 
1886  | 0  |             }  | 
1887  |  |  | 
1888  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), 16);  | 
1889  |  | 
  | 
1890  | 0  |             out = util::malloc(op.ciphertext.GetSize());  | 
1891  |  | 
  | 
1892  | 0  |             WC_CHECK_EQ(wc_AesInit(&aes, nullptr, INVALID_DEVID), 0);  | 
1893  | 0  |             aes_inited = true;  | 
1894  |  | 
  | 
1895  | 0  |             WC_CHECK_EQ(wc_AesSetKey(&aes, op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize(), op.cipher.iv.GetPtr(&ds), AES_DECRYPTION), 0);  | 
1896  | 0  |             WC_CHECK_EQ(wc_AesCbcDecrypt(&aes, out, op.ciphertext.GetPtr(&ds), op.ciphertext.GetSize()), 0);  | 
1897  |  | 
  | 
1898  | 0  |             const auto unpaddedCleartext = util::Pkcs7Unpad( std::vector<uint8_t>(out, out + op.ciphertext.GetSize()), AES_BLOCK_SIZE );  | 
1899  | 0  |             CF_CHECK_NE(unpaddedCleartext, std::nullopt);  | 
1900  | 0  |             ret = component::Cleartext(Buffer(*unpaddedCleartext));  | 
1901  | 0  |         }  | 
1902  | 0  |         break;  | 
1903  |  |  | 
1904  | 0  |         case CF_CIPHER("CAMELLIA_128_CBC"): | 
1905  | 0  |         case CF_CIPHER("CAMELLIA_192_CBC"): | 
1906  | 0  |         case CF_CIPHER("CAMELLIA_256_CBC"): | 
1907  | 0  |         { | 
1908  | 0  |             Camellia ctx;  | 
1909  |  | 
  | 
1910  | 0  |             switch ( op.cipher.cipherType.Get() ) { | 
1911  | 0  |                 case CF_CIPHER("CAMELLIA_128_CBC"): | 
1912  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 16);  | 
1913  | 0  |                     break;  | 
1914  | 0  |                 case CF_CIPHER("CAMELLIA_192_CBC"): | 
1915  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 24);  | 
1916  | 0  |                     break;  | 
1917  | 0  |                 case CF_CIPHER("CAMELLIA_256_CBC"): | 
1918  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 32);  | 
1919  | 0  |                     break;  | 
1920  | 0  |             }  | 
1921  |  |  | 
1922  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), 16);  | 
1923  |  | 
  | 
1924  | 0  |             out = util::malloc(op.ciphertext.GetSize());  | 
1925  |  | 
  | 
1926  | 0  |             WC_CHECK_EQ(wc_CamelliaSetKey(  | 
1927  | 0  |                         &ctx,  | 
1928  | 0  |                         op.cipher.key.GetPtr(&ds),  | 
1929  | 0  |                         op.cipher.key.GetSize(),  | 
1930  | 0  |                         op.cipher.iv.GetPtr(&ds)), 0);  | 
1931  | 0  |             WC_CHECK_EQ(wc_CamelliaCbcDecrypt(&ctx, out, op.ciphertext.GetPtr(&ds), op.ciphertext.GetSize()), 0);  | 
1932  |  | 
  | 
1933  | 0  |             const auto unpaddedCleartext = util::Pkcs7Unpad( std::vector<uint8_t>(out, out + op.ciphertext.GetSize()), CAMELLIA_BLOCK_SIZE );  | 
1934  | 0  |             CF_CHECK_NE(unpaddedCleartext, std::nullopt);  | 
1935  | 0  |             ret = component::Cleartext(Buffer(*unpaddedCleartext));  | 
1936  | 0  |         }  | 
1937  | 0  |         break;  | 
1938  |  |  | 
1939  | 0  |         case CF_CIPHER("AES_128_GCM"): | 
1940  | 0  |         case CF_CIPHER("AES_192_GCM"): | 
1941  | 0  |         case CF_CIPHER("AES_256_GCM"): | 
1942  | 0  |         { | 
1943  | 0  |             ret = wolfCrypt_detail::OpSymmetricDecrypt_AES_GCM(op, ds);  | 
1944  | 0  |         }  | 
1945  | 0  |         break;  | 
1946  |  |  | 
1947  | 0  |         case CF_CIPHER("AES_128_CCM"): | 
1948  | 0  |         case CF_CIPHER("AES_192_CCM"): | 
1949  | 0  |         case CF_CIPHER("AES_256_CCM"): | 
1950  | 0  |         { | 
1951  | 0  |             Aes ctx;  | 
1952  |  | 
  | 
1953  | 0  |             switch ( op.cipher.cipherType.Get() ) { | 
1954  | 0  |                 case CF_CIPHER("AES_128_CCM"): | 
1955  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 16);  | 
1956  | 0  |                     break;  | 
1957  | 0  |                 case CF_CIPHER("AES_192_CCM"): | 
1958  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 24);  | 
1959  | 0  |                     break;  | 
1960  | 0  |                 case CF_CIPHER("AES_256_CCM"): | 
1961  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 32);  | 
1962  | 0  |                     break;  | 
1963  | 0  |             }  | 
1964  |  |  | 
1965  | 0  |             CF_CHECK_NE(op.aad, std::nullopt);  | 
1966  | 0  |             CF_CHECK_NE(op.tag, std::nullopt);  | 
1967  |  | 
  | 
1968  | 0  |             out = util::malloc(op.ciphertext.GetSize());  | 
1969  |  | 
  | 
1970  | 0  |             WC_CHECK_EQ(wc_AesInit(&ctx, nullptr, INVALID_DEVID), 0);  | 
1971  | 0  |             WC_CHECK_EQ(wc_AesCcmSetKey(&ctx, op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize()), 0);  | 
1972  | 0  |             WC_CHECK_EQ(wc_AesCcmDecrypt(  | 
1973  | 0  |                         &ctx,  | 
1974  | 0  |                         out,  | 
1975  | 0  |                         op.ciphertext.GetPtr(&ds),  | 
1976  | 0  |                         op.ciphertext.GetSize(),  | 
1977  | 0  |                         op.cipher.iv.GetPtr(&ds),  | 
1978  | 0  |                         op.cipher.iv.GetSize(),  | 
1979  | 0  |                         op.tag->GetPtr(&ds),  | 
1980  | 0  |                         op.tag->GetSize(),  | 
1981  | 0  |                         op.aad->GetPtr(&ds),  | 
1982  | 0  |                         op.aad->GetSize()), 0);  | 
1983  |  | 
  | 
1984  | 0  |             ret = component::Cleartext(Buffer(out, op.ciphertext.GetSize()));  | 
1985  | 0  |         }  | 
1986  | 0  |         break;  | 
1987  |  |  | 
1988  | 0  |         case CF_CIPHER("CHACHA20_POLY1305"): | 
1989  | 0  |         { | 
1990  | 0  |             CF_CHECK_NE(op.tag, std::nullopt);  | 
1991  | 0  |             CF_CHECK_EQ(op.tag->GetSize(), CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE);  | 
1992  | 0  |             CF_CHECK_EQ(op.cipher.key.GetSize(), CHACHA20_POLY1305_AEAD_KEYSIZE);  | 
1993  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), CHACHA20_POLY1305_AEAD_IV_SIZE);  | 
1994  | 0  |             CF_CHECK_NE(op.aad, std::nullopt);  | 
1995  |  | 
  | 
1996  | 0  |             out = util::malloc(op.ciphertext.GetSize());  | 
1997  |  | 
  | 
1998  | 0  |             bool oneShot = true;  | 
1999  | 0  |             try { | 
2000  | 0  |                 oneShot = ds.Get<bool>();  | 
2001  | 0  |             } catch ( ... ) { } | 
2002  |  | 
  | 
2003  | 0  |             if ( oneShot == true ) { | 
2004  | 0  |                 WC_CHECK_EQ(wc_ChaCha20Poly1305_Decrypt(  | 
2005  | 0  |                             op.cipher.key.GetPtr(&ds),  | 
2006  | 0  |                             op.cipher.iv.GetPtr(&ds),  | 
2007  | 0  |                             op.aad->GetPtr(&ds),  | 
2008  | 0  |                             op.aad->GetSize(),  | 
2009  | 0  |                             op.ciphertext.GetPtr(&ds),  | 
2010  | 0  |                             op.ciphertext.GetSize(),  | 
2011  | 0  |                             op.tag->GetPtr(&ds),  | 
2012  | 0  |                             out), 0);  | 
2013  | 0  |             } else { | 
2014  | 0  |                 ChaChaPoly_Aead aead;  | 
2015  |  | 
  | 
2016  | 0  |                 WC_CHECK_EQ(wc_ChaCha20Poly1305_Init(&aead, op.cipher.key.GetPtr(&ds), op.cipher.iv.GetPtr(&ds), 0), 0);  | 
2017  |  | 
  | 
2018  | 0  |                 { | 
2019  | 0  |                     const auto partsAAD = util::ToParts(ds, *op.aad);  | 
2020  | 0  |                     for (const auto& part : partsAAD) { | 
2021  | 0  |                         WC_CHECK_EQ(wc_ChaCha20Poly1305_UpdateAad(&aead, part.first, part.second), 0);  | 
2022  | 0  |                     }  | 
2023  | 0  |                 }  | 
2024  |  |  | 
2025  | 0  |                 { | 
2026  | 0  |                     const auto partsData = util::ToParts(ds, op.ciphertext);  | 
2027  | 0  |                     size_t pos = 0;  | 
2028  | 0  |                     for (const auto& part : partsData) { | 
2029  | 0  |                         WC_CHECK_EQ(wc_ChaCha20Poly1305_UpdateData(&aead, part.first, out + pos, part.second), 0);  | 
2030  | 0  |                         pos += part.second;  | 
2031  | 0  |                     }  | 
2032  |  | 
  | 
2033  | 0  |                 }  | 
2034  |  |  | 
2035  | 0  |                 { | 
2036  | 0  |                     uint8_t outTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE];  | 
2037  | 0  |                     WC_CHECK_EQ(wc_ChaCha20Poly1305_Final(&aead, outTag), 0);  | 
2038  | 0  |                     WC_CHECK_EQ(wc_ChaCha20Poly1305_CheckTag(outTag, op.tag->GetPtr(&ds)), 0);  | 
2039  | 0  |                 }  | 
2040  | 0  |             }  | 
2041  |  |  | 
2042  | 0  |             ret = component::Cleartext(Buffer(out, op.ciphertext.GetSize()));  | 
2043  | 0  |         }  | 
2044  | 0  |         break;  | 
2045  |  |  | 
2046  | 0  | #if defined(HAVE_XCHACHA)  | 
2047  | 0  |         case CF_CIPHER("XCHACHA20_POLY1305"): | 
2048  | 0  |         { | 
2049  | 0  |             const size_t inSize = op.ciphertext.GetSize() + CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE;  | 
2050  | 0  |             CF_CHECK_NE(op.tag, std::nullopt);  | 
2051  | 0  |             CF_CHECK_EQ(op.tag->GetSize(), CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE);  | 
2052  | 0  |             CF_CHECK_NE(op.aad, std::nullopt);  | 
2053  |  |  | 
2054  |  |             /* Concatenate ciphertext + tag */  | 
2055  | 0  |             in = util::malloc(inSize);  | 
2056  | 0  |             if ( op.ciphertext.GetSize() ) { | 
2057  | 0  |                 memcpy(in, op.ciphertext.GetPtr(&ds), op.ciphertext.GetSize());  | 
2058  | 0  |             }  | 
2059  | 0  |             memcpy(in + op.ciphertext.GetSize(), op.tag->GetPtr(&ds), op.tag->GetSize());  | 
2060  |  | 
  | 
2061  | 0  |             out = util::malloc(op.cleartextSize);  | 
2062  |  | 
  | 
2063  | 0  |             WC_CHECK_EQ(wc_XChaCha20Poly1305_Decrypt(  | 
2064  | 0  |                         out, op.cleartextSize,  | 
2065  | 0  |                         in, inSize,  | 
2066  | 0  |                         op.aad->GetPtr(&ds), op.aad->GetSize(),  | 
2067  | 0  |                         op.cipher.iv.GetPtr(&ds), op.cipher.iv.GetSize(),  | 
2068  | 0  |                         op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize()), 0);  | 
2069  | 0  |             ret = component::Cleartext(Buffer(out, op.ciphertext.GetSize()));  | 
2070  | 0  |         }  | 
2071  | 0  |         break;  | 
2072  | 0  | #endif  | 
2073  |  |  | 
2074  | 0  |         case CF_CIPHER("AES_128_CTR"): | 
2075  | 0  |         case CF_CIPHER("AES_192_CTR"): | 
2076  | 0  |         case CF_CIPHER("AES_256_CTR"): | 
2077  | 0  |         { | 
2078  | 0  |             Aes ctx;  | 
2079  | 0  |             util::Multipart parts;  | 
2080  | 0  |             size_t outIdx = 0;  | 
2081  |  | 
  | 
2082  | 0  |             switch ( op.cipher.cipherType.Get() ) { | 
2083  | 0  |                 case CF_CIPHER("AES_128_CTR"): | 
2084  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 16);  | 
2085  | 0  |                     break;  | 
2086  | 0  |                 case CF_CIPHER("AES_192_CTR"): | 
2087  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 24);  | 
2088  | 0  |                     break;  | 
2089  | 0  |                 case CF_CIPHER("AES_256_CTR"): | 
2090  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 32);  | 
2091  | 0  |                     break;  | 
2092  | 0  |             }  | 
2093  |  |  | 
2094  | 0  |             CF_CHECK_EQ(op.ciphertext.GetSize() % 16, 0);  | 
2095  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), 16);  | 
2096  | 0  |             CF_CHECK_GT(op.cipher.key.GetSize(), 0);  | 
2097  |  | 
  | 
2098  | 0  |             out = util::malloc(op.ciphertext.GetSize());  | 
2099  |  | 
  | 
2100  | 0  |             WC_CHECK_EQ(wc_AesInit(&ctx, nullptr, INVALID_DEVID), 0);  | 
2101  | 0  |             WC_CHECK_EQ(wc_AesSetKeyDirect(&ctx, op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize(), op.cipher.iv.GetPtr(&ds), AES_ENCRYPTION), 0);  | 
2102  |  | 
  | 
2103  | 0  |             parts = util::ToParts(ds, op.ciphertext);  | 
2104  | 0  |             for (const auto& part : parts) { | 
2105  | 0  |                 WC_CHECK_EQ(wc_AesCtrEncrypt(&ctx, out + outIdx, part.first, part.second), 0);  | 
2106  | 0  |                 outIdx += part.second;  | 
2107  | 0  |             }  | 
2108  |  |  | 
2109  | 0  |             ret = component::Cleartext(Buffer(out, op.ciphertext.GetSize()));  | 
2110  | 0  |         }  | 
2111  | 0  |         break;  | 
2112  |  |  | 
2113  | 0  |         case CF_CIPHER("AES_128_ECB"): | 
2114  | 0  |         case CF_CIPHER("AES_192_ECB"): | 
2115  | 0  |         case CF_CIPHER("AES_256_ECB"): | 
2116  | 0  |         { | 
2117  | 0  | #if defined(HAVE_AES_ECB)  | 
2118  | 0  |             Aes ctx;  | 
2119  |  | 
  | 
2120  | 0  |             switch ( op.cipher.cipherType.Get() ) { | 
2121  | 0  |                 case CF_CIPHER("AES_128_ECB"): | 
2122  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 16);  | 
2123  | 0  |                     break;  | 
2124  | 0  |                 case CF_CIPHER("AES_192_ECB"): | 
2125  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 24);  | 
2126  | 0  |                     break;  | 
2127  | 0  |                 case CF_CIPHER("AES_256_ECB"): | 
2128  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 32);  | 
2129  | 0  |                     break;  | 
2130  | 0  |             }  | 
2131  |  |  | 
2132  | 0  |             CF_CHECK_EQ(op.ciphertext.GetSize() % 16, 0);  | 
2133  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), 16);  | 
2134  | 0  |             CF_CHECK_GT(op.cipher.key.GetSize(), 0);  | 
2135  |  | 
  | 
2136  | 0  |             out = util::malloc(op.ciphertext.GetSize());  | 
2137  |  | 
  | 
2138  | 0  |             WC_CHECK_EQ(wc_AesInit(&ctx, nullptr, INVALID_DEVID), 0);  | 
2139  | 0  |             WC_CHECK_EQ(wc_AesSetKeyDirect(&ctx, op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize(), op.cipher.iv.GetPtr(&ds), AES_DECRYPTION), 0);  | 
2140  |  |  | 
2141  |  |             /* Note: wc_AesEcbDecrypt does not support streaming */  | 
2142  | 0  |             WC_CHECK_EQ(wc_AesEcbDecrypt(&ctx, out, op.ciphertext.GetPtr(&ds), op.ciphertext.GetSize()), 0);  | 
2143  |  | 
  | 
2144  | 0  |             ret = component::Cleartext(Buffer(out, op.ciphertext.GetSize()));  | 
2145  | 0  | #endif  | 
2146  | 0  |         }  | 
2147  | 0  |         break;  | 
2148  |  |  | 
2149  | 0  |         case CF_CIPHER("AES_128_XTS"): | 
2150  | 0  |         case CF_CIPHER("AES_192_XTS"): | 
2151  | 0  |         case CF_CIPHER("AES_256_XTS"): | 
2152  | 0  |         { | 
2153  | 0  |             XtsAes ctx;  | 
2154  |  | 
  | 
2155  | 0  |             switch ( op.cipher.cipherType.Get() ) { | 
2156  | 0  |                 case CF_CIPHER("AES_128_XTS"): | 
2157  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 16);  | 
2158  | 0  |                     break;  | 
2159  | 0  |                 case CF_CIPHER("AES_192_XTS"): | 
2160  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 24);  | 
2161  | 0  |                     break;  | 
2162  | 0  |                 case CF_CIPHER("AES_256_XTS"): | 
2163  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 32);  | 
2164  | 0  |                     break;  | 
2165  | 0  |             }  | 
2166  |  |  | 
2167  | 0  |             CF_CHECK_EQ(op.ciphertext.GetSize() % 16, 0);  | 
2168  |  | 
  | 
2169  | 0  |             out = util::malloc(op.ciphertext.GetSize());  | 
2170  |  | 
  | 
2171  | 0  |             WC_CHECK_EQ(wc_AesXtsSetKey(&ctx, op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize(), AES_DECRYPTION, nullptr, INVALID_DEVID), 0);  | 
2172  | 0  |             WC_CHECK_EQ(wc_AesXtsDecrypt(&ctx, out, op.ciphertext.GetPtr(&ds), op.ciphertext.GetSize(), op.cipher.iv.GetPtr(&ds), op.cipher.iv.GetSize()), 0);  | 
2173  |  | 
  | 
2174  | 0  |             ret = component::Cleartext(Buffer(out, op.ciphertext.GetSize()));  | 
2175  | 0  |         }  | 
2176  | 0  |         break;  | 
2177  |  |  | 
2178  | 0  |         case CF_CIPHER("AES_128_CFB"): | 
2179  | 0  |         case CF_CIPHER("AES_192_CFB"): | 
2180  | 0  |         case CF_CIPHER("AES_256_CFB"): | 
2181  | 0  |         { | 
2182  | 0  |             Aes ctx;  | 
2183  | 0  |             util::Multipart parts;  | 
2184  | 0  |             size_t outIdx = 0;  | 
2185  |  | 
  | 
2186  | 0  |             switch ( op.cipher.cipherType.Get() ) { | 
2187  | 0  |                 case CF_CIPHER("AES_128_CFB"): | 
2188  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 16);  | 
2189  | 0  |                     break;  | 
2190  | 0  |                 case CF_CIPHER("AES_192_CFB"): | 
2191  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 24);  | 
2192  | 0  |                     break;  | 
2193  | 0  |                 case CF_CIPHER("AES_256_CFB"): | 
2194  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 32);  | 
2195  | 0  |                     break;  | 
2196  | 0  |             }  | 
2197  |  |  | 
2198  | 0  |             CF_CHECK_EQ(op.ciphertext.GetSize() % 16, 0);  | 
2199  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), 16);  | 
2200  | 0  |             CF_CHECK_GT(op.cipher.key.GetSize(), 0);  | 
2201  |  | 
  | 
2202  | 0  |             out = util::malloc(op.ciphertext.GetSize());  | 
2203  |  | 
  | 
2204  | 0  |             WC_CHECK_EQ(wc_AesInit(&ctx, nullptr, INVALID_DEVID), 0);  | 
2205  | 0  |             WC_CHECK_EQ(wc_AesSetKeyDirect(&ctx, op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize(), op.cipher.iv.GetPtr(&ds), AES_ENCRYPTION), 0);  | 
2206  |  | 
  | 
2207  | 0  |             parts = util::ToParts(ds, op.ciphertext);  | 
2208  | 0  |             for (const auto& part : parts) { | 
2209  | 0  |                 WC_CHECK_EQ(wc_AesCfbDecrypt(&ctx, out + outIdx, part.first, part.second), 0);  | 
2210  | 0  |                 outIdx += part.second;  | 
2211  | 0  |             }  | 
2212  |  |  | 
2213  | 0  |             ret = component::Cleartext(Buffer(out, op.ciphertext.GetSize()));  | 
2214  | 0  |         }  | 
2215  | 0  |         break;  | 
2216  |  |  | 
2217  | 0  |         case CF_CIPHER("AES_128_CFB1"): | 
2218  | 0  |         case CF_CIPHER("AES_192_CFB1"): | 
2219  | 0  |         case CF_CIPHER("AES_256_CFB1"): | 
2220  | 0  |         { | 
2221  | 0  |             Aes ctx;  | 
2222  | 0  |             util::Multipart parts;  | 
2223  | 0  |             size_t outIdx = 0;  | 
2224  |  | 
  | 
2225  | 0  |             switch ( op.cipher.cipherType.Get() ) { | 
2226  | 0  |                 case CF_CIPHER("AES_128_CFB1"): | 
2227  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 16);  | 
2228  | 0  |                     break;  | 
2229  | 0  |                 case CF_CIPHER("AES_192_CFB1"): | 
2230  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 24);  | 
2231  | 0  |                     break;  | 
2232  | 0  |                 case CF_CIPHER("AES_256_CFB1"): | 
2233  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 32);  | 
2234  | 0  |                     break;  | 
2235  | 0  |             }  | 
2236  |  |  | 
2237  | 0  |             CF_CHECK_EQ(op.ciphertext.GetSize() % 16, 0);  | 
2238  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), 16);  | 
2239  | 0  |             CF_CHECK_GT(op.cipher.key.GetSize(), 0);  | 
2240  |  | 
  | 
2241  | 0  |             out = util::malloc(op.ciphertext.GetSize());  | 
2242  |  | 
  | 
2243  | 0  |             WC_CHECK_EQ(wc_AesInit(&ctx, nullptr, INVALID_DEVID), 0);  | 
2244  | 0  |             WC_CHECK_EQ(wc_AesSetKeyDirect(&ctx, op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize(), op.cipher.iv.GetPtr(&ds), AES_ENCRYPTION), 0);  | 
2245  |  | 
  | 
2246  | 0  |             parts = util::ToParts(ds, op.ciphertext);  | 
2247  | 0  |             for (const auto& part : parts) { | 
2248  | 0  |                 WC_CHECK_EQ(wc_AesCfb1Decrypt(&ctx, out + outIdx, part.first, part.second * 8), 0);  | 
2249  | 0  |                 outIdx += part.second;  | 
2250  | 0  |             }  | 
2251  |  |  | 
2252  | 0  |             ret = component::Cleartext(Buffer(out, op.ciphertext.GetSize()));  | 
2253  | 0  |         }  | 
2254  | 0  |         break;  | 
2255  |  |  | 
2256  | 0  |         case CF_CIPHER("AES_128_CFB8"): | 
2257  | 0  |         case CF_CIPHER("AES_192_CFB8"): | 
2258  | 0  |         case CF_CIPHER("AES_256_CFB8"): | 
2259  | 0  |         { | 
2260  | 0  |             Aes ctx;  | 
2261  | 0  |             util::Multipart parts;  | 
2262  | 0  |             size_t outIdx = 0;  | 
2263  |  | 
  | 
2264  | 0  |             switch ( op.cipher.cipherType.Get() ) { | 
2265  | 0  |                 case CF_CIPHER("AES_128_CFB8"): | 
2266  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 16);  | 
2267  | 0  |                     break;  | 
2268  | 0  |                 case CF_CIPHER("AES_192_CFB8"): | 
2269  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 24);  | 
2270  | 0  |                     break;  | 
2271  | 0  |                 case CF_CIPHER("AES_256_CFB8"): | 
2272  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 32);  | 
2273  | 0  |                     break;  | 
2274  | 0  |             }  | 
2275  |  |  | 
2276  | 0  |             CF_CHECK_EQ(op.ciphertext.GetSize() % 16, 0);  | 
2277  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), 16);  | 
2278  | 0  |             CF_CHECK_GT(op.cipher.key.GetSize(), 0);  | 
2279  |  | 
  | 
2280  | 0  |             out = util::malloc(op.ciphertext.GetSize());  | 
2281  |  | 
  | 
2282  | 0  |             WC_CHECK_EQ(wc_AesInit(&ctx, nullptr, INVALID_DEVID), 0);  | 
2283  | 0  |             WC_CHECK_EQ(wc_AesSetKeyDirect(&ctx, op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize(), op.cipher.iv.GetPtr(&ds), AES_ENCRYPTION), 0);  | 
2284  |  | 
  | 
2285  | 0  |             parts = util::ToParts(ds, op.ciphertext);  | 
2286  | 0  |             for (const auto& part : parts) { | 
2287  | 0  |                 WC_CHECK_EQ(wc_AesCfb8Decrypt(&ctx, out + outIdx, part.first, part.second), 0);  | 
2288  | 0  |                 outIdx += part.second;  | 
2289  | 0  |             }  | 
2290  |  |  | 
2291  | 0  |             ret = component::Cleartext(Buffer(out, op.ciphertext.GetSize()));  | 
2292  | 0  |         }  | 
2293  | 0  |         break;  | 
2294  |  |  | 
2295  | 0  |         case CF_CIPHER("AES_128_OFB"): | 
2296  | 0  |         case CF_CIPHER("AES_192_OFB"): | 
2297  | 0  |         case CF_CIPHER("AES_256_OFB"): | 
2298  | 0  |         { | 
2299  | 0  |             Aes ctx;  | 
2300  | 0  |             util::Multipart parts;  | 
2301  | 0  |             size_t outIdx = 0;  | 
2302  |  | 
  | 
2303  | 0  |             switch ( op.cipher.cipherType.Get() ) { | 
2304  | 0  |                 case CF_CIPHER("AES_128_OFB"): | 
2305  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 16);  | 
2306  | 0  |                     break;  | 
2307  | 0  |                 case CF_CIPHER("AES_192_OFB"): | 
2308  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 24);  | 
2309  | 0  |                     break;  | 
2310  | 0  |                 case CF_CIPHER("AES_256_OFB"): | 
2311  | 0  |                     CF_CHECK_EQ(op.cipher.key.GetSize(), 32);  | 
2312  | 0  |                     break;  | 
2313  | 0  |             }  | 
2314  |  |  | 
2315  | 0  |             CF_CHECK_EQ(op.ciphertext.GetSize() % 16, 0);  | 
2316  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), 16);  | 
2317  | 0  |             CF_CHECK_GT(op.cipher.key.GetSize(), 0);  | 
2318  |  | 
  | 
2319  | 0  |             out = util::malloc(op.ciphertext.GetSize());  | 
2320  |  | 
  | 
2321  | 0  |             WC_CHECK_EQ(wc_AesInit(&ctx, nullptr, INVALID_DEVID), 0);  | 
2322  | 0  |             WC_CHECK_EQ(wc_AesSetKeyDirect(&ctx, op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize(), op.cipher.iv.GetPtr(&ds), AES_ENCRYPTION), 0);  | 
2323  |  | 
  | 
2324  | 0  |             parts = util::ToParts(ds, op.ciphertext);  | 
2325  | 0  |             for (const auto& part : parts) { | 
2326  | 0  |                 WC_CHECK_EQ(wc_AesOfbDecrypt(&ctx, out + outIdx, part.first, part.second), 0);  | 
2327  | 0  |                 outIdx += part.second;  | 
2328  | 0  |             }  | 
2329  |  |  | 
2330  | 0  |             ret = component::Cleartext(Buffer(out, op.ciphertext.GetSize()));  | 
2331  | 0  |         }  | 
2332  | 0  |         break;  | 
2333  |  |  | 
2334  | 0  |         case CF_CIPHER("RC4"): | 
2335  | 0  |         { | 
2336  | 0  |             Arc4 ctx;  | 
2337  |  | 
  | 
2338  | 0  |             out = util::malloc(op.ciphertext.GetSize());  | 
2339  |  | 
  | 
2340  | 0  |             WC_CHECK_EQ(wc_Arc4Init(&ctx, NULL, INVALID_DEVID), 0);  | 
2341  | 0  |             WC_CHECK_EQ(wc_Arc4SetKey(  | 
2342  | 0  |                         &ctx,  | 
2343  | 0  |                         op.cipher.key.GetPtr(&ds),  | 
2344  | 0  |                         op.cipher.key.GetSize()), 0);  | 
2345  | 0  |             WC_CHECK_EQ(wc_Arc4Process(&ctx, out, op.ciphertext.GetPtr(&ds), op.ciphertext.GetSize()), 0);  | 
2346  |  | 
  | 
2347  | 0  |             ret = component::Cleartext(Buffer(out, op.ciphertext.GetSize()));  | 
2348  | 0  |         }  | 
2349  | 0  |         break;  | 
2350  |  |  | 
2351  | 0  |         case CF_CIPHER("CHACHA20"): | 
2352  | 0  |         { | 
2353  | 0  |             ChaCha ctx;  | 
2354  | 0  |             util::Multipart parts;  | 
2355  | 0  |             size_t outIdx = 0;  | 
2356  |  | 
  | 
2357  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), CHACHA_IV_BYTES);  | 
2358  |  | 
  | 
2359  | 0  |             out = util::malloc(op.ciphertext.GetSize());  | 
2360  |  | 
  | 
2361  | 0  |             WC_CHECK_EQ(wc_Chacha_SetKey(&ctx, op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize()), 0);  | 
2362  | 0  |             WC_CHECK_EQ(wc_Chacha_SetIV(&ctx, op.cipher.iv.GetPtr(&ds), 0), 0);  | 
2363  |  | 
  | 
2364  | 0  |             parts = util::ToParts(ds, op.ciphertext);  | 
2365  | 0  |             for (const auto& part : parts) { | 
2366  | 0  |                 WC_CHECK_EQ(wc_Chacha_Process(&ctx, out + outIdx, part.first, part.second), 0);  | 
2367  | 0  |                 outIdx += part.second;  | 
2368  | 0  |             }  | 
2369  |  |  | 
2370  | 0  |             ret = component::Cleartext(Buffer(out, op.ciphertext.GetSize()));  | 
2371  | 0  |         }  | 
2372  | 0  |         break;  | 
2373  |  |  | 
2374  | 0  |         case CF_CIPHER("DES_CBC"): | 
2375  | 0  |         { | 
2376  | 0  |             Des ctx;  | 
2377  |  | 
  | 
2378  | 0  |             CF_CHECK_EQ(op.cipher.key.GetSize(), 8);  | 
2379  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), 8);  | 
2380  |  | 
  | 
2381  | 0  |             out = util::malloc(op.ciphertext.GetSize());  | 
2382  |  | 
  | 
2383  | 0  |             WC_CHECK_EQ(wc_Des_SetKey(&ctx, op.cipher.key.GetPtr(&ds), op.cipher.iv.GetPtr(&ds), DES_DECRYPTION), 0);  | 
2384  | 0  |             WC_CHECK_EQ(wc_Des_CbcDecrypt(&ctx, out, op.ciphertext.GetPtr(&ds), op.ciphertext.GetSize()), 0);  | 
2385  |  | 
  | 
2386  | 0  |             const auto unpaddedCleartext = util::Pkcs7Unpad( std::vector<uint8_t>(out, out + op.ciphertext.GetSize()), DES_BLOCK_SIZE );  | 
2387  | 0  |             CF_CHECK_NE(unpaddedCleartext, std::nullopt);  | 
2388  | 0  |             ret = component::Cleartext(Buffer(*unpaddedCleartext));  | 
2389  | 0  |         }  | 
2390  | 0  |         break;  | 
2391  |  |  | 
2392  | 0  |         case CF_CIPHER("DES3_CBC"): | 
2393  | 0  |         { | 
2394  | 0  |             Des3 ctx;  | 
2395  |  | 
  | 
2396  | 0  |             CF_CHECK_EQ(op.cipher.key.GetSize(), 24);  | 
2397  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), 24);  | 
2398  |  | 
  | 
2399  | 0  |             out = util::malloc(op.ciphertext.GetSize());  | 
2400  |  | 
  | 
2401  | 0  |             WC_CHECK_EQ(wc_Des3Init(&ctx, nullptr, -1), 0);  | 
2402  | 0  |             WC_CHECK_EQ(wc_Des3_SetKey(&ctx, op.cipher.key.GetPtr(&ds), op.cipher.iv.GetPtr(&ds), DES_DECRYPTION), 0);  | 
2403  | 0  |             WC_CHECK_EQ(wc_Des3_CbcDecrypt(&ctx, out, op.ciphertext.GetPtr(&ds), op.ciphertext.GetSize()), 0);  | 
2404  |  | 
  | 
2405  | 0  |             const auto unpaddedCleartext = util::Pkcs7Unpad( std::vector<uint8_t>(out, out + op.ciphertext.GetSize()), DES_BLOCK_SIZE );  | 
2406  | 0  |             CF_CHECK_NE(unpaddedCleartext, std::nullopt);  | 
2407  | 0  |             ret = component::Cleartext(Buffer(*unpaddedCleartext));  | 
2408  | 0  |         }  | 
2409  | 0  |         break;  | 
2410  |  |  | 
2411  | 0  |         case CF_CIPHER("DES_ECB"): | 
2412  | 0  |         { | 
2413  | 0  | #if defined(WOLFSSL_DES_ECB)  | 
2414  | 0  |             Des ctx;  | 
2415  |  | 
  | 
2416  | 0  |             CF_CHECK_EQ(op.cipher.key.GetSize(), 8);  | 
2417  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), 8);  | 
2418  | 0  |             CF_CHECK_EQ(op.ciphertext.GetSize() % 8, 0);  | 
2419  |  | 
  | 
2420  | 0  |             out = util::malloc(op.ciphertext.GetSize());  | 
2421  |  | 
  | 
2422  | 0  |             WC_CHECK_EQ(wc_Des_SetKey(&ctx, op.cipher.key.GetPtr(&ds), op.cipher.iv.GetPtr(&ds), DES_DECRYPTION), 0);  | 
2423  | 0  |             WC_CHECK_EQ(wc_Des_EcbDecrypt(&ctx, out, op.ciphertext.GetPtr(&ds), op.ciphertext.GetSize()), 0);  | 
2424  |  | 
  | 
2425  | 0  |             ret = component::Cleartext(Buffer(out, op.ciphertext.GetSize()));  | 
2426  | 0  | #endif  | 
2427  | 0  |         }  | 
2428  | 0  |         break;  | 
2429  |  |  | 
2430  | 0  |         case CF_CIPHER("AES_128_WRAP"): | 
2431  | 0  |         case CF_CIPHER("AES_192_WRAP"): | 
2432  | 0  |         case CF_CIPHER("AES_256_WRAP"): | 
2433  | 0  |         { | 
2434  | 0  |             int outSize;  | 
2435  | 0  |             CF_CHECK_EQ(op.cipher.iv.GetSize(), KEYWRAP_BLOCK_SIZE);  | 
2436  |  | 
  | 
2437  | 0  |             out = util::malloc(op.cleartextSize);  | 
2438  |  | 
  | 
2439  | 0  |             CF_CHECK_GTE(outSize = wc_AesKeyUnWrap(  | 
2440  | 0  |                         op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize(),  | 
2441  | 0  |                         op.ciphertext.GetPtr(&ds), op.ciphertext.GetSize(),  | 
2442  | 0  |                         out, op.cleartextSize,  | 
2443  | 0  |                         op.cipher.iv.GetPtr(&ds)), 0);  | 
2444  |  | 
  | 
2445  | 0  |             ret = component::Cleartext(Buffer(out, outSize));  | 
2446  | 0  |         }  | 
2447  | 0  |         break;  | 
2448  |  |  | 
2449  | 0  |         case CF_CIPHER("GMAC_128"): | 
2450  | 0  |         case CF_CIPHER("GMAC_192"): | 
2451  | 0  |         case CF_CIPHER("GMAC_256"): | 
2452  | 0  |         { | 
2453  | 0  |             CF_CHECK_NE(op.tag, std::nullopt);  | 
2454  | 0  |             CF_CHECK_NE(op.aad, std::nullopt);  | 
2455  |  | 
  | 
2456  | 0  |             WC_CHECK_EQ(wc_GmacVerify(  | 
2457  | 0  |                         op.cipher.key.GetPtr(&ds),  | 
2458  | 0  |                         op.cipher.key.GetSize(),  | 
2459  | 0  |                         op.cipher.iv.GetPtr(&ds),  | 
2460  | 0  |                         op.cipher.iv.GetSize(),  | 
2461  | 0  |                         op.aad->GetPtr(&ds),  | 
2462  | 0  |                         op.aad->GetSize(),  | 
2463  | 0  |                         op.tag->GetPtr(&ds),  | 
2464  | 0  |                         op.tag->GetSize()), 0);  | 
2465  |  | 
  | 
2466  | 0  |             ret = component::Cleartext(Buffer(op.ciphertext.GetPtr(&ds), op.ciphertext.GetSize()));  | 
2467  | 0  |         }  | 
2468  | 0  |         break;  | 
2469  | 0  |         case CF_CIPHER("AES_128_SIV_CMAC"): | 
2470  | 0  |         case CF_CIPHER("AES_192_SIV_CMAC"): | 
2471  | 0  |         case CF_CIPHER("AES_256_SIV_CMAC"): | 
2472  | 0  |         { | 
2473  | 0  |             out = util::malloc(op.ciphertext.GetSize());  | 
2474  |  | 
  | 
2475  | 0  |             CF_CHECK_NE(op.tag, std::nullopt);  | 
2476  | 0  |             CF_CHECK_EQ(op.tag->GetSize(), AES_BLOCK_SIZE);  | 
2477  |  | 
  | 
2478  | 0  |             auto tag = op.tag->Get();  | 
2479  |  | 
  | 
2480  | 0  |             WC_CHECK_EQ(wc_AesSivDecrypt(  | 
2481  | 0  |                         op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize(),  | 
2482  | 0  |                         op.aad ? op.aad->GetPtr(&ds) : nullptr, op.aad ? op.aad->GetSize() : 0,  | 
2483  | 0  |                         op.cipher.iv.GetPtr(&ds), op.cipher.iv.GetSize(),  | 
2484  | 0  |                         op.ciphertext.GetPtr(&ds), op.ciphertext.GetSize(),  | 
2485  | 0  |                         tag.data(), out), 0);  | 
2486  |  | 
  | 
2487  | 0  |             ret = component::Cleartext(Buffer(out, op.ciphertext.GetSize()));  | 
2488  | 0  |         }  | 
2489  | 0  |         break;  | 
2490  | 0  |     }  | 
2491  |  |  | 
2492  | 0  | end:  | 
2493  | 0  |     if ( aes_inited == true ) { | 
2494  | 0  |         CF_NORET(wc_AesFree(&aes));  | 
2495  | 0  |     }  | 
2496  | 0  |     util::free(in);  | 
2497  | 0  |     util::free(out);  | 
2498  |  | 
  | 
2499  | 0  |     wolfCrypt_detail::UnsetGlobalDs();  | 
2500  |  | 
  | 
2501  | 0  |     return ret;  | 
2502  | 0  | }  | 
2503  |  |  | 
2504  | 0  | std::optional<component::MAC> wolfCrypt::OpCMAC(operation::CMAC& op) { | 
2505  |  |     /* Other ciphers not supported for CMAC in wolfCrypt */  | 
2506  | 0  |     if ( op.cipher.cipherType.Get() != CF_CIPHER("AES") ) { | 
2507  | 0  |         return std::nullopt;  | 
2508  | 0  |     }  | 
2509  |  |  | 
2510  | 0  |     std::optional<component::MAC> ret = std::nullopt;  | 
2511  | 0  |     Datasource ds(op.modifier.GetPtr(), op.modifier.GetSize());  | 
2512  | 0  |     wolfCrypt_detail::SetGlobalDs(&ds);  | 
2513  |  | 
  | 
2514  | 0  |     Cmac ctx;  | 
2515  | 0  |     uint8_t out[AES_BLOCK_SIZE];  | 
2516  | 0  |     util::Multipart parts;  | 
2517  | 0  |     uint32_t outSize = sizeof(out);  | 
2518  |  | 
  | 
2519  | 0  |     bool useOneShot = true;  | 
2520  |  | 
  | 
2521  | 0  |     try { | 
2522  | 0  |         useOneShot = ds.Get<bool>();  | 
2523  | 0  |     } catch ( fuzzing::datasource::Datasource::OutOfData ) { } | 
2524  |  | 
  | 
2525  | 0  |     if ( useOneShot == true ) { | 
2526  | 0  |         WC_CHECK_EQ(wc_AesCmacGenerate(  | 
2527  | 0  |                     out,  | 
2528  | 0  |                     &outSize,  | 
2529  | 0  |                     op.cleartext.GetPtr(&ds),  | 
2530  | 0  |                     op.cleartext.GetSize(),  | 
2531  | 0  |                     op.cipher.key.GetPtr(&ds),  | 
2532  | 0  |                     op.cipher.key.GetSize()), 0);  | 
2533  | 0  |     } else { /* Multi-part CMAC */ | 
2534  |  |  | 
2535  |  |         /* Initialize */  | 
2536  | 0  |         { | 
2537  | 0  |             parts = util::ToParts(ds, op.cleartext);  | 
2538  |  | 
  | 
2539  | 0  |             WC_CHECK_EQ(wc_InitCmac(&ctx, op.cipher.key.GetPtr(&ds), op.cipher.key.GetSize(), WC_CMAC_AES, nullptr), 0);  | 
2540  | 0  |         }  | 
2541  |  |  | 
2542  |  |         /* Process */  | 
2543  | 0  |         for (const auto& part : parts) { | 
2544  | 0  |             WC_CHECK_EQ(wc_CmacUpdate(&ctx, part.first, part.second), 0);  | 
2545  | 0  |         }  | 
2546  |  |  | 
2547  |  |         /* Finalize */  | 
2548  | 0  |         { | 
2549  | 0  |             WC_CHECK_EQ(wc_CmacFinal(&ctx, out, &outSize), 0);  | 
2550  | 0  |             ret = component::MAC(out, outSize);  | 
2551  | 0  |         }  | 
2552  | 0  |     }  | 
2553  |  |  | 
2554  |  |     /* wc_AesCmacVerify return values:  | 
2555  |  |      * 0: Verification succeeded  | 
2556  |  |      * < 0: Internal error (e.g. memory failure)  | 
2557  |  |      * 1: Verification failed  | 
2558  |  |      *  | 
2559  |  |      * Only abort if wc_AesCmacVerify signals explicit  | 
2560  |  |      * verification failure (e.g. returns 1).  | 
2561  |  |      *  | 
2562  |  |      */  | 
2563  | 0  |     CF_ASSERT(wc_AesCmacVerify(  | 
2564  | 0  |                     out,  | 
2565  | 0  |                     outSize,  | 
2566  | 0  |                     op.cleartext.GetPtr(&ds),  | 
2567  | 0  |                     op.cleartext.GetSize(),  | 
2568  | 0  |                     op.cipher.key.GetPtr(&ds),  | 
2569  | 0  |                     op.cipher.key.GetSize()) != 1,  | 
2570  | 0  |             "Cannot verify self-generated CMAC");  | 
2571  | 0  | end:  | 
2572  |  | 
  | 
2573  | 0  |     wolfCrypt_detail::UnsetGlobalDs();  | 
2574  |  | 
  | 
2575  | 0  |     return ret;  | 
2576  | 0  | }  | 
2577  |  |  | 
2578  | 0  | std::optional<component::Key> wolfCrypt::OpKDF_PBKDF(operation::KDF_PBKDF& op) { | 
2579  | 0  |     std::optional<component::Key> ret = std::nullopt;  | 
2580  | 0  |     Datasource ds(op.modifier.GetPtr(), op.modifier.GetSize());  | 
2581  | 0  |     wolfCrypt_detail::SetGlobalDs(&ds);  | 
2582  |  | 
  | 
2583  | 0  |     uint8_t* out = util::malloc(op.keySize);  | 
2584  |  | 
  | 
2585  | 0  |     const auto hashType = wolfCrypt_detail::toHashType(op.digestType);  | 
2586  |  | 
  | 
2587  | 0  |     CF_CHECK_NE(hashType, std::nullopt);  | 
2588  |  | 
  | 
2589  | 0  |     WC_CHECK_EQ(wc_PKCS12_PBKDF(out,  | 
2590  | 0  |                 op.password.GetPtr(&ds),  | 
2591  | 0  |                 op.password.GetSize(),  | 
2592  | 0  |                 op.salt.GetPtr(&ds),  | 
2593  | 0  |                 op.salt.GetSize(),  | 
2594  | 0  |                 op.iterations,  | 
2595  | 0  |                 op.keySize,  | 
2596  | 0  |                 *hashType,  | 
2597  | 0  |                 1), 0);  | 
2598  |  | 
  | 
2599  | 0  |     ret = component::Key(out, op.keySize);  | 
2600  |  | 
  | 
2601  | 0  | end:  | 
2602  | 0  |     util::free(out);  | 
2603  |  | 
  | 
2604  | 0  |     wolfCrypt_detail::UnsetGlobalDs();  | 
2605  |  | 
  | 
2606  | 0  |     return ret;  | 
2607  | 0  | }  | 
2608  |  |  | 
2609  | 0  | std::optional<component::Key> wolfCrypt::OpKDF_PBKDF1(operation::KDF_PBKDF1& op) { | 
2610  | 0  |     std::optional<component::Key> ret = std::nullopt;  | 
2611  | 0  |     Datasource ds(op.modifier.GetPtr(), op.modifier.GetSize());  | 
2612  | 0  |     wolfCrypt_detail::SetGlobalDs(&ds);  | 
2613  |  | 
  | 
2614  | 0  |     uint8_t* out = util::malloc(op.keySize);  | 
2615  |  | 
  | 
2616  | 0  |     const auto hashType = wolfCrypt_detail::toHashType(op.digestType);  | 
2617  |  | 
  | 
2618  | 0  |     CF_CHECK_NE(hashType, std::nullopt);  | 
2619  |  | 
  | 
2620  | 0  |     CF_CHECK_EQ(  | 
2621  | 0  |             wc_PBKDF1(  | 
2622  | 0  |                 out,  | 
2623  | 0  |                 op.password.GetPtr(&ds),  | 
2624  | 0  |                 op.password.GetSize(),  | 
2625  | 0  |                 op.salt.GetPtr(&ds),  | 
2626  | 0  |                 op.salt.GetSize(),  | 
2627  | 0  |                 op.iterations,  | 
2628  | 0  |                 op.keySize,  | 
2629  | 0  |                 *hashType), 0);  | 
2630  |  | 
  | 
2631  | 0  |     ret = component::Key(out, op.keySize);  | 
2632  |  | 
  | 
2633  | 0  | end:  | 
2634  | 0  |     util::free(out);  | 
2635  |  | 
  | 
2636  | 0  |     wolfCrypt_detail::UnsetGlobalDs();  | 
2637  |  | 
  | 
2638  | 0  |     return ret;  | 
2639  | 0  | }  | 
2640  |  |  | 
2641  | 0  | std::optional<component::Key> wolfCrypt::OpKDF_PBKDF2(operation::KDF_PBKDF2& op) { | 
2642  | 0  |     std::optional<component::Key> ret = std::nullopt;  | 
2643  | 0  |     Datasource ds(op.modifier.GetPtr(), op.modifier.GetSize());  | 
2644  | 0  |     wolfCrypt_detail::SetGlobalDs(&ds);  | 
2645  |  | 
  | 
2646  | 0  |     uint8_t* out = util::malloc(op.keySize);  | 
2647  |  | 
  | 
2648  | 0  |     const auto hashType = wolfCrypt_detail::toHashType(op.digestType);  | 
2649  |  | 
  | 
2650  | 0  |     CF_CHECK_NE(hashType, std::nullopt);  | 
2651  |  | 
  | 
2652  | 0  |     CF_CHECK_EQ(  | 
2653  | 0  |             wc_PBKDF2(  | 
2654  | 0  |                 out,  | 
2655  | 0  |                 op.password.GetPtr(&ds),  | 
2656  | 0  |                 op.password.GetSize(),  | 
2657  | 0  |                 op.salt.GetPtr(&ds),  | 
2658  | 0  |                 op.salt.GetSize(),  | 
2659  | 0  |                 op.iterations,  | 
2660  | 0  |                 op.keySize,  | 
2661  | 0  |                 *hashType), 0);  | 
2662  |  | 
  | 
2663  | 0  |     ret = component::Key(out, op.keySize);  | 
2664  |  | 
  | 
2665  | 0  | end:  | 
2666  | 0  |     util::free(out);  | 
2667  |  | 
  | 
2668  | 0  |     wolfCrypt_detail::UnsetGlobalDs();  | 
2669  |  | 
  | 
2670  | 0  |     return ret;  | 
2671  | 0  | }  | 
2672  |  |  | 
2673  | 0  | std::optional<component::Key> wolfCrypt::OpKDF_SCRYPT(operation::KDF_SCRYPT& op) { | 
2674  | 0  |     std::optional<component::Key> ret = std::nullopt;  | 
2675  | 0  |     Datasource ds(op.modifier.GetPtr(), op.modifier.GetSize());  | 
2676  | 0  |     wolfCrypt_detail::SetGlobalDs(&ds);  | 
2677  |  | 
  | 
2678  | 0  |     uint8_t* out = util::malloc(op.keySize);  | 
2679  |  | 
  | 
2680  | 0  |     const size_t N = op.N >> 1;  | 
2681  |  | 
  | 
2682  | 0  |     CF_CHECK_EQ(N << 1, op.N);  | 
2683  | 0  |     CF_CHECK_GT(op.p, 0);  | 
2684  |  | 
  | 
2685  | 0  |     WC_CHECK_EQ(wc_scrypt(  | 
2686  | 0  |             out,  | 
2687  | 0  |             op.password.GetPtr(&ds),  | 
2688  | 0  |             op.password.GetSize(),  | 
2689  | 0  |             op.salt.GetPtr(&ds),  | 
2690  | 0  |             op.salt.GetSize(),  | 
2691  | 0  |             op.N >> 1,  | 
2692  | 0  |             op.r,  | 
2693  | 0  |             op.p,  | 
2694  | 0  |             op.keySize), 0);  | 
2695  |  | 
  | 
2696  | 0  |     ret = component::Key(out, op.keySize);  | 
2697  |  | 
  | 
2698  | 0  | end:  | 
2699  | 0  |     util::free(out);  | 
2700  |  | 
  | 
2701  | 0  |     wolfCrypt_detail::UnsetGlobalDs();  | 
2702  |  | 
  | 
2703  | 0  |     return ret;  | 
2704  | 0  | }  | 
2705  |  |  | 
2706  | 0  | std::optional<component::Key> wolfCrypt::OpKDF_HKDF(operation::KDF_HKDF& op) { | 
2707  | 0  |     std::optional<component::Key> ret = std::nullopt;  | 
2708  | 0  |     Datasource ds(op.modifier.GetPtr(), op.modifier.GetSize());  | 
2709  | 0  |     wolfCrypt_detail::SetGlobalDs(&ds);  | 
2710  |  | 
  | 
2711  | 0  |     uint8_t* out = util::malloc(op.keySize);  | 
2712  |  | 
  | 
2713  | 0  |     auto hashType = wolfCrypt_detail::toHashType(op.digestType);  | 
2714  |  | 
  | 
2715  | 0  |     CF_CHECK_NE(hashType, std::nullopt);  | 
2716  |  | 
  | 
2717  | 0  |     WC_CHECK_EQ(wc_HKDF(  | 
2718  | 0  |                 *hashType,  | 
2719  | 0  |                 op.password.GetPtr(&ds),  | 
2720  | 0  |                 op.password.GetSize(),  | 
2721  | 0  |                 op.salt.GetPtr(&ds),  | 
2722  | 0  |                 op.salt.GetSize(),  | 
2723  | 0  |                 op.info.GetPtr(&ds),  | 
2724  | 0  |                 op.info.GetSize(),  | 
2725  | 0  |                 out,  | 
2726  | 0  |                 op.keySize), 0);  | 
2727  |  | 
  | 
2728  | 0  |     ret = component::Key(out, op.keySize);  | 
2729  |  | 
  | 
2730  | 0  | end:  | 
2731  | 0  |     util::free(out);  | 
2732  |  | 
  | 
2733  | 0  |     wolfCrypt_detail::UnsetGlobalDs();  | 
2734  |  | 
  | 
2735  | 0  |     return ret;  | 
2736  | 0  | }  | 
2737  |  |  | 
2738  | 0  | std::optional<component::Key> wolfCrypt::OpKDF_TLS1_PRF(operation::KDF_TLS1_PRF& op) { | 
2739  | 0  |     std::optional<component::Key> ret = std::nullopt;  | 
2740  | 0  |     Datasource ds(op.modifier.GetPtr(), op.modifier.GetSize());  | 
2741  | 0  |     wolfCrypt_detail::SetGlobalDs(&ds);  | 
2742  |  | 
  | 
2743  | 0  |     uint8_t* out = util::malloc(op.keySize);  | 
2744  |  | 
  | 
2745  | 0  |     CF_CHECK_EQ(op.digestType.Get(), CF_DIGEST("MD5_SHA1")); | 
2746  |  | 
  | 
2747  | 0  |     WC_CHECK_EQ(wc_PRF_TLSv1(out,  | 
2748  | 0  |             op.keySize,  | 
2749  | 0  |             op.secret.GetPtr(&ds),  | 
2750  | 0  |             op.secret.GetSize(),  | 
2751  | 0  |             nullptr,  | 
2752  | 0  |             0,  | 
2753  | 0  |             op.seed.GetPtr(&ds),  | 
2754  | 0  |             op.seed.GetSize(),  | 
2755  | 0  |             nullptr,  | 
2756  | 0  |             INVALID_DEVID), 0);  | 
2757  |  | 
  | 
2758  | 0  |     ret = component::Key(out, op.keySize);  | 
2759  |  | 
  | 
2760  | 0  | end:  | 
2761  | 0  |     util::free(out);  | 
2762  |  | 
  | 
2763  | 0  |     wolfCrypt_detail::UnsetGlobalDs();  | 
2764  |  | 
  | 
2765  | 0  |     return ret;  | 
2766  | 0  | }  | 
2767  |  |  | 
2768  | 0  | std::optional<component::Key> wolfCrypt::OpKDF_X963(operation::KDF_X963& op) { | 
2769  | 0  |     std::optional<component::Key> ret = std::nullopt;  | 
2770  | 0  |     Datasource ds(op.modifier.GetPtr(), op.modifier.GetSize());  | 
2771  | 0  |     wolfCrypt_detail::SetGlobalDs(&ds);  | 
2772  |  | 
  | 
2773  | 0  |     uint8_t* out = util::malloc(op.keySize);  | 
2774  |  | 
  | 
2775  | 0  |     auto hashType = wolfCrypt_detail::toHashType(op.digestType);  | 
2776  |  | 
  | 
2777  | 0  |     CF_CHECK_NE(hashType, std::nullopt);  | 
2778  |  | 
  | 
2779  | 0  |     WC_CHECK_EQ(wc_X963_KDF(  | 
2780  | 0  |             *hashType,  | 
2781  | 0  |             op.secret.GetPtr(&ds),  | 
2782  | 0  |             op.secret.GetSize(),  | 
2783  | 0  |             op.info.GetPtr(&ds),  | 
2784  | 0  |             op.info.GetSize(),  | 
2785  | 0  |             out,  | 
2786  | 0  |             op.keySize), 0);  | 
2787  |  | 
  | 
2788  | 0  |     ret = component::Key(out, op.keySize);  | 
2789  |  | 
  | 
2790  | 0  | end:  | 
2791  | 0  |     util::free(out);  | 
2792  |  | 
  | 
2793  | 0  |     wolfCrypt_detail::UnsetGlobalDs();  | 
2794  |  | 
  | 
2795  | 0  |     return ret;  | 
2796  | 0  | }  | 
2797  |  |  | 
2798  |  | namespace wolfCrypt_detail { | 
2799  | 1.87k  |     std::optional<int> toCurveID(const component::CurveType& curveType) { | 
2800  | 1.87k  |         static const std::map<uint64_t, int> LUT = { | 
2801  |  |             /* Reference: wolfssl/wolfcrypt/ecc.h */  | 
2802  |  |  | 
2803  |  |             /* NIST */  | 
2804  | 1.87k  |             { CF_ECC_CURVE("secp192r1"), ECC_SECP192R1 }, | 
2805  | 1.87k  |             { CF_ECC_CURVE("secp256r1"), ECC_SECP256R1 }, | 
2806  |  |  | 
2807  |  |             /* SECP */  | 
2808  | 1.87k  |             { CF_ECC_CURVE("secp112r1"), ECC_SECP112R1 }, | 
2809  | 1.87k  |             { CF_ECC_CURVE("secp112r2"), ECC_SECP112R2 }, | 
2810  | 1.87k  |             { CF_ECC_CURVE("secp128r1"), ECC_SECP128R1 }, | 
2811  | 1.87k  |             { CF_ECC_CURVE("secp128r2"), ECC_SECP128R2 }, | 
2812  | 1.87k  |             { CF_ECC_CURVE("secp160r1"), ECC_SECP160R1 }, | 
2813  | 1.87k  |             { CF_ECC_CURVE("secp160r2"), ECC_SECP160R2 }, | 
2814  | 1.87k  |             { CF_ECC_CURVE("secp224r1"), ECC_SECP224R1 }, | 
2815  | 1.87k  |             { CF_ECC_CURVE("secp384r1"), ECC_SECP384R1 }, | 
2816  | 1.87k  |             { CF_ECC_CURVE("secp521r1"), ECC_SECP521R1 }, | 
2817  |  |  | 
2818  |  |             /* Koblitz */  | 
2819  | 1.87k  |             { CF_ECC_CURVE("secp160k1"), ECC_SECP160K1 }, | 
2820  | 1.87k  |             { CF_ECC_CURVE("secp192k1"), ECC_SECP192K1 }, | 
2821  | 1.87k  |             { CF_ECC_CURVE("secp224k1"), ECC_SECP224K1 }, | 
2822  | 1.87k  |             { CF_ECC_CURVE("secp256k1"), ECC_SECP256K1 }, | 
2823  |  |  | 
2824  |  |             /* Brainpool */  | 
2825  | 1.87k  |             { CF_ECC_CURVE("brainpool160r1"), ECC_BRAINPOOLP160R1 }, | 
2826  | 1.87k  |             { CF_ECC_CURVE("brainpool192r1"), ECC_BRAINPOOLP192R1 }, | 
2827  | 1.87k  |             { CF_ECC_CURVE("brainpool224r1"), ECC_BRAINPOOLP224R1 }, | 
2828  | 1.87k  |             { CF_ECC_CURVE("brainpool256r1"), ECC_BRAINPOOLP256R1 }, | 
2829  | 1.87k  |             { CF_ECC_CURVE("brainpool320r1"), ECC_BRAINPOOLP320R1 }, | 
2830  | 1.87k  |             { CF_ECC_CURVE("brainpool384r1"), ECC_BRAINPOOLP384R1 }, | 
2831  | 1.87k  |             { CF_ECC_CURVE("brainpool512r1"), ECC_BRAINPOOLP512R1 }, | 
2832  |  |  | 
2833  |  |             /* ANSI X9.62 */  | 
2834  | 1.87k  |             { CF_ECC_CURVE("x962_p192v2"), ECC_PRIME192V2 }, | 
2835  | 1.87k  |             { CF_ECC_CURVE("x962_p192v3"), ECC_PRIME192V3 }, | 
2836  | 1.87k  |             { CF_ECC_CURVE("x962_p239v1"), ECC_PRIME239V1 }, | 
2837  | 1.87k  |             { CF_ECC_CURVE("x962_p239v2"), ECC_PRIME239V2 }, | 
2838  | 1.87k  |             { CF_ECC_CURVE("x962_p239v3"), ECC_PRIME239V3 }, | 
2839  | 1.87k  |         };  | 
2840  |  |  | 
2841  | 1.87k  |         if ( LUT.find(curveType.Get()) == LUT.end() ) { | 
2842  | 66  |             return std::nullopt;  | 
2843  | 66  |         }  | 
2844  |  |  | 
2845  | 1.81k  |         return LUT.at(curveType.Get());  | 
2846  | 1.87k  |     }  | 
2847  |  | }  | 
2848  |  |  | 
2849  | 496  | std::optional<component::ECC_PublicKey> wolfCrypt::OpECC_PrivateToPublic(operation::ECC_PrivateToPublic& op) { | 
2850  | 496  |     if ( op.curveType.Get() == CF_ECC_CURVE("x25519") ) { | 
2851  | 75  |         return wolfCrypt_detail::OpECC_PrivateToPublic_Curve25519(op);  | 
2852  | 421  |     } else if ( op.curveType.Get() == CF_ECC_CURVE("x448") ) { | 
2853  | 6  |         return wolfCrypt_detail::OpECC_PrivateToPublic_Curve448(op);  | 
2854  | 415  |     } else if ( op.curveType.Get() == CF_ECC_CURVE("ed25519") ) { | 
2855  | 23  |         return wolfCrypt_detail::OpECC_PrivateToPublic_Ed25519(op);  | 
2856  | 392  |     } else if ( op.curveType.Get() == CF_ECC_CURVE("ed448") ) { | 
2857  | 12  |         return wolfCrypt_detail::OpECC_PrivateToPublic_Ed448(op);  | 
2858  | 380  |     } else { | 
2859  | 380  |         return wolfCrypt_detail::OpECC_PrivateToPublic_Generic(op);  | 
2860  | 380  |     }  | 
2861  | 496  | }  | 
2862  |  |  | 
2863  | 0  | std::optional<bool> wolfCrypt::OpECC_ValidatePubkey(operation::ECC_ValidatePubkey& op) { | 
2864  | 0  |     if ( op.curveType.Get() == CF_ECC_CURVE("x25519") ) { | 
2865  | 0  |         return wolfCrypt_detail::OpECC_ValidatePubkey_Curve25519(op);  | 
2866  | 0  |     } else if ( op.curveType.Get() == CF_ECC_CURVE("x448") ) { | 
2867  | 0  |         return wolfCrypt_detail::OpECC_ValidatePubkey_Curve448(op);  | 
2868  | 0  |     } else if ( op.curveType.Get() == CF_ECC_CURVE("ed25519") ) { | 
2869  | 0  |         return wolfCrypt_detail::OpECC_ValidatePubkey_Ed25519(op);  | 
2870  | 0  |     } else if ( op.curveType.Get() == CF_ECC_CURVE("ed448") ) { | 
2871  | 0  |         return wolfCrypt_detail::OpECC_ValidatePubkey_Ed448(op);  | 
2872  | 0  |     } else { | 
2873  | 0  |         return wolfCrypt_detail::OpECC_ValidatePubkey_Generic(op);  | 
2874  | 0  |     }  | 
2875  | 0  | }  | 
2876  |  |  | 
2877  | 0  | std::optional<component::ECC_KeyPair> wolfCrypt::OpECC_GenerateKeyPair(operation::ECC_GenerateKeyPair& op) { | 
2878  | 0  |     std::optional<component::ECC_KeyPair> ret = std::nullopt;  | 
2879  | 0  |     Datasource ds(op.modifier.GetPtr(), op.modifier.GetSize());  | 
2880  | 0  |     wolfCrypt_detail::SetGlobalDs(&ds);  | 
2881  |  | 
  | 
2882  | 0  |     std::optional<std::string> priv_str, pub_x_str, pub_y_str;  | 
2883  | 0  |     ecc_key* key = nullptr;  | 
2884  | 0  |     uint8_t* priv_bytes = nullptr, *pub_bytes = nullptr;  | 
2885  | 0  |     word32 outSize = 0;  | 
2886  |  | 
  | 
2887  | 0  |     ed25519_key e25519_key;  | 
2888  | 0  |     bool e25519_key_inited = false;  | 
2889  |  | 
  | 
2890  | 0  |     ed448_key e448_key;  | 
2891  | 0  |     bool e448_key_inited = false;  | 
2892  |  | 
  | 
2893  | 0  |     curve25519_key c25519_key;  | 
2894  | 0  |     bool c25519_key_inited = false;  | 
2895  |  | 
  | 
2896  | 0  |     curve448_key c448_key;  | 
2897  | 0  |     bool c448_key_inited = false;  | 
2898  |  | 
  | 
2899  | 0  |     if ( op.curveType.Get() == CF_ECC_CURVE("ed25519") ) { | 
2900  | 0  |         WC_CHECK_EQ(wc_ed25519_init(&e25519_key), 0);  | 
2901  | 0  |         e25519_key_inited = true;  | 
2902  |  | 
  | 
2903  | 0  |         WC_CHECK_EQ(wc_ed25519_make_key(wolfCrypt_detail::GetRNG(), ED25519_KEY_SIZE, &e25519_key), 0);  | 
2904  |  | 
  | 
2905  | 0  |         wolfCrypt_detail::haveAllocFailure = false;  | 
2906  | 0  |         if ( wc_ed25519_check_key(&e25519_key) != 0 && wolfCrypt_detail::haveAllocFailure == false ) { | 
2907  | 0  |             CF_ASSERT(0, "Key created with wc_ed25519_make_key() fails validation");  | 
2908  | 0  |         }  | 
2909  |  |  | 
2910  |  |         /* Export private key */  | 
2911  | 0  |         { | 
2912  | 0  |             std::optional<component::Bignum> priv = std::nullopt;  | 
2913  |  | 
  | 
2914  | 0  |             outSize = 0;  | 
2915  | 0  |             try { outSize = ds.Get<uint16_t>(); } catch ( fuzzing::datasource::Datasource::OutOfData ) { } | 
2916  | 0  |             priv_bytes = util::malloc(outSize);  | 
2917  |  | 
  | 
2918  | 0  |             WC_CHECK_EQ(wc_ed25519_export_private_only(&e25519_key, priv_bytes, &outSize), 0);  | 
2919  | 0  |             CF_ASSERT(outSize = ED25519_KEY_SIZE,  | 
2920  | 0  |                     "Private key exported with wc_ed25519_export_private_only() is not of length ED25519_KEY_SIZE");  | 
2921  |  | 
  | 
2922  | 0  |             CF_CHECK_NE(priv = wolfCrypt_bignum::Bignum::BinToBignum(ds, priv_bytes, outSize), std::nullopt);  | 
2923  |  | 
  | 
2924  | 0  |             priv_str = priv->ToTrimmedString();  | 
2925  | 0  |         }  | 
2926  |  |  | 
2927  |  |         /* Export public key */  | 
2928  | 0  |         { | 
2929  | 0  |             std::optional<component::Bignum> pub = std::nullopt;  | 
2930  |  | 
  | 
2931  | 0  |             outSize = 0;  | 
2932  | 0  |             try { outSize = ds.Get<uint16_t>(); } catch ( fuzzing::datasource::Datasource::OutOfData ) { } | 
2933  | 0  |             pub_bytes = util::malloc(outSize);  | 
2934  |  | 
  | 
2935  | 0  |             WC_CHECK_EQ(wc_ed25519_export_public(&e25519_key, pub_bytes, &outSize), 0);  | 
2936  | 0  |             CF_ASSERT(outSize = ED25519_PUB_KEY_SIZE,  | 
2937  | 0  |                     "Public key exported with wc_ed25519_export_public() is not of length ED25519_PUB_KEY_SIZE");  | 
2938  |  | 
  | 
2939  | 0  |             CF_CHECK_NE(pub = wolfCrypt_bignum::Bignum::BinToBignum(ds, pub_bytes, outSize), std::nullopt);  | 
2940  |  | 
  | 
2941  | 0  |             pub_x_str = pub->ToTrimmedString();  | 
2942  | 0  |             pub_y_str = "0";  | 
2943  | 0  |         }  | 
2944  | 0  |     } else if ( op.curveType.Get() == CF_ECC_CURVE("ed448") ) { | 
2945  | 0  |         WC_CHECK_EQ(wc_ed448_init(&e448_key), 0);  | 
2946  | 0  |         e448_key_inited = true;  | 
2947  |  | 
  | 
2948  | 0  |         WC_CHECK_EQ(wc_ed448_make_key(wolfCrypt_detail::GetRNG(), ED448_KEY_SIZE, &e448_key), 0);  | 
2949  |  | 
  | 
2950  | 0  |         wolfCrypt_detail::haveAllocFailure = false;  | 
2951  | 0  |         if ( wc_ed448_check_key(&e448_key) != 0 && wolfCrypt_detail::haveAllocFailure == false ) { | 
2952  | 0  |             CF_ASSERT(0, "Key created with wc_ed448_make_key() fails validation");  | 
2953  | 0  |         }  | 
2954  |  |  | 
2955  |  |         /* Export private key */  | 
2956  | 0  |         { | 
2957  | 0  |             std::optional<component::Bignum> priv = std::nullopt;  | 
2958  |  | 
  | 
2959  | 0  |             outSize = 0;  | 
2960  | 0  |             try { outSize = ds.Get<uint16_t>(); } catch ( fuzzing::datasource::Datasource::OutOfData ) { } | 
2961  | 0  |             priv_bytes = util::malloc(outSize);  | 
2962  |  | 
  | 
2963  | 0  |             WC_CHECK_EQ(wc_ed448_export_private_only(&e448_key, priv_bytes, &outSize), 0);  | 
2964  | 0  |             CF_ASSERT(outSize = ED448_KEY_SIZE,  | 
2965  | 0  |                     "Private key exported with wc_ed448_export_private_only() is not of length ED448_KEY_SIZE");  | 
2966  |  | 
  | 
2967  | 0  |             CF_CHECK_NE(priv = wolfCrypt_bignum::Bignum::BinToBignum(ds, priv_bytes, outSize), std::nullopt);  | 
2968  |  | 
  | 
2969  | 0  |             priv_str = priv->ToTrimmedString();  | 
2970  | 0  |         }  | 
2971  |  |  | 
2972  |  |         /* Export public key */  | 
2973  | 0  |         { | 
2974  | 0  |             std::optional<component::Bignum> pub = std::nullopt;  | 
2975  |  | 
  | 
2976  | 0  |             outSize = 0;  | 
2977  | 0  |             try { outSize = ds.Get<uint16_t>(); } catch ( fuzzing::datasource::Datasource::OutOfData ) { } | 
2978  | 0  |             pub_bytes = util::malloc(outSize);  | 
2979  |  | 
  | 
2980  | 0  |             WC_CHECK_EQ(wc_ed448_export_public(&e448_key, pub_bytes, &outSize), 0);  | 
2981  | 0  |             CF_ASSERT(outSize = ED448_PUB_KEY_SIZE,  | 
2982  | 0  |                     "Public key exported with wc_ed448_export_public() is not of length ED448_PUB_KEY_SIZE");  | 
2983  |  | 
  | 
2984  | 0  |             CF_CHECK_NE(pub = wolfCrypt_bignum::Bignum::BinToBignum(ds, pub_bytes, outSize), std::nullopt);  | 
2985  |  | 
  | 
2986  | 0  |             pub_x_str = pub->ToTrimmedString();  | 
2987  | 0  |             pub_y_str = "0";  | 
2988  | 0  |         }  | 
2989  | 0  |     } else if ( op.curveType.Get() == CF_ECC_CURVE("x25519") ) { | 
2990  | 0  |         WC_CHECK_EQ(wc_curve25519_init(&c25519_key), 0);  | 
2991  | 0  |         c25519_key_inited = true;  | 
2992  |  | 
  | 
2993  | 0  |         WC_CHECK_EQ(wc_curve25519_make_key(wolfCrypt_detail::GetRNG(), CURVE25519_KEYSIZE, &c25519_key), 0);  | 
2994  |  | 
  | 
2995  | 0  |         wolfCrypt_detail::haveAllocFailure = false;  | 
2996  | 0  |         if ( wc_curve25519_check_public(c25519_key.p.point, CURVE25519_KEYSIZE, EC25519_LITTLE_ENDIAN) != 0 && wolfCrypt_detail::haveAllocFailure == false ) { | 
2997  | 0  |             CF_ASSERT(0, "Key created with wc_curve25519_make_key() fails validation");  | 
2998  | 0  |         }  | 
2999  |  |  | 
3000  |  |         /* Export private key */  | 
3001  | 0  |         { | 
3002  | 0  |             std::optional<component::Bignum> priv = std::nullopt;  | 
3003  |  | 
  | 
3004  | 0  |             outSize = 0;  | 
3005  | 0  |             try { outSize = ds.Get<uint16_t>(); } catch ( fuzzing::datasource::Datasource::OutOfData ) { } | 
3006  | 0  |             priv_bytes = util::malloc(outSize);  | 
3007  |  | 
  | 
3008  | 0  |             WC_CHECK_EQ(wc_curve25519_export_private_raw_ex(&c25519_key, priv_bytes, &outSize, EC25519_LITTLE_ENDIAN), 0);  | 
3009  | 0  |             CF_ASSERT(outSize = CURVE25519_KEYSIZE,  | 
3010  | 0  |                     "Private key exported with wc_curve25519_export_private_raw_ex() is not of length CURVE25519_KEYSIZE");  | 
3011  |  | 
  | 
3012  | 0  |             CF_CHECK_NE(priv = wolfCrypt_bignum::Bignum::BinToBignum(ds, priv_bytes, outSize), std::nullopt);  | 
3013  |  | 
  | 
3014  | 0  |             priv_str = priv->ToTrimmedString();  | 
3015  | 0  |         }  | 
3016  |  |  | 
3017  |  |         /* Export public key */  | 
3018  | 0  |         { | 
3019  | 0  |             std::optional<component::Bignum> pub = std::nullopt;  | 
3020  |  | 
  | 
3021  | 0  |             outSize = 0;  | 
3022  | 0  |             try { outSize = ds.Get<uint16_t>(); } catch ( fuzzing::datasource::Datasource::OutOfData ) { } | 
3023  | 0  |             pub_bytes = util::malloc(outSize);  | 
3024  |  | 
  | 
3025  | 0  |             WC_CHECK_EQ(wc_curve25519_export_public_ex(&c25519_key, pub_bytes, &outSize, EC25519_LITTLE_ENDIAN), 0);  | 
3026  | 0  |             CF_ASSERT(outSize = CURVE25519_KEYSIZE,  | 
3027  | 0  |                     "Public key exported with wc_curve25519_export_public_ex() is not of length CURVE25519_KEYSIZE");  | 
3028  |  | 
  | 
3029  | 0  |             CF_CHECK_NE(pub = wolfCrypt_bignum::Bignum::BinToBignum(ds, pub_bytes, outSize), std::nullopt);  | 
3030  |  | 
  | 
3031  | 0  |             pub_x_str = pub->ToTrimmedString();  | 
3032  | 0  |             pub_y_str = "0";  | 
3033  | 0  |         }  | 
3034  | 0  |     } else if ( op.curveType.Get() == CF_ECC_CURVE("x448") ) { | 
3035  | 0  |         WC_CHECK_EQ(wc_curve448_init(&c448_key), 0);  | 
3036  | 0  |         c448_key_inited = true;  | 
3037  |  | 
  | 
3038  | 0  |         WC_CHECK_EQ(wc_curve448_make_key(wolfCrypt_detail::GetRNG(), CURVE448_KEY_SIZE, &c448_key), 0);  | 
3039  |  | 
  | 
3040  | 0  |         wolfCrypt_detail::haveAllocFailure = false;  | 
3041  | 0  |         if ( wc_curve448_check_public(c448_key.p, CURVE448_KEY_SIZE, EC448_BIG_ENDIAN) != 0 && wolfCrypt_detail::haveAllocFailure == false ) { | 
3042  | 0  |             CF_ASSERT(0, "Key created with wc_curve448_make_key() fails validation");  | 
3043  | 0  |         }  | 
3044  |  |  | 
3045  |  |         /* Export private key */  | 
3046  | 0  |         { | 
3047  | 0  |             std::optional<component::Bignum> priv = std::nullopt;  | 
3048  |  | 
  | 
3049  | 0  |             outSize = 0;  | 
3050  | 0  |             try { outSize = ds.Get<uint16_t>(); } catch ( fuzzing::datasource::Datasource::OutOfData ) { } | 
3051  | 0  |             priv_bytes = util::malloc(outSize);  | 
3052  |  | 
  | 
3053  | 0  |             WC_CHECK_EQ(wc_curve448_export_private_raw_ex(&c448_key, priv_bytes, &outSize, EC448_LITTLE_ENDIAN), 0);  | 
3054  | 0  |             CF_ASSERT(outSize = CURVE448_KEY_SIZE,  | 
3055  | 0  |                     "Private key exported with wc_curve448_export_private_raw_ex() is not of length CURVE448_KEY_SIZE");  | 
3056  |  | 
  | 
3057  | 0  |             CF_CHECK_NE(priv = wolfCrypt_bignum::Bignum::BinToBignum(ds, priv_bytes, outSize), std::nullopt);  | 
3058  |  | 
  | 
3059  | 0  |             priv_str = priv->ToTrimmedString();  | 
3060  | 0  |         }  | 
3061  |  |  | 
3062  |  |         /* Export public key */  | 
3063  | 0  |         { | 
3064  | 0  |             std::optional<component::Bignum> pub = std::nullopt;  | 
3065  |  | 
  | 
3066  | 0  |             outSize = 0;  | 
3067  | 0  |             try { outSize = ds.Get<uint16_t>(); } catch ( fuzzing::datasource::Datasource::OutOfData ) { } | 
3068  | 0  |             pub_bytes = util::malloc(outSize);  | 
3069  |  | 
  | 
3070  | 0  |             WC_CHECK_EQ(wc_curve448_export_public_ex(&c448_key, pub_bytes, &outSize, EC448_LITTLE_ENDIAN), 0);  | 
3071  | 0  |             CF_ASSERT(outSize = CURVE448_KEY_SIZE,  | 
3072  | 0  |                     "Public key exported with wc_curve448_export_public_ex() is not of length CURVE448_KEY_SIZE");  | 
3073  |  | 
  | 
3074  | 0  |             CF_CHECK_NE(pub = wolfCrypt_bignum::Bignum::BinToBignum(ds, pub_bytes, outSize), std::nullopt);  | 
3075  |  | 
  | 
3076  | 0  |             pub_x_str = pub->ToTrimmedString();  | 
3077  | 0  |             pub_y_str = "0";  | 
3078  | 0  |         }  | 
3079  | 0  |     } else { | 
3080  | 0  |         std::optional<int> curveID;  | 
3081  |  |  | 
3082  |  |         /* Initialize */  | 
3083  | 0  |         { | 
3084  | 0  |             CF_CHECK_NE(curveID = wolfCrypt_detail::toCurveID(op.curveType), std::nullopt);  | 
3085  |  | 
  | 
3086  | 0  |             CF_CHECK_NE(key = wc_ecc_key_new(nullptr), nullptr);  | 
3087  | 0  |         }  | 
3088  |  |  | 
3089  |  |         /* Process */  | 
3090  | 0  |         { | 
3091  | 0  |             WC_CHECK_EQ(wc_ecc_make_key_ex(wolfCrypt_detail::GetRNG(), 0, key, *curveID), 0);  | 
3092  |  | 
  | 
3093  | 0  |             wolfCrypt_detail::haveAllocFailure = false;  | 
3094  | 0  |             if ( wc_ecc_check_key(key) != 0 && wolfCrypt_detail::haveAllocFailure == false ) { | 
3095  | 0  |                 CF_ASSERT(0, "Key created with wc_ecc_make_key_ex() fails validation");  | 
3096  | 0  |             }  | 
3097  |  |  | 
3098  | 0  |             { | 
3099  | 0  |                 wolfCrypt_bignum::Bignum priv(&key->k, ds);  | 
3100  | 0  |                 wolfCrypt_bignum::Bignum pub_x(key->pubkey.x, ds);  | 
3101  | 0  |                 wolfCrypt_bignum::Bignum pub_y(key->pubkey.y, ds);  | 
3102  |  | 
  | 
3103  | 0  |                 CF_CHECK_NE(priv_str = priv.ToDecString(), std::nullopt);  | 
3104  | 0  |                 CF_CHECK_NE(pub_x_str = pub_x.ToDecString(), std::nullopt);  | 
3105  | 0  |                 CF_CHECK_NE(pub_y_str = pub_y.ToDecString(), std::nullopt);  | 
3106  | 0  |             }  | 
3107  | 0  |         }  | 
3108  | 0  |     }  | 
3109  |  |  | 
3110  |  |     /* Finalize */  | 
3111  | 0  |     { | 
3112  | 0  |         ret = { | 
3113  | 0  |             std::string(*priv_str),  | 
3114  | 0  |             { std::string(*pub_x_str), std::string(*pub_y_str) } | 
3115  | 0  |         };  | 
3116  | 0  |     }  | 
3117  | 0  | end:  | 
3118  | 0  |     util::free(priv_bytes);  | 
3119  | 0  |     util::free(pub_bytes);  | 
3120  |  | 
  | 
3121  | 0  |     if ( e25519_key_inited == true ) { | 
3122  | 0  |         wc_ed25519_free(&e25519_key);  | 
3123  | 0  |     }  | 
3124  |  | 
  | 
3125  | 0  |     if ( e448_key_inited == true ) { | 
3126  | 0  |         wc_ed448_free(&e448_key);  | 
3127  | 0  |     }  | 
3128  |  | 
  | 
3129  | 0  |     if ( c25519_key_inited == true ) { | 
3130  | 0  |         wc_curve25519_free(&c25519_key);  | 
3131  | 0  |     }  | 
3132  |  | 
  | 
3133  | 0  |     if ( c448_key_inited == true ) { | 
3134  | 0  |         wc_curve448_free(&c448_key);  | 
3135  | 0  |     }  | 
3136  |  | 
  | 
3137  | 0  |     CF_NORET(wc_ecc_key_free(key));  | 
3138  |  | 
  | 
3139  | 0  |     wolfCrypt_detail::UnsetGlobalDs();  | 
3140  |  | 
  | 
3141  | 0  |     return ret;  | 
3142  | 0  | }  | 
3143  |  |  | 
3144  | 0  | std::optional<component::DH_KeyPair> wolfCrypt::OpDH_GenerateKeyPair(operation::DH_GenerateKeyPair& op) { | 
3145  | 0  |     std::optional<component::DH_KeyPair> ret = std::nullopt;  | 
3146  | 0  |     Datasource ds(op.modifier.GetPtr(), op.modifier.GetSize());  | 
3147  | 0  |     wolfCrypt_detail::SetGlobalDs(&ds);  | 
3148  |  | 
  | 
3149  | 0  |     DhKey key;  | 
3150  | 0  |     uint8_t* priv_bytes = nullptr;  | 
3151  | 0  |     uint8_t* pub_bytes = nullptr;  | 
3152  | 0  |     word32 privSz = 8192;  | 
3153  | 0  |     word32 pubSz = 8192;  | 
3154  | 0  |     std::optional<std::vector<uint8_t>> prime;  | 
3155  | 0  |     std::optional<std::vector<uint8_t>> base;  | 
3156  |  | 
  | 
3157  | 0  |     memset(&key, 0, sizeof(key));  | 
3158  |  | 
  | 
3159  | 0  |     try { | 
3160  | 0  |         privSz = ds.Get<uint16_t>();  | 
3161  | 0  |         pubSz = ds.Get<uint16_t>();  | 
3162  | 0  |     } catch ( fuzzing::datasource::Datasource::OutOfData ) { } | 
3163  |  | 
  | 
3164  | 0  |     priv_bytes = util::malloc(privSz);  | 
3165  | 0  |     pub_bytes  = util::malloc(pubSz);  | 
3166  |  |  | 
3167  |  |     /* Prevent timeouts if wolfCrypt is compiled with --disable-fastmath */  | 
3168  | 0  | #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)  | 
3169  | 0  |     CF_CHECK_LT(op.prime.GetSize(), 200);  | 
3170  | 0  |     CF_CHECK_LT(op.base.GetSize(), 200);  | 
3171  | 0  | #endif  | 
3172  |  | 
  | 
3173  | 0  |     WC_CHECK_EQ(wc_InitDhKey(&key), 0);  | 
3174  |  | 
  | 
3175  | 0  |     CF_CHECK_NE(prime = wolfCrypt_bignum::Bignum::ToBin(ds, op.prime), std::nullopt);  | 
3176  | 0  |     CF_CHECK_NE(base = wolfCrypt_bignum::Bignum::ToBin(ds, op.base), std::nullopt);  | 
3177  | 0  |     WC_CHECK_EQ(wc_DhSetKey(&key, prime->data(), prime->size(), base->data(), base->size()), 0);  | 
3178  |  | 
  | 
3179  | 0  |     WC_CHECK_EQ(wc_DhGenerateKeyPair(&key, wolfCrypt_detail::GetRNG(), priv_bytes, &privSz, pub_bytes, &pubSz), 0);  | 
3180  |  | 
  | 
3181  | 0  |     { | 
3182  | 0  |         std::optional<std::string> pub_str, priv_str;  | 
3183  | 0  |         wolfCrypt_bignum::Bignum pub(ds), priv(ds);  | 
3184  |  | 
  | 
3185  | 0  |         CF_CHECK_EQ(mp_read_unsigned_bin(pub.GetPtr(), pub_bytes, pubSz), MP_OKAY);  | 
3186  | 0  |         CF_CHECK_EQ(mp_read_unsigned_bin(priv.GetPtr(), priv_bytes, privSz), MP_OKAY);  | 
3187  |  | 
  | 
3188  | 0  |         CF_CHECK_NE(pub_str = pub.ToDecString(), std::nullopt);  | 
3189  | 0  |         CF_CHECK_NE(priv_str = priv.ToDecString(), std::nullopt);  | 
3190  |  | 
  | 
3191  | 0  |         ret = {*priv_str, *pub_str}; | 
3192  | 0  |     }  | 
3193  |  |  | 
3194  | 0  | end:  | 
3195  | 0  |     util::free(priv_bytes);  | 
3196  | 0  |     util::free(pub_bytes);  | 
3197  |  | 
  | 
3198  | 0  |     CF_ASSERT(wc_FreeDhKey(&key) == 0, "Cannot free DH key");  | 
3199  | 0  |     wolfCrypt_detail::UnsetGlobalDs();  | 
3200  |  | 
  | 
3201  | 0  |     return ret;  | 
3202  | 0  | }  | 
3203  |  |  | 
3204  | 0  | std::optional<component::Bignum> wolfCrypt::OpDH_Derive(operation::DH_Derive& op) { | 
3205  | 0  |     std::optional<component::Bignum> ret = std::nullopt;  | 
3206  | 0  |     Datasource ds(op.modifier.GetPtr(), op.modifier.GetSize());  | 
3207  | 0  |     wolfCrypt_detail::SetGlobalDs(&ds);  | 
3208  |  | 
  | 
3209  | 0  |     DhKey key;  | 
3210  | 0  |     uint8_t agree[8192];  | 
3211  | 0  |     word32 agreeSz;  | 
3212  | 0  |     std::optional<std::vector<uint8_t>> prime;  | 
3213  | 0  |     std::optional<std::vector<uint8_t>> base;  | 
3214  | 0  |     std::optional<std::vector<uint8_t>> priv;  | 
3215  | 0  |     std::optional<std::vector<uint8_t>> pub;  | 
3216  |  | 
  | 
3217  | 0  |     memset(&key, 0, sizeof(key));  | 
3218  |  |  | 
3219  |  |     /* Prevent timeouts if wolfCrypt is compiled with --disable-fastmath  | 
3220  |  |      * or 8 bit SP math */  | 
3221  | 0  | #if (!defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH)) || \  | 
3222  | 0  |     SP_WORD_SIZE==8  | 
3223  | 0  |     CF_CHECK_LT(op.prime.GetSize(), 200);  | 
3224  | 0  |     CF_CHECK_LT(op.base.GetSize(), 200);  | 
3225  | 0  |     CF_CHECK_LT(op.pub.GetSize(), 200);  | 
3226  | 0  |     CF_CHECK_LT(op.priv.GetSize(), 200);  | 
3227  | 0  | #endif  | 
3228  |  | 
  | 
3229  | 0  |     WC_CHECK_EQ(wc_InitDhKey(&key), 0);  | 
3230  |  | 
  | 
3231  | 0  |     CF_CHECK_NE(prime = wolfCrypt_bignum::Bignum::ToBin(ds, op.prime), std::nullopt);  | 
3232  | 0  |     CF_CHECK_NE(base = wolfCrypt_bignum::Bignum::ToBin(ds, op.base), std::nullopt);  | 
3233  | 0  |     WC_CHECK_EQ(wc_DhSetKey(&key, prime->data(), prime->size(), base->data(), base->size()), 0);  | 
3234  |  | 
  | 
3235  | 0  |     CF_CHECK_NE(pub = wolfCrypt_bignum::Bignum::ToBin(ds, op.pub), std::nullopt);  | 
3236  | 0  |     CF_CHECK_NE(priv = wolfCrypt_bignum::Bignum::ToBin(ds, op.priv), std::nullopt);  | 
3237  | 0  |     WC_CHECK_EQ(wc_DhAgree(&key, agree, &agreeSz, priv->data(), priv->size(), pub->data(), pub->size()), 0);  | 
3238  |  | 
  | 
3239  | 0  |     { | 
3240  | 0  |         std::optional<std::string> derived_str;  | 
3241  | 0  |         wolfCrypt_bignum::Bignum derived(ds);  | 
3242  | 0  |         CF_CHECK_EQ(mp_read_unsigned_bin(derived.GetPtr(), agree, agreeSz), MP_OKAY);  | 
3243  | 0  |         CF_CHECK_NE(derived_str = derived.ToDecString(), std::nullopt);  | 
3244  | 0  |         if ( *derived_str != "0" ) { | 
3245  | 0  |             ret = *derived_str;  | 
3246  | 0  |         }  | 
3247  | 0  |     }  | 
3248  |  |  | 
3249  | 0  | end:  | 
3250  | 0  |     CF_ASSERT(wc_FreeDhKey(&key) == 0, "Cannot free DH key");  | 
3251  | 0  |     wolfCrypt_detail::UnsetGlobalDs();  | 
3252  |  | 
  | 
3253  | 0  |     return ret;  | 
3254  | 0  | }  | 
3255  |  |  | 
3256  | 0  | std::optional<component::ECCSI_Signature> wolfCrypt::OpECCSI_Sign(operation::ECCSI_Sign& op) { | 
3257  | 0  |     return wolfCrypt_detail::OpECCSI_Sign(op);  | 
3258  | 0  | }  | 
3259  |  |  | 
3260  | 610  | std::optional<component::ECDSA_Signature> wolfCrypt::OpECDSA_Sign(operation::ECDSA_Sign& op) { | 
3261  | 610  |     std::optional<component::ECDSA_Signature> ret = std::nullopt;  | 
3262  |  |  | 
3263  | 610  |     if ( op.curveType.Get() == CF_ECC_CURVE("ed25519") ) { | 
3264  | 51  |         return wolfCrypt_detail::OpECDSA_Sign_ed25519(op);  | 
3265  | 559  |     } else if ( op.curveType.Get() == CF_ECC_CURVE("ed448") ) { | 
3266  | 40  |         return wolfCrypt_detail::OpECDSA_Sign_ed448(op);  | 
3267  | 519  |     } else { | 
3268  | 519  |         return wolfCrypt_detail::OpECDSA_Sign_Generic(op);  | 
3269  | 519  |     }  | 
3270  | 610  | }  | 
3271  |  |  | 
3272  | 0  | std::optional<bool> wolfCrypt::OpECCSI_Verify(operation::ECCSI_Verify& op) { | 
3273  | 0  |     return wolfCrypt_detail::OpECCSI_Verify(op);  | 
3274  | 0  | }  | 
3275  |  |  | 
3276  | 597  | std::optional<bool> wolfCrypt::OpECDSA_Verify(operation::ECDSA_Verify& op) { | 
3277  | 597  |     if ( op.curveType.Get() == CF_ECC_CURVE("ed25519") ) { | 
3278  | 87  |         return wolfCrypt_detail::OpECDSA_Verify_ed25519(op);  | 
3279  | 510  |     } else if ( op.curveType.Get() == CF_ECC_CURVE("ed448") ) { | 
3280  | 61  |         return wolfCrypt_detail::OpECDSA_Verify_ed448(op);  | 
3281  | 449  |     } else { | 
3282  | 449  |         return wolfCrypt_detail::OpECDSA_Verify_Generic(op);  | 
3283  | 449  |     }  | 
3284  | 597  | }  | 
3285  |  |  | 
3286  | 0  | std::optional<bool> wolfCrypt::OpDSA_Verify(operation::DSA_Verify& op) { | 
3287  | 0  | #if defined(NO_DSA)  | 
3288  | 0  |     (void)op;  | 
3289  | 0  |     return std::nullopt;  | 
3290  |  | #else  | 
3291  |  |     std::optional<bool> ret = std::nullopt;  | 
3292  |  |     Datasource ds(op.modifier.GetPtr(), op.modifier.GetSize());  | 
3293  |  |     wolfCrypt_detail::SetGlobalDs(&ds);  | 
3294  |  |  | 
3295  |  |     DsaKey key;  | 
3296  |  |     memset(&key, 0, sizeof(key));  | 
3297  |  |  | 
3298  |  |     CF_CHECK_EQ(wc_InitDsaKey(&key), 0);  | 
3299  |  |  | 
3300  |  |     { | 
3301  |  |         wolfCrypt_bignum::Bignum p(&key.p, ds);  | 
3302  |  |         CF_CHECK_EQ(p.Set(op.parameters.p.ToString(ds)), true);  | 
3303  |  |  | 
3304  |  |         wolfCrypt_bignum::Bignum q(&key.q, ds);  | 
3305  |  |         CF_CHECK_EQ(q.Set(op.parameters.q.ToString(ds)), true);  | 
3306  |  |  | 
3307  |  |         wolfCrypt_bignum::Bignum g(&key.g, ds);  | 
3308  |  |         CF_CHECK_EQ(g.Set(op.parameters.g.ToString(ds)), true);  | 
3309  |  |  | 
3310  |  |         wolfCrypt_bignum::Bignum pub(&key.y, ds);  | 
3311  |  |         CF_CHECK_EQ(pub.Set(op.pub.ToString(ds)), true);  | 
3312  |  |     }  | 
3313  |  |  | 
3314  |  |     { | 
3315  |  |         auto halfSz = mp_unsigned_bin_size(&key.q);  | 
3316  |  |  | 
3317  |  |         std::optional<std::vector<uint8_t>> r, s;  | 
3318  |  |         std::vector<uint8_t> rs;  | 
3319  |  |  | 
3320  |  |         /* XXX move these checks to ToBin() */  | 
3321  |  |         CF_CHECK_FALSE(op.signature.first.IsNegative());  | 
3322  |  |         CF_CHECK_FALSE(op.signature.second.IsNegative());  | 
3323  |  |  | 
3324  |  |         CF_CHECK_NE(r = wolfCrypt_bignum::Bignum::ToBin(ds, op.signature.first, halfSz), std::nullopt);  | 
3325  |  |         CF_CHECK_NE(s = wolfCrypt_bignum::Bignum::ToBin(ds, op.signature.second, halfSz), std::nullopt);  | 
3326  |  |  | 
3327  |  |         rs.insert(rs.end(), r->begin(), r->end());  | 
3328  |  |         rs.insert(rs.end(), s->begin(), s->end());  | 
3329  |  |  | 
3330  |  |         auto digest = op.cleartext.Get();  | 
3331  |  |         digest.resize(WC_SHA_DIGEST_SIZE);  | 
3332  |  |         int verified;  | 
3333  |  |         CF_CHECK_EQ(wc_DsaVerify(digest.data(), rs.data(), &key, &verified), 0);  | 
3334  |  |  | 
3335  |  |         ret = verified;  | 
3336  |  |     }  | 
3337  |  |  | 
3338  |  | end:  | 
3339  |  |     wc_FreeDsaKey(&key);  | 
3340  |  |     wolfCrypt_detail::UnsetGlobalDs();  | 
3341  |  |  | 
3342  |  |     return ret;  | 
3343  |  | #endif  | 
3344  | 0  | }  | 
3345  |  |  | 
3346  | 0  | std::optional<component::DSA_Signature> wolfCrypt::OpDSA_Sign(operation::DSA_Sign& op) { | 
3347  | 0  | #if defined(NO_DSA)  | 
3348  | 0  |     (void)op;  | 
3349  | 0  |     return std::nullopt;  | 
3350  |  | #else  | 
3351  |  |     std::optional<component::DSA_Signature> ret = std::nullopt;  | 
3352  |  |     if ( op.priv.IsZero() ) { | 
3353  |  |         return std::nullopt;  | 
3354  |  |     }  | 
3355  |  |     Datasource ds(op.modifier.GetPtr(), op.modifier.GetSize());  | 
3356  |  |     wolfCrypt_detail::SetGlobalDs(&ds);  | 
3357  |  |  | 
3358  |  |     DsaKey key1, key2;  | 
3359  |  |     bool key1_inited = false, key2_inited = false;  | 
3360  |  |  | 
3361  |  |     uint8_t ber_encoded_key[8192];  | 
3362  |  |     int ber_encoded_size;  | 
3363  |  |     uint8_t* signature = nullptr;  | 
3364  |  |  | 
3365  |  |     wolfCrypt_bignum::Bignum p(&key1.p, ds);  | 
3366  |  |     wolfCrypt_bignum::Bignum q(&key1.q, ds);  | 
3367  |  |     wolfCrypt_bignum::Bignum g(&key1.g, ds);  | 
3368  |  |     wolfCrypt_bignum::Bignum priv(&key1.x, ds);  | 
3369  |  |     { | 
3370  |  |         CF_CHECK_EQ(wc_InitDsaKey(&key1), 0);  | 
3371  |  |         key1_inited = true;  | 
3372  |  |  | 
3373  |  |         CF_CHECK_EQ(p.Set(op.parameters.p.ToString(ds)), true);  | 
3374  |  |  | 
3375  |  |         CF_CHECK_NE(op.parameters.q.ToTrimmedString(), "0");  | 
3376  |  |         CF_CHECK_NE(op.parameters.q.ToTrimmedString(), "1");  | 
3377  |  |         CF_CHECK_EQ(q.Set(op.parameters.q.ToString(ds)), true);  | 
3378  |  |  | 
3379  |  |         CF_CHECK_EQ(g.Set(op.parameters.g.ToString(ds)), true);  | 
3380  |  |  | 
3381  |  |         CF_CHECK_EQ(priv.Set(op.priv.ToString(ds)), true);  | 
3382  |  |  | 
3383  |  |         CF_CHECK_EQ(mp_exptmod_ex(&key1.g, &key1.x, key1.q.used, &key1.p, &key1.y), MP_OKAY);  | 
3384  |  |  | 
3385  |  |         key1.type = DSA_PRIVATE;  | 
3386  |  |  | 
3387  |  |         CF_CHECK_GT(ber_encoded_size = wc_DsaKeyToDer(&key1, ber_encoded_key, sizeof(ber_encoded_key)), 0);  | 
3388  |  |     }  | 
3389  |  |  | 
3390  |  |     { | 
3391  |  |         WC_CHECK_EQ(wc_InitDsaKey(&key2), 0);  | 
3392  |  |         key2_inited = true;  | 
3393  |  |  | 
3394  |  |         word32 idx = 0;  | 
3395  |  |         WC_CHECK_EQ(wc_DsaPrivateKeyDecode(ber_encoded_key, &idx, &key2, ber_encoded_size), 0);  | 
3396  |  |  | 
3397  |  |         auto digest = op.cleartext.Get();  | 
3398  |  |         digest.resize(WC_SHA_DIGEST_SIZE);  | 
3399  |  |  | 
3400  |  |         signature = util::malloc(DSA_MAX_SIG_SIZE);  | 
3401  |  |  | 
3402  |  |         CF_CHECK_EQ(wc_DsaSign(digest.data(), signature, &key2, &wolfCrypt_detail::rng), 0);  | 
3403  |  |  | 
3404  |  |         { | 
3405  |  |             auto halfSz = mp_unsigned_bin_size(&key2.q);  | 
3406  |  |  | 
3407  |  |             if ( DSA_MAX_HALF_SIZE < halfSz ) { | 
3408  |  |                 halfSz = DSA_MAX_HALF_SIZE;  | 
3409  |  |             }  | 
3410  |  |  | 
3411  |  |             std::optional<std::string> r_str, s_str, pub_str;  | 
3412  |  |             wolfCrypt_bignum::Bignum r(ds), s(ds);  | 
3413  |  |  | 
3414  |  |             CF_CHECK_EQ(mp_read_unsigned_bin(r.GetPtr(), signature, halfSz), MP_OKAY);  | 
3415  |  |             CF_CHECK_EQ(mp_read_unsigned_bin(s.GetPtr(), signature + halfSz, halfSz), MP_OKAY);  | 
3416  |  |  | 
3417  |  |             CF_CHECK_NE(r_str = r.ToDecString(), std::nullopt);  | 
3418  |  |             CF_CHECK_NE(s_str = s.ToDecString(), std::nullopt);  | 
3419  |  |  | 
3420  |  |             wolfCrypt_bignum::Bignum pub(&key1.y, ds);  | 
3421  |  |             CF_CHECK_NE(pub_str = pub.ToDecString(), std::nullopt);  | 
3422  |  |  | 
3423  |  |             ret = component::DSA_Signature({*r_str, *s_str}, *pub_str); | 
3424  |  |         }  | 
3425  |  |     }  | 
3426  |  | end:  | 
3427  |  |     if ( key1_inited == true ) { | 
3428  |  |         wc_FreeDsaKey(&key1);  | 
3429  |  |     }  | 
3430  |  |     if ( key2_inited == true ) { | 
3431  |  |         wc_FreeDsaKey(&key2);  | 
3432  |  |     }  | 
3433  |  |     util::free(signature);  | 
3434  |  |     wolfCrypt_detail::UnsetGlobalDs();  | 
3435  |  |  | 
3436  |  |     return ret;  | 
3437  |  | #endif  | 
3438  | 0  | }  | 
3439  |  |  | 
3440  | 0  | std::optional<component::DSA_Parameters> wolfCrypt::OpDSA_GenerateParameters(operation::DSA_GenerateParameters& op) { | 
3441  | 0  | #if defined(NO_DSA)  | 
3442  | 0  |     (void)op;  | 
3443  | 0  |     return std::nullopt;  | 
3444  |  | #else  | 
3445  |  |     (void)op;  | 
3446  |  |     std::optional<component::DSA_Parameters> ret = std::nullopt;  | 
3447  |  |     Datasource ds(op.modifier.GetPtr(), op.modifier.GetSize());  | 
3448  |  |     wolfCrypt_detail::SetGlobalDs(&ds);  | 
3449  |  |  | 
3450  |  |     DsaKey key;  | 
3451  |  |     std::optional<std::string> p_str, q_str, g_str;  | 
3452  |  |  | 
3453  |  |     CF_CHECK_EQ(wc_InitDsaKey(&key), 0);  | 
3454  |  |     CF_CHECK_EQ(wc_MakeDsaParameters(wolfCrypt_detail::GetRNG(), 1024, &key), 0);  | 
3455  |  |  | 
3456  |  |     { | 
3457  |  |         wolfCrypt_bignum::Bignum p(&key.p, ds);  | 
3458  |  |         wolfCrypt_bignum::Bignum q(&key.q, ds);  | 
3459  |  |         wolfCrypt_bignum::Bignum g(&key.g, ds);  | 
3460  |  |  | 
3461  |  |         CF_CHECK_NE(p_str = p.ToDecString(), std::nullopt);  | 
3462  |  |         CF_CHECK_NE(q_str = q.ToDecString(), std::nullopt);  | 
3463  |  |         CF_CHECK_NE(g_str = g.ToDecString(), std::nullopt);  | 
3464  |  |  | 
3465  |  |         ret = { *p_str, *q_str, *g_str }; | 
3466  |  |     }  | 
3467  |  | end:  | 
3468  |  |     wc_FreeDsaKey(&key);  | 
3469  |  |     wolfCrypt_detail::UnsetGlobalDs();  | 
3470  |  |  | 
3471  |  |     return ret;  | 
3472  |  | #endif  | 
3473  | 0  | }  | 
3474  |  |  | 
3475  | 0  | std::optional<component::Bignum> wolfCrypt::OpDSA_PrivateToPublic(operation::DSA_PrivateToPublic& op) { | 
3476  | 0  | #if defined(NO_DSA)  | 
3477  | 0  |     (void)op;  | 
3478  | 0  |     return std::nullopt;  | 
3479  |  | #else  | 
3480  |  |     std::optional<component::Bignum> ret = std::nullopt;  | 
3481  |  |     Datasource ds(op.modifier.GetPtr(), op.modifier.GetSize());  | 
3482  |  |     wolfCrypt_detail::SetGlobalDs(&ds);  | 
3483  |  |  | 
3484  |  |     wolfCrypt_bignum::Bignum g(ds);  | 
3485  |  |     wolfCrypt_bignum::Bignum p(ds);  | 
3486  |  |     wolfCrypt_bignum::Bignum priv(ds);  | 
3487  |  |     wolfCrypt_bignum::Bignum pub(ds);  | 
3488  |  |     CF_CHECK_TRUE(priv.Set(op.g.ToString(ds)));  | 
3489  |  |     CF_CHECK_TRUE(priv.Set(op.p.ToString(ds)));  | 
3490  |  |     CF_CHECK_TRUE(priv.Set(op.priv.ToString(ds)));  | 
3491  |  |     CF_CHECK_EQ(mp_exptmod(g.GetPtr(), priv.GetPtr(), p.GetPtr(), pub.GetPtr()), MP_OKAY);  | 
3492  |  |  | 
3493  |  | end:  | 
3494  |  |     wolfCrypt_detail::UnsetGlobalDs();  | 
3495  |  |  | 
3496  |  |     return ret;  | 
3497  |  | #endif  | 
3498  | 0  | }  | 
3499  |  |  | 
3500  | 0  | std::optional<component::DSA_KeyPair> wolfCrypt::OpDSA_GenerateKeyPair(operation::DSA_GenerateKeyPair& op) { | 
3501  | 0  | #if defined(NO_DSA)  | 
3502  | 0  |     (void)op;  | 
3503  | 0  |     return std::nullopt;  | 
3504  |  | #else  | 
3505  |  |     std::optional<component::DSA_KeyPair> ret = std::nullopt;  | 
3506  |  |     Datasource ds(op.modifier.GetPtr(), op.modifier.GetSize());  | 
3507  |  |     wolfCrypt_detail::SetGlobalDs(&ds);  | 
3508  |  |  | 
3509  |  |     DsaKey key;  | 
3510  |  |     std::optional<std::string> pub_str, priv_str;;  | 
3511  |  |  | 
3512  |  |     memset(&key, 0, sizeof(key));  | 
3513  |  |  | 
3514  |  |     CF_CHECK_EQ(wc_InitDsaKey(&key), 0);  | 
3515  |  |  | 
3516  |  |     { | 
3517  |  |         const auto p = util::DecToHex(op.p.ToTrimmedString());  | 
3518  |  |         const auto q = util::DecToHex(op.q.ToTrimmedString());  | 
3519  |  |         const auto g = util::DecToHex(op.g.ToTrimmedString());  | 
3520  |  |         CF_CHECK_EQ(wc_DsaImportParamsRaw(&key, p.c_str(), q.c_str(), g.c_str()), 0);  | 
3521  |  |     }  | 
3522  |  |  | 
3523  |  |     CF_CHECK_EQ(wc_MakeDsaKey(wolfCrypt_detail::GetRNG(), &key), 0);  | 
3524  |  |  | 
3525  |  |     { | 
3526  |  |         wolfCrypt_bignum::Bignum pub(&key.y, ds);  | 
3527  |  |         wolfCrypt_bignum::Bignum priv(&key.x, ds);  | 
3528  |  |  | 
3529  |  |         CF_CHECK_NE(pub_str = pub.ToDecString(), std::nullopt);  | 
3530  |  |         CF_CHECK_NE(priv_str = priv.ToDecString(), std::nullopt);  | 
3531  |  |     }  | 
3532  |  |  | 
3533  |  |     /* Finalize */  | 
3534  |  |     { | 
3535  |  |         ret = { std::string(*priv_str), std::string(*pub_str) }; | 
3536  |  |     }  | 
3537  |  |  | 
3538  |  | end:  | 
3539  |  |     wc_FreeDsaKey(&key);  | 
3540  |  |     wolfCrypt_detail::UnsetGlobalDs();  | 
3541  |  |  | 
3542  |  |     return ret;  | 
3543  |  | #endif  | 
3544  | 0  | }  | 
3545  |  |  | 
3546  | 4.42k  | std::optional<component::Bignum> wolfCrypt::OpBignumCalc(operation::BignumCalc& op) { | 
3547  | 4.42k  |     std::optional<component::Bignum> ret = std::nullopt;  | 
3548  | 4.42k  |     Datasource ds(op.modifier.GetPtr(), op.modifier.GetSize());  | 
3549  | 4.42k  |     wolfCrypt_detail::SetGlobalDs(&ds);  | 
3550  |  |  | 
3551  | 4.42k  | #if defined(CRYPTOFUZZ_WOLFCRYPT_ALLOCATION_FAILURES)  | 
3552  |  |     /* If allocation failures are induced, it is expected  | 
3553  |  |      * that the Bignum class will throw if initialization  | 
3554  |  |      * of the mp_int variable fails. Catch these exceptions  | 
3555  |  |      * and silently proceed.  | 
3556  |  |      */  | 
3557  | 4.42k  |     try { | 
3558  | 4.42k  | #endif  | 
3559  |  |  | 
3560  | 4.42k  |     std::unique_ptr<wolfCrypt_bignum::Operation> opRunner = nullptr;  | 
3561  |  |  | 
3562  | 4.42k  |     wolfCrypt_bignum::BignumCluster bn(ds,  | 
3563  | 4.42k  |         std::move(wolfCrypt_bignum::Bignum(ds)),  | 
3564  | 4.42k  |         std::move(wolfCrypt_bignum::Bignum(ds)),  | 
3565  | 4.42k  |         std::move(wolfCrypt_bignum::Bignum(ds)),  | 
3566  | 4.42k  |         std::move(wolfCrypt_bignum::Bignum(ds))  | 
3567  | 4.42k  |     );  | 
3568  | 4.42k  |     wolfCrypt_bignum::Bignum res(ds);  | 
3569  |  |  | 
3570  | 4.42k  |     CF_NORET(res.Randomize());  | 
3571  |  |  | 
3572  | 4.42k  |     CF_CHECK_EQ(bn.Set(0, op.bn0.ToString(ds)), true);  | 
3573  | 3.73k  |     CF_CHECK_EQ(bn.Set(1, op.bn1.ToString(ds)), true);  | 
3574  | 3.59k  |     CF_CHECK_EQ(bn.Set(2, op.bn2.ToString(ds)), true);  | 
3575  | 3.53k  |     CF_CHECK_EQ(bn.Set(3, op.bn3.ToString(ds)), true);  | 
3576  |  |  | 
3577  |  |     /* Save the current values of bn[0..3] */  | 
3578  | 3.53k  |     CF_NORET(bn.Save());  | 
3579  |  |  | 
3580  | 3.53k  |     switch ( op.calcOp.Get() ) { | 
3581  | 63  |         case    CF_CALCOP("Add(A,B)"): | 
3582  | 63  |             opRunner = std::make_unique<wolfCrypt_bignum::Add>();  | 
3583  | 63  |             break;  | 
3584  | 152  |         case    CF_CALCOP("Sub(A,B)"): | 
3585  | 152  |             opRunner = std::make_unique<wolfCrypt_bignum::Sub>();  | 
3586  | 152  |             break;  | 
3587  | 101  |         case    CF_CALCOP("Mul(A,B)"): | 
3588  | 101  |             opRunner = std::make_unique<wolfCrypt_bignum::Mul>();  | 
3589  | 101  |             break;  | 
3590  | 0  |         case    CF_CALCOP("Div(A,B)"): | 
3591  | 0  |             opRunner = std::make_unique<wolfCrypt_bignum::Div>();  | 
3592  | 0  |             break;  | 
3593  | 0  |         case    CF_CALCOP("ExpMod(A,B,C)"): | 
3594  | 0  |             opRunner = std::make_unique<wolfCrypt_bignum::ExpMod>();  | 
3595  | 0  |             break;  | 
3596  | 121  |         case    CF_CALCOP("Sqr(A)"): | 
3597  | 121  |             opRunner = std::make_unique<wolfCrypt_bignum::Sqr>();  | 
3598  | 121  |             break;  | 
3599  | 697  |         case    CF_CALCOP("GCD(A,B)"): | 
3600  | 697  |             opRunner = std::make_unique<wolfCrypt_bignum::GCD>();  | 
3601  | 697  |             break;  | 
3602  | 1.08k  |         case    CF_CALCOP("InvMod(A,B)"): | 
3603  | 1.08k  |             opRunner = std::make_unique<wolfCrypt_bignum::InvMod>();  | 
3604  | 1.08k  |             break;  | 
3605  | 0  |         case    CF_CALCOP("Cmp(A,B)"): | 
3606  | 0  |             opRunner = std::make_unique<wolfCrypt_bignum::Cmp>();  | 
3607  | 0  |             break;  | 
3608  | 0  |         case    CF_CALCOP("Abs(A)"): | 
3609  | 0  |             opRunner = std::make_unique<wolfCrypt_bignum::Abs>();  | 
3610  | 0  |             break;  | 
3611  | 0  |         case    CF_CALCOP("Neg(A)"): | 
3612  | 0  |             opRunner = std::make_unique<wolfCrypt_bignum::Neg>();  | 
3613  | 0  |             break;  | 
3614  | 118  |         case    CF_CALCOP("RShift(A,B)"): | 
3615  | 118  |             opRunner = std::make_unique<wolfCrypt_bignum::RShift>();  | 
3616  | 118  |             break;  | 
3617  | 91  |         case    CF_CALCOP("LShift1(A)"): | 
3618  | 91  |             opRunner = std::make_unique<wolfCrypt_bignum::LShift1>();  | 
3619  | 91  |             break;  | 
3620  | 0  |         case    CF_CALCOP("IsNeg(A)"): | 
3621  | 0  |             opRunner = std::make_unique<wolfCrypt_bignum::IsNeg>();  | 
3622  | 0  |             break;  | 
3623  | 0  |         case    CF_CALCOP("IsEq(A,B)"): | 
3624  | 0  |             opRunner = std::make_unique<wolfCrypt_bignum::IsEq>();  | 
3625  | 0  |             break;  | 
3626  | 4  |         case    CF_CALCOP("IsZero(A)"): | 
3627  | 4  |             opRunner = std::make_unique<wolfCrypt_bignum::IsZero>();  | 
3628  | 4  |             break;  | 
3629  | 62  |         case    CF_CALCOP("IsOne(A)"): | 
3630  | 62  |             opRunner = std::make_unique<wolfCrypt_bignum::IsOne>();  | 
3631  | 62  |             break;  | 
3632  | 77  |         case    CF_CALCOP("MulMod(A,B,C)"): | 
3633  | 77  |             opRunner = std::make_unique<wolfCrypt_bignum::MulMod>();  | 
3634  | 77  |             break;  | 
3635  | 188  |         case    CF_CALCOP("AddMod(A,B,C)"): | 
3636  | 188  |             opRunner = std::make_unique<wolfCrypt_bignum::AddMod>();  | 
3637  | 188  |             break;  | 
3638  | 212  |         case    CF_CALCOP("SubMod(A,B,C)"): | 
3639  | 212  |             opRunner = std::make_unique<wolfCrypt_bignum::SubMod>();  | 
3640  | 212  |             break;  | 
3641  | 0  |         case    CF_CALCOP("SqrMod(A,B)"): | 
3642  | 0  |             opRunner = std::make_unique<wolfCrypt_bignum::SqrMod>();  | 
3643  | 0  |             break;  | 
3644  | 73  |         case    CF_CALCOP("Bit(A,B)"): | 
3645  | 73  |             opRunner = std::make_unique<wolfCrypt_bignum::Bit>();  | 
3646  | 73  |             break;  | 
3647  | 0  |         case    CF_CALCOP("CmpAbs(A,B)"): | 
3648  | 0  |             opRunner = std::make_unique<wolfCrypt_bignum::CmpAbs>();  | 
3649  | 0  |             break;  | 
3650  | 0  |         case    CF_CALCOP("SetBit(A,B)"): | 
3651  | 0  |             opRunner = std::make_unique<wolfCrypt_bignum::SetBit>();  | 
3652  | 0  |             break;  | 
3653  | 0  |         case    CF_CALCOP("LCM(A,B)"): | 
3654  | 0  |             opRunner = std::make_unique<wolfCrypt_bignum::LCM>();  | 
3655  | 0  |             break;  | 
3656  | 271  |         case    CF_CALCOP("Mod(A,B)"): | 
3657  | 271  |             opRunner = std::make_unique<wolfCrypt_bignum::Mod>();  | 
3658  | 271  |             break;  | 
3659  | 0  |         case    CF_CALCOP("IsEven(A)"): | 
3660  | 0  |             opRunner = std::make_unique<wolfCrypt_bignum::IsEven>();  | 
3661  | 0  |             break;  | 
3662  | 10  |         case    CF_CALCOP("IsOdd(A)"): | 
3663  | 10  |             opRunner = std::make_unique<wolfCrypt_bignum::IsOdd>();  | 
3664  | 10  |             break;  | 
3665  | 0  |         case    CF_CALCOP("MSB(A)"): | 
3666  | 0  |             opRunner = std::make_unique<wolfCrypt_bignum::MSB>();  | 
3667  | 0  |             break;  | 
3668  | 13  |         case    CF_CALCOP("NumBits(A)"): | 
3669  | 13  |             opRunner = std::make_unique<wolfCrypt_bignum::NumBits>();  | 
3670  | 13  |             break;  | 
3671  | 0  |         case    CF_CALCOP("Set(A)"): | 
3672  | 0  |             opRunner = std::make_unique<wolfCrypt_bignum::Set>();  | 
3673  | 0  |             break;  | 
3674  | 0  |         case    CF_CALCOP("Jacobi(A,B)"): | 
3675  | 0  |             opRunner = std::make_unique<wolfCrypt_bignum::Jacobi>();  | 
3676  | 0  |             break;  | 
3677  | 0  |         case    CF_CALCOP("Exp2(A)"): | 
3678  | 0  |             opRunner = std::make_unique<wolfCrypt_bignum::Exp2>();  | 
3679  | 0  |             break;  | 
3680  | 0  |         case    CF_CALCOP("NumLSZeroBits(A)"): | 
3681  | 0  |             opRunner = std::make_unique<wolfCrypt_bignum::NumLSZeroBits>();  | 
3682  | 0  |             break;  | 
3683  | 0  |         case    CF_CALCOP("MulAdd(A,B,C)"): | 
3684  | 0  |             opRunner = std::make_unique<wolfCrypt_bignum::MulAdd>();  | 
3685  | 0  |             break;  | 
3686  | 0  |         case    CF_CALCOP("CondSet(A,B)"): | 
3687  | 0  |             opRunner = std::make_unique<wolfCrypt_bignum::CondSet>();  | 
3688  | 0  |             break;  | 
3689  | 0  |         case    CF_CALCOP("Rand()"): | 
3690  | 0  |             opRunner = std::make_unique<wolfCrypt_bignum::Rand>();  | 
3691  | 0  |             break;  | 
3692  | 0  |         case    CF_CALCOP("Zero()"): | 
3693  | 0  |             opRunner = std::make_unique<wolfCrypt_bignum::Zero>();  | 
3694  | 0  |             break;  | 
3695  | 3.53k  |     }  | 
3696  |  |  | 
3697  | 3.53k  |     CF_CHECK_NE(opRunner, nullptr);  | 
3698  | 3.33k  |     CF_CHECK_EQ(opRunner->Run(ds, res, bn), true);  | 
3699  |  |  | 
3700  | 2.37k  |     ret = res.ToComponentBignum();  | 
3701  |  |  | 
3702  |  |     /* Verify that no parameter (bn[0..3]) was altered during the operation */  | 
3703  | 2.37k  |     CF_ASSERT(bn.EqualsCache() == true, "Bignum parameters were changed");  | 
3704  |  |  | 
3705  | 2.37k  | #if defined(CRYPTOFUZZ_WOLFCRYPT_ALLOCATION_FAILURES)  | 
3706  | 2.37k  |     } catch ( std::exception ) { } | 
3707  | 0  | #endif  | 
3708  |  |  | 
3709  | 4.42k  | end:  | 
3710  |  |  | 
3711  | 4.42k  |     wolfCrypt_detail::UnsetGlobalDs();  | 
3712  |  |  | 
3713  | 4.42k  |     return ret;  | 
3714  | 4.42k  | }  | 
3715  |  |  | 
3716  | 0  | std::optional<component::Ciphertext> wolfCrypt::OpECIES_Encrypt(operation::ECIES_Encrypt& op) { | 
3717  | 0  |     return wolfCrypt_detail::OpECIES_Encrypt_Generic(op);  | 
3718  | 0  | }  | 
3719  |  |  | 
3720  | 0  | std::optional<component::Cleartext> wolfCrypt::OpECIES_Decrypt(operation::ECIES_Decrypt& op) { | 
3721  | 0  |     return wolfCrypt_detail::OpECIES_Decrypt_Generic(op);  | 
3722  | 0  | }  | 
3723  |  |  | 
3724  | 118  | std::optional<component::ECC_Point> wolfCrypt::OpECC_Point_Add(operation::ECC_Point_Add& op) { | 
3725  | 118  |     return wolfCrypt_detail::OpECC_Point_Add(op);  | 
3726  | 118  | }  | 
3727  |  |  | 
3728  | 309  | std::optional<component::ECC_Point> wolfCrypt::OpECC_Point_Mul(operation::ECC_Point_Mul& op) { | 
3729  | 309  |     return wolfCrypt_detail::OpECC_Point_Mul(op);  | 
3730  | 309  | }  | 
3731  |  |  | 
3732  | 264  | std::optional<component::ECC_Point> wolfCrypt::OpECC_Point_Dbl(operation::ECC_Point_Dbl& op) { | 
3733  | 264  |     return wolfCrypt_detail::OpECC_Point_Dbl(op);  | 
3734  | 264  | }  | 
3735  |  |  | 
3736  | 0  | std::optional<bool> wolfCrypt::OpECC_Point_Cmp(operation::ECC_Point_Cmp& op) { | 
3737  | 0  |     return wolfCrypt_detail::OpECC_Point_Cmp(op);  | 
3738  | 0  | }  | 
3739  |  |  | 
3740  | 71  | std::optional<component::Secret> wolfCrypt::OpECDH_Derive(operation::ECDH_Derive& op) { | 
3741  | 71  |     return wolfCrypt_detail::OpECDH_Derive(op);  | 
3742  | 71  | }  | 
3743  |  |  | 
3744  |  | } /* namespace module */  | 
3745  |  | } /* namespace cryptofuzz */  |