Lines Matching +full:sha3 +full:- +full:256

1 // SPDX-License-Identifier: GPL-2.0-only
51 "SHA512", "SHA512/224", "SHA512/256", "SHA3-224", "SHA3-256",
52 "SHA3-384", "SHA3-512"
55 static char *spu2_hash_mode_names[] = { "CMAC", "CBC-MAC", "XCBC-MAC", "HMAC",
120 return -EINVAL; in spu2_cipher_mode_xlate()
126 * spu2_cipher_xlate() - Convert a cipher {alg/mode/type} triple to a SPU2
156 err = -EINVAL; in spu2_cipher_xlate()
177 err = -EINVAL; in spu2_cipher_xlate()
182 err = -EINVAL; in spu2_cipher_xlate()
216 return -EINVAL; in spu2_hash_mode_xlate()
222 * spu2_hash_xlate() - Convert a hash {alg/mode/type} triple to a SPU2 hash type
280 err = -EINVAL; in spu2_hash_xlate()
297 err = -EINVAL; in spu2_hash_xlate()
470 spu2_dump_fmd_ctrl0(le64_to_cpu(fmd->ctrl0)); in spu2_dump_fmd()
471 spu2_dump_fmd_ctrl1(le64_to_cpu(fmd->ctrl1)); in spu2_dump_fmd()
472 spu2_dump_fmd_ctrl2(le64_to_cpu(fmd->ctrl2)); in spu2_dump_fmd()
473 spu2_dump_fmd_ctrl3(le64_to_cpu(fmd->ctrl3)); in spu2_dump_fmd()
525 ctrl1 = le64_to_cpu(fmd->ctrl1); in spu2_dump_msg_hdr()
544 * spu2_fmd_init() - At setkey time, initialize the fixed meta data for
589 fmd->ctrl0 = cpu_to_le64(ctrl0); in spu2_fmd_init()
590 fmd->ctrl1 = cpu_to_le64(ctrl1); in spu2_fmd_init()
591 fmd->ctrl2 = cpu_to_le64(ctrl2); in spu2_fmd_init()
592 fmd->ctrl3 = cpu_to_le64(ctrl3); in spu2_fmd_init()
598 * spu2_fmd_ctrl0_write() - Write ctrl0 field in fixed metadata (FMD) field of
637 fmd->ctrl0 = cpu_to_le64(ctrl0); in spu2_fmd_ctrl0_write()
641 * spu2_fmd_ctrl1_write() - Write ctrl1 field in fixed metadata (FMD) field of
718 fmd->ctrl1 = cpu_to_le64(ctrl1); in spu2_fmd_ctrl1_write()
722 * spu2_fmd_ctrl2_write() - Set the ctrl2 field in the fixed metadata field of
752 fmd->ctrl2 = cpu_to_le64(ctrl2); in spu2_fmd_ctrl2_write()
756 * spu2_fmd_ctrl3_write() - Set the ctrl3 field in FMD
766 fmd->ctrl3 = cpu_to_le64(ctrl3); in spu2_fmd_ctrl3_write()
770 * spu2_ctx_max_payload() - Determine the maximum length of the payload for a
791 return SPU2_MAX_PAYLOAD - excess; in spu2_ctx_max_payload()
798 * spu2_payload_length() - Given a SPU2 message header, extract the payload
810 ctrl3 = le64_to_cpu(fmd->ctrl3); in spu2_payload_length()
817 * spu2_response_hdr_len() - Determine the expected length of a SPU response
833 * spu2_hash_pad_len() - Calculate the length of hash padding required to extend
851 * spu2_gcm_ccm_pad_len() - Determine the length of GCM/CCM padding for either
856 * Return: 0. Unlike SPU-M, SPU2 hardware does any GCM/CCM padding required.
865 * spu2_assoc_resp_len() - Determine the size of the AAD2 buffer needed to catch
881 /* gcm aes esp has to write 8-byte IV in response */ in spu2_assoc_resp_len()
887 * spu2_aead_ivlen() - Calculate the length of the AEAD IV to be included
903 * spu2_hash_type() - Determine the type of hash operation.
915 * spu2_digest_size() - Determine the size of a hash digest to expect the SPU to
929 * spu2_create_request() - Build a SPU2 request message header, includint FMD and
940 * in DMA-able memory at least SPU_HEADER_ALLOC_LEN bytes long.
964 hash_parms->prebuf_len + data_size + hash_parms->pad_len - in spu2_create_request()
965 ((req_opts->is_aead && req_opts->is_inbound) ? in spu2_create_request()
966 hash_parms->digestsize : 0); in spu2_create_request()
969 unsigned int cipher_offset = aead_parms->assoc_size + in spu2_create_request()
970 aead_parms->aad_pad_len + aead_parms->iv_len; in spu2_create_request()
973 unsigned int real_db_size = spu_real_db_size(aead_parms->assoc_size, in spu2_create_request()
974 aead_parms->iv_len, in spu2_create_request()
975 hash_parms->prebuf_len, in spu2_create_request()
977 aead_parms->aad_pad_len, in spu2_create_request()
978 aead_parms->data_pad_len, in spu2_create_request()
979 hash_parms->pad_len); in spu2_create_request()
980 unsigned int assoc_size = aead_parms->assoc_size; in spu2_create_request()
982 if (req_opts->is_aead && in spu2_create_request()
983 (cipher_parms->alg == CIPHER_ALG_AES) && in spu2_create_request()
984 (cipher_parms->mode == CIPHER_MODE_GCM)) in spu2_create_request()
989 req_opts->auth_first = req_opts->is_inbound; in spu2_create_request()
992 if (req_opts->is_aead && in spu2_create_request()
993 (cipher_parms->alg == CIPHER_ALG_AES) && in spu2_create_request()
994 (cipher_parms->mode == CIPHER_MODE_CCM)) in spu2_create_request()
995 req_opts->auth_first = !req_opts->is_inbound; in spu2_create_request()
999 req_opts->is_inbound, req_opts->auth_first); in spu2_create_request()
1000 flow_log(" cipher alg:%u mode:%u type %u\n", cipher_parms->alg, in spu2_create_request()
1001 cipher_parms->mode, cipher_parms->type); in spu2_create_request()
1002 flow_log(" is_esp: %s\n", req_opts->is_esp ? "yes" : "no"); in spu2_create_request()
1003 flow_log(" key: %d\n", cipher_parms->key_len); in spu2_create_request()
1004 flow_dump(" key: ", cipher_parms->key_buf, cipher_parms->key_len); in spu2_create_request()
1005 flow_log(" iv: %d\n", cipher_parms->iv_len); in spu2_create_request()
1006 flow_dump(" iv: ", cipher_parms->iv_buf, cipher_parms->iv_len); in spu2_create_request()
1008 hash_parms->alg, hash_parms->mode, hash_parms->type); in spu2_create_request()
1009 flow_log(" digestsize: %u\n", hash_parms->digestsize); in spu2_create_request()
1010 flow_log(" authkey: %d\n", hash_parms->key_len); in spu2_create_request()
1011 flow_dump(" authkey: ", hash_parms->key_buf, hash_parms->key_len); in spu2_create_request()
1013 flow_log(" prebuf_len:%u\n", hash_parms->prebuf_len); in spu2_create_request()
1015 flow_log(" hash_pad_len:%u\n", hash_parms->pad_len); in spu2_create_request()
1019 flow_log(" aead_iv: %u\n", aead_parms->iv_len); in spu2_create_request()
1022 err = spu2_cipher_xlate(cipher_parms->alg, cipher_parms->mode, in spu2_create_request()
1023 cipher_parms->type, in spu2_create_request()
1026 /* If we are doing GCM hashing only - either via rfc4543 transform in spu2_create_request()
1027 * or because we happen to do GCM with AAD only and no payload - we in spu2_create_request()
1029 * and put data into payload. This is because unlike SPU-M, running in spu2_create_request()
1032 if ((req_opts->is_rfc4543) || in spu2_create_request()
1037 hash_parms->key_len = cipher_parms->key_len; in spu2_create_request()
1038 memcpy(hash_parms->key_buf, cipher_parms->key_buf, in spu2_create_request()
1039 cipher_parms->key_len); in spu2_create_request()
1040 cipher_parms->key_len = 0; in spu2_create_request()
1042 if (req_opts->is_rfc4543) in spu2_create_request()
1057 err = spu2_hash_xlate(hash_parms->alg, hash_parms->mode, in spu2_create_request()
1058 hash_parms->type, in spu2_create_request()
1059 cipher_parms->type, in spu2_create_request()
1070 spu2_fmd_ctrl0_write(fmd, req_opts->is_inbound, req_opts->auth_first, in spu2_create_request()
1074 spu2_fmd_ctrl1_write(fmd, req_opts->is_inbound, assoc_size, in spu2_create_request()
1075 hash_parms->key_len, cipher_parms->key_len, in spu2_create_request()
1077 aead_parms->return_iv, aead_parms->ret_iv_len, in spu2_create_request()
1078 aead_parms->ret_iv_off, in spu2_create_request()
1079 cipher_parms->iv_len, hash_parms->digestsize, in spu2_create_request()
1080 !req_opts->bd_suppress, return_md); in spu2_create_request()
1082 spu2_fmd_ctrl2_write(fmd, cipher_offset, hash_parms->key_len, 0, in spu2_create_request()
1083 cipher_parms->key_len, cipher_parms->iv_len); in spu2_create_request()
1091 if (hash_parms->key_len) { in spu2_create_request()
1092 memcpy(ptr, hash_parms->key_buf, hash_parms->key_len); in spu2_create_request()
1093 ptr += hash_parms->key_len; in spu2_create_request()
1094 buf_len += hash_parms->key_len; in spu2_create_request()
1096 if (cipher_parms->key_len) { in spu2_create_request()
1097 memcpy(ptr, cipher_parms->key_buf, cipher_parms->key_len); in spu2_create_request()
1098 ptr += cipher_parms->key_len; in spu2_create_request()
1099 buf_len += cipher_parms->key_len; in spu2_create_request()
1101 if (cipher_parms->iv_len) { in spu2_create_request()
1102 memcpy(ptr, cipher_parms->iv_buf, cipher_parms->iv_len); in spu2_create_request()
1103 ptr += cipher_parms->iv_len; in spu2_create_request()
1104 buf_len += cipher_parms->iv_len; in spu2_create_request()
1113 * spu2_cipher_req_init() - Build an skcipher SPU2 request message header,
1120 * Caller should allocate this buffer in DMA-able memory at least
1135 flow_log(" cipher alg:%u mode:%u type %u\n", cipher_parms->alg, in spu2_cipher_req_init()
1136 cipher_parms->mode, cipher_parms->type); in spu2_cipher_req_init()
1137 flow_log(" cipher_iv_len: %u\n", cipher_parms->iv_len); in spu2_cipher_req_init()
1138 flow_log(" key: %d\n", cipher_parms->key_len); in spu2_cipher_req_init()
1139 flow_dump(" key: ", cipher_parms->key_buf, cipher_parms->key_len); in spu2_cipher_req_init()
1142 err = spu2_cipher_xlate(cipher_parms->alg, cipher_parms->mode, in spu2_cipher_req_init()
1143 cipher_parms->type, &spu2_type, &spu2_mode); in spu2_cipher_req_init()
1153 err = spu2_fmd_init(fmd, spu2_type, spu2_mode, cipher_parms->key_len, in spu2_cipher_req_init()
1154 cipher_parms->iv_len); in spu2_cipher_req_init()
1160 if (cipher_parms->key_buf && cipher_parms->key_len) in spu2_cipher_req_init()
1161 memcpy(omd, cipher_parms->key_buf, cipher_parms->key_len); in spu2_cipher_req_init()
1164 FMD_SIZE + cipher_parms->key_len + cipher_parms->iv_len); in spu2_cipher_req_init()
1166 return FMD_SIZE + cipher_parms->key_len + cipher_parms->iv_len; in spu2_cipher_req_init()
1170 * spu2_cipher_req_finish() - Finish building a SPU request message header for a
1195 flow_log(" cipher alg: %u, cipher_type: %u\n", cipher_parms->alg, in spu2_cipher_req_finish()
1196 cipher_parms->type); in spu2_cipher_req_finish()
1197 flow_log(" iv len: %d\n", cipher_parms->iv_len); in spu2_cipher_req_finish()
1198 flow_dump(" iv: ", cipher_parms->iv_buf, cipher_parms->iv_len); in spu2_cipher_req_finish()
1208 ctrl0 = le64_to_cpu(fmd->ctrl0); in spu2_cipher_req_finish()
1213 fmd->ctrl0 = cpu_to_le64(ctrl0); in spu2_cipher_req_finish()
1215 if (cipher_parms->alg && cipher_parms->iv_buf && cipher_parms->iv_len) { in spu2_cipher_req_finish()
1217 memcpy(omd + cipher_parms->key_len, cipher_parms->iv_buf, in spu2_cipher_req_finish()
1218 cipher_parms->iv_len); in spu2_cipher_req_finish()
1221 ctrl3 = le64_to_cpu(fmd->ctrl3); in spu2_cipher_req_finish()
1224 fmd->ctrl3 = cpu_to_le64(ctrl3); in spu2_cipher_req_finish()
1230 * spu2_request_pad() - Create pad bytes at the end of the data.
1240 * 1. GCM pad - for GCM mode ciphers, pad to 16-byte alignment
1241 * 2. hash pad - pad to a block length, with 0x80 data terminator and
1243 * 3. STAT pad - to ensure the STAT field is 4-byte aligned
1265 ptr += (hash_pad_len - sizeof(u64)); in spu2_request_pad()
1270 else /* SHA1, SHA2-224, SHA2-256 */ in spu2_request_pad()
1286 * spu2_xts_tweak_in_payload() - Indicate that SPU2 does NOT place the XTS
1297 * spu2_tx_status_len() - Return the length of the STATUS field in a SPU
1308 * spu2_rx_status_len() - Return the length of the STATUS field in a SPU
1319 * spu2_status_process() - Process the status from a SPU response message.
1322 * Return: 0 - if status is good and response should be processed
1323 * !0 - status indicates an error and response is invalid
1327 /* SPU2 status is 2 bytes by default - SPU_RX_STATUS_LEN */ in spu2_status_process()
1337 return -EBADMSG; in spu2_status_process()
1341 * spu2_ccm_update_iv() - Update the IV as per the requirements for CCM mode.
1360 * testmgr contains (L-1) in bottom 3 bits of first byte, in spu2_ccm_update_iv()
1366 L = ((cipher_parms->iv_buf[0] & CCM_B0_L_PRIME) >> in spu2_ccm_update_iv()
1370 cipher_parms->iv_len -= (1 + L); in spu2_ccm_update_iv()
1371 memmove(cipher_parms->iv_buf, &cipher_parms->iv_buf[1], in spu2_ccm_update_iv()
1372 cipher_parms->iv_len); in spu2_ccm_update_iv()
1376 * spu2_wordalign_padlen() - SPU2 does not require padding.