Skip to content

Commit 8042faa

Browse files
amitk18xYogaraj-Alamenda
authored andcommitted
Fix issue with SM4-CCM & GCM enable flag
Signed-off-by: Amit Kumar <amit1x.kumar@intel.com>
1 parent cf4df01 commit 8042faa

File tree

10 files changed

+62
-34
lines changed

10 files changed

+62
-34
lines changed

e_qat.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,12 @@
110110
# include "qat_sw_ec.h"
111111
# include "qat_sw_polling.h"
112112
# include "crypto_mb/cpu_features.h"
113-
# include "crypto_mb/sm4.h"
114-
# include "crypto_mb/sm4_gcm.h"
115-
# include "crypto_mb/sm4_ccm.h"
113+
# ifdef ENABLE_QAT_SW_SM4_GCM
114+
# include "crypto_mb/sm4_gcm.h"
115+
# endif
116+
# ifdef ENABLE_QAT_SW_SM4_CCM
117+
# include "crypto_mb/sm4_ccm.h"
118+
# endif
116119
#endif
117120

118121
#ifdef QAT_SW_IPSEC

qat_evp.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,17 @@
8888
# include "qat_sw_sm3.h"
8989
# ifndef QAT_BORINGSSL
9090
# include "qat_sw_sm4_cbc.h"
91-
# include "qat_sw_sm4_gcm.h"
92-
# include "qat_sw_sm4_ccm.h"
93-
# include "crypto_mb/sm4.h"
9491
# endif /* QAT_BORINGSSL */
9592
# include "crypto_mb/cpu_features.h"
9693
# ifndef QAT_BORINGSSL
97-
# include "crypto_mb/sm4_gcm.h"
98-
# include "crypto_mb/sm4_ccm.h"
94+
# ifdef ENABLE_QAT_SW_SM4_GCM
95+
# include "qat_sw_sm4_gcm.h"
96+
# include "crypto_mb/sm4_gcm.h"
97+
# endif
98+
# ifdef ENABLE_QAT_SW_SM4_CCM
99+
# include "qat_sw_sm4_ccm.h"
100+
# include "crypto_mb/sm4_ccm.h"
101+
# endif
99102
# endif /* QAT_BORINGSSL */
100103
#endif
101104

@@ -856,7 +859,6 @@ const EVP_CIPHER *qat_create_sm4_cbc_cipher_meth(int nid, int keylen)
856859
* Create a new EVP_CIPHER based on requested nid for qat_sw
857860
******************************************************************************/
858861
#ifdef ENABLE_QAT_SW_SM4_GCM
859-
# if !defined(QAT_OPENSSL_3) && !defined(QAT_OPENSSL_PROVIDER)
860862
const EVP_CIPHER *qat_create_sm4_gcm_cipher_meth(int nid, int keylen)
861863
{
862864
EVP_CIPHER *c = NULL;
@@ -899,7 +901,6 @@ const EVP_CIPHER *qat_create_sm4_gcm_cipher_meth(int nid, int keylen)
899901
}
900902
return c;
901903
}
902-
# endif
903904
#endif /* ENABLE_QAT_SW_SM4_GCM */
904905

905906
/******************************************************************************
@@ -914,13 +915,10 @@ const EVP_CIPHER *qat_create_sm4_gcm_cipher_meth(int nid, int keylen)
914915
* Create a new EVP_CIPHER based on requested nid for qat_sw
915916
******************************************************************************/
916917
#ifdef ENABLE_QAT_SW_SM4_CCM
917-
# if !defined(QAT_OPENSSL_3) && !defined(QAT_OPENSSL_PROVIDER)
918918
const EVP_CIPHER *qat_create_sm4_ccm_cipher_meth(int nid, int keylen)
919919
{
920920
EVP_CIPHER *c = NULL;
921-
#ifdef ENABLE_QAT_SW_SM4_CCM
922921
int res = 1;
923-
#endif
924922

925923
if ((c = EVP_CIPHER_meth_new(nid, SM4_BLOCK_SIZE, keylen)) == NULL) {
926924
QATerr(QAT_F_QAT_CREATE_SM4_CCM_CIPHER_METH, QAT_R_SM4_MALLOC_FAILED);
@@ -960,7 +958,6 @@ const EVP_CIPHER *qat_create_sm4_ccm_cipher_meth(int nid, int keylen)
960958
}
961959
return c;
962960
}
963-
# endif
964961
#endif /* ENABLE_QAT_SW_SM4_CCM */
965962

