forked from intel/QAT_Engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqat_ciphers.h
More file actions
126 lines (114 loc) · 5.38 KB
/
qat_ciphers.h
File metadata and controls
126 lines (114 loc) · 5.38 KB
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
/* ====================================================================
*
*
* BSD LICENSE
*
* Copyright(c) 2016 Intel Corporation.
* All rights reserved.
*
* 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.
*
*
* ====================================================================
*/
/*****************************************************************************
* @file qat_ciphers.h
*
* This file provides an interface for engine cipher operations
*
*****************************************************************************/
#ifndef QAT_CIPHERS_H
# define QAT_CIPHERS_H
# include <openssl/engine.h>
# include <openssl/crypto.h>
# include <openssl/aes.h>
# define AES_IV_LEN 16
# define AES_KEY_SIZE_256 32
# define AES_KEY_SIZE_128 16
# define QAT_BYTE_SHIFT 8
# define HMAC_KEY_SIZE 64
# define TLS_VIRT_HDR_SIZE 13
# define TLS_MAX_PADDING_LENGTH 255
/* Use these flags to mark stages in the
* initialisation sequence for pipes.
*/
# define INIT_SEQ_QAT_CTX_INIT 0x0001
# define INIT_SEQ_HMAC_KEY_SET 0x0002
# define INIT_SEQ_QAT_SESSION_INIT 0x0004
# define INIT_SEQ_TLS_HDR_SET 0x0008
# define INIT_SEQ_PPL_IBUF_SET 0x0100
# define INIT_SEQ_PPL_OBUF_SET 0x0200
# define INIT_SEQ_PPL_BUF_LEN_SET 0x0400
# define INIT_SEQ_PPL_AADCTR_SET 0x0800
# define INIT_SEQ_PPL_USED 0x1000
# define qat_chained_data(ctx) \
((qat_chained_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx))
# define QAT_COMMON_CIPHER_FLAG EVP_CIPH_FLAG_DEFAULT_ASN1
# define QAT_CBC_FLAGS (QAT_COMMON_CIPHER_FLAG | \
EVP_CIPH_CBC_MODE | \
EVP_CIPH_CUSTOM_IV)
# define QAT_CHAINED_FLAG (QAT_CBC_FLAGS | \
EVP_CIPH_FLAG_AEAD_CIPHER | \
EVP_CIPH_FLAG_PIPELINE)
# define INIT_SEQ_PPL_INIT_COMPLETE (INIT_SEQ_PPL_IBUF_SET | \
INIT_SEQ_PPL_OBUF_SET | \
INIT_SEQ_PPL_AADCTR_SET | \
INIT_SEQ_PPL_BUF_LEN_SET)
# define INIT_SEQ_CLEAR_ALL_FLAGS(qctx) ((qctx)->init_flags = 0)
# define INIT_SEQ_SET_FLAG(qctx, f) ((qctx)->init_flags |= (f))
# define INIT_SEQ_CLEAR_FLAG(qctx, f) ((qctx)->init_flags &= ~(f))
# define INIT_SEQ_IS_FLAG_SET(qctx,f) ((qctx)->init_flags & (f))
# define TLS_HDR_SET(qctx) ((qctx)->init_flags & INIT_SEQ_TLS_HDR_SET)
# define PIPELINE_SET(qctx) \
(((qctx)->init_flags & INIT_SEQ_PPL_INIT_COMPLETE) \
== INIT_SEQ_PPL_INIT_COMPLETE)
# define PIPELINE_NOT_SET(qctx) \
(((qctx)->init_flags & INIT_SEQ_PPL_INIT_COMPLETE) \
== 0)
# define PIPELINE_USED(qctx) ((qctx)->init_flags & INIT_SEQ_PPL_USED)
# define PIPELINE_INCOMPLETE_INIT(qctx) \
(!PIPELINE_SET(qctx) && !PIPELINE_NOT_SET(qctx) \
&& !PIPELINE_USED(qctx))
# define CLEAR_PIPELINE(qctx) \
do { \
(qctx)->init_flags &= ~(INIT_SEQ_PPL_INIT_COMPLETE); \
(qctx)->numpipes = 1; \
} while(0)
void qat_create_ciphers(void);
void qat_free_ciphers(void);
int qat_ciphers(ENGINE *e, const EVP_CIPHER **cipher, const int **nids,
int nid);
# ifndef OPENSSL_ENABLE_QAT_SMALL_PACKET_CIPHER_OFFLOADS
extern CRYPTO_ONCE qat_pkt_threshold_table_once;
extern CRYPTO_THREAD_LOCAL qat_pkt_threshold_table_key;
void qat_pkt_threshold_table_make_key(void);
LHASH_OF(PKT_THRESHOLD) *qat_create_pkt_threshold_table(void);
void qat_free_pkt_threshold_table(void *);
int qat_pkt_threshold_table_set_threshold(int nid, int threshold);
int qat_pkt_threshold_table_get_threshold(int nid);
# endif
#endif /* QAT_CIPHERS_H */