Skip to content

Commit

Permalink
Add SHA3-224/256/384/512 support using QAT_HW
Browse files Browse the repository at this point in the history
Signed-off-by: Yogaraj Alamenda <yogarajx.alamenda@intel.com>
  • Loading branch information
Hemachander authored and Yogaraj-Alamenda committed Sep 17, 2021
1 parent c34ac30 commit d10a26f
Show file tree
Hide file tree
Showing 17 changed files with 1,875 additions and 357 deletions.
5 changes: 3 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ if QAT_HW
qat_hw_dsa.c \
qat_hw_ec.c \
qat_hw_prf.c \
qat_hw_gcm.c
qat_hw_gcm.c \
qat_hw_sha3.c

if !QAT_OPENSSL_110
QAT_HW_111_SRC = qat_hw_hkdf.c \
Expand Down Expand Up @@ -91,7 +92,7 @@ AM_CFLAGS = $(cflags) $(cflags_cc_opt) $(cflags_qat_debug_file) \
$(enable_qat_auto_engine_init_on_fork) \
$(enable_qat_debug) $(enable_qat_warnings) \
$(enable_qat_mem_debug) $(enable_qat_mem_warnings) \
$(enable_qat_cycle_counts)
$(enable_qat_cycle_counts) $(enable_qat_hw_sha3)


qatengine_la_LDFLAGS = -module -no-undefined -avoid-version \
Expand Down
14 changes: 14 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ AC_ARG_ENABLE(qat_hw_gcm,
[Enable qat_hw AES-GCM acceleration (experimental)]))
AC_SUBST(enable_qat_hw_gcm)

AC_ARG_ENABLE(qat_hw_sha3,
AS_HELP_STRING([--disable-qat_hw_sha3],
[Disable qat_hw SHA3 offload]))
AC_SUBST(enable_qat_hw_sha3)

AC_ARG_ENABLE(qat_sw_gcm,
AS_HELP_STRING([--disable-qat_sw_gcm],
[Disable qat_sw AES-GCM acceleration]))
Expand Down Expand Up @@ -565,6 +570,15 @@ fi
fi
fi

if test "x$enable_qat_hw_sha3" != "xno" -a "x$cflags_qat_hw" != "x"
then
enable_qat_hw_sha3="-DENABLE_QAT_HW_SHA3"
AC_MSG_NOTICE([Accelerating SHA3 to Hardware])
else
enable_qat_hw_sha3="-DDISABLE_QAT_HW_SHA3"
AC_MSG_NOTICE([Not Accelerating SHA3 to Hardware])
fi

if test "x$enable_qat_hw_small_pkt_offload" = "xyes" -a "x$cflags_qat_hw" != "x"
then
enable_qat_hw_small_pkt_offload="-DENABLE_QAT_HW_SMALL_PKT_OFFLOAD"
Expand Down
7 changes: 7 additions & 0 deletions e_qat.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,13 @@ static int bind_qat(ENGINE *e, const char *id)
goto end;
}
# endif

# ifdef ENABLE_QAT_HW_SHA3
if (!ENGINE_set_digests(e, qat_digest_methods)) {
WARN("ENGINE_set_digests failed\n");
goto end;
}
# endif
#endif
}

