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