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