| 1 |
From f1bbe83893f1baba17d8b21d4aa434d8fdd6742c 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 v3 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 |
@@ -268,6 +273,29 @@ struct kpp_secret { |
| 58 |
unsigned short len; |
| 59 |
}; |
| 60 |
|
| 61 |
+/** |
| 62 |
+ * crypto_kpp_set_params() - Set parameters needed for kpp operation |
| 63 |
+ * |
| 64 |
+ * Function invokes the specific kpp operation for a given alg. |
| 65 |
+ * |
| 66 |
+ * @tfm: tfm handle |
| 67 |
+ * @buffer: Buffer holding the protocol specific representation of the |
| 68 |
+ * parameters (e.g. PKCS#3 DER for DH) |
| 69 |
+ * @len: Length of the parameter buffer. |
| 70 |
+ * |
| 71 |
+ * Return: zero on success; error code in case of error |
| 72 |
+ */ |
| 73 |
+static inline int crypto_kpp_set_params(struct crypto_kpp *tfm, |
| 74 |
+ const void *buffer, unsigned int len) |
| 75 |
+{ |
| 76 |
+ struct kpp_alg *alg = crypto_kpp_alg(tfm); |
| 77 |
+ |
| 78 |
+ if (alg->set_params) |
| 79 |
+ return alg->set_params(tfm, buffer, len); |
| 80 |
+ else |
| 81 |
+ return -EOPNOTSUPP; |
| 82 |
+} |
| 83 |
+ |
| 84 |
/** |
| 85 |
* crypto_kpp_set_secret() - Invoke kpp operation |
| 86 |
* |
| 87 |
-- |
| 88 |
2.14.3 |
| 89 |
|