Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * ECDH helper functions - KPP wrappings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2017 Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * it under the terms of the GNU General Public License version 2 as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * published by the Free Software Foundation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * SOFTWARE IS DISCLAIMED.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include "ecdh_helper.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/scatterlist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <crypto/ecdh.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) struct ecdh_completion {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	struct completion completion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static void ecdh_complete(struct crypto_async_request *req, int err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct ecdh_completion *res = req->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	if (err == -EINPROGRESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	res->err = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	complete(&res->completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) static inline void swap_digits(u64 *in, u64 *out, unsigned int ndigits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	for (i = 0; i < ndigits; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		out[i] = __swab64(in[ndigits - 1 - i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) /* compute_ecdh_secret() - function assumes that the private key was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  *                         already set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * @tfm:          KPP tfm handle allocated with crypto_alloc_kpp().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * @public_key:   pair's ecc public key.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * secret:        memory where the ecdh computed shared secret will be saved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * Return: zero on success; error code in case of error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) int compute_ecdh_secret(struct crypto_kpp *tfm, const u8 public_key[64],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 			u8 secret[32])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	struct kpp_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	u8 *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	struct ecdh_completion result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	struct scatterlist src, dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	tmp = kmalloc(64, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	if (!tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	req = kpp_request_alloc(tfm, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	if (!req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		goto free_tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	init_completion(&result.completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	swap_digits((u64 *)public_key, (u64 *)tmp, 4); /* x */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	swap_digits((u64 *)&public_key[32], (u64 *)&tmp[32], 4); /* y */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	sg_init_one(&src, tmp, 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	sg_init_one(&dst, secret, 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	kpp_request_set_input(req, &src, 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	kpp_request_set_output(req, &dst, 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 				 ecdh_complete, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	err = crypto_kpp_compute_shared_secret(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	if (err == -EINPROGRESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		wait_for_completion(&result.completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		err = result.err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		pr_err("alg: ecdh: compute shared secret failed. err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		       err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		goto free_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	swap_digits((u64 *)secret, (u64 *)tmp, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	memcpy(secret, tmp, 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) free_all:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	kpp_request_free(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) free_tmp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	kfree_sensitive(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /* set_ecdh_privkey() - set or generate ecc private key.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)  * Function generates an ecc private key in the crypto subsystem when receiving
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)  * a NULL private key or sets the received key when not NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)  * @tfm:           KPP tfm handle allocated with crypto_alloc_kpp().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  * @private_key:   user's ecc private key. When not NULL, the key is expected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  *                 in little endian format.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  * Return: zero on success; error code in case of error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) int set_ecdh_privkey(struct crypto_kpp *tfm, const u8 private_key[32])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	u8 *buf, *tmp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	unsigned int buf_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	struct ecdh p = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	p.curve_id = ECC_CURVE_NIST_P256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if (private_key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		tmp = kmalloc(32, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		if (!tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		swap_digits((u64 *)private_key, (u64 *)tmp, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		p.key = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		p.key_size = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	buf_len = crypto_ecdh_key_len(&p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	buf = kmalloc(buf_len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		goto free_tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	err = crypto_ecdh_encode_key(buf, buf_len, &p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		goto free_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	err = crypto_kpp_set_secret(tfm, buf, buf_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	/* fall through */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) free_all:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	kfree_sensitive(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) free_tmp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	kfree_sensitive(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) /* generate_ecdh_public_key() - function assumes that the private key was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  *                              already set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)  * @tfm:          KPP tfm handle allocated with crypto_alloc_kpp().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)  * @public_key:   memory where the computed ecc public key will be saved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)  * Return: zero on success; error code in case of error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) int generate_ecdh_public_key(struct crypto_kpp *tfm, u8 public_key[64])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	struct kpp_request *req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	u8 *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	struct ecdh_completion result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	struct scatterlist dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	tmp = kmalloc(64, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	if (!tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	req = kpp_request_alloc(tfm, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	if (!req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		goto free_tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	init_completion(&result.completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	sg_init_one(&dst, tmp, 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	kpp_request_set_input(req, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	kpp_request_set_output(req, &dst, 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	kpp_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 				 ecdh_complete, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	err = crypto_kpp_generate_public_key(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if (err == -EINPROGRESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		wait_for_completion(&result.completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		err = result.err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		goto free_all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	/* The public key is handed back in little endian as expected by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	 * the Security Manager Protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	swap_digits((u64 *)tmp, (u64 *)public_key, 4); /* x */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	swap_digits((u64 *)&tmp[32], (u64 *)&public_key[32], 4); /* y */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) free_all:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	kpp_request_free(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) free_tmp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	kfree(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) /* generate_ecdh_keys() - generate ecc key pair.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  * @tfm:          KPP tfm handle allocated with crypto_alloc_kpp().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)  * @public_key:   memory where the computed ecc public key will be saved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)  * Return: zero on success; error code in case of error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) int generate_ecdh_keys(struct crypto_kpp *tfm, u8 public_key[64])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	err = set_ecdh_privkey(tfm, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	return generate_ecdh_public_key(tfm, public_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }