Lines Matching +full:key +full:-

3  * Copyright (c) 2006-2014, Jouni Malinen <j@w1.fi>
18 int private_key; /* whether private key is set */
25 struct bignum *dmp1; /* d mod (p - 1); CRT exponent */
26 struct bignum *dmq1; /* d mod (q - 1); CRT exponent */
39 if (asn1_get_next(pos, end - pos, &hdr) < 0 || in crypto_rsa_parse_integer()
55 * crypto_rsa_import_public_key - Import an RSA public key
56 * @buf: Key buffer (DER encoded RSA public key)
57 * @len: Key buffer length in bytes
58 * Returns: Pointer to the public key or %NULL on failure
63 struct crypto_rsa_key *key; in crypto_rsa_import_public_key() local
67 key = os_zalloc(sizeof(*key)); in crypto_rsa_import_public_key()
68 if (key == NULL) in crypto_rsa_import_public_key()
71 key->n = bignum_init(); in crypto_rsa_import_public_key()
72 key->e = bignum_init(); in crypto_rsa_import_public_key()
73 if (key->n == NULL || key->e == NULL) { in crypto_rsa_import_public_key()
74 crypto_rsa_free(key); in crypto_rsa_import_public_key()
81 * modulus INTEGER, -- n in crypto_rsa_import_public_key()
82 * publicExponent INTEGER -- e in crypto_rsa_import_public_key()
87 asn1_unexpected(&hdr, "RSA: Expected SEQUENCE (public key)"); in crypto_rsa_import_public_key()
93 pos = crypto_rsa_parse_integer(pos, end, key->n); in crypto_rsa_import_public_key()
94 pos = crypto_rsa_parse_integer(pos, end, key->e); in crypto_rsa_import_public_key()
101 "RSA: Extra data in public key SEQUENCE", in crypto_rsa_import_public_key()
102 pos, end - pos); in crypto_rsa_import_public_key()
106 return key; in crypto_rsa_import_public_key()
109 crypto_rsa_free(key); in crypto_rsa_import_public_key()
118 struct crypto_rsa_key *key; in crypto_rsa_import_public_key_parts() local
120 key = os_zalloc(sizeof(*key)); in crypto_rsa_import_public_key_parts()
121 if (key == NULL) in crypto_rsa_import_public_key_parts()
124 key->n = bignum_init(); in crypto_rsa_import_public_key_parts()
125 key->e = bignum_init(); in crypto_rsa_import_public_key_parts()
126 if (key->n == NULL || key->e == NULL || in crypto_rsa_import_public_key_parts()
127 bignum_set_unsigned_bin(key->n, n, n_len) < 0 || in crypto_rsa_import_public_key_parts()
128 bignum_set_unsigned_bin(key->e, e, e_len) < 0) { in crypto_rsa_import_public_key_parts()
129 crypto_rsa_free(key); in crypto_rsa_import_public_key_parts()
133 return key; in crypto_rsa_import_public_key_parts()
138 * crypto_rsa_import_private_key - Import an RSA private key
139 * @buf: Key buffer (DER encoded RSA private key)
140 * @len: Key buffer length in bytes
141 * Returns: Pointer to the private key or %NULL on failure
146 struct crypto_rsa_key *key; in crypto_rsa_import_private_key() local
151 key = os_zalloc(sizeof(*key)); in crypto_rsa_import_private_key()
152 if (key == NULL) in crypto_rsa_import_private_key()
155 key->private_key = 1; in crypto_rsa_import_private_key()
157 key->n = bignum_init(); in crypto_rsa_import_private_key()
158 key->e = bignum_init(); in crypto_rsa_import_private_key()
159 key->d = bignum_init(); in crypto_rsa_import_private_key()
160 key->p = bignum_init(); in crypto_rsa_import_private_key()
161 key->q = bignum_init(); in crypto_rsa_import_private_key()
162 key->dmp1 = bignum_init(); in crypto_rsa_import_private_key()
163 key->dmq1 = bignum_init(); in crypto_rsa_import_private_key()
164 key->iqmp = bignum_init(); in crypto_rsa_import_private_key()
166 if (key->n == NULL || key->e == NULL || key->d == NULL || in crypto_rsa_import_private_key()
167 key->p == NULL || key->q == NULL || key->dmp1 == NULL || in crypto_rsa_import_private_key()
168 key->dmq1 == NULL || key->iqmp == NULL) { in crypto_rsa_import_private_key()
169 crypto_rsa_free(key); in crypto_rsa_import_private_key()
177 * modulus INTEGER, -- n in crypto_rsa_import_private_key()
178 * publicExponent INTEGER, -- e in crypto_rsa_import_private_key()
179 * privateExponent INTEGER, -- d in crypto_rsa_import_private_key()
180 * prime1 INTEGER, -- p in crypto_rsa_import_private_key()
181 * prime2 INTEGER, -- q in crypto_rsa_import_private_key()
182 * exponent1 INTEGER, -- d mod (p-1) in crypto_rsa_import_private_key()
183 * exponent2 INTEGER, -- d mod (q-1) in crypto_rsa_import_private_key()
184 * coefficient INTEGER -- (inverse of q) mod p in crypto_rsa_import_private_key()
187 * Version ::= INTEGER -- shall be 0 for this version of the standard in crypto_rsa_import_private_key()
190 asn1_unexpected(&hdr, "RSA: Expected SEQUENCE (public key)"); in crypto_rsa_import_private_key()
202 "beginning of private key; not found"); in crypto_rsa_import_private_key()
208 pos = crypto_rsa_parse_integer(pos, end, key->n); in crypto_rsa_import_private_key()
209 pos = crypto_rsa_parse_integer(pos, end, key->e); in crypto_rsa_import_private_key()
210 pos = crypto_rsa_parse_integer(pos, end, key->d); in crypto_rsa_import_private_key()
211 pos = crypto_rsa_parse_integer(pos, end, key->p); in crypto_rsa_import_private_key()
212 pos = crypto_rsa_parse_integer(pos, end, key->q); in crypto_rsa_import_private_key()
213 pos = crypto_rsa_parse_integer(pos, end, key->dmp1); in crypto_rsa_import_private_key()
214 pos = crypto_rsa_parse_integer(pos, end, key->dmq1); in crypto_rsa_import_private_key()
215 pos = crypto_rsa_parse_integer(pos, end, key->iqmp); in crypto_rsa_import_private_key()
222 "RSA: Extra data in public key SEQUENCE", in crypto_rsa_import_private_key()
223 pos, end - pos); in crypto_rsa_import_private_key()
227 return key; in crypto_rsa_import_private_key()
230 crypto_rsa_free(key); in crypto_rsa_import_private_key()
236 * crypto_rsa_get_modulus_len - Get the modulus length of the RSA key
237 * @key: RSA key
238 * Returns: Modulus length of the key
240 size_t crypto_rsa_get_modulus_len(struct crypto_rsa_key *key) in crypto_rsa_get_modulus_len() argument
242 return bignum_get_unsigned_bin_len(key->n); in crypto_rsa_get_modulus_len()
247 * crypto_rsa_exptmod - RSA modular exponentiation
252 * @key: RSA key
253 * @use_private: 1 = Use RSA private key, 0 = Use RSA public key
254 * Returns: 0 on success, -1 on failure
257 struct crypto_rsa_key *key, int use_private) in crypto_rsa_exptmod() argument
260 int ret = -1; in crypto_rsa_exptmod()
263 if (use_private && !key->private_key) in crypto_rsa_exptmod()
264 return -1; in crypto_rsa_exptmod()
268 return -1; in crypto_rsa_exptmod()
272 if (bignum_cmp(key->n, tmp) < 0) { in crypto_rsa_exptmod()
273 /* Too large input value for the RSA key modulus */ in crypto_rsa_exptmod()
283 * dmp1 = (1/e) mod (p-1) in crypto_rsa_exptmod()
284 * dmq1 = (1/e) mod (q-1) in crypto_rsa_exptmod()
288 * h = q^-1 (m1 - m2) mod p in crypto_rsa_exptmod()
297 if (bignum_exptmod(tmp, key->dmp1, key->p, a) < 0) in crypto_rsa_exptmod()
301 if (bignum_exptmod(tmp, key->dmq1, key->q, b) < 0) in crypto_rsa_exptmod()
304 /* tmp = (a - b) * (1/q mod p) (mod p) */ in crypto_rsa_exptmod()
306 bignum_mulmod(tmp, key->iqmp, key->p, tmp) < 0) in crypto_rsa_exptmod()
310 if (bignum_mul(tmp, key->q, tmp) < 0 || in crypto_rsa_exptmod()
316 if (bignum_exptmod(tmp, key->e, key->n, tmp) < 0) in crypto_rsa_exptmod()
320 modlen = crypto_rsa_get_modulus_len(key); in crypto_rsa_exptmod()
333 (modlen - bignum_get_unsigned_bin_len(tmp)), NULL) < 0) in crypto_rsa_exptmod()
347 * crypto_rsa_free - Free RSA key
348 * @key: RSA key to be freed
350 * This function frees an RSA key imported with either
353 void crypto_rsa_free(struct crypto_rsa_key *key) in crypto_rsa_free() argument
355 if (key) { in crypto_rsa_free()
356 bignum_deinit(key->n); in crypto_rsa_free()
357 bignum_deinit(key->e); in crypto_rsa_free()
358 bignum_deinit(key->d); in crypto_rsa_free()
359 bignum_deinit(key->p); in crypto_rsa_free()
360 bignum_deinit(key->q); in crypto_rsa_free()
361 bignum_deinit(key->dmp1); in crypto_rsa_free()
362 bignum_deinit(key->dmq1); in crypto_rsa_free()
363 bignum_deinit(key->iqmp); in crypto_rsa_free()
364 os_free(key); in crypto_rsa_free()