Lines Matching +full:integer +full:- +full:n

3  * Copyright (c) 2006-2014, Jouni Malinen <j@w1.fi>
19 struct bignum *n; /* modulus (p * q) */ member
23 struct bignum *p; /* prime p (factor of n) */
24 struct bignum *q; /* prime q (factor of n) */
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()
41 asn1_unexpected(&hdr, "RSA: Expected INTEGER"); in crypto_rsa_parse_integer()
46 wpa_printf(MSG_DEBUG, "RSA: Failed to parse INTEGER"); in crypto_rsa_parse_integer()
55 * crypto_rsa_import_public_key - Import an RSA 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()
81 * modulus INTEGER, -- n in crypto_rsa_import_public_key()
82 * publicExponent INTEGER -- e 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()
102 pos, end - pos); in crypto_rsa_import_public_key()
115 crypto_rsa_import_public_key_parts(const u8 *n, size_t n_len, in crypto_rsa_import_public_key_parts() argument
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()
138 * crypto_rsa_import_private_key - Import an RSA 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()
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()
201 wpa_printf(MSG_DEBUG, "RSA: Expected zero INTEGER in the " 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()
223 pos, end - pos); in crypto_rsa_import_private_key()
236 * crypto_rsa_get_modulus_len - Get the modulus length of the RSA key
242 return bignum_get_unsigned_bin_len(key->n); in crypto_rsa_get_modulus_len()
247 * crypto_rsa_exptmod - RSA modular exponentiation
254 * Returns: 0 on success, -1 on failure
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()
280 * up calculation. This is equivalent to tmp = tmp^d mod n 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()
315 /* tmp = tmp^e mod N */ in crypto_rsa_exptmod()
316 if (bignum_exptmod(tmp, key->e, key->n, tmp) < 0) 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
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()