966963
void qat_create_ciphers(void)

qat_evp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ int qat_sw_sm3_update(EVP_MD_CTX *ctx, const void *in, size_t len);
130130
int qat_sw_sm3_final(EVP_MD_CTX *ctx, unsigned char *md);
131131
# endif
132132

133-
#ifdef ENABLE_QAT_SW_SM4_GCM
133+
# ifdef ENABLE_QAT_SW_SM4_GCM
134134
int qat_sw_sm4_gcm_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
135135
const unsigned char *iv, int enc);
136136
int qat_sw_sm4_gcm_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);
@@ -139,14 +139,14 @@ int qat_sw_sm4_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
139139
int qat_sw_sm4_gcm_cleanup(EVP_CIPHER_CTX *ctx);
140140
# endif
141141

142-
#ifdef ENABLE_QAT_SW_SM4_CCM
142+
# ifdef ENABLE_QAT_SW_SM4_CCM
143143
int qat_sw_sm4_ccm_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
144144
const unsigned char *iv, int enc);
145145
int qat_sw_sm4_ccm_ctrl(EVP_CIPHER_CTX *ctx, int type, int p1, void *p2);
146146
int qat_sw_sm4_ccm_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
147147
const unsigned char *in, size_t len);
148148
int qat_sw_sm4_ccm_cleanup(EVP_CIPHER_CTX *ctx);
149-
#endif
149+
# endif
150150

151151
int qat_pkey_methods(ENGINE *e, EVP_PKEY_METHOD **pmeth,
152152
const int **nids, int nid);

qat_sw_freelist.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,6 +1537,7 @@ sm4_cbc_cipher_op_data
15371537
return item;
15381538
}
15391539

1540+
#ifdef ENABLE_QAT_SW_SM4_GCM
15401541
mb_flist_sm4_gcm_encrypt *mb_flist_sm4_gcm_encrypt_create()
15411542
{
15421543
mb_flist_sm4_gcm_encrypt *freelist = NULL;
@@ -1722,7 +1723,9 @@ sm4_gcm_decrypt_op_data
17221723

17231724
return item;
17241725
}
1726+
#endif
17251727

1728+
#ifdef ENABLE_QAT_SW_SM4_CCM
17261729
mb_flist_sm4_ccm_encrypt *mb_flist_sm4_ccm_encrypt_create()
17271730
{
17281731
mb_flist_sm4_ccm_encrypt *freelist = NULL;
@@ -1908,3 +1911,4 @@ sm4_ccm_decrypt_op_data
19081911

19091912
return item;
19101913
}
1914+
#endif

qat_sw_freelist.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ typedef struct _mb_flist_sm4_cbc_cipher
148148
sm4_cbc_cipher_op_data *head;
149149
} mb_flist_sm4_cbc_cipher;
150150

151+
# ifdef ENABLE_QAT_SW_SM4_GCM
151152
typedef struct _mb_flist_sm4_gcm_encrypt
152153
{
153154
pthread_mutex_t mb_flist_mutex;
@@ -159,7 +160,9 @@ typedef struct _mb_flist_sm4_gcm_decrypt
159160
pthread_mutex_t mb_flist_mutex;
160161
sm4_gcm_decrypt_op_data *head;
161162
} mb_flist_sm4_gcm_decrypt;
163+
# endif
162164

165+
# ifdef ENABLE_QAT_SW_SM4_CCM
163166
typedef struct _mb_flist_sm4_ccm_encrypt
164167
{
165168
pthread_mutex_t mb_flist_mutex;
@@ -171,6 +174,7 @@ typedef struct _mb_flist_sm4_ccm_decrypt
171174
pthread_mutex_t mb_flist_mutex;
172175
sm4_ccm_decrypt_op_data *head;
173176
} mb_flist_sm4_ccm_decrypt;
177+
# endif
174178

