Lines Matching refs:key

18 	int private_key; /* whether private key is set */
56 * crypto_rsa_import_public_key - Import an RSA public key
57 * @buf: Key buffer (DER encoded RSA public key)
59 * Returns: Pointer to the public key or %NULL on failure
64 struct crypto_rsa_key *key;
68 key = os_zalloc(sizeof(*key));
69 if (key == NULL)
72 key->n = bignum_init();
73 key->e = bignum_init();
74 if (key->n == NULL || key->e == NULL) {
75 crypto_rsa_free(key);
91 "(public key) - found class %d tag 0x%x",
98 pos = crypto_rsa_parse_integer(pos, end, key->n);
99 pos = crypto_rsa_parse_integer(pos, end, key->e);
106 "RSA: Extra data in public key SEQUENCE",
111 return key;
114 crypto_rsa_free(key);
123 struct crypto_rsa_key *key;
125 key = os_zalloc(sizeof(*key));
126 if (key == NULL)
129 key->n = bignum_init();
130 key->e = bignum_init();
131 if (key->n == NULL || key->e == NULL ||
132 bignum_set_unsigned_bin(key->n, n, n_len) < 0 ||
133 bignum_set_unsigned_bin(key->e, e, e_len) < 0) {
134 crypto_rsa_free(key);
138 return key;
143 * crypto_rsa_import_private_key - Import an RSA private key
144 * @buf: Key buffer (DER encoded RSA private key)
146 * Returns: Pointer to the private key or %NULL on failure
151 struct crypto_rsa_key *key;
156 key = os_zalloc(sizeof(*key));
157 if (key == NULL)
160 key->private_key = 1;
162 key->n = bignum_init();
163 key->e = bignum_init();
164 key->d = bignum_init();
165 key->p = bignum_init();
166 key->q = bignum_init();
167 key->dmp1 = bignum_init();
168 key->dmq1 = bignum_init();
169 key->iqmp = bignum_init();
171 if (key->n == NULL || key->e == NULL || key->d == NULL ||
172 key->p == NULL || key->q == NULL || key->dmp1 == NULL ||
173 key->dmq1 == NULL || key->iqmp == NULL) {
174 crypto_rsa_free(key);
198 "(public key) - found class %d tag 0x%x",
211 "beginning of private key; not found");
217 pos = crypto_rsa_parse_integer(pos, end, key->n);
218 pos = crypto_rsa_parse_integer(pos, end, key->e);
219 pos = crypto_rsa_parse_integer(pos, end, key->d);
220 pos = crypto_rsa_parse_integer(pos, end, key->p);
221 pos = crypto_rsa_parse_integer(pos, end, key->q);
222 pos = crypto_rsa_parse_integer(pos, end, key->dmp1);
223 pos = crypto_rsa_parse_integer(pos, end, key->dmq1);
224 pos = crypto_rsa_parse_integer(pos, end, key->iqmp);
231 "RSA: Extra data in public key SEQUENCE",
236 return key;
239 crypto_rsa_free(key);
245 * crypto_rsa_get_modulus_len - Get the modulus length of the RSA key
246 * @key: RSA key
247 * Returns: Modulus length of the key
249 size_t crypto_rsa_get_modulus_len(struct crypto_rsa_key *key)
251 return bignum_get_unsigned_bin_len(key->n);
261 * @key: RSA key
262 * @use_private: 1 = Use RSA private key, 0 = Use RSA public key
266 struct crypto_rsa_key *key, int use_private)
272 if (use_private && !key->private_key)
281 if (bignum_cmp(key->n, tmp) < 0) {
282 /* Too large input value for the RSA key modulus */
306 if (bignum_exptmod(tmp, key->dmp1, key->p, a) < 0)
310 if (bignum_exptmod(tmp, key->dmq1, key->q, b) < 0)
315 bignum_mulmod(tmp, key->iqmp, key->p, tmp) < 0)
319 if (bignum_mul(tmp, key->q, tmp) < 0 ||
325 if (bignum_exptmod(tmp, key->e, key->n, tmp) < 0)
329 modlen = crypto_rsa_get_modulus_len(key);
356 * crypto_rsa_free - Free RSA key
357 * @key: RSA key to be freed
359 * This function frees an RSA key imported with either
362 void crypto_rsa_free(struct crypto_rsa_key *key)
364 if (key) {
365 bignum_deinit(key->n);
366 bignum_deinit(key->e);
367 bignum_deinit(key->d);
368 bignum_deinit(key->p);
369 bignum_deinit(key->q);
370 bignum_deinit(key->dmp1);
371 bignum_deinit(key->dmq1);
372 bignum_deinit(key->iqmp);
373 os_free(key);