18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * CAAM/SEC 4.x definitions for handling key-generation jobs 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright 2008-2011 Freescale Semiconductor, Inc. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci/** 108c2ecf20Sopenharmony_ci * split_key_len - Compute MDHA split key length for a given algorithm 118c2ecf20Sopenharmony_ci * @hash: Hashing algorithm selection, one of OP_ALG_ALGSEL_* - MD5, SHA1, 128c2ecf20Sopenharmony_ci * SHA224, SHA384, SHA512. 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * Return: MDHA split key length 158c2ecf20Sopenharmony_ci */ 168c2ecf20Sopenharmony_cistatic inline u32 split_key_len(u32 hash) 178c2ecf20Sopenharmony_ci{ 188c2ecf20Sopenharmony_ci /* Sizes for MDHA pads (*not* keys): MD5, SHA1, 224, 256, 384, 512 */ 198c2ecf20Sopenharmony_ci static const u8 mdpadlen[] = { 16, 20, 32, 32, 64, 64 }; 208c2ecf20Sopenharmony_ci u32 idx; 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci idx = (hash & OP_ALG_ALGSEL_SUBMASK) >> OP_ALG_ALGSEL_SHIFT; 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci return (u32)(mdpadlen[idx] * 2); 258c2ecf20Sopenharmony_ci} 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci/** 288c2ecf20Sopenharmony_ci * split_key_pad_len - Compute MDHA split key pad length for a given algorithm 298c2ecf20Sopenharmony_ci * @hash: Hashing algorithm selection, one of OP_ALG_ALGSEL_* - MD5, SHA1, 308c2ecf20Sopenharmony_ci * SHA224, SHA384, SHA512. 318c2ecf20Sopenharmony_ci * 328c2ecf20Sopenharmony_ci * Return: MDHA split key pad length 338c2ecf20Sopenharmony_ci */ 348c2ecf20Sopenharmony_cistatic inline u32 split_key_pad_len(u32 hash) 358c2ecf20Sopenharmony_ci{ 368c2ecf20Sopenharmony_ci return ALIGN(split_key_len(hash), 16); 378c2ecf20Sopenharmony_ci} 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_cistruct split_key_result { 408c2ecf20Sopenharmony_ci struct completion completion; 418c2ecf20Sopenharmony_ci int err; 428c2ecf20Sopenharmony_ci}; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_civoid split_key_done(struct device *dev, u32 *desc, u32 err, void *context); 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ciint gen_split_key(struct device *jrdev, u8 *key_out, 478c2ecf20Sopenharmony_ci struct alginfo * const adata, const u8 *key_in, u32 keylen, 488c2ecf20Sopenharmony_ci int max_keylen); 49