Linux Audio

Check our new training course

Loading...
v6.8
 1/* SPDX-License-Identifier: GPL-2.0-or-later */
 2/*
 3 * RSA internal helpers
 4 *
 5 * Copyright (c) 2015, Intel Corporation
 6 * Authors: Tadeusz Struk <tadeusz.struk@intel.com>
 7 */
 8#ifndef _RSA_HELPER_
 9#define _RSA_HELPER_
10#include <linux/types.h>
 
11
12/**
13 * rsa_key - RSA key structure
14 * @n           : RSA modulus raw byte stream
15 * @e           : RSA public exponent raw byte stream
16 * @d           : RSA private exponent raw byte stream
17 * @p           : RSA prime factor p of n raw byte stream
18 * @q           : RSA prime factor q of n raw byte stream
19 * @dp          : RSA exponent d mod (p - 1) raw byte stream
20 * @dq          : RSA exponent d mod (q - 1) raw byte stream
21 * @qinv        : RSA CRT coefficient q^(-1) mod p raw byte stream
22 * @n_sz        : length in bytes of RSA modulus n
23 * @e_sz        : length in bytes of RSA public exponent
24 * @d_sz        : length in bytes of RSA private exponent
25 * @p_sz        : length in bytes of p field
26 * @q_sz        : length in bytes of q field
27 * @dp_sz       : length in bytes of dp field
28 * @dq_sz       : length in bytes of dq field
29 * @qinv_sz     : length in bytes of qinv field
30 */
31struct rsa_key {
32	const u8 *n;
33	const u8 *e;
34	const u8 *d;
35	const u8 *p;
36	const u8 *q;
37	const u8 *dp;
38	const u8 *dq;
39	const u8 *qinv;
40	size_t n_sz;
41	size_t e_sz;
42	size_t d_sz;
43	size_t p_sz;
44	size_t q_sz;
45	size_t dp_sz;
46	size_t dq_sz;
47	size_t qinv_sz;
48};
49
50int rsa_parse_pub_key(struct rsa_key *rsa_key, const void *key,
51		      unsigned int key_len);
52
53int rsa_parse_priv_key(struct rsa_key *rsa_key, const void *key,
54		       unsigned int key_len);
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56extern struct crypto_template rsa_pkcs1pad_tmpl;
 
57#endif
v6.13.7
 1/* SPDX-License-Identifier: GPL-2.0-or-later */
 2/*
 3 * RSA internal helpers
 4 *
 5 * Copyright (c) 2015, Intel Corporation
 6 * Authors: Tadeusz Struk <tadeusz.struk@intel.com>
 7 */
 8#ifndef _RSA_HELPER_
 9#define _RSA_HELPER_
10#include <linux/types.h>
11#include <crypto/akcipher.h>
12
13/**
14 * rsa_key - RSA key structure
15 * @n           : RSA modulus raw byte stream
16 * @e           : RSA public exponent raw byte stream
17 * @d           : RSA private exponent raw byte stream
18 * @p           : RSA prime factor p of n raw byte stream
19 * @q           : RSA prime factor q of n raw byte stream
20 * @dp          : RSA exponent d mod (p - 1) raw byte stream
21 * @dq          : RSA exponent d mod (q - 1) raw byte stream
22 * @qinv        : RSA CRT coefficient q^(-1) mod p raw byte stream
23 * @n_sz        : length in bytes of RSA modulus n
24 * @e_sz        : length in bytes of RSA public exponent
25 * @d_sz        : length in bytes of RSA private exponent
26 * @p_sz        : length in bytes of p field
27 * @q_sz        : length in bytes of q field
28 * @dp_sz       : length in bytes of dp field
29 * @dq_sz       : length in bytes of dq field
30 * @qinv_sz     : length in bytes of qinv field
31 */
32struct rsa_key {
33	const u8 *n;
34	const u8 *e;
35	const u8 *d;
36	const u8 *p;
37	const u8 *q;
38	const u8 *dp;
39	const u8 *dq;
40	const u8 *qinv;
41	size_t n_sz;
42	size_t e_sz;
43	size_t d_sz;
44	size_t p_sz;
45	size_t q_sz;
46	size_t dp_sz;
47	size_t dq_sz;
48	size_t qinv_sz;
49};
50
51int rsa_parse_pub_key(struct rsa_key *rsa_key, const void *key,
52		      unsigned int key_len);
53
54int rsa_parse_priv_key(struct rsa_key *rsa_key, const void *key,
55		       unsigned int key_len);
56
57#define RSA_PUB (true)
58#define RSA_PRIV (false)
59
60static inline int rsa_set_key(struct crypto_akcipher *child,
61			      unsigned int *key_size, bool is_pubkey,
62			      const void *key, unsigned int keylen)
63{
64	int err;
65
66	*key_size = 0;
67
68	if (is_pubkey)
69		err = crypto_akcipher_set_pub_key(child, key, keylen);
70	else
71		err = crypto_akcipher_set_priv_key(child, key, keylen);
72	if (err)
73		return err;
74
75	/* Find out new modulus size from rsa implementation */
76	err = crypto_akcipher_maxsize(child);
77	if (err > PAGE_SIZE)
78		return -ENOTSUPP;
79
80	*key_size = err;
81	return 0;
82}
83
84extern struct crypto_template rsa_pkcs1pad_tmpl;
85extern struct crypto_template rsassa_pkcs1_tmpl;
86#endif