aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/crypto/api-kpp.rst92
-rw-r--r--Documentation/crypto/api.rst1
-rw-r--r--Documentation/crypto/architecture.rst6
-rw-r--r--include/crypto/dh.h58
-rw-r--r--include/crypto/ecdh.h58
-rw-r--r--include/crypto/kpp.h15
6 files changed, 227 insertions, 3 deletions
diff --git a/Documentation/crypto/api-kpp.rst b/Documentation/crypto/api-kpp.rst
new file mode 100644
index 000000000000..d87be9224f49
--- /dev/null
+++ b/Documentation/crypto/api-kpp.rst
@@ -0,0 +1,92 @@
1Key-agreement Protocol Primitives (KPP) Cipher Algorithm Definitions
2--------------------------------------------------------------------
3
4.. kernel-doc:: include/crypto/kpp.h
5 :functions: kpp_request
6
7.. kernel-doc:: include/crypto/kpp.h
8 :functions: crypto_kpp
9
10.. kernel-doc:: include/crypto/kpp.h
11 :functions: kpp_alg
12
13.. kernel-doc:: include/crypto/kpp.h
14 :functions: kpp_secret
15
16Key-agreement Protocol Primitives (KPP) Cipher API
17--------------------------------------------------
18
19.. kernel-doc:: include/crypto/kpp.h
20 :doc: Generic Key-agreement Protocol Primitives API
21
22.. kernel-doc:: include/crypto/kpp.h
23 :functions: crypto_alloc_kpp
24
25.. kernel-doc:: include/crypto/kpp.h
26 :functions: crypto_free_kpp
27
28.. kernel-doc:: include/crypto/kpp.h
29 :functions: crypto_kpp_set_secret
30
31.. kernel-doc:: include/crypto/kpp.h
32 :functions: crypto_kpp_generate_public_key
33
34.. kernel-doc:: include/crypto/kpp.h
35 :functions: crypto_kpp_compute_shared_secret
36
37.. kernel-doc:: include/crypto/kpp.h
38 :functions: crypto_kpp_maxsize
39
40Key-agreement Protocol Primitives (KPP) Cipher Request Handle
41-------------------------------------------------------------
42
43.. kernel-doc:: include/crypto/kpp.h
44 :functions: kpp_request_alloc
45
46.. kernel-doc:: include/crypto/kpp.h
47 :functions: kpp_request_free
48
49.. kernel-doc:: include/crypto/kpp.h
50 :functions: kpp_request_set_callback
51
52.. kernel-doc:: include/crypto/kpp.h
53 :functions: kpp_request_set_input
54
55.. kernel-doc:: include/crypto/kpp.h
56 :functions: kpp_request_set_output
57
58ECDH Helper Functions
59---------------------
60
61.. kernel-doc:: include/crypto/ecdh.h
62 :doc: ECDH Helper Functions
63
64.. kernel-doc:: include/crypto/ecdh.h
65 :functions: ecdh
66
67.. kernel-doc:: include/crypto/ecdh.h
68 :functions: crypto_ecdh_key_len
69
70.. kernel-doc:: include/crypto/ecdh.h
71 :functions: crypto_ecdh_encode_key
72
73.. kernel-doc:: include/crypto/ecdh.h
74 :functions: crypto_ecdh_decode_key
75
76DH Helper Functions
77-------------------
78
79.. kernel-doc:: include/crypto/dh.h
80 :doc: DH Helper Functions
81
82.. kernel-doc:: include/crypto/dh.h
83 :functions: dh
84
85.. kernel-doc:: include/crypto/dh.h
86 :functions: crypto_dh_key_len
87
88.. kernel-doc:: include/crypto/dh.h
89 :functions: crypto_dh_encode_key
90
91.. kernel-doc:: include/crypto/dh.h
92 :functions: crypto_dh_decode_key
diff --git a/Documentation/crypto/api.rst b/Documentation/crypto/api.rst
index f2bbeb0fe9aa..2e519193ab4a 100644
--- a/Documentation/crypto/api.rst
+++ b/Documentation/crypto/api.rst
@@ -22,3 +22,4 @@ the IV. Different IV generators are available.
22 api-digest 22 api-digest
23 api-rng 23 api-rng
24 api-akcipher 24 api-akcipher
25 api-kpp
diff --git a/Documentation/crypto/architecture.rst b/Documentation/crypto/architecture.rst
index 34e396bbc6e6..ca2d09b991f5 100644
--- a/Documentation/crypto/architecture.rst
+++ b/Documentation/crypto/architecture.rst
@@ -161,6 +161,9 @@ applicable to a cipher, it is not displayed:
161 entry below for the specification of the IV generator type used by 161 entry below for the specification of the IV generator type used by
162 the cipher implementation) 162 the cipher implementation)
163 163
164 - kpp for a Key-agreement Protocol Primitive (KPP) cipher such as
165 an ECDH or DH implementation
166
164- blocksize: blocksize of cipher in bytes 167- blocksize: blocksize of cipher in bytes
165 168
166- keysize: key size in bytes 169- keysize: key size in bytes
@@ -219,6 +222,9 @@ the aforementioned cipher types:
219 together with an IV generator (see geniv field in the /proc/crypto 222 together with an IV generator (see geniv field in the /proc/crypto
220 listing for the known IV generators) 223 listing for the known IV generators)
221 224
225- CRYPTO_ALG_TYPE_KPP Key-agreement Protocol Primitive (KPP) such as
226 an ECDH or DH implementation
227
222- CRYPTO_ALG_TYPE_DIGEST Raw message digest 228- CRYPTO_ALG_TYPE_DIGEST Raw message digest
223 229
224- CRYPTO_ALG_TYPE_HASH Alias for CRYPTO_ALG_TYPE_DIGEST 230- CRYPTO_ALG_TYPE_HASH Alias for CRYPTO_ALG_TYPE_DIGEST
diff --git a/include/crypto/dh.h b/include/crypto/dh.h
index 5102a8f282e6..6b424ad3482e 100644
--- a/include/crypto/dh.h
+++ b/include/crypto/dh.h
@@ -13,6 +13,27 @@
13#ifndef _CRYPTO_DH_ 13#ifndef _CRYPTO_DH_
14#define _CRYPTO_DH_ 14#define _CRYPTO_DH_
15 15
16/**
17 * DOC: DH Helper Functions
18 *
19 * To use DH with the KPP cipher API, the following data structure and
20 * functions should be used.
21 *
22 * To use DH with KPP, the following functions should be used to operate on
23 * a DH private key. The packet private key that can be set with
24 * the KPP API function call of crypto_kpp_set_secret.
25 */
26
27/**
28 * struct dh - define a DH private key
29 *
30 * @key: Private DH key
31 * @p: Diffie-Hellman parameter P
32 * @g: Diffie-Hellman generator G
33 * @key_size: Size of the private DH key
34 * @p_size: Size of DH parameter P
35 * @g_size: Size of DH generator G
36 */
16struct dh { 37struct dh {
17 void *key; 38 void *key;
18 void *p; 39 void *p;
@@ -22,8 +43,45 @@ struct dh {
22 unsigned int g_size; 43 unsigned int g_size;
23}; 44};
24 45
46/**
47 * crypto_dh_key_len() - Obtain the size of the private DH key
48 * @params: private DH key
49 *
50 * This function returns the packet DH key size. A caller can use that
51 * with the provided DH private key reference to obtain the required
52 * memory size to hold a packet key.
53 *
54 * Return: size of the key in bytes
55 */
25int crypto_dh_key_len(const struct dh *params); 56int crypto_dh_key_len(const struct dh *params);
57
58/**
59 * crypto_dh_encode_key() - encode the private key
60 * @buf: Buffer allocated by the caller to hold the packet DH
61 * private key. The buffer should be at least crypto_dh_key_len
62 * bytes in size.
63 * @len: Length of the packet private key buffer
64 * @params: Buffer with the caller-specified private key
65 *
66 * The DH implementations operate on a packet representation of the private
67 * key.
68 *
69 * Return: -EINVAL if buffer has insufficient size, 0 on success
70 */
26int crypto_dh_encode_key(char *buf, unsigned int len, const struct dh *params); 71int crypto_dh_encode_key(char *buf, unsigned int len, const struct dh *params);
72
73/**
74 * crypto_dh_decode_key() - decode a private key
75 * @buf: Buffer holding a packet key that should be decoded
76 * @len: Lenth of the packet private key buffer
77 * @params: Buffer allocated by the caller that is filled with the
78 * unpacket DH private key.
79 *
80 * The unpacking obtains the private key by pointing @p to the correct location
81 * in @buf. Thus, both pointers refer to the same memory.
82 *
83 * Return: -EINVAL if buffer has insufficient size, 0 on success
84 */
27int crypto_dh_decode_key(const char *buf, unsigned int len, struct dh *params); 85int crypto_dh_decode_key(const char *buf, unsigned int len, struct dh *params);
28 86
29#endif 87#endif
diff --git a/include/crypto/ecdh.h b/include/crypto/ecdh.h
index 84bad548d194..03a64f62ba7a 100644
--- a/include/crypto/ecdh.h
+++ b/include/crypto/ecdh.h
@@ -13,18 +13,76 @@
13#ifndef _CRYPTO_ECDH_ 13#ifndef _CRYPTO_ECDH_
14#define _CRYPTO_ECDH_ 14#define _CRYPTO_ECDH_
15 15
16/**
17 * DOC: ECDH Helper Functions
18 *
19 * To use ECDH with the KPP cipher API, the following data structure and
20 * functions should be used.
21 *
22 * The ECC curves known to the ECDH implementation are specified in this
23 * header file.
24 *
25 * To use ECDH with KPP, the following functions should be used to operate on
26 * an ECDH private key. The packet private key that can be set with
27 * the KPP API function call of crypto_kpp_set_secret.
28 */
29
16/* Curves IDs */ 30/* Curves IDs */
17#define ECC_CURVE_NIST_P192 0x0001 31#define ECC_CURVE_NIST_P192 0x0001
18#define ECC_CURVE_NIST_P256 0x0002 32#define ECC_CURVE_NIST_P256 0x0002
19 33
34/**
35 * struct ecdh - define an ECDH private key
36 *
37 * @curve_id: ECC curve the key is based on.
38 * @key: Private ECDH key
39 * @key_size: Size of the private ECDH key
40 */
20struct ecdh { 41struct ecdh {
21 unsigned short curve_id; 42 unsigned short curve_id;
22 char *key; 43 char *key;
23 unsigned short key_size; 44 unsigned short key_size;
24}; 45};
25 46
47/**
48 * crypto_ecdh_key_len() - Obtain the size of the private ECDH key
49 * @params: private ECDH key
50 *
51 * This function returns the packet ECDH key size. A caller can use that
52 * with the provided ECDH private key reference to obtain the required
53 * memory size to hold a packet key.
54 *
55 * Return: size of the key in bytes
56 */
26int crypto_ecdh_key_len(const struct ecdh *params); 57int crypto_ecdh_key_len(const struct ecdh *params);
58
59/**
60 * crypto_ecdh_encode_key() - encode the private key
61 * @buf: Buffer allocated by the caller to hold the packet ECDH
62 * private key. The buffer should be at least crypto_ecdh_key_len
63 * bytes in size.
64 * @len: Length of the packet private key buffer
65 * @p: Buffer with the caller-specified private key
66 *
67 * The ECDH implementations operate on a packet representation of the private
68 * key.
69 *
70 * Return: -EINVAL if buffer has insufficient size, 0 on success
71 */
27int crypto_ecdh_encode_key(char *buf, unsigned int len, const struct ecdh *p); 72int crypto_ecdh_encode_key(char *buf, unsigned int len, const struct ecdh *p);
73
74/**
75 * crypto_ecdh_decode_key() - decode a private key
76 * @buf: Buffer holding a packet key that should be decoded
77 * @len: Lenth of the packet private key buffer
78 * @p: Buffer allocated by the caller that is filled with the
79 * unpacket ECDH private key.
80 *
81 * The unpacking obtains the private key by pointing @p to the correct location
82 * in @buf. Thus, both pointers refer to the same memory.
83 *
84 * Return: -EINVAL if buffer has insufficient size, 0 on success
85 */
28int crypto_ecdh_decode_key(const char *buf, unsigned int len, struct ecdh *p); 86int crypto_ecdh_decode_key(const char *buf, unsigned int len, struct ecdh *p);
29 87
30#endif 88#endif
diff --git a/include/crypto/kpp.h b/include/crypto/kpp.h
index 30791f75c180..4307a2f2365f 100644
--- a/include/crypto/kpp.h
+++ b/include/crypto/kpp.h
@@ -71,7 +71,7 @@ struct crypto_kpp {
71 * 71 *
72 * @reqsize: Request context size required by algorithm 72 * @reqsize: Request context size required by algorithm
73 * implementation 73 * implementation
74 * @base Common crypto API algorithm data structure 74 * @base: Common crypto API algorithm data structure
75 */ 75 */
76struct kpp_alg { 76struct kpp_alg {
77 int (*set_secret)(struct crypto_kpp *tfm, void *buffer, 77 int (*set_secret)(struct crypto_kpp *tfm, void *buffer,
@@ -89,7 +89,7 @@ struct kpp_alg {
89}; 89};
90 90
91/** 91/**
92 * DOC: Generic Key-agreement Protocol Primitevs API 92 * DOC: Generic Key-agreement Protocol Primitives API
93 * 93 *
94 * The KPP API is used with the algorithm type 94 * The KPP API is used with the algorithm type
95 * CRYPTO_ALG_TYPE_KPP (listed as type "kpp" in /proc/crypto) 95 * CRYPTO_ALG_TYPE_KPP (listed as type "kpp" in /proc/crypto)
@@ -264,6 +264,12 @@ struct kpp_secret {
264 * Function invokes the specific kpp operation for a given alg. 264 * Function invokes the specific kpp operation for a given alg.
265 * 265 *
266 * @tfm: tfm handle 266 * @tfm: tfm handle
267 * @buffer: Buffer holding the packet representation of the private
268 * key. The structure of the packet key depends on the particular
269 * KPP implementation. Packing and unpacking helpers are provided
270 * for ECDH and DH (see the respective header files for those
271 * implementations).
272 * @len: Length of the packet private key buffer.
267 * 273 *
268 * Return: zero on success; error code in case of error 274 * Return: zero on success; error code in case of error
269 */ 275 */
@@ -279,7 +285,10 @@ static inline int crypto_kpp_set_secret(struct crypto_kpp *tfm, void *buffer,
279 * crypto_kpp_generate_public_key() - Invoke kpp operation 285 * crypto_kpp_generate_public_key() - Invoke kpp operation
280 * 286 *
281 * Function invokes the specific kpp operation for generating the public part 287 * Function invokes the specific kpp operation for generating the public part
282 * for a given kpp algorithm 288 * for a given kpp algorithm.
289 *
290 * To generate a private key, the caller should use a random number generator.
291 * The output of the requested length serves as the private key.
283 * 292 *
284 * @req: kpp key request 293 * @req: kpp key request
285 * 294 *