Debian Codegraph @

kernel-patches/4.14-rc1/kpp/v2-0004-crypto-KPP-add-API-crypto_kpp_set_params.patch

raw
1 From f55869aea48350375d08c89a23f0a19562abf701 Mon Sep 17 00:00:00 2001
2 From: Stephan Mueller <[email protected]>
3 Date: Thu, 28 Sep 2017 03:16:50 +0200
4 Subject: [PATCH v2 4/8] crypto: KPP - add API crypto_kpp_set_params
5
6 KPP mechanisms like DH require a parameter set to be provided by the
7 caller. That parameter set may be provided by the crypto_kpp_set_secret
8 function. Yet, the parameters hare handled independently from the secret
9 key which implies that they should be able to be set independently from
10 the key.
11
12 The new API allows KPP mechanisms to register a callback allowing to set
13 such parameters.
14
15 Signed-off-by: Stephan Mueller <[email protected]>
16 ---
17 Documentation/crypto/api-kpp.rst | 2 +-
18 include/crypto/kpp.h | 28 ++++++++++++++++++++++++++++
19 2 files changed, 29 insertions(+), 1 deletion(-)
20
21 diff --git a/Documentation/crypto/api-kpp.rst b/Documentation/crypto/api-kpp.rst
22 index 7d86ab906bdf..7b2c0d4a9d4a 100644
23 --- a/Documentation/crypto/api-kpp.rst
24 +++ b/Documentation/crypto/api-kpp.rst
25 @@ -11,7 +11,7 @@ Key-agreement Protocol Primitives (KPP) Cipher API
26 :doc: Generic Key-agreement Protocol Primitives API
27
28 .. kernel-doc:: include/crypto/kpp.h
29 - :functions: crypto_alloc_kpp crypto_free_kpp crypto_kpp_set_secret crypto_kpp_generate_public_key crypto_kpp_compute_shared_secret crypto_kpp_maxsize
30 + :functions: crypto_alloc_kpp crypto_free_kpp crypto_kpp_set_params crypto_kpp_set_secret crypto_kpp_generate_public_key crypto_kpp_compute_shared_secret crypto_kpp_maxsize
31
32 Key-agreement Protocol Primitives (KPP) Cipher Request Handle
33 -------------------------------------------------------------
34 diff --git a/include/crypto/kpp.h b/include/crypto/kpp.h
35 index 1bde0a6514fa..88a9cf4c0179 100644
36 --- a/include/crypto/kpp.h
37 +++ b/include/crypto/kpp.h
38 @@ -51,6 +51,9 @@ struct crypto_kpp {
39 /**
40 * struct kpp_alg - generic key-agreement protocol primitives
41 *
42 + * @set_params: Function allows the caller to set the parameters
43 + * separately from the key. The format of the parameters
44 + * is protocol specific.
45 * @set_secret: Function invokes the protocol specific function to
46 * store the secret private key along with parameters.
47 * The implementation knows how to decode the buffer
48 @@ -74,6 +77,8 @@ struct crypto_kpp {
49 * @base: Common crypto API algorithm data structure
50 */
51 struct kpp_alg {
52 + int (*set_params)(struct crypto_kpp *tfm, const void *buffer,
53 + unsigned int len);
54 int (*set_secret)(struct crypto_kpp *tfm, const void *buffer,
55 unsigned int len);
56 int (*generate_public_key)(struct kpp_request *req);
57 @@ -269,6 +274,29 @@ struct kpp_secret {
58 };
59
60 /**
61 + * crypto_kpp_set_params() - Set parameters needed for kpp operation
62 + *
63 + * Function invokes the specific kpp operation for a given alg.
64 + *
65 + * @tfm: tfm handle
66 + * @buffer: Buffer holding the protocol specific representation of the
67 + * parameters (e.g. PKCS#3 DER for DH)
68 + * @len: Length of the parameter buffer.
69 + *
70 + * Return: zero on success; error code in case of error
71 + */
72 +static inline int crypto_kpp_set_params(struct crypto_kpp *tfm,
73 + const void *buffer, unsigned int len)
74 +{
75 + struct kpp_alg *alg = crypto_kpp_alg(tfm);
76 +
77 + if (alg->set_params)
78 + return alg->set_params(tfm, buffer, len);
79 + else
80 + return -EOPNOTSUPP;
81 +}
82 +
83 +/**
84 * crypto_kpp_set_secret() - Invoke kpp operation
85 *
86 * Function invokes the specific kpp operation for a given alg.
87 --
88 2.13.5
89