1e5b75505Sopenharmony_ci/*
2e5b75505Sopenharmony_ci * RSA
3e5b75505Sopenharmony_ci * Copyright (c) 2006-2014, Jouni Malinen <j@w1.fi>
4e5b75505Sopenharmony_ci *
5e5b75505Sopenharmony_ci * This software may be distributed under the terms of the BSD license.
6e5b75505Sopenharmony_ci * See README for more details.
7e5b75505Sopenharmony_ci */
8e5b75505Sopenharmony_ci
9e5b75505Sopenharmony_ci#include "includes.h"
10e5b75505Sopenharmony_ci
11e5b75505Sopenharmony_ci#include "common.h"
12e5b75505Sopenharmony_ci#include "asn1.h"
13e5b75505Sopenharmony_ci#include "bignum.h"
14e5b75505Sopenharmony_ci#include "rsa.h"
15e5b75505Sopenharmony_ci
16e5b75505Sopenharmony_ci
17e5b75505Sopenharmony_cistruct crypto_rsa_key {
18e5b75505Sopenharmony_ci	int private_key; /* whether private key is set */
19e5b75505Sopenharmony_ci	struct bignum *n; /* modulus (p * q) */
20e5b75505Sopenharmony_ci	struct bignum *e; /* public exponent */
21e5b75505Sopenharmony_ci	/* The following parameters are available only if private_key is set */
22e5b75505Sopenharmony_ci	struct bignum *d; /* private exponent */
23e5b75505Sopenharmony_ci	struct bignum *p; /* prime p (factor of n) */
24e5b75505Sopenharmony_ci	struct bignum *q; /* prime q (factor of n) */
25e5b75505Sopenharmony_ci	struct bignum *dmp1; /* d mod (p - 1); CRT exponent */
26e5b75505Sopenharmony_ci	struct bignum *dmq1; /* d mod (q - 1); CRT exponent */
27e5b75505Sopenharmony_ci	struct bignum *iqmp; /* 1 / q mod p; CRT coefficient */
28e5b75505Sopenharmony_ci};
29e5b75505Sopenharmony_ci
30e5b75505Sopenharmony_ci
31e5b75505Sopenharmony_cistatic const u8 * crypto_rsa_parse_integer(const u8 *pos, const u8 *end,
32e5b75505Sopenharmony_ci					   struct bignum *num)
33e5b75505Sopenharmony_ci{
34e5b75505Sopenharmony_ci	struct asn1_hdr hdr;
35e5b75505Sopenharmony_ci
36e5b75505Sopenharmony_ci	if (pos == NULL)
37e5b75505Sopenharmony_ci		return NULL;
38e5b75505Sopenharmony_ci
39e5b75505Sopenharmony_ci	if (asn1_get_next(pos, end - pos, &hdr) < 0 ||
40e5b75505Sopenharmony_ci	    !asn1_is_integer(&hdr)) {
41e5b75505Sopenharmony_ci		asn1_unexpected(&hdr, "RSA: Expected INTEGER");
42e5b75505Sopenharmony_ci		return NULL;
43e5b75505Sopenharmony_ci	}
44e5b75505Sopenharmony_ci
45e5b75505Sopenharmony_ci	if (bignum_set_unsigned_bin(num, hdr.payload, hdr.length) < 0) {
46e5b75505Sopenharmony_ci		wpa_printf(MSG_DEBUG, "RSA: Failed to parse INTEGER");
47e5b75505Sopenharmony_ci		return NULL;
48e5b75505Sopenharmony_ci	}
49e5b75505Sopenharmony_ci
50e5b75505Sopenharmony_ci	return hdr.payload + hdr.length;
51e5b75505Sopenharmony_ci}
52e5b75505Sopenharmony_ci
53e5b75505Sopenharmony_ci
54e5b75505Sopenharmony_ci/**
55e5b75505Sopenharmony_ci * crypto_rsa_import_public_key - Import an RSA public key
56e5b75505Sopenharmony_ci * @buf: Key buffer (DER encoded RSA public key)
57e5b75505Sopenharmony_ci * @len: Key buffer length in bytes
58e5b75505Sopenharmony_ci * Returns: Pointer to the public key or %NULL on failure
59e5b75505Sopenharmony_ci */
60e5b75505Sopenharmony_cistruct crypto_rsa_key *
61e5b75505Sopenharmony_cicrypto_rsa_import_public_key(const u8 *buf, size_t len)
62e5b75505Sopenharmony_ci{
63e5b75505Sopenharmony_ci	struct crypto_rsa_key *key;
64e5b75505Sopenharmony_ci	struct asn1_hdr hdr;
65e5b75505Sopenharmony_ci	const u8 *pos, *end;
66e5b75505Sopenharmony_ci
67e5b75505Sopenharmony_ci	key = os_zalloc(sizeof(*key));
68e5b75505Sopenharmony_ci	if (key == NULL)
69e5b75505Sopenharmony_ci		return NULL;
70e5b75505Sopenharmony_ci
71e5b75505Sopenharmony_ci	key->n = bignum_init();
72e5b75505Sopenharmony_ci	key->e = bignum_init();
73e5b75505Sopenharmony_ci	if (key->n == NULL || key->e == NULL) {
74e5b75505Sopenharmony_ci		crypto_rsa_free(key);
75e5b75505Sopenharmony_ci		return NULL;
76e5b75505Sopenharmony_ci	}
77e5b75505Sopenharmony_ci
78e5b75505Sopenharmony_ci	/*
79e5b75505Sopenharmony_ci	 * PKCS #1, 7.1:
80e5b75505Sopenharmony_ci	 * RSAPublicKey ::= SEQUENCE {
81e5b75505Sopenharmony_ci	 *     modulus INTEGER, -- n
82e5b75505Sopenharmony_ci	 *     publicExponent INTEGER -- e
83e5b75505Sopenharmony_ci	 * }
84e5b75505Sopenharmony_ci	 */
85e5b75505Sopenharmony_ci
86e5b75505Sopenharmony_ci	if (asn1_get_next(buf, len, &hdr) < 0 || !asn1_is_sequence(&hdr)) {
87e5b75505Sopenharmony_ci		asn1_unexpected(&hdr, "RSA: Expected SEQUENCE (public key)");
88e5b75505Sopenharmony_ci		goto error;
89e5b75505Sopenharmony_ci	}
90e5b75505Sopenharmony_ci	pos = hdr.payload;
91e5b75505Sopenharmony_ci	end = pos + hdr.length;
92e5b75505Sopenharmony_ci
93e5b75505Sopenharmony_ci	pos = crypto_rsa_parse_integer(pos, end, key->n);
94e5b75505Sopenharmony_ci	pos = crypto_rsa_parse_integer(pos, end, key->e);
95e5b75505Sopenharmony_ci
96e5b75505Sopenharmony_ci	if (pos == NULL)
97e5b75505Sopenharmony_ci		goto error;
98e5b75505Sopenharmony_ci
99e5b75505Sopenharmony_ci	if (pos != end) {
100e5b75505Sopenharmony_ci		wpa_hexdump(MSG_DEBUG,
101e5b75505Sopenharmony_ci			    "RSA: Extra data in public key SEQUENCE",
102e5b75505Sopenharmony_ci			    pos, end - pos);
103e5b75505Sopenharmony_ci		goto error;
104e5b75505Sopenharmony_ci	}
105e5b75505Sopenharmony_ci
106e5b75505Sopenharmony_ci	return key;
107e5b75505Sopenharmony_ci
108e5b75505Sopenharmony_cierror:
109e5b75505Sopenharmony_ci	crypto_rsa_free(key);
110e5b75505Sopenharmony_ci	return NULL;
111e5b75505Sopenharmony_ci}
112e5b75505Sopenharmony_ci
113e5b75505Sopenharmony_ci
114e5b75505Sopenharmony_cistruct crypto_rsa_key *
115e5b75505Sopenharmony_cicrypto_rsa_import_public_key_parts(const u8 *n, size_t n_len,
116e5b75505Sopenharmony_ci				   const u8 *e, size_t e_len)
117e5b75505Sopenharmony_ci{
118e5b75505Sopenharmony_ci	struct crypto_rsa_key *key;
119e5b75505Sopenharmony_ci
120e5b75505Sopenharmony_ci	key = os_zalloc(sizeof(*key));
121e5b75505Sopenharmony_ci	if (key == NULL)
122e5b75505Sopenharmony_ci		return NULL;
123e5b75505Sopenharmony_ci
124e5b75505Sopenharmony_ci	key->n = bignum_init();
125e5b75505Sopenharmony_ci	key->e = bignum_init();
126e5b75505Sopenharmony_ci	if (key->n == NULL || key->e == NULL ||
127e5b75505Sopenharmony_ci	    bignum_set_unsigned_bin(key->n, n, n_len) < 0 ||
128e5b75505Sopenharmony_ci	    bignum_set_unsigned_bin(key->e, e, e_len) < 0) {
129e5b75505Sopenharmony_ci		crypto_rsa_free(key);
130e5b75505Sopenharmony_ci		return NULL;
131e5b75505Sopenharmony_ci	}
132e5b75505Sopenharmony_ci
133e5b75505Sopenharmony_ci	return key;
134e5b75505Sopenharmony_ci}
135e5b75505Sopenharmony_ci
136e5b75505Sopenharmony_ci
137e5b75505Sopenharmony_ci/**
138e5b75505Sopenharmony_ci * crypto_rsa_import_private_key - Import an RSA private key
139e5b75505Sopenharmony_ci * @buf: Key buffer (DER encoded RSA private key)
140e5b75505Sopenharmony_ci * @len: Key buffer length in bytes
141e5b75505Sopenharmony_ci * Returns: Pointer to the private key or %NULL on failure
142e5b75505Sopenharmony_ci */
143e5b75505Sopenharmony_cistruct crypto_rsa_key *
144e5b75505Sopenharmony_cicrypto_rsa_import_private_key(const u8 *buf, size_t len)
145e5b75505Sopenharmony_ci{
146e5b75505Sopenharmony_ci	struct crypto_rsa_key *key;
147e5b75505Sopenharmony_ci	struct bignum *zero;
148e5b75505Sopenharmony_ci	struct asn1_hdr hdr;
149e5b75505Sopenharmony_ci	const u8 *pos, *end;
150e5b75505Sopenharmony_ci
151e5b75505Sopenharmony_ci	key = os_zalloc(sizeof(*key));
152e5b75505Sopenharmony_ci	if (key == NULL)
153e5b75505Sopenharmony_ci		return NULL;
154e5b75505Sopenharmony_ci
155e5b75505Sopenharmony_ci	key->private_key = 1;
156e5b75505Sopenharmony_ci
157e5b75505Sopenharmony_ci	key->n = bignum_init();
158e5b75505Sopenharmony_ci	key->e = bignum_init();
159e5b75505Sopenharmony_ci	key->d = bignum_init();
160e5b75505Sopenharmony_ci	key->p = bignum_init();
161e5b75505Sopenharmony_ci	key->q = bignum_init();
162e5b75505Sopenharmony_ci	key->dmp1 = bignum_init();
163e5b75505Sopenharmony_ci	key->dmq1 = bignum_init();
164e5b75505Sopenharmony_ci	key->iqmp = bignum_init();
165e5b75505Sopenharmony_ci
166e5b75505Sopenharmony_ci	if (key->n == NULL || key->e == NULL || key->d == NULL ||
167e5b75505Sopenharmony_ci	    key->p == NULL || key->q == NULL || key->dmp1 == NULL ||
168e5b75505Sopenharmony_ci	    key->dmq1 == NULL || key->iqmp == NULL) {
169e5b75505Sopenharmony_ci		crypto_rsa_free(key);
170e5b75505Sopenharmony_ci		return NULL;
171e5b75505Sopenharmony_ci	}
172e5b75505Sopenharmony_ci
173e5b75505Sopenharmony_ci	/*
174e5b75505Sopenharmony_ci	 * PKCS #1, 7.2:
175e5b75505Sopenharmony_ci	 * RSAPrivateKey ::= SEQUENCE {
176e5b75505Sopenharmony_ci	 *    version Version,
177e5b75505Sopenharmony_ci	 *    modulus INTEGER, -- n
178e5b75505Sopenharmony_ci	 *    publicExponent INTEGER, -- e
179e5b75505Sopenharmony_ci	 *    privateExponent INTEGER, -- d
180e5b75505Sopenharmony_ci	 *    prime1 INTEGER, -- p
181e5b75505Sopenharmony_ci	 *    prime2 INTEGER, -- q
182e5b75505Sopenharmony_ci	 *    exponent1 INTEGER, -- d mod (p-1)
183e5b75505Sopenharmony_ci	 *    exponent2 INTEGER, -- d mod (q-1)
184e5b75505Sopenharmony_ci	 *    coefficient INTEGER -- (inverse of q) mod p
185e5b75505Sopenharmony_ci	 * }
186e5b75505Sopenharmony_ci	 *
187e5b75505Sopenharmony_ci	 * Version ::= INTEGER -- shall be 0 for this version of the standard
188e5b75505Sopenharmony_ci	 */
189e5b75505Sopenharmony_ci	if (asn1_get_next(buf, len, &hdr) < 0 || !asn1_is_sequence(&hdr)) {
190e5b75505Sopenharmony_ci		asn1_unexpected(&hdr, "RSA: Expected SEQUENCE (public key)");
191e5b75505Sopenharmony_ci		goto error;
192e5b75505Sopenharmony_ci	}
193e5b75505Sopenharmony_ci	pos = hdr.payload;
194e5b75505Sopenharmony_ci	end = pos + hdr.length;
195e5b75505Sopenharmony_ci
196e5b75505Sopenharmony_ci	zero = bignum_init();
197e5b75505Sopenharmony_ci	if (zero == NULL)
198e5b75505Sopenharmony_ci		goto error;
199e5b75505Sopenharmony_ci	pos = crypto_rsa_parse_integer(pos, end, zero);
200e5b75505Sopenharmony_ci	if (pos == NULL || bignum_cmp_d(zero, 0) != 0) {
201e5b75505Sopenharmony_ci		wpa_printf(MSG_DEBUG, "RSA: Expected zero INTEGER in the "
202e5b75505Sopenharmony_ci			   "beginning of private key; not found");
203e5b75505Sopenharmony_ci		bignum_deinit(zero);
204e5b75505Sopenharmony_ci		goto error;
205e5b75505Sopenharmony_ci	}
206e5b75505Sopenharmony_ci	bignum_deinit(zero);
207e5b75505Sopenharmony_ci
208e5b75505Sopenharmony_ci	pos = crypto_rsa_parse_integer(pos, end, key->n);
209e5b75505Sopenharmony_ci	pos = crypto_rsa_parse_integer(pos, end, key->e);
210e5b75505Sopenharmony_ci	pos = crypto_rsa_parse_integer(pos, end, key->d);
211e5b75505Sopenharmony_ci	pos = crypto_rsa_parse_integer(pos, end, key->p);
212e5b75505Sopenharmony_ci	pos = crypto_rsa_parse_integer(pos, end, key->q);
213e5b75505Sopenharmony_ci	pos = crypto_rsa_parse_integer(pos, end, key->dmp1);
214e5b75505Sopenharmony_ci	pos = crypto_rsa_parse_integer(pos, end, key->dmq1);
215e5b75505Sopenharmony_ci	pos = crypto_rsa_parse_integer(pos, end, key->iqmp);
216e5b75505Sopenharmony_ci
217e5b75505Sopenharmony_ci	if (pos == NULL)
218e5b75505Sopenharmony_ci		goto error;
219e5b75505Sopenharmony_ci
220e5b75505Sopenharmony_ci	if (pos != end) {
221e5b75505Sopenharmony_ci		wpa_hexdump(MSG_DEBUG,
222e5b75505Sopenharmony_ci			    "RSA: Extra data in public key SEQUENCE",
223e5b75505Sopenharmony_ci			    pos, end - pos);
224e5b75505Sopenharmony_ci		goto error;
225e5b75505Sopenharmony_ci	}
226e5b75505Sopenharmony_ci
227e5b75505Sopenharmony_ci	return key;
228e5b75505Sopenharmony_ci
229e5b75505Sopenharmony_cierror:
230e5b75505Sopenharmony_ci	crypto_rsa_free(key);
231e5b75505Sopenharmony_ci	return NULL;
232e5b75505Sopenharmony_ci}
233e5b75505Sopenharmony_ci
234e5b75505Sopenharmony_ci
235e5b75505Sopenharmony_ci/**
236e5b75505Sopenharmony_ci * crypto_rsa_get_modulus_len - Get the modulus length of the RSA key
237e5b75505Sopenharmony_ci * @key: RSA key
238e5b75505Sopenharmony_ci * Returns: Modulus length of the key
239e5b75505Sopenharmony_ci */
240e5b75505Sopenharmony_cisize_t crypto_rsa_get_modulus_len(struct crypto_rsa_key *key)
241e5b75505Sopenharmony_ci{
242e5b75505Sopenharmony_ci	return bignum_get_unsigned_bin_len(key->n);
243e5b75505Sopenharmony_ci}
244e5b75505Sopenharmony_ci
245e5b75505Sopenharmony_ci
246e5b75505Sopenharmony_ci/**
247e5b75505Sopenharmony_ci * crypto_rsa_exptmod - RSA modular exponentiation
248e5b75505Sopenharmony_ci * @in: Input data
249e5b75505Sopenharmony_ci * @inlen: Input data length
250e5b75505Sopenharmony_ci * @out: Buffer for output data
251e5b75505Sopenharmony_ci * @outlen: Maximum size of the output buffer and used size on success
252e5b75505Sopenharmony_ci * @key: RSA key
253e5b75505Sopenharmony_ci * @use_private: 1 = Use RSA private key, 0 = Use RSA public key
254e5b75505Sopenharmony_ci * Returns: 0 on success, -1 on failure
255e5b75505Sopenharmony_ci */
256e5b75505Sopenharmony_ciint crypto_rsa_exptmod(const u8 *in, size_t inlen, u8 *out, size_t *outlen,
257e5b75505Sopenharmony_ci		       struct crypto_rsa_key *key, int use_private)
258e5b75505Sopenharmony_ci{
259e5b75505Sopenharmony_ci	struct bignum *tmp, *a = NULL, *b = NULL;
260e5b75505Sopenharmony_ci	int ret = -1;
261e5b75505Sopenharmony_ci	size_t modlen;
262e5b75505Sopenharmony_ci
263e5b75505Sopenharmony_ci	if (use_private && !key->private_key)
264e5b75505Sopenharmony_ci		return -1;
265e5b75505Sopenharmony_ci
266e5b75505Sopenharmony_ci	tmp = bignum_init();
267e5b75505Sopenharmony_ci	if (tmp == NULL)
268e5b75505Sopenharmony_ci		return -1;
269e5b75505Sopenharmony_ci
270e5b75505Sopenharmony_ci	if (bignum_set_unsigned_bin(tmp, in, inlen) < 0)
271e5b75505Sopenharmony_ci		goto error;
272e5b75505Sopenharmony_ci	if (bignum_cmp(key->n, tmp) < 0) {
273e5b75505Sopenharmony_ci		/* Too large input value for the RSA key modulus */
274e5b75505Sopenharmony_ci		goto error;
275e5b75505Sopenharmony_ci	}
276e5b75505Sopenharmony_ci
277e5b75505Sopenharmony_ci	if (use_private) {
278e5b75505Sopenharmony_ci		/*
279e5b75505Sopenharmony_ci		 * Decrypt (or sign) using Chinese remainder theorem to speed
280e5b75505Sopenharmony_ci		 * up calculation. This is equivalent to tmp = tmp^d mod n
281e5b75505Sopenharmony_ci		 * (which would require more CPU to calculate directly).
282e5b75505Sopenharmony_ci		 *
283e5b75505Sopenharmony_ci		 * dmp1 = (1/e) mod (p-1)
284e5b75505Sopenharmony_ci		 * dmq1 = (1/e) mod (q-1)
285e5b75505Sopenharmony_ci		 * iqmp = (1/q) mod p, where p > q
286e5b75505Sopenharmony_ci		 * m1 = c^dmp1 mod p
287e5b75505Sopenharmony_ci		 * m2 = c^dmq1 mod q
288e5b75505Sopenharmony_ci		 * h = q^-1 (m1 - m2) mod p
289e5b75505Sopenharmony_ci		 * m = m2 + hq
290e5b75505Sopenharmony_ci		 */
291e5b75505Sopenharmony_ci		a = bignum_init();
292e5b75505Sopenharmony_ci		b = bignum_init();
293e5b75505Sopenharmony_ci		if (a == NULL || b == NULL)
294e5b75505Sopenharmony_ci			goto error;
295e5b75505Sopenharmony_ci
296e5b75505Sopenharmony_ci		/* a = tmp^dmp1 mod p */
297e5b75505Sopenharmony_ci		if (bignum_exptmod(tmp, key->dmp1, key->p, a) < 0)
298e5b75505Sopenharmony_ci			goto error;
299e5b75505Sopenharmony_ci
300e5b75505Sopenharmony_ci		/* b = tmp^dmq1 mod q */
301e5b75505Sopenharmony_ci		if (bignum_exptmod(tmp, key->dmq1, key->q, b) < 0)
302e5b75505Sopenharmony_ci			goto error;
303e5b75505Sopenharmony_ci
304e5b75505Sopenharmony_ci		/* tmp = (a - b) * (1/q mod p) (mod p) */
305e5b75505Sopenharmony_ci		if (bignum_sub(a, b, tmp) < 0 ||
306e5b75505Sopenharmony_ci		    bignum_mulmod(tmp, key->iqmp, key->p, tmp) < 0)
307e5b75505Sopenharmony_ci			goto error;
308e5b75505Sopenharmony_ci
309e5b75505Sopenharmony_ci		/* tmp = b + q * tmp */
310e5b75505Sopenharmony_ci		if (bignum_mul(tmp, key->q, tmp) < 0 ||
311e5b75505Sopenharmony_ci		    bignum_add(tmp, b, tmp) < 0)
312e5b75505Sopenharmony_ci			goto error;
313e5b75505Sopenharmony_ci	} else {
314e5b75505Sopenharmony_ci		/* Encrypt (or verify signature) */
315e5b75505Sopenharmony_ci		/* tmp = tmp^e mod N */
316e5b75505Sopenharmony_ci		if (bignum_exptmod(tmp, key->e, key->n, tmp) < 0)
317e5b75505Sopenharmony_ci			goto error;
318e5b75505Sopenharmony_ci	}
319e5b75505Sopenharmony_ci
320e5b75505Sopenharmony_ci	modlen = crypto_rsa_get_modulus_len(key);
321e5b75505Sopenharmony_ci	if (modlen > *outlen) {
322e5b75505Sopenharmony_ci		*outlen = modlen;
323e5b75505Sopenharmony_ci		goto error;
324e5b75505Sopenharmony_ci	}
325e5b75505Sopenharmony_ci
326e5b75505Sopenharmony_ci	if (bignum_get_unsigned_bin_len(tmp) > modlen)
327e5b75505Sopenharmony_ci		goto error; /* should never happen */
328e5b75505Sopenharmony_ci
329e5b75505Sopenharmony_ci	*outlen = modlen;
330e5b75505Sopenharmony_ci	os_memset(out, 0, modlen);
331e5b75505Sopenharmony_ci	if (bignum_get_unsigned_bin(
332e5b75505Sopenharmony_ci		    tmp, out +
333e5b75505Sopenharmony_ci		    (modlen - bignum_get_unsigned_bin_len(tmp)), NULL) < 0)
334e5b75505Sopenharmony_ci		goto error;
335e5b75505Sopenharmony_ci
336e5b75505Sopenharmony_ci	ret = 0;
337e5b75505Sopenharmony_ci
338e5b75505Sopenharmony_cierror:
339e5b75505Sopenharmony_ci	bignum_deinit(tmp);
340e5b75505Sopenharmony_ci	bignum_deinit(a);
341e5b75505Sopenharmony_ci	bignum_deinit(b);
342e5b75505Sopenharmony_ci	return ret;
343e5b75505Sopenharmony_ci}
344e5b75505Sopenharmony_ci
345e5b75505Sopenharmony_ci
346e5b75505Sopenharmony_ci/**
347e5b75505Sopenharmony_ci * crypto_rsa_free - Free RSA key
348e5b75505Sopenharmony_ci * @key: RSA key to be freed
349e5b75505Sopenharmony_ci *
350e5b75505Sopenharmony_ci * This function frees an RSA key imported with either
351e5b75505Sopenharmony_ci * crypto_rsa_import_public_key() or crypto_rsa_import_private_key().
352e5b75505Sopenharmony_ci */
353e5b75505Sopenharmony_civoid crypto_rsa_free(struct crypto_rsa_key *key)
354e5b75505Sopenharmony_ci{
355e5b75505Sopenharmony_ci	if (key) {
356e5b75505Sopenharmony_ci		bignum_deinit(key->n);
357e5b75505Sopenharmony_ci		bignum_deinit(key->e);
358e5b75505Sopenharmony_ci		bignum_deinit(key->d);
359e5b75505Sopenharmony_ci		bignum_deinit(key->p);
360e5b75505Sopenharmony_ci		bignum_deinit(key->q);
361e5b75505Sopenharmony_ci		bignum_deinit(key->dmp1);
362e5b75505Sopenharmony_ci		bignum_deinit(key->dmq1);
363e5b75505Sopenharmony_ci		bignum_deinit(key->iqmp);
364e5b75505Sopenharmony_ci		os_free(key);
365e5b75505Sopenharmony_ci	}
366e5b75505Sopenharmony_ci}
367