Expand Down
334 changes: 171 additions & 163 deletions e_qat.txt

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions e_qat_err.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ static ERR_STRING_DATA QAT_str_functs[] = {
"qat_set_affine_coordinates"},
{ERR_PACK(0, QAT_F_QAT_SET_INSTANCE_FOR_THREAD, 0),
"qat_set_instance_for_thread"},
{ERR_PACK(0, QAT_F_QAT_SHA3_CLEANUP, 0), "qat_sha3_cleanup"},
{ERR_PACK(0, QAT_F_QAT_SHA3_CTRL, 0), "qat_sha3_ctrl"},
{ERR_PACK(0, QAT_F_QAT_SHA3_FINAL, 0), "qat_sha3_final"},
{ERR_PACK(0, QAT_F_QAT_SHA3_SESSION_DATA_INIT, 0),
"qat_sha3_session_data_init"},
{ERR_PACK(0, QAT_F_QAT_SHA3_SETUP_PARAM, 0), "qat_sha3_setup_param"},
{ERR_PACK(0, QAT_F_QAT_SHA3_UPDATE, 0), "qat_sha3_update"},
{ERR_PACK(0, QAT_F_QAT_SYM_PERFORM_OP, 0), "qat_sym_perform_op"},
{ERR_PACK(0, QAT_F_QAT_VALIDATE_ECX_DERIVE, 0), "qat_validate_ecx_derive"},
{ERR_PACK(0, QAT_F_QAT_X25519_PMETH, 0), "qat_x25519_pmeth"},
Expand Down Expand Up @@ -236,6 +243,7 @@ static ERR_STRING_DATA QAT_str_reasons[] = {
"instance handle malloc failure"},
{ERR_PACK(0, 0, QAT_R_INSTANCE_UNAVAILABLE), "instance unavailable"},
{ERR_PACK(0, 0, QAT_R_INVALID_CTRL_TYPE), "invalid ctrl type"},
{ERR_PACK(0, 0, QAT_R_INVALID_HASH_DATA), "invalid hash data"},
{ERR_PACK(0, 0, QAT_R_INVALID_INPUT_PARAMETER), "invalid input parameter"},
{ERR_PACK(0, 0, QAT_R_INVALID_IVLEN), "invalid ivlen"},
{ERR_PACK(0, 0, QAT_R_INVALID_LEN), "invalid len"},
Expand Down Expand Up @@ -424,6 +432,7 @@ static ERR_STRING_DATA QAT_str_reasons[] = {
{ERR_PACK(0, 0, QAT_R_SET_QAT_RSA_METH_FAILURE),
"set qat rsa meth failure"},
{ERR_PACK(0, 0, QAT_R_SET_TAG_INVALID_OP), "set tag invalid op"},
{ERR_PACK(0, 0, QAT_R_SHA3_CTX_NULL), "sha3 ctx null"},
{ERR_PACK(0, 0, QAT_R_SIG_GET_R_S_FAILURE), "sig get r s failure"},
{ERR_PACK(0, 0, QAT_R_SIG_MALLOC_FAILURE), "sig malloc failure"},
{ERR_PACK(0, 0, QAT_R_SSD_MALLOC_FAILURE), "ssd malloc failure"},
Expand Down
334 changes: 171 additions & 163 deletions e_qat_err.h

Large diffs are not rendered by default.

90 changes: 90 additions & 0 deletions qat_evp.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#ifdef QAT_HW
# include "qat_hw_ciphers.h"
# include "qat_hw_gcm.h"
# include "qat_hw_sha3.h"
#endif

#ifdef QAT_SW_IPSEC
Expand Down Expand Up @@ -139,6 +140,95 @@ int qat_evp_nids[] = {
};
const int num_evp_nids = sizeof(qat_evp_nids) / sizeof(qat_evp_nids[0]);

typedef struct _digest_data {
const int m_type;
const int pkey_type;
} sha3_data;

static sha3_data data[] = {
#ifdef QAT_HW
{ NID_sha3_224, NID_RSA_SHA3_224},
{ NID_sha3_256, NID_RSA_SHA3_256},
{ NID_sha3_384, NID_RSA_SHA3_384},
{ NID_sha3_512, NID_RSA_SHA3_512},
#endif
};

/* QAT SHA3 function register */
int qat_sha3_nids[] = {
#ifdef QAT_HW
NID_sha3_224,
NID_sha3_256,
NID_sha3_384,
NID_sha3_512,
#endif
};
const int num_sha3_nids = sizeof(qat_sha3_nids) / sizeof(qat_sha3_nids[0]);


/******************************************************************************
* function:
* qat_create_digest_meth(int nid , int pkeytype)
*
* @param nid [IN] - EVP operation id
*
* description:
* Creates qat EVP MD methods for the nid
******************************************************************************/
static const EVP_MD *qat_create_digest_meth(int nid , int pkeytype)
{
switch (nid) {
case NID_sha3_224:
case NID_sha3_256:
case NID_sha3_384:
case NID_sha3_512:
if (qat_hw_offload)
return qat_create_sha3_meth(nid , pkeytype);
default:
WARN("Invalid nid %d\n", nid);
return NULL;
}
}
/******************************************************************************
* function:
* qat_digest_methods(ENGINE *e,
* const EVP_MD **md,
* const int **nids,
* int nid)
*
* @param e [IN] - OpenSSL engine pointer
* @param pmeth [IN] - EVP methods structure pointer
* @param nids [IN] - EVP function nids
* @param nid [IN] - EVP operation id
*
* description:
* QAT engine digest operations register.
******************************************************************************/
int qat_digest_methods(ENGINE *e, const EVP_MD **md,
const int **nids, int nid)
{
int i;
if (md == NULL) {
if (unlikely(nids == NULL)) {
WARN("Invalid input params.\n");
return 0;
}
*nids = qat_sha3_nids;
return num_sha3_nids;
}

for (i = 0; i < num_sha3_nids; i++) {
if (nid == qat_sha3_nids[i]) {
*md = qat_create_digest_meth( data[i].m_type , data[i].pkey_type);
return 1;
}
}

WARN("NID %d not supported\n", nid);
*md = NULL;
return 0;
}

/******************************************************************************
* function:
* qat_create_pkey_meth(int nid)
Expand Down
2 changes: 2 additions & 0 deletions qat_evp.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@

int qat_pkey_methods(ENGINE *e, EVP_PKEY_METHOD **pmeth,
const int **nids, int nid);
int qat_digest_methods(ENGINE *e, const EVP_MD **md,
const int **nids, int nid);
EVP_PKEY_METHOD *qat_prf_pmeth(void);
EVP_PKEY_METHOD *qat_hkdf_pmeth(void);
EVP_PKEY_METHOD *qat_x25519_pmeth(void);
Expand Down

0 comments on commit d10a26f

Please sign in to comment.