^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * CAAM/SEC 4.x definitions for handling key-generation jobs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2008-2011 Freescale Semiconductor, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * split_key_len - Compute MDHA split key length for a given algorithm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * @hash: Hashing algorithm selection, one of OP_ALG_ALGSEL_* - MD5, SHA1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * SHA224, SHA384, SHA512.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Return: MDHA split key length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) static inline u32 split_key_len(u32 hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) /* Sizes for MDHA pads (*not* keys): MD5, SHA1, 224, 256, 384, 512 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) static const u8 mdpadlen[] = { 16, 20, 32, 32, 64, 64 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) u32 idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) idx = (hash & OP_ALG_ALGSEL_SUBMASK) >> OP_ALG_ALGSEL_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) return (u32)(mdpadlen[idx] * 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * split_key_pad_len - Compute MDHA split key pad length for a given algorithm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * @hash: Hashing algorithm selection, one of OP_ALG_ALGSEL_* - MD5, SHA1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * SHA224, SHA384, SHA512.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * Return: MDHA split key pad length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static inline u32 split_key_pad_len(u32 hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) return ALIGN(split_key_len(hash), 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct split_key_result {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct completion completion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) void split_key_done(struct device *dev, u32 *desc, u32 err, void *context);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) int gen_split_key(struct device *jrdev, u8 *key_out,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct alginfo * const adata, const u8 *key_in, u32 keylen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) int max_keylen);