175179
typedef struct _mb_thread_data{
176180
pthread_t polling_thread;
@@ -242,17 +246,20 @@ typedef struct _mb_thread_data{
242246
mb_queue_sm4_cbc_cipher *sm4_cbc_cipher_queue;
243247
mb_queue_sm4_cbc_cipher *sm4_cbc_cipher_dec_queue;
244248
/* SM4_GCM */
249+
# ifdef ENABLE_QAT_SW_SM4_GCM
245250
mb_flist_sm4_gcm_encrypt *sm4_gcm_encrypt_freelist;
246251
mb_flist_sm4_gcm_decrypt *sm4_gcm_decrypt_freelist;
247252
mb_queue_sm4_gcm_encrypt *sm4_gcm_encrypt_queue;
248253
mb_queue_sm4_gcm_decrypt *sm4_gcm_decrypt_queue;
254+
# endif
249255

250256
/* SM4_CCM */
257+
# ifdef ENABLE_QAT_SW_SM4_CCM
251258
mb_flist_sm4_ccm_encrypt *sm4_ccm_encrypt_freelist;
252259
mb_flist_sm4_ccm_decrypt *sm4_ccm_decrypt_freelist;
253260
mb_queue_sm4_ccm_encrypt *sm4_ccm_encrypt_queue;
254261
mb_queue_sm4_ccm_decrypt *sm4_ccm_decrypt_queue;
255-
262+
# endif
256263
} mb_thread_data;
257264

258265
mb_flist_rsa_priv * mb_flist_rsa_priv_create();
@@ -356,6 +363,7 @@ int mb_flist_sm4_cbc_cipher_push(mb_flist_sm4_cbc_cipher *freelist,
356363
sm4_cbc_cipher_op_data
357364
*mb_flist_sm4_cbc_cipher_pop(mb_flist_sm4_cbc_cipher *flist);
358365

366+
# ifdef ENABLE_QAT_SW_SM4_GCM
359367
mb_flist_sm4_gcm_encrypt * mb_flist_sm4_gcm_encrypt_create();
360368
int mb_flist_sm4_gcm_encrypt_cleanup(mb_flist_sm4_gcm_encrypt *freelist);
361369
int mb_flist_sm4_gcm_encrypt_push(mb_flist_sm4_gcm_encrypt *freelist,
@@ -369,7 +377,9 @@ int mb_flist_sm4_gcm_decrypt_push(mb_flist_sm4_gcm_decrypt *freelist,
369377
sm4_gcm_decrypt_op_data *item);
370378
sm4_gcm_decrypt_op_data
371379
*mb_flist_sm4_gcm_decrypt_pop(mb_flist_sm4_gcm_decrypt *flist);
380+
# endif
372381

382+
# ifdef ENABLE_QAT_SW_SM4_CCM
373383
mb_flist_sm4_ccm_encrypt * mb_flist_sm4_ccm_encrypt_create();
374384
int mb_flist_sm4_ccm_encrypt_cleanup(mb_flist_sm4_ccm_encrypt *freelist);
375385
int mb_flist_sm4_ccm_encrypt_push(mb_flist_sm4_ccm_encrypt *freelist,
@@ -383,5 +393,5 @@ int mb_flist_sm4_ccm_decrypt_push(mb_flist_sm4_ccm_decrypt *freelist,
383393
sm4_ccm_decrypt_op_data *item);
384394
sm4_ccm_decrypt_op_data
385395
*mb_flist_sm4_ccm_decrypt_pop(mb_flist_sm4_ccm_decrypt *flist);
386-
396+
# endif
387397
#endif /* QAT_SW_FREELIST_H */

qat_sw_queue.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3752,6 +3752,7 @@ int mb_queue_sm4_cbc_cipher_get_size(mb_queue_sm4_cbc_cipher *queue)
37523752
return queue->num_items;
37533753
}
37543754

3755+
#ifdef ENABLE_QAT_SW_SM4_GCM
37553756
mb_queue_sm4_gcm_encrypt * mb_queue_sm4_gcm_encrypt_create()
37563757
{
37573758
mb_queue_sm4_gcm_encrypt *queue = NULL;
@@ -4011,7 +4012,9 @@ int mb_queue_sm4_gcm_decrypt_get_size(mb_queue_sm4_gcm_decrypt *queue)
40114012

40124013
return queue->num_items;
40134014
}
4015+
#endif
40144016

4017+
#ifdef ENABLE_QAT_SW_SM4_CCM
40154018
mb_queue_sm4_ccm_encrypt * mb_queue_sm4_ccm_encrypt_create()
40164019
{
40174020
mb_queue_sm4_ccm_encrypt *queue = NULL;
@@ -4271,3 +4274,4 @@ int mb_queue_sm4_ccm_decrypt_get_size(mb_queue_sm4_ccm_decrypt *queue)
42714274

42724275
return queue->num_items;
42734276
}
4277+
#endif

qat_sw_queue.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ typedef struct _mb_queue_sm4_cbc_cipher
302302
int disabled;
303303
} mb_queue_sm4_cbc_cipher;
304304

305+
# ifdef ENABLE_QAT_SW_SM4_GCM
305306
typedef struct _mb_queue_sm4_gcm_encrypt
306307
{
307308
pthread_mutex_t mb_queue_mutex;
@@ -319,7 +320,9 @@ typedef struct _mb_queue_sm4_gcm_decrypt
319320
int num_items;
320321
int disabled;
321322
} mb_queue_sm4_gcm_decrypt;
323+
# endif
322324

325+
# ifdef ENABLE_QAT_SW_SM4_CCM
323326
typedef struct _mb_queue_sm4_ccm_encrypt
324327
{
325328
pthread_mutex_t mb_queue_mutex;
@@ -337,6 +340,7 @@ typedef struct _mb_queue_sm4_ccm_decrypt
337340
int num_items;
338341
int disabled;
339342
} mb_queue_sm4_ccm_decrypt;
343+
# endif
340344

341345
mb_queue_rsa2k_priv * mb_queue_rsa2k_priv_create();
342346
int mb_queue_rsa2k_priv_disable(mb_queue_rsa2k_priv * queue);
@@ -592,6 +596,7 @@ sm4_cbc_cipher_op_data
592596
*mb_queue_sm4_cbc_cipher_dec_dequeue(mb_queue_sm4_cbc_cipher *queue);
593597

594598
/* SM4_GCM encrypt */
599+
# ifdef ENABLE_QAT_SW_SM4_GCM
595600
mb_queue_sm4_gcm_encrypt * mb_queue_sm4_gcm_encrypt_create();
596601
int mb_queue_sm4_gcm_encrypt_disable(mb_queue_sm4_gcm_encrypt * queue);
597602
int mb_queue_sm4_gcm_encrypt_cleanup(mb_queue_sm4_gcm_encrypt * queue);
@@ -610,8 +615,10 @@ int mb_queue_sm4_gcm_decrypt_enqueue(mb_queue_sm4_gcm_decrypt *queue,
610615
sm4_gcm_decrypt_op_data
611616
*mb_queue_sm4_gcm_decrypt_dequeue(mb_queue_sm4_gcm_decrypt *queue);
612617
int mb_queue_sm4_gcm_decrypt_get_size(mb_queue_sm4_gcm_decrypt *queue);
618+
# endif /* ENABLE_QAT_SW_SM4_GCM */
613619

614620
/* SM4_CCM */
621+
# ifdef ENABLE_QAT_SW_SM4_CCM
615622
mb_queue_sm4_ccm_encrypt * mb_queue_sm4_ccm_encrypt_create();
616623
int mb_queue_sm4_ccm_encrypt_disable(mb_queue_sm4_ccm_encrypt * queue);
617624
int mb_queue_sm4_ccm_encrypt_cleanup(mb_queue_sm4_ccm_encrypt * queue);
@@ -629,5 +636,5 @@ int mb_queue_sm4_ccm_decrypt_enqueue(mb_queue_sm4_ccm_decrypt *queue,
629636
sm4_ccm_decrypt_op_data
630637
*mb_queue_sm4_ccm_decrypt_dequeue(mb_queue_sm4_ccm_decrypt *queue);
631638
int mb_queue_sm4_ccm_decrypt_get_size(mb_queue_sm4_ccm_decrypt *queue);
632-
639+
# endif /* ENABLE_QAT_SW_SM4_CCM */
633640
#endif /* QAT_SW_QUEUE_H */

qat_sw_request.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,12 @@
6161
/* Crypto_mb includes */
6262
#include "crypto_mb/sm3.h"
6363
#include "crypto_mb/sm4.h"
64-
# include "crypto_mb/sm4_gcm.h"
65-
# include "crypto_mb/sm4_ccm.h"
66-
64+
# ifdef ENABLE_QAT_SW_SM4_GCM
65+
# include "crypto_mb/sm4_gcm.h"
66+
# endif
67+
# ifdef ENABLE_QAT_SW_SM4_CCM
68+
# include "crypto_mb/sm4_ccm.h"
69+
# endif
6770
#define X25519_KEYLEN 32
6871
#define MAX_KEYLEN 57
6972
#define IV_LEN 16
@@ -292,6 +295,7 @@ typedef struct _sm4_cbc_cipher_op_data {
292295
int in_enc;
293296
} sm4_cbc_cipher_op_data;
294297

298+
# ifdef ENABLE_QAT_SW_SM4_GCM
295299
typedef struct _sm4_gcm_encrypt_op_data {
296300
struct _sm4_gcm_encrypt_op_data *next;
297301
struct _sm4_gcm_encrypt_op_data *prev;
@@ -329,7 +333,9 @@ typedef struct _sm4_gcm_decrypt_op_data {
329333
int sm4_taglen;
330334
int *sts;
331335
} sm4_gcm_decrypt_op_data;
336+
# endif
332337

338+
# ifdef ENABLE_QAT_SW_SM4_CCM
333339
typedef struct _sm4_ccm_encrypt_op_data {
334340
struct _sm4_ccm_encrypt_op_data *next;
335341
struct _sm4_ccm_encrypt_op_data *prev;
@@ -369,5 +375,5 @@ typedef struct _sm4_ccm_decrypt_op_data {
369375
int sm4_msglen;
370376
int *sts;
371377
} sm4_ccm_decrypt_op_data;
372-
378+
# endif /* ENABLE_QAT_SW_SM4_CCM */
373379
#endif /* QAT_SW_REQUEST_H */

qat_sw_sm4_ccm.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@
6666
#include "qat_sw_sm4_ccm.h"
6767

6868
/* Crypto_mb includes */
69-
#include "crypto_mb/sm4.h"
70-
#include "crypto_mb/sm4_ccm.h"
69+
#ifdef ENABLE_QAT_SW_SM4_CCM
70+
#include "crypto_mb/sm4_ccm.h"
71+
#endif
7172
#include "crypto_mb/cpu_features.h"
7273

7374
#ifdef ENABLE_QAT_SW_SM4_CCM
74-
#if !defined(QAT_OPENSSL_3) && !defined(QAT_OPENSSL_PROVIDER)
7575

7676
# define GET_SW_CIPHER(ctx) \
7777
sm4_cipher_sw_impl(EVP_CIPHER_CTX_nid((ctx)))
@@ -1138,5 +1138,4 @@ int qat_sw_sm4_ccm_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
11381138
}
11391139
return ret_val;
11401140
}
1141-
#endif
11421141
#endif

qat_sw_sm4_gcm.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,13 @@
6565
#include "qat_sw_sm4_gcm.h"
6666

6767
/* Crypto_mb includes */
68-
#include "crypto_mb/sm4.h"
69-
#include "crypto_mb/sm4_gcm.h"
68+
69+
#ifdef ENABLE_QAT_SW_SM4_GCM
70+
#include "crypto_mb/sm4_gcm.h"
71+
#endif
7072
#include "crypto_mb/cpu_features.h"
7173

7274
#ifdef ENABLE_QAT_SW_SM4_GCM
73-
# if !defined(QAT_OPENSSL_3) && !defined(QAT_OPENSSL_PROVIDER)
7475

7576
# define GET_SW_CIPHER(ctx) \
7677
sm4_cipher_sw_impl(EVP_CIPHER_CTX_nid((ctx)))
@@ -241,11 +242,9 @@ void process_mb_sm4_gcm_encrypt_reqs(mb_thread_data *tlv)
241242
STOP_RDTSC(&sm4_gcm_cycles_encrypt_execute, 1, "[SM4_GCM:encrypt_execute]");
242243
DEBUG("Processed SM4_GCM encrypt Request\n");
243244
}
244-
# endif
245245
#endif /* ENABLE_QAT_SW_SM4_GCM */
246246

247247
#ifdef ENABLE_QAT_SW_SM4_GCM
248-
# if !defined(QAT_OPENSSL_3) && !defined(QAT_OPENSSL_PROVIDER)
249248
int qat_sw_sm4_gcm_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
250249
const unsigned char *iv, int enc)
251250
{
@@ -1234,5 +1233,4 @@ int qat_sw_sm4_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
12341233
err:
12351234
return sts;
12361235
}
1237-
# endif
12381236
#endif /* ENABLE_QAT_SW_SM4_GCM */

0 commit comments

Comments
 (0)