secapi-sys 0.2.0

FFI bindings to SecAPI
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
/*
 * Copyright 2020-2023 Comcast Cable Communications Management, LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#ifndef CLIENT_TEST_HELPERS_H
#define CLIENT_TEST_HELPERS_H

#include "common.h"
#include "log.h"
#include "sa.h"
#include "sa_public_key.h"
#include "test_helpers.h"
#include <ctime>
#include <memory>
#include <openssl/ec.h>
#include <openssl/rsa.h>
#include <string>
#include <vector>

typedef enum {
    TYPEJ_DATA_AND_KEY = 0,
    DATA_ONLY = 1,
    KEY_ONLY = 2,
    SOC_DATA_AND_KEY = 3
} key_usage;

#define EC_KEY_SIZE(ec_group) (EC_GROUP_get_degree(ec_group) / 8 + (EC_GROUP_get_degree(ec_group) % 8 == 0 ? 0 : 1))

#define UNSUPPORTED_OPENSSL_KEY static_cast<uintptr_t>(-1)

namespace client_test_helpers {
    using namespace test_helpers;

    /**
     * Obtain a sample DH Prime - 768.
     *
     * @return DH Prime 96 bytes.
     */
    std::vector<uint8_t> sample_dh_p_768();

    /**
     * Obtain a sample DH Generator - 768
     *
     * @return DH Generator.
     */
    std::vector<uint8_t> sample_dh_g_768();

    /**
     * Obtain a sample DH Prime - 1024.
     *
     * @return DH Prime 128 bytes.
     */
    std::vector<uint8_t> sample_dh_p_1024();

    /**
     * Obtain a sample DH Generator - 1024
     *
     * @return DH Generator.
     */
    std::vector<uint8_t> sample_dh_g_1024();

    /**
     * Obtain a sample DH Prime - 1536.
     *
     * @return DH Prime 192 bytes.
     */
    std::vector<uint8_t> sample_dh_p_1536();

    /**
     * Obtain a sample DH Generator - 1536
     *
     * @return DH Generator.
     */
    std::vector<uint8_t> sample_dh_g_1536();

    /**
     * Obtain a sample DH Prime - 2048.
     *
     * @return DH Prime 256 bytes.
     */
    std::vector<uint8_t> sample_dh_p_2048();

    /**
     * Obtain a sample DH Generator - 2048
     *
     * @return DH Generator.
     */
    std::vector<uint8_t> sample_dh_g_2048();

    /**
     * Obtain a sample DH Prime - 3072.
     *
     * @return DH Prime 384 bytes.
     */
    std::vector<uint8_t> sample_dh_p_3072();

    /**
     * Obtain a sample DH Generator - 3072
     *
     * @return DH Generator.
     */
    std::vector<uint8_t> sample_dh_g_3072();

    /**
     * Obtain a sample DH Prime - 4096.
     *
     * @return DH Prime 512 bytes.
     */
    std::vector<uint8_t> sample_dh_p_4096();

    /**
     * Obtain a sample DH Generator - 4096
     *
     * @return DH Generator.
     */
    std::vector<uint8_t> sample_dh_g_4096();

    /**
     * Obtain a sample invalid DH Prime - 4096.
     *
     * @return invalid DH Prime 512 bytes.
     */
    std::vector<uint8_t> sample_dh_invalid_p_4096();

    /**
     * Obtain a sample RSA 1024 key in PKCS8 format.
     *
     * @return PKCS8 key.
     */
    std::vector<uint8_t> sample_rsa_1024_pkcs8();

    /**
     * Obtain a sample RSA 1024 key with a public exponent of 3 in PKCS8 format.
     *
     * @return PKCS8 key.
     */
    std::vector<uint8_t> sample_rsa_1024_pkcs8_e3();

    /**
     * Obtain a sample RSA 2048 key in PKCS8 format.
     *
     * @return PKCS8 key.
     */
    std::vector<uint8_t> sample_rsa_2048_pkcs8();

    /**
     * Obtain a sample RSA 3072 key in PKCS8 format.
     *
     * @return PKCS8 key.
     */
    std::vector<uint8_t> sample_rsa_3072_pkcs8();

    /**
     * Obtain a sample RSA 4096 key in PKCS8 format.
     *
     * @return PKCS8 key.
     */
    std::vector<uint8_t> sample_rsa_4096_pkcs8();

    /**
     * Obtain a sample RSA 6144 key in PKCS8 format.
     *
     * @return PKCS8 key.
     */
    std::vector<uint8_t> sample_rsa_6144_pkcs8();

    /**
     * Gets DH parameters based on key size.
     * @param[in] key_size the size of the DH parameters to retrieve.
     * @return the requested parameters key.
     */
    std::tuple<std::vector<uint8_t>, std::vector<uint8_t>> get_dh_parameters(size_t key_size);

    /**
     * Gets an RSA private key based on key size.
     * @param[in] key_size the size of the RSA to retrieve.
     * @return the requested RSA key.
     */
    std::vector<uint8_t> get_rsa_private_key(size_t key_size);

    /**
     * Convert time instant into ISO8601 format.
     *
     * @param[in] instant instant to convert.
     * @return ISO8601 time.
     */
    std::string iso8601(uint64_t instant);

    /**
     * Creates a shared pointer holding the sa_key value. Key will be released using
     * sa_key_release when the shared pointer gets destroyed.
     *
     * @return created shared pointer.
     */
    std::shared_ptr<sa_key> create_uninitialized_sa_key();

    /**
     * Creates a shared pointer holding the sa_crypto_cipher_context value. Context will be
     * released using sa_crypto_cipher_release when the shared pointer gets destroyed.
     *
     * @return created shared pointer.
     */
    std::shared_ptr<sa_crypto_cipher_context> create_uninitialized_sa_crypto_cipher_context();

    /**
     * Creates a shared pointer holding the sa_crypto_mac_context value. Context will be
     * released using sa_crypto_mac_release when the shared pointer gets destroyed.
     *
     * @return created shared pointer.
     */
    std::shared_ptr<sa_crypto_mac_context> create_uninitialized_sa_crypto_mac_context();

    /**
     * Create a symmetric SecApi key.
     *
     * @param[in] rights key rights.
     * @param[in] clear_key key cleartext.
     * @return created key, UNSUPPORTED_KEY (if unsupported), or nullptr (if failure).
     */
    std::shared_ptr<sa_key> create_sa_key_symmetric(
            const sa_rights* rights,
            const std::vector<uint8_t>& clear_key);

    /**
     * Create an RSA SecApi key.
     *
     * @param[in] rights key rights.
     * @param[in] clear_key key cleartext.
     * @return created key, UNSUPPORTED_KEY (if unsupported), or nullptr (if failure).
     */
    std::shared_ptr<sa_key> create_sa_key_rsa(
            const sa_rights* rights,
            const std::vector<uint8_t>& clear_key);

    /**
     * Create an EC SecApi key.
     *
     * @param[in] rights key rights.
     * @param[in] curve ec curve.
     * @param[in] clear_key key cleartext.
     * @return created key, UNSUPPORTED_KEY (if unsupported), or nullptr (if failure).
     */
    std::shared_ptr<sa_key> create_sa_key_ec(
            const sa_rights* rights,
            sa_elliptic_curve curve,
            const std::vector<uint8_t>& clear_key);

    /**
     * Create a DH SecApi key.
     *
     * @param[in] rights key rights.
     * @param[in] dh_parameters the DH p and g values.
     * @return created key, UNSUPPORTED_KEY (if unsupported), or nullptr (if failure).
     */
    std::shared_ptr<sa_key> create_sa_key_dh(
            const sa_rights* rights,
            std::tuple<std::vector<uint8_t>, std::vector<uint8_t>>& dh_parameters);

    /**
     * Creates an sa_key.
     *
     * @param[in] key_type the type of the key to create.
     * @param[in] key_length the curve for EC keys or the key length for all others.
     * @param[out] clear_key the clear_key. (NULL for DH).
     * @param[out] curve the ec curve.
     * @return the created key or nullptr if not created.
     */
    std::shared_ptr<sa_key> create_sa_key(
            sa_key_type key_type,
            size_t& key_length,
            std::vector<uint8_t>& clear_key,
            sa_elliptic_curve& curve);

    /**
     * Obtain a key header.
     *
     * @param[in] key key to extract header from.
     * @return header shared pointer.
     */
    std::shared_ptr<sa_header> key_header(sa_key key);

    /**
     * Perform key check on a symmetric key. Key check method will be picked based on the
     * enabled key rights.
     *
     * @param[in] key key to check.
     * @param[in] clear_key key cleartext.
     * @return status of the operation.
     */
    bool key_check_sym(
            sa_key key,
            std::vector<uint8_t>& clear_key);

    /**
     * Perform key check on an RSA key. Key check method will be picked based on the
     * enabled key rights.
     *
     * @param[in] key key to check.
     * @param[in] clear_key key cleartext.
     * @return status of the operation.
     */
    bool key_check_rsa(
            sa_key key,
            const std::vector<uint8_t>& clear_key);

    /**
     * Perform key check on an EC key. Key check method will be picked based on the
     * enabled key rights.
     *
     * @param[in] key key to check.
     * @param[in] clear_key key cleartext.
     * @return status of the operation.
     */
    bool key_check_ec(
            sa_key key,
            const std::vector<uint8_t>& clear_key);

    /**
     * Exports a public key into a DER SubjectPublicKeyInfo byte vector.
     *
     * @param out the DER encoded public key.
     * @param evp_pkey the private key.
     * @return status of the operation.
     */
    bool export_public_key(
            std::vector<uint8_t>& out,
            std::shared_ptr<EVP_PKEY>& evp_pkey);

    /**
     * Import a PKCS8 RSA key into OpenSSL EVP_PKEY key.
     *
     * @param[in] in pkcs8 data.
     * @return imported key.
     */
    std::shared_ptr<EVP_PKEY> rsa_import_pkcs8(const std::vector<uint8_t>& in);

    /**
     * Verify RSA PSS signature.
     *
     * @param[in] evp_key RSA key.
     * @param[in] digest_algorithm digest algorithm.
     * @param[in] mgf1_digest_algorithm the digest algorithm for the MGF1 function.
     * @param[in] salt_length salt length.
     * @param[in] in input message.
     * @param[in] signature message signature.
     * @return status of the operation.
     */
    bool verify_rsa_pss_openssl(
            const std::shared_ptr<EVP_PKEY>& evp_key,
            sa_digest_algorithm digest_algorithm,
            sa_digest_algorithm mgf1_digest_algorithm,
            size_t salt_length,
            const std::vector<uint8_t>& in,
            const std::vector<uint8_t>& signature);

    /**
     * Verify RSA PKCS1v15 signature.
     *
     * @param[in] evp_key RSA key.
     * @param[in] digest_algorithm digest algorithm.
     * @param[in] in input message.
     * @param[in] signature message signature.
     * @return status of the operation.
     */
    bool verify_rsa_pkcs1v15_openssl(
            const std::shared_ptr<EVP_PKEY>& evp_key,
            sa_digest_algorithm digest_algorithm,
            const std::vector<uint8_t>& in,
            const std::vector<uint8_t>& signature);

    /**
     * Encrypt using RSA OAEP algorithm.
     *
     * @param[out] out output buffer.
     * @param[in] in input buffer.
     * @param[in] evp_pkey RSA key.
     * @param[in] digest_algorithm the digest algorithm for OAEP padding.
     * @param[in] mgf1_digest_algorithm the digest algorithm for the MGF1 function.
     * @param[in] label the label for the OAEP padding. May be empty.
     * @return status of the operation.
     */
    bool encrypt_rsa_oaep_openssl(
            std::vector<uint8_t>& out,
            const std::vector<uint8_t>& in,
            const std::shared_ptr<EVP_PKEY>& evp_pkey,
            sa_digest_algorithm digest_algorithm,
            sa_digest_algorithm mgf1_digest_algorithm,
            const std::vector<uint8_t>& label);

    /**
     * Encrypt using RSA PKCS1v15 algorithm.
     *
     * @param[out] out output buffer.
     * @param[in] in input buffer.
     * @param[in] evp_pkey RSA key.
     * @return status of the operation.
     */
    bool encrypt_rsa_pkcs1v15_openssl(
            std::vector<uint8_t>& out,
            const std::vector<uint8_t>& in,
            const std::shared_ptr<EVP_PKEY>& evp_pkey);

    /**
     * Import a EC key into OpenSSL EVP_PKEY key.
     *
     * @param[in] curve Elliptic curve to use.
     * @param[in] in private data.
     * @return imported key.
     */
    std::shared_ptr<EVP_PKEY> ec_import_private(
            sa_elliptic_curve curve,
            const std::vector<uint8_t>& in);

    /**
     * Generate a EC Key in OneAsymmetricKey format.
     *
     * @param[in] size size of the EC key.
     * @return generated EC key.
     */
    std::vector<uint8_t> ec_generate_key_bytes(sa_elliptic_curve curve);

    /**
     * Verify an ECDSA signature.
     *
     * @param[in] evp_pkey EC key.
     * @param[in] curve the elliptic curve algorithm.
     * @param[in] digest_algorithm digest algorithm.
     * @param[in] in input data.
     * @param[in] signature signature.
     * @return status of the operation.
     */
    bool verify_ec_ecdsa_openssl(
            EVP_PKEY* evp_pkey,
            sa_elliptic_curve curve,
            sa_digest_algorithm digest_algorithm,
            const std::vector<uint8_t>& in,
            const std::vector<uint8_t>& signature);

    /**
     * Verify an EDDSA signature.
     *
     * @param[in] evp_pkey EC key.
     * @param[in] curve the elliptic curve algorithm.
     * @param[in] in input data.
     * @param[in] signature signature.
     * @return status of the operation.
     */
    bool verify_ec_eddsa_openssl(
            EVP_PKEY* evp_pkey,
            sa_elliptic_curve curve,
            const std::vector<uint8_t>& in,
            const std::vector<uint8_t>& signature);

    /**
     * Encrypt input buffer with EC ElGamal algorithm. The last 4 bytes of in are used as a counter to use to locate a
     * valid point. These should be set to 0.
     *
     * @param[out] out output buffer.
     * @param[in] in the input data to encrypt.
     * @param[in] curve the ellipic curve algorithm.
     * @param[in] public_key the ec public key.
     * @return status of the operation.
     */
    bool encrypt_ec_elgamal_openssl(
            std::vector<uint8_t>& out,
            std::vector<uint8_t>& in,
            sa_elliptic_curve curve,
            const std::shared_ptr<EVP_PKEY>& public_key);

    /**
     * Encrypt data using AES CBC mode using OpenSSL.
     *
     * @param[out] out output buffer.
     * @param[in] in input buffer.
     * @param[in] iv initialization vector.
     * @param[in] key key.
     * @param[in] pad apply pkcs7 padding.
     * @return status of the operation.
     */
    bool encrypt_aes_cbc_openssl(
            std::vector<uint8_t>& out,
            const std::vector<uint8_t>& in,
            const std::vector<uint8_t>& iv,
            const std::vector<uint8_t>& key,
            bool pad);

    /**
     * Decrypt data using AES CBC mode using OpenSSL.
     *
     * @param[out] out output buffer.
     * @param[in] in input buffer.
     * @param[in] iv initialization vector.
     * @param[in] key key.
     * @param[in] pad check pkcs7 padding.
     * @return status of the operation.
     */
    bool decrypt_aes_cbc_openssl(
            std::vector<uint8_t>& out,
            const std::vector<uint8_t>& in,
            const std::vector<uint8_t>& iv,
            const std::vector<uint8_t>& key,
            bool pad);

    /**
     * Encrypt data using AES ECB mode using OpenSSL.
     *
     * @param[out] out output buffer.
     * @param[in] in input buffer.
     * @param[in] key key.
     * @param[in] pad apply pkcs7 padding.
     * @return status of the operation.
     */
    bool encrypt_aes_ecb_openssl(
            std::vector<uint8_t>& out,
            const std::vector<uint8_t>& in,
            const std::vector<uint8_t>& key,
            bool pad);

    /**
     * Decrypt data using AES ECB mode using OpenSSL.
     *
     * @param[out] out output buffer.
     * @param[in] in input buffer.
     * @param[in] key key.
     * @param[in] pad check pkcs7 padding.
     * @return status of the operation.
     */
    bool decrypt_aes_ecb_openssl(
            std::vector<uint8_t>& out,
            const std::vector<uint8_t>& in,
            const std::vector<uint8_t>& key,
            bool pad);

    /**
     * Encrypt data using AES CTR mode using OpenSSL.
     *
     * @param[out] out output buffer.
     * @param[in] in input buffer.
     * @param[in] counter initialization vector.
     * @param[in] key key.
     * @return status of the operation.
     */
    bool encrypt_aes_ctr_openssl(
            std::vector<uint8_t>& out,
            const std::vector<uint8_t>& in,
            const std::vector<uint8_t>& counter,
            const std::vector<uint8_t>& key);

    /**
     * Decrypt data using AES CTR mode using OpenSSL.
     *
     * @param[out] out output buffer.
     * @param[in] in input buffer.
     * @param[in] counter counter.
     * @param[in] key key.
     * @return status of the operation.
     */
    bool decrypt_aes_ctr_openssl(
            std::vector<uint8_t>& out,
            const std::vector<uint8_t>& in,
            const std::vector<uint8_t>& counter,
            const std::vector<uint8_t>& key);

    /**
     * Encrypt data using AES GCM mode using OpenSSL.
     *
     * @param[out] out output buffer.
     * @param[in] in input buffer.
     * @param[in] iv initialization vector.
     * @param[in] aad additional authenticated data.
     * @param[out] tag authentication tag.
     * @param[in] key key.
     * @return status of the operation.
     */
    bool encrypt_aes_gcm_openssl(
            std::vector<uint8_t>& out,
            const std::vector<uint8_t>& in,
            const std::vector<uint8_t>& iv,
            const std::vector<uint8_t>& aad,
            std::vector<uint8_t>& tag,
            const std::vector<uint8_t>& key);

    /**
     * Decrypt data using AES GCM mode using OpenSSL.
     *
     * @param[out] out output buffer.
     * @param[in] in input buffer.
     * @param[in] iv initialization vector.
     * @param[in] aad additional authenticated data.
     * @param[in] tag authentication tag.
     * @param[in] key key.
     * @return status of the operation.
     */
    bool decrypt_aes_gcm_openssl(
            std::vector<uint8_t>& out,
            const std::vector<uint8_t>& in,
            const std::vector<uint8_t>& iv,
            const std::vector<uint8_t>& aad,
            const std::vector<uint8_t>& tag,
            const std::vector<uint8_t>& key);

    /**
     * Encrypt data using CHACHA20 mode using OpenSSL.
     *
     * @param[out] out output buffer.
     * @param[in] in input buffer.
     * @param[in] counter counter.
     * @param[in] nonce nonce.
     * @param[in] key key.
     * @return status of the operation.
     */
    bool encrypt_chacha20_openssl(
            std::vector<uint8_t>& out,
            const std::vector<uint8_t>& in,
            const std::vector<uint8_t>& counter,
            const std::vector<uint8_t>& nonce,
            const std::vector<uint8_t>& key);

    /**
     * Decrypt data using CHACHA20 mode using OpenSSL.
     *
     * @param[out] out output buffer.
     * @param[in] in input buffer.
     * @param[in] counter counter.
     * @param[in] nonce nonce.
     * @param[in] key key.
     * @return status of the operation.
     */
    bool decrypt_chacha20_openssl(
            std::vector<uint8_t>& out,
            const std::vector<uint8_t>& in,
            const std::vector<uint8_t>& counter,
            const std::vector<uint8_t>& nonce,
            const std::vector<uint8_t>& key);

    /**
     * Encrypt data using CHACHA20-POLY1305 mode using OpenSSL.
     *
     * @param[out] out output buffer.
     * @param[in] in input buffer.
     * @param[in] nonce nonce.
     * @param[in] aad additional authenticated data.
     * @param[out] tag authentication tag.
     * @param[in] key key.
     * @return status of the operation.
     */
    bool encrypt_chacha20_poly1305_openssl(
            std::vector<uint8_t>& out,
            const std::vector<uint8_t>& in,
            const std::vector<uint8_t>& nonce,
            const std::vector<uint8_t>& aad,
            std::vector<uint8_t>& tag,
            const std::vector<uint8_t>& key);

    /**
     * Decrypt data using AES GCM mode using OpenSSL.
     *
     * @param[out] out output buffer.
     * @param[in] in input buffer.
     * @param[in] nonce nonce.
     * @param[in] aad additional authenticated data.
     * @param[in] tag authentication tag.
     * @param[in] key key.
     * @return status of the operation.
     */
    bool decrypt_chacha20_poly1305_openssl(
            std::vector<uint8_t>& out,
            const std::vector<uint8_t>& in,
            const std::vector<uint8_t>& nonce,
            const std::vector<uint8_t>& aad,
            const std::vector<uint8_t>& tag,
            const std::vector<uint8_t>& key);

    /**
     * Compute HMAC value over inputs.
     *
     * @param[out] out output buffer for computed digest value.
     * @param[in] key the key for the HMAC calculation.
     * @param[in] in the input for the calculation
     * @param[in] digest_algorithm the digest algorithm to use in the HMAC.
     * @return status of the operation
     */
    bool hmac_openssl(
            std::vector<uint8_t>& out,
            const std::vector<uint8_t>& key,
            const std::vector<uint8_t>& in,
            sa_digest_algorithm digest_algorithm);

    /**
     * Compute CMAC value over inputs.
     *
     * @param[out] out output buffer for computed digest value.
     * @param[in] key the key for the HMAC calculation.
     * @param[in] in the input for the calculation
     * @return status of the operation
     */
    bool cmac_openssl(
            std::vector<uint8_t>& out,
            const std::vector<uint8_t>& key,
            const std::vector<uint8_t>& in);

    /**
     * Exports an EC_POINT into a byte array.
     * @param out the resulting byte array.
     * @param ec_point the point to export.
     * @param ec_group the EC group of the point.
     * @return
     */
    bool ec_point_export_xy(
            std::vector<uint8_t>& out,
            const EC_POINT* ec_point,
            const EC_GROUP* ec_group);

    /**
     * Allocates an sa_buffer with the given type and size.
     *
     * @param buffer_type the type of the buffer.
     * @param size the size of the buffer.
     * @return the buffer.
     */
    std::shared_ptr<sa_buffer> buffer_alloc(
            sa_buffer_type buffer_type,
            size_t size);

    /**
     * Allocates an sa_buffer with the given type and initializes it with the given value.
     *
     * @param buffer_type the type of the buffer.
     * @param initial_value the value to initialize the buffer.
     * @return the buffer.
     */
    std::shared_ptr<sa_buffer> buffer_alloc(
            sa_buffer_type buffer_type,
            std::vector<uint8_t>& initial_value);

} // namespace client_test_helpers

#endif // CLIENT_TEST_HELPERS_H