Coverage Report

Created: 2025-07-23 06:59

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