-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathintel-ipsec-mb.h
4087 lines (3807 loc) · 161 KB
/
intel-ipsec-mb.h
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
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
Copyright (c) 2012-2022, Intel Corporation
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/
#ifndef IMB_IPSEC_MB_H
#define IMB_IPSEC_MB_H
#include <stdlib.h>
#include <stdint.h>
#include <errno.h>
#ifdef __cplusplus
extern "C" {
#endif
/* 128-bit data type that is not in sdtint.h */
typedef struct {
uint64_t low;
uint64_t high;
} imb_uint128_t;
/**
* Macros for aligning data structures and function inlines
*/
#if defined __linux__ || defined __FreeBSD__
/**< Linux/FreeBSD */
#define DECLARE_ALIGNED(decl, alignval) \
decl __attribute__((aligned(alignval)))
#define __forceinline \
static inline __attribute__((always_inline))
#if __GNUC__ >= 4
#define IMB_DLL_EXPORT __attribute__((visibility("default")))
#define IMB_DLL_LOCAL __attribute__((visibility("hidden")))
#else /* GNU C 4.0 and later */
#define IMB_DLL_EXPORT
#define IMB_DLL_LOCAL
#endif /**< different C compiler */
#else
/* Windows */
#ifdef __MINGW32__
/* MinGW-w64 */
#define DECLARE_ALIGNED(decl, alignval) \
decl __attribute__((aligned(alignval)))
#undef __forceinline
#define __forceinline \
static inline __attribute__((always_inline))
#else
/* MSVS */
#define DECLARE_ALIGNED(decl, alignval) \
__declspec(align(alignval)) decl
#define __forceinline \
static __forceinline
#endif /* __MINGW__ */
/**
* Windows DLL export is done via DEF file
*/
#define IMB_DLL_EXPORT
#define IMB_DLL_LOCAL
#endif /* defined __linux__ || defined __FreeBSD__ */
/**
* Library version
*/
#define IMB_VERSION_STR "1.3.0"
#define IMB_VERSION_NUM 0x10300
/**
* Macro to translate version number
*/
#define IMB_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c))
/**
* Custom ASSERT and DIM macros
*/
#ifdef DEBUG
#include <assert.h>
#define IMB_ASSERT(x) assert(x)
#else
#define IMB_ASSERT(x)
#endif
#ifndef IMB_DIM
#define IMB_DIM(x) (sizeof(x) / sizeof(x[0]))
#endif
/**
* Architecture definitions
*/
typedef enum {
IMB_ARCH_NONE = 0,
IMB_ARCH_NOAESNI,
IMB_ARCH_SSE,
IMB_ARCH_AVX,
IMB_ARCH_AVX2,
IMB_ARCH_AVX512,
IMB_ARCH_NUM,
} IMB_ARCH;
/**
* Algorithm constants
*/
#define IMB_DES_KEY_SCHED_SIZE (16 * 8) /**< 16 rounds x 8 bytes */
#define IMB_DES_BLOCK_SIZE 8
#define IMB_AES_BLOCK_SIZE 16
#define IMB_SHA1_DIGEST_SIZE_IN_BYTES 20
#define IMB_SHA224_DIGEST_SIZE_IN_BYTES 28
#define IMB_SHA256_DIGEST_SIZE_IN_BYTES 32
#define IMB_SHA384_DIGEST_SIZE_IN_BYTES 48
#define IMB_SHA512_DIGEST_SIZE_IN_BYTES 64
#define IMB_SHA1_BLOCK_SIZE 64 /**< 512 bits is 64 byte blocks */
#define IMB_SHA_256_BLOCK_SIZE 64 /**< 512 bits is 64 byte blocks */
#define IMB_SHA_384_BLOCK_SIZE 128
#define IMB_SHA_512_BLOCK_SIZE 128
#define IMB_KASUMI_KEY_SIZE 16
#define IMB_KASUMI_IV_SIZE 8
#define IMB_KASUMI_BLOCK_SIZE 8
#define IMB_KASUMI_DIGEST_SIZE 4
/**
* Minimum Ethernet frame size to calculate CRC32
* Source Address (6 bytes) + Destination Address (6 bytes) + Type/Len (2 bytes)
*/
#define IMB_DOCSIS_CRC32_MIN_ETH_PDU_SIZE 14
#define IMB_DOCSIS_CRC32_TAG_SIZE 4
/**
* Job structure definitions
*/
typedef enum {
IMB_STATUS_BEING_PROCESSED = 0,
IMB_STATUS_COMPLETED_CIPHER = 1,
IMB_STATUS_COMPLETED_AUTH = 2,
IMB_STATUS_COMPLETED = 3, /**< COMPLETED_CIPHER |
COMPLETED_AUTH */
IMB_STATUS_INVALID_ARGS = 4,
IMB_STATUS_INTERNAL_ERROR,
IMB_STATUS_ERROR
} IMB_STATUS;
/**
* Library error types
*/
typedef enum {
IMB_ERR_MIN = 2000,
IMB_ERR_NULL_MBMGR,
IMB_ERR_JOB_NULL_SRC,
IMB_ERR_JOB_NULL_DST,
IMB_ERR_JOB_NULL_KEY,
IMB_ERR_JOB_NULL_IV,
IMB_ERR_JOB_NULL_AUTH,
IMB_ERR_JOB_NULL_AAD,
IMB_ERR_JOB_CIPH_LEN,
IMB_ERR_JOB_AUTH_LEN,
IMB_ERR_JOB_IV_LEN,
IMB_ERR_JOB_KEY_LEN,
IMB_ERR_JOB_AUTH_TAG_LEN,
IMB_ERR_JOB_AAD_LEN,
IMB_ERR_JOB_SRC_OFFSET,
IMB_ERR_JOB_CHAIN_ORDER,
IMB_ERR_CIPH_MODE,
IMB_ERR_HASH_ALGO,
IMB_ERR_JOB_NULL_AUTH_KEY,
IMB_ERR_JOB_NULL_SGL_CTX,
IMB_ERR_JOB_NULL_NEXT_IV,
IMB_ERR_JOB_PON_PLI,
IMB_ERR_NULL_SRC,
IMB_ERR_NULL_DST,
IMB_ERR_NULL_KEY,
IMB_ERR_NULL_EXP_KEY,
IMB_ERR_NULL_IV,
IMB_ERR_NULL_AUTH,
IMB_ERR_NULL_AAD,
IMB_ERR_CIPH_LEN,
IMB_ERR_AUTH_LEN,
IMB_ERR_IV_LEN,
IMB_ERR_KEY_LEN,
IMB_ERR_AUTH_TAG_LEN,
IMB_ERR_AAD_LEN,
IMB_ERR_SRC_OFFSET,
IMB_ERR_NULL_AUTH_KEY,
IMB_ERR_NULL_CTX,
IMB_ERR_NO_AESNI_EMU,
IMB_ERR_JOB_NULL_HMAC_OPAD,
IMB_ERR_JOB_NULL_HMAC_IPAD,
IMB_ERR_JOB_NULL_XCBC_K1_EXP,
IMB_ERR_JOB_NULL_XCBC_K2,
IMB_ERR_JOB_NULL_XCBC_K3,
IMB_ERR_JOB_CIPH_DIR,
IMB_ERR_JOB_NULL_GHASH_INIT_TAG,
IMB_ERR_MISSING_CPUFLAGS_INIT_MGR,
IMB_ERR_NULL_JOB,
IMB_ERR_QUEUE_SPACE,
IMB_ERR_NULL_BURST,
IMB_ERR_BURST_SIZE,
IMB_ERR_BURST_OOO,
IMB_ERR_SELFTEST,
/* add new error types above this comment */
IMB_ERR_MAX /* don't move this one */
} IMB_ERR;
/**
* IMB_ERR_MIN should be higher than __ELASTERROR
* to avoid overlap with standard error values
*/
#ifdef __ELASTERROR
#if __ELASTERROR > 2000
#error "Library error codes conflict with errno.h - please update IMB_ERR_MIN!"
#endif
#endif
/**
* Define enums from API v0.53, so applications that were using this version
* will still be compiled successfully.
* Note: this list has been extended with new names after version 0.55.
* This list does not need to be extended for new enums.
*/
#ifndef NO_COMPAT_IMB_API_053
/* Previous cipher mode enums */
#define CBC IMB_CIPHER_CBC
#define CNTR IMB_CIPHER_CNTR
#define NULL_CIPHER IMB_CIPHER_NULL
#define DOCSIS_SEC_BPI IMB_CIPHER_DOCSIS_SEC_BPI
#define GCM IMB_CIPHER_GCM
#define CUSTOM_CIPHER IMB_CIPHER_CUSTOM
#define DES IMB_CIPHER_DES
#define DOCSIS_DES IMB_CIPHER_DOCSIS_DES
#define CCM IMB_CIPHER_CCM
#define DES3 IMB_CIPHER_DES3
#define PON_AES_CNTR IMB_CIPHER_PON_AES_CNTR
#define ECB IMB_CIPHER_ECB
#define CNTR_BITLEN IMB_CIPHER_CNTR_BITLEN
/* Previous hash algo enums */
#define SHA1 IMB_AUTH_HMAC_SHA_1
#define SHA_224 IMB_AUTH_HMAC_SHA_224
#define SHA_256 IMB_AUTH_HMAC_SHA_256
#define SHA_384 IMB_AUTH_HMAC_SHA_384
#define SHA_512 IMB_AUTH_HMAC_SHA_512
#define AES_XCBC IMB_AUTH_AES_XCBC
#define MD5 IMB_AUTH_MD5
#define NULL_HASH IMB_AUTH_NULL
#define AES_GMAC IMB_AUTH_AES_GMAC
#define CUSTOM_HASH IMB_AUTH_CUSTOM
#define AES_CCM IMB_AUTH_AES_CCM
#define AES_CMAC IMB_AUTH_AES_CMAC
#define PLAIN_SHA1 IMB_AUTH_SHA_1
#define PLAIN_SHA_224 IMB_AUTH_SHA_224
#define PLAIN_SHA_256 IMB_AUTH_SHA_256
#define PLAIN_SHA_384 IMB_AUTH_SHA_384
#define PLAIN_SHA_512 IMB_AUTH_SHA_512
#define AES_CMAC_BITLEN IMB_AUTH_AES_CMAC_BITLEN
#define PON_CRC_BIP IMB_AUTH_PON_CRC_BIP
/* Previous cipher direction enums */
#define ENCRYPT IMB_DIR_ENCRYPT
#define DECRYPT IMB_DIR_DECRYPT
/* Previous chain order enums */
#define HASH_CIPHER IMB_ORDER_HASH_CIPHER
#define CIPHER_HASH IMB_ORDER_CIPHER_HASH
/* Previous key size enums */
#define AES_128_BYTES IMB_KEY_128_BYTES
#define AES_192_BYTES IMB_KEY_192_BYTES
#define AES_256_BYTES IMB_KEY_256_BYTES
#define IMB_KEY_AES_128_BYTES IMB_KEY_128_BYTES
#define IMB_KEY_AES_192_BYTES IMB_KEY_192_BYTES
#define IMB_KEY_AES_256_BYTES IMB_KEY_256_BYTES
#define AES_KEY_SIZE_BYTES IMB_KEY_SIZE_BYTES
#define MB_MGR IMB_MGR
#define JOB_AES_HMAC IMB_JOB
#define JOB_STS IMB_STATUS
#define IMB_JOB_STS IMB_STATUS
#define JOB_CIPHER_MODE IMB_CIPHER_MODE
#define JOB_CIPHER_DIRECTION IMB_CIPHER_DIRECTION
#define JOB_HASH_ALG IMB_HASH_ALG
#define JOB_CHAIN_ORDER IMB_CHAIN_ORDER
#define MAX_JOBS IMB_MAX_JOBS
#define STS_BEING_PROCESSED IMB_STATUS_BEING_PROCESSED
#define STS_COMPLETED_AES IMB_STATUS_COMPLETED_CIPHER
#define STS_COMPLETED_HMAC IMB_STATUS_COMPLETED_AUTH
#define STS_COMPLETED IMB_STATUS_COMPLETED
#define STS_INVALID_ARGS IMB_STATUS_INVALID_ARGS
#define STS_INTERNAL_ERROR IMB_STATUS_INTERNAL_ERROR
#define STS_ERROR IMB_STATUS_ERROR
#define MAX_TAG_LEN IMB_MAX_TAG_LEN
#define GCM_IV_DATA_LEN IMB_GCM_IV_DATA_LEN
#define GCM_128_KEY_LEN IMB_GCM_128_KEY_LEN
#define GCM_192_KEY_LEN IMB_GCM_192_KEY_LEN
#define GCM_256_KEY_LEN IMB_GCM_256_KEY_LEN
#define DES_KEY_SCHED_SIZE IMB_DES_KEY_SCHED_SIZE
#define DES_BLOCK_SIZE IMB_DES_BLOCK_SIZE
#define AES_BLOCK_SIZE IMB_AES_BLOCK_SIZE
#define SHA1_DIGEST_SIZE_IN_BYTES IMB_SHA1_DIGEST_SIZE_IN_BYTES
#define SHA224_DIGEST_SIZE_IN_BYTES IMB_SHA224_DIGEST_SIZE_IN_BYTES
#define SHA256_DIGEST_SIZE_IN_BYTES IMB_SHA256_DIGEST_SIZE_IN_BYTES
#define SHA384_DIGEST_SIZE_IN_BYTES IMB_SHA384_DIGEST_SIZE_IN_BYTES
#define SHA512_DIGEST_SIZE_IN_BYTES IMB_SHA512_DIGEST_SIZE_IN_BYTES
#define SHA1_BLOCK_SIZE IMB_SHA1_BLOCK_SIZE
#define SHA_256_BLOCK_SIZE IMB_SHA_256_BLOCK_SIZE
#define SHA_384_BLOCK_SIZE IMB_SHA_384_BLOCK_SIZE
#define SHA_512_BLOCK_SIZE IMB_SHA_512_BLOCK_SIZE
#define KASUMI_KEY_SIZE IMB_KASUMI_KEY_SIZE
#define KASUMI_IV_SIZE IMB_KASUMI_IV_SIZE
#define KASUMI_BLOCK_SIZE IMB_KASUMI_BLOCK_SIZE
#define KASUMI_DIGEST_SIZE IMB_KASUMI_DIGEST_SIZE
#define DOCSIS_CRC32_MIN_ETH_PDU_SIZE IMB_DOCSIS_CRC32_MIN_ETH_PDU_SIZE
#define DOCSIS_CRC32_TAG_SIZE IMB_DOCSIS_CRC32_TAG_SIZE
/* Previous fields in IMB_JOB/JOB_AES_HMAC */
#define aes_enc_key_expanded enc_keys
#define aes_dec_key_expanded dec_keys
#define aes_key_len_in_bytes key_len_in_bytes
#endif /* !NO_COMPAT_IMB_API_053 */
typedef enum {
IMB_CIPHER_CBC = 1,
IMB_CIPHER_CNTR,
IMB_CIPHER_NULL,
IMB_CIPHER_DOCSIS_SEC_BPI,
IMB_CIPHER_GCM,
IMB_CIPHER_CUSTOM,
IMB_CIPHER_DES,
IMB_CIPHER_DOCSIS_DES,
IMB_CIPHER_CCM,
IMB_CIPHER_DES3,
IMB_CIPHER_PON_AES_CNTR,
IMB_CIPHER_ECB,
IMB_CIPHER_CNTR_BITLEN, /**< 128-EEA2/NEA2 (3GPP) */
IMB_CIPHER_ZUC_EEA3, /**< 128-EEA3/NEA3 (3GPP) */
IMB_CIPHER_SNOW3G_UEA2_BITLEN,/**< 128-UEA2 (3GPP) */
IMB_CIPHER_KASUMI_UEA1_BITLEN,/**< 128-UEA1 (3GPP) */
IMB_CIPHER_CBCS_1_9, /**< MPEG CENC (ISO 23001-7) */
IMB_CIPHER_CHACHA20,
IMB_CIPHER_CHACHA20_POLY1305, /**< AEAD CHACHA20 */
IMB_CIPHER_CHACHA20_POLY1305_SGL, /**< AEAD CHACHA20 with SGL support*/
IMB_CIPHER_SNOW_V,
IMB_CIPHER_SNOW_V_AEAD,
IMB_CIPHER_GCM_SGL,
IMB_CIPHER_NUM
} IMB_CIPHER_MODE;
typedef enum {
IMB_DIR_ENCRYPT = 1,
IMB_DIR_DECRYPT
} IMB_CIPHER_DIRECTION;
typedef enum {
IMB_AUTH_HMAC_SHA_1 = 1, /**< HMAC-SHA1 */
IMB_AUTH_HMAC_SHA_224, /**< HMAC-SHA224 */
IMB_AUTH_HMAC_SHA_256, /**< HMAC-SHA256 */
IMB_AUTH_HMAC_SHA_384, /**< HMAC-SHA384 */
IMB_AUTH_HMAC_SHA_512, /**< HMAC-SHA512 */
IMB_AUTH_AES_XCBC,
IMB_AUTH_MD5, /**< HMAC-MD5 */
IMB_AUTH_NULL,
IMB_AUTH_AES_GMAC,
IMB_AUTH_CUSTOM,
IMB_AUTH_AES_CCM, /**< AES128-CCM */
IMB_AUTH_AES_CMAC, /**< AES128-CMAC */
IMB_AUTH_SHA_1, /**< SHA1 */
IMB_AUTH_SHA_224, /**< SHA224 */
IMB_AUTH_SHA_256, /**< SHA256 */
IMB_AUTH_SHA_384, /**< SHA384 */
IMB_AUTH_SHA_512, /**< SHA512 */
IMB_AUTH_AES_CMAC_BITLEN, /**< 128-EIA2/NIA2 (3GPP) */
IMB_AUTH_PON_CRC_BIP,
IMB_AUTH_ZUC_EIA3_BITLEN, /**< 128-EIA3/NIA3 (3GPP) */
IMB_AUTH_DOCSIS_CRC32, /**< with DOCSIS_SEC_BPI only */
IMB_AUTH_SNOW3G_UIA2_BITLEN, /**< 128-UIA2 (3GPP) */
IMB_AUTH_KASUMI_UIA1, /**< 128-UIA1 (3GPP) */
IMB_AUTH_AES_GMAC_128, /**< AES-GMAC (128-bit key) */
IMB_AUTH_AES_GMAC_192, /**< AES-GMAC (192-bit key) */
IMB_AUTH_AES_GMAC_256, /**< AES-GMAC (256-bit key) */
IMB_AUTH_AES_CMAC_256, /**< AES256-CMAC */
IMB_AUTH_POLY1305, /**< POLY1305 */
IMB_AUTH_CHACHA20_POLY1305, /**< AEAD POLY1305 */
IMB_AUTH_CHACHA20_POLY1305_SGL, /**< AEAD CHACHA20 with SGL support */
IMB_AUTH_ZUC256_EIA3_BITLEN, /**< 256-EIA3/NIA3 (3GPP) */
IMB_AUTH_SNOW_V_AEAD, /**< SNOW-V-AEAD */
IMB_AUTH_GCM_SGL, /**< AES-GCM with SGL support */
IMB_AUTH_CRC32_ETHERNET_FCS, /**< CRC32-ETHERNET-FCS */
IMB_AUTH_CRC32_SCTP, /**< CRC32-SCTP */
IMB_AUTH_CRC32_WIMAX_OFDMA_DATA,/**< CRC32-WIMAX-OFDMA-DATA */
IMB_AUTH_CRC24_LTE_A, /**< CRC32-LTE-A */
IMB_AUTH_CRC24_LTE_B, /**< CRC32-LTE-B */
IMB_AUTH_CRC16_X25, /**< CRC16-X25 */
IMB_AUTH_CRC16_FP_DATA, /**< CRC16-FP-DATA */
IMB_AUTH_CRC11_FP_HEADER, /**< CRC11-FP-HEADER */
IMB_AUTH_CRC10_IUUP_DATA, /**< CRC10-IUUP-DATA */
IMB_AUTH_CRC8_WIMAX_OFDMA_HCS, /**< CRC8-WIMAX-OFDMA-HCS */
IMB_AUTH_CRC7_FP_HEADER, /**< CRC7-FP-HEADER */
IMB_AUTH_CRC6_IUUP_HEADER, /**< CRC6-IUUP-HEADER */
IMB_AUTH_GHASH, /**< GHASH */
IMB_AUTH_NUM
} IMB_HASH_ALG;
typedef enum {
IMB_ORDER_CIPHER_HASH = 1,
IMB_ORDER_HASH_CIPHER
} IMB_CHAIN_ORDER;
typedef enum {
IMB_KEY_128_BYTES = 16,
IMB_KEY_192_BYTES = 24,
IMB_KEY_256_BYTES = 32
} IMB_KEY_SIZE_BYTES;
typedef enum {
IMB_SGL_INIT = 0,
IMB_SGL_UPDATE,
IMB_SGL_COMPLETE,
IMB_SGL_ALL
} IMB_SGL_STATE;
/**
* Input/output SGL segment structure.
*/
struct IMB_SGL_IOV {
const void *in; /**< Input segment */
void *out; /**< Output segment */
uint64_t len; /** Length of segment */
};
/**
* Job structure.
*
* For AES, enc_keys and dec_keys are
* expected to point to expanded keys structure.
* - AES-CTR, AES-ECB and AES-CCM, only enc_keys is used
* - DOCSIS (AES-CBC + AES-CFB), both pointers are used
* enc_keys has to be set always for the partial block
*
* For DES, enc_keys and dec_keys are
* expected to point to DES key schedule.
* - same key schedule used for enc and dec operations
*
* For 3DES, enc_keys and dec_keys are
* expected to point to an array of 3 pointers for
* the corresponding 3 key schedules.
* - same key schedule used for enc and dec operations
*/
typedef struct IMB_JOB {
const void *enc_keys; /**< Encryption key pointer */
const void *dec_keys; /**< Decryption key pointer */
uint64_t key_len_in_bytes; /**< Key length in bytes */
union {
const uint8_t *src; /**< Input buffer.
May be ciphertext or plaintext.
In-place ciphering allowed. */
const struct IMB_SGL_IOV *sgl_io_segs;
/**< Pointer to array of input/output SGL segments */
};
union {
uint8_t *dst; /**< Output buffer.
May be ciphertext or plaintext.
In-place ciphering allowed, i.e. dst = src. */
uint64_t num_sgl_io_segs;
/**< Number of input/output SGL segments */
};
union {
uint64_t cipher_start_src_offset_in_bytes;
/**< Offset into input buffer to start ciphering (in bytes) */
uint64_t cipher_start_src_offset_in_bits;
/**< Offset into input buffer to start ciphering (in bits) */
uint64_t cipher_start_offset_in_bits;
/**< Offset into input buffer to start ciphering (in bits) */
}; /**< Offset into input buffer to start ciphering */
union {
uint64_t msg_len_to_cipher_in_bytes;
/**< Length of message to cipher (in bytes) */
uint64_t msg_len_to_cipher_in_bits;
/**< Length of message to cipher (in bits) */
}; /**< Length of message to cipher */
uint64_t hash_start_src_offset_in_bytes;
union {
uint64_t msg_len_to_hash_in_bytes;
/**< Length of message to hash (in bytes) */
uint64_t msg_len_to_hash_in_bits;
/**< Length of message to hash (in bits) */
}; /**< Length of message to hash */
const uint8_t *iv; /**< Initialization Vector (IV) */
uint64_t iv_len_in_bytes; /**< IV length in bytes */
uint8_t *auth_tag_output; /**< Authentication tag output */
uint64_t auth_tag_output_len_in_bytes; /**< Authentication tag output
length in bytes */
/* Start hash algorithm-specific fields */
union {
struct _HMAC_specific_fields {
const uint8_t *_hashed_auth_key_xor_ipad;
/**< Hashed result of HMAC key xor'd
* with ipad (0x36). */
const uint8_t *_hashed_auth_key_xor_opad;
/**< Hashed result of HMAC key xor'd
* with opad (0x5c). */
} HMAC; /**< HMAC specific fields */
struct _AES_XCBC_specific_fields {
const uint32_t *_k1_expanded;
/**< k1 expanded key pointer (16-byte aligned) */
const uint8_t *_k2;
/**< k2 expanded key pointer (16-byte aligned) */
const uint8_t *_k3;
/**< k3 expanded key pointer (16-byte aligned) */
} XCBC; /**< AES-XCBC specific fields */
struct _AES_CCM_specific_fields {
const void *aad;
/**< Additional Authentication Data (AAD) */
uint64_t aad_len_in_bytes; /**< Length of AAD */
} CCM; /**< AES-CCM specific fields */
struct _AES_CMAC_specific_fields {
const void *_key_expanded;
/**< Expanded key (16-byte aligned) */
const void *_skey1; /**< S key 1 (16-byte aligned) */
const void *_skey2; /**< S key 2 (16-byte aligned) */
} CMAC; /**< AES-CMAC specific fields */
struct _AES_GCM_specific_fields {
const void *aad;
/**< Additional Authentication Data (AAD) */
uint64_t aad_len_in_bytes; /**< Length of AAD */
struct gcm_context_data *ctx;
/**< AES-GCM context (for SGL only) */
} GCM; /**< AES-GCM specific fields */
struct _ZUC_EIA3_specific_fields {
const uint8_t *_key;
/**< Authentication key (16-byte aligned) */
const uint8_t *_iv;
/**< Authentication 25-byte IV (16-byte aligned) */
const uint8_t *_iv23;
/**< Authentication 23-byte IV (16-byte aligned) */
} ZUC_EIA3; /**< ZUC-EIA3 specific fields */
struct _SNOW3G_UIA2_specific_fields {
const void *_key;
/**< Authentication key (16-byte aligned) */
const void *_iv;
/**< Authentication IV (16-byte aligned) */
} SNOW3G_UIA2; /**< SNOW3G-UIA2 specific fields */
struct _KASUMI_UIA1_specific_fields {
const void *_key;
/**< Authentication key (16-byte aligned) */
} KASUMI_UIA1; /**< KASUMI-UIA2 specific fields */
struct _AES_GMAC_specific_fields {
const struct gcm_key_data *_key;
/**< Authentication key */
const void *_iv;
/**< Authentication IV */
uint64_t iv_len_in_bytes;
/**< Authentication IV length in bytes */
} GMAC; /**< AES-GMAC specific fields */
struct _GHASH_specific_fields {
const struct gcm_key_data *_key;
/**< Expanded GHASH key */
const void *_init_tag; /**< initial tag value */
} GHASH; /**< GHASH specific fields */
struct _POLY1305_specific_fields {
const void *_key;
/**< Poly1305 key */
} POLY1305; /**< Poly1305 specific fields */
struct _CHACHA20_POLY1305_specific_fields {
const void *aad;
/**< Additional Authentication Data (AAD) */
uint64_t aad_len_in_bytes;
/**< Length of AAD */
struct chacha20_poly1305_context_data *ctx;
/**< Chacha20-Poly1305 context (for SGL only) */
} CHACHA20_POLY1305; /**< Chacha20-Poly1305 specific fields */
struct _SNOW_V_AEAD_specific_fields {
const void *aad;
/**< Additional Authentication Data (AAD) */
uint64_t aad_len_in_bytes;
/**< Length of AAD */
void *reserved;
/**< Reserved bytes */
} SNOW_V_AEAD; /**< SNOW-V AEAD specific fields */
} u; /**< Hash algorithm-specific fields */
IMB_STATUS status; /**< Job status */
IMB_CIPHER_MODE cipher_mode; /**< Cipher mode */
IMB_CIPHER_DIRECTION cipher_direction; /**< Cipher direction */
IMB_HASH_ALG hash_alg; /**< Hashing algorithm */
IMB_CHAIN_ORDER chain_order;
/**< Chain order (IMB_ORDER_CIPHER_HASH / IMB_ORDER_HASH_CIPHER).*/
void *user_data; /**< Pointer 1 to user data */
void *user_data2; /**< Pointer 2 to user data */
int (*cipher_func)(struct IMB_JOB *);
/**< Customer cipher function */
int (*hash_func)(struct IMB_JOB *);
/**< Customer hash function */
IMB_SGL_STATE sgl_state;
/**< SGL state (IMB_SGL_INIT/IMB_SGL_UPDATE/IMB_SGL_COMPLETE/
IMB_SGL_ALL) */
union {
struct _CBCS_specific_fields {
void *next_iv;
/**< Pointer to next IV (last ciphertext block) */
} CBCS; /**< CBCS specific fields */
} cipher_fields; /**< Cipher algorithm-specific fields */
} IMB_JOB;
/* KASUMI */
/* 64 precomputed words for key schedule */
#define KASUMI_KEY_SCHEDULE_SIZE 64
/**
* Structure to maintain internal key scheduling
*/
typedef struct kasumi_key_sched_s {
/**< Kasumi internal scheduling */
uint16_t sk16[KASUMI_KEY_SCHEDULE_SIZE]; /**< key schedule */
uint16_t msk16[KASUMI_KEY_SCHEDULE_SIZE]; /**< modified key schedule */
} kasumi_key_sched_t;
/* GCM data structures */
#define IMB_GCM_BLOCK_LEN 16
/**
* @brief holds GCM operation context
*
* init, update and finalize context data
*/
struct gcm_context_data {
uint8_t aad_hash[IMB_GCM_BLOCK_LEN];
uint64_t aad_length;
uint64_t in_length;
uint8_t partial_block_enc_key[IMB_GCM_BLOCK_LEN];
uint8_t orig_IV[IMB_GCM_BLOCK_LEN];
uint8_t current_counter[IMB_GCM_BLOCK_LEN];
uint64_t partial_block_length;
};
#undef IMB_GCM_BLOCK_LEN
/**
* @brief holds Chacha20-Poly1305 operation context
*/
struct chacha20_poly1305_context_data {
uint64_t hash[3]; /**< Intermediate computation of hash value */
uint64_t aad_len; /**< Total AAD length */
uint64_t hash_len; /**< Total length to digest (excluding AAD) */
uint8_t last_ks[64]; /**< Last 64 bytes of KS */
uint8_t poly_key[32]; /**< Poly key */
uint8_t poly_scratch[16]; /**< Scratchpad to compute Poly on 16 bytes */
uint64_t last_block_count; /**< Last block count used in last segment */
uint64_t remain_ks_bytes;/**< Amount of bytes still to use of keystream
(up to 63 bytes) */
uint64_t remain_ct_bytes; /**< Amount of ciphertext bytes still to use
of previous segment to authenticate
(up to 16 bytes) */
uint8_t IV[12]; /**< IV (12 bytes) */
};
/**
* Authenticated Tag Length in bytes.
* Valid values are 16 (most likely), 12 or 8.
*/
#define IMB_MAX_TAG_LEN (16)
/**
* IV data is limited to 16 bytes as follows:
* 12 bytes is provided by an application -
* pre-counter block j0: 4 byte salt (from Security Association)
* concatenated with 8 byte Initialization Vector (from IPSec ESP
* Payload).
* 4 byte value 0x00000001 is padded automatically by the library -
* there is no need to add these 4 bytes on application side anymore.
*/
#define IMB_GCM_IV_DATA_LEN (12)
#define IMB_GCM_128_KEY_LEN (16)
#define IMB_GCM_192_KEY_LEN (24)
#define IMB_GCM_256_KEY_LEN (32)
#define IMB_GCM_ENC_KEY_LEN 16
#define IMB_GCM_KEY_SETS (15) /**< exp key + 14 exp round keys*/
/**
* @brief holds intermediate key data needed to improve performance
*
* gcm_key_data hold internal key information used by gcm128, gcm192 and gcm256.
*/
#ifdef __WIN32
__declspec(align(64))
#endif /* WIN32 */
struct gcm_key_data {
uint8_t expanded_keys[IMB_GCM_ENC_KEY_LEN * IMB_GCM_KEY_SETS];
union {
/**< Storage for precomputed hash keys */
struct {
/**
* This is needed for schoolbook multiply purposes.
* (HashKey<<1 mod poly), (HashKey^2<<1 mod poly), ...,
* (Hashkey^48<<1 mod poly)
*/
uint8_t shifted_hkey[IMB_GCM_ENC_KEY_LEN * 8];
/**
* This is needed for Karatsuba multiply purposes.
* Storage for XOR of High 64 bits and low 64 bits
* of HashKey mod poly.
*
* (HashKey<<1 mod poly), (HashKey^2<<1 mod poly), ...,
* (Hashkey^128<<1 mod poly)
*/
uint8_t shifted_hkey_k[IMB_GCM_ENC_KEY_LEN * 8];
} sse_avx;
struct {
/**
* This is needed for schoolbook multiply purposes.
* (HashKey<<1 mod poly), (HashKey^2<<1 mod poly), ...,
* (Hashkey^48<<1 mod poly)
*/
uint8_t shifted_hkey[IMB_GCM_ENC_KEY_LEN * 8];
} avx2_avx512;
struct {
/**
* (HashKey<<1 mod poly), (HashKey^2<<1 mod poly), ...,
* (Hashkey^48<<1 mod poly)
*/
uint8_t shifted_hkey[IMB_GCM_ENC_KEY_LEN * 48];
} vaes_avx512;
} ghash_keys;
}
#ifdef LINUX
__attribute__((aligned(64)));
#else
;
#endif
#undef IMB_GCM_ENC_KEY_LEN
#undef IMB_GCM_KEY_SETS
/* API data type definitions */
struct IMB_MGR;
typedef void (*init_mb_mgr_t)(struct IMB_MGR *);
typedef IMB_JOB *(*get_next_job_t)(struct IMB_MGR *);
typedef IMB_JOB *(*submit_job_t)(struct IMB_MGR *);
typedef IMB_JOB *(*get_completed_job_t)(struct IMB_MGR *);
typedef IMB_JOB *(*flush_job_t)(struct IMB_MGR *);
typedef uint32_t (*queue_size_t)(struct IMB_MGR *);
typedef uint32_t (*burst_fn_t)(struct IMB_MGR *,
const uint32_t,
struct IMB_JOB **);
typedef uint32_t (*submit_cipher_burst_t)(struct IMB_MGR *,
struct IMB_JOB *,
const uint32_t,
const IMB_CIPHER_MODE cipher,
const IMB_CIPHER_DIRECTION dir,
const IMB_KEY_SIZE_BYTES key_size);
typedef uint32_t (*submit_hash_burst_t)(struct IMB_MGR *,
struct IMB_JOB *,
const uint32_t,
const IMB_HASH_ALG hash);
typedef void (*keyexp_t)(const void *, void *, void *);
typedef void (*cmac_subkey_gen_t)(const void *, void *, void *);
typedef void (*hash_one_block_t)(const void *, void *);
typedef void (*hash_fn_t)(const void *, const uint64_t, void *);
typedef void (*xcbc_keyexp_t)(const void *, void *, void *, void *);
typedef int (*des_keysched_t)(uint64_t *, const void *);
typedef void (*aes_cfb_t)(void *, const void *, const void *, const void *,
uint64_t);
typedef void (*aes_gcm_enc_dec_t)(const struct gcm_key_data *,
struct gcm_context_data *,
uint8_t *, uint8_t const *, uint64_t,
const uint8_t *, uint8_t const *, uint64_t,
uint8_t *, uint64_t);
typedef void (*aes_gcm_enc_dec_iv_t)(const struct gcm_key_data *,
struct gcm_context_data *, uint8_t *,
uint8_t const *, const uint64_t,
const uint8_t *, uint8_t const *,
const uint64_t, uint8_t *,
const uint64_t, const uint64_t);
typedef void (*aes_gcm_init_t)(const struct gcm_key_data *,
struct gcm_context_data *,
const uint8_t *, uint8_t const *, uint64_t);
typedef void (*aes_gcm_init_var_iv_t)(const struct gcm_key_data *,
struct gcm_context_data *,
const uint8_t *, const uint64_t,
const uint8_t *, const uint64_t);
typedef void (*aes_gcm_enc_dec_update_t)(const struct gcm_key_data *,
struct gcm_context_data *,
uint8_t *, const uint8_t *, uint64_t);
typedef void (*aes_gcm_enc_dec_finalize_t)(const struct gcm_key_data *,
struct gcm_context_data *,
uint8_t *, uint64_t);
typedef void (*aes_gcm_precomp_t)(struct gcm_key_data *);
typedef void (*aes_gcm_pre_t)(const void *, struct gcm_key_data *);
typedef void (*aes_gmac_init_t)(const struct gcm_key_data *,
struct gcm_context_data *,
const uint8_t *, const uint64_t);
typedef void (*aes_gmac_update_t)(const struct gcm_key_data *,
struct gcm_context_data *,
const uint8_t *, const uint64_t);
typedef void (*aes_gmac_finalize_t)(const struct gcm_key_data *,
struct gcm_context_data *,
uint8_t *, const uint64_t);
typedef void (*chacha_poly_init_t)(const void *,
struct chacha20_poly1305_context_data *,
const void *, const void *, const uint64_t);
typedef void (*chacha_poly_enc_dec_update_t)(const void *,
struct chacha20_poly1305_context_data *,
void *, const void *, const uint64_t);
typedef void (*chacha_poly_finalize_t)(struct chacha20_poly1305_context_data *,
void *, const uint64_t);
typedef void (*ghash_t)(const struct gcm_key_data *, const void *,
const uint64_t, void *, const uint64_t);
typedef void (*zuc_eea3_1_buffer_t)(const void *, const void *, const void *,
void *, const uint32_t);
typedef void (*zuc_eea3_4_buffer_t)(const void * const *, const void * const *,
const void * const *, void **,
const uint32_t *);
typedef void (*zuc_eea3_n_buffer_t)(const void * const *, const void * const *,
const void * const *, void **,
const uint32_t *, const uint32_t);
typedef void (*zuc_eia3_1_buffer_t)(const void *, const void *, const void *,
const uint32_t, uint32_t *);
typedef void (*zuc_eia3_n_buffer_t)(const void * const *, const void * const *,
const void * const *,
const uint32_t *, uint32_t **,
const uint32_t);
typedef void (*kasumi_f8_1_buffer_t)(const kasumi_key_sched_t *,
const uint64_t, const void *, void *,
const uint32_t);
typedef void (*kasumi_f8_1_buffer_bit_t)(const kasumi_key_sched_t *,
const uint64_t, const void *,
void *,
const uint32_t, const uint32_t);
typedef void (*kasumi_f8_2_buffer_t)(const kasumi_key_sched_t *,
const uint64_t, const uint64_t,
const void *, void *,
const uint32_t,
const void *, void *,
const uint32_t);
typedef void (*kasumi_f8_3_buffer_t)(const kasumi_key_sched_t *,
const uint64_t, const uint64_t,
const uint64_t,
const void *, void *,
const void *, void *,
const void *, void *,
const uint32_t);
typedef void (*kasumi_f8_4_buffer_t)(const kasumi_key_sched_t *,
const uint64_t, const uint64_t,
const uint64_t, const uint64_t,
const void *, void *,
const void *, void *,
const void *, void *,
const void *, void *,
const uint32_t);
typedef void (*kasumi_f8_n_buffer_t)(const kasumi_key_sched_t *,
const uint64_t *, const void * const *,
void **, const uint32_t *,
const uint32_t);
typedef void (*kasumi_f9_1_buffer_user_t)(const kasumi_key_sched_t *,
const uint64_t, const void *,
const uint32_t, void *,
const uint32_t);
typedef void (*kasumi_f9_1_buffer_t)(const kasumi_key_sched_t *,
const void *,
const uint32_t, void *);
typedef int (*kasumi_init_f8_key_sched_t)(const void *,
kasumi_key_sched_t *);
typedef int (*kasumi_init_f9_key_sched_t)(const void *,
kasumi_key_sched_t *);
typedef size_t (*kasumi_key_sched_size_t)(void);
/**
* Snow3G key scheduling structure
*/
typedef struct snow3g_key_schedule_s {
/* KEY */
uint32_t k[4];
} snow3g_key_schedule_t;
typedef void (*snow3g_f8_1_buffer_t)(const snow3g_key_schedule_t *,
const void *, const void *,
void *, const uint32_t);
typedef void (*snow3g_f8_1_buffer_bit_t)(const snow3g_key_schedule_t *,
const void *, const void *, void *,
const uint32_t, const uint32_t);
typedef void (*snow3g_f8_2_buffer_t)(const snow3g_key_schedule_t *,
const void *, const void *,
const void *, void *, const uint32_t,
const void *, void *, const uint32_t);
typedef void (*snow3g_f8_4_buffer_t)(const snow3g_key_schedule_t *,
const void *, const void *, const void *,
const void *, const void *, void *,
const uint32_t, const void *, void *,
const uint32_t, const void *, void *,
const uint32_t, const void *, void *,
const uint32_t);
typedef void (*snow3g_f8_8_buffer_t)(const snow3g_key_schedule_t *,
const void *, const void *, const void *,
const void *, const void *, const void *,
const void *, const void *, const void *,
void *, const uint32_t, const void *,
void *, const uint32_t, const void *,
void *, const uint32_t, const void *,
void *, const uint32_t, const void *,
void *, const uint32_t, const void *,
void *, const uint32_t, const void *,
void *, const uint32_t, const void *,
void *, const uint32_t);
typedef void
(*snow3g_f8_8_buffer_multikey_t)(const snow3g_key_schedule_t * const [],
const void * const [], const void * const [],
void *[], const uint32_t[]);
typedef void (*snow3g_f8_n_buffer_t)(const snow3g_key_schedule_t *,
const void * const [],
const void * const [],
void *[], const uint32_t[],
const uint32_t);
typedef void
(*snow3g_f8_n_buffer_multikey_t)(const snow3g_key_schedule_t * const [],
const void * const [],
const void * const [],
void *[], const uint32_t[],
const uint32_t);
typedef void (*snow3g_f9_1_buffer_t)(const snow3g_key_schedule_t *,
const void *, const void *,
const uint64_t, void *);
typedef int (*snow3g_init_key_sched_t)(const void *,
snow3g_key_schedule_t *);
typedef size_t (*snow3g_key_sched_size_t)(void);
typedef uint32_t (*hec_32_t)(const uint8_t *);
typedef uint64_t (*hec_64_t)(const uint8_t *);
typedef uint32_t (*crc32_fn_t)(const void *, const uint64_t);
/* Multi-buffer manager flags passed to alloc_mb_mgr() */
#define IMB_FLAG_SHANI_OFF (1ULL << 0) /**< disable use of SHANI extension */