Lines Matching refs:key

37 static void subtract_modulus(const struct rsa_public_key *key, uint32_t num[])  in subtract_modulus()  argument
42 for (i = 0; i < key->len; i++) { in subtract_modulus()
43 acc += (uint64_t)num[i] - key->modulus[i]; in subtract_modulus()
56 static int greater_equal_modulus(const struct rsa_public_key *key, in greater_equal_modulus() argument
61 for (i = (int)key->len - 1; i >= 0; i--) { in greater_equal_modulus()
62 if (num[i] < key->modulus[i]) in greater_equal_modulus()
64 if (num[i] > key->modulus[i]) in greater_equal_modulus()
81 static void montgomery_mul_add_step(const struct rsa_public_key *key, in montgomery_mul_add_step() argument
89 d0 = (uint32_t)acc_a * key->n0inv; in montgomery_mul_add_step()
90 acc_b = (uint64_t)d0 * key->modulus[0] + (uint32_t)acc_a; in montgomery_mul_add_step()
91 for (i = 1; i < key->len; i++) { in montgomery_mul_add_step()
93 acc_b = (acc_b >> 32) + (uint64_t)d0 * key->modulus[i] + in montgomery_mul_add_step()
103 subtract_modulus(key, result); in montgomery_mul_add_step()
116 static void montgomery_mul(const struct rsa_public_key *key, in montgomery_mul() argument
121 for (i = 0; i < key->len; ++i) in montgomery_mul()
123 for (i = 0; i < key->len; ++i) in montgomery_mul()
124 montgomery_mul_add_step(key, result, a[i], b); in montgomery_mul()
133 static int num_public_exponent_bits(const struct rsa_public_key *key, in num_public_exponent_bits() argument
140 exponent = key->exponent; in num_public_exponent_bits()
163 static int is_public_exponent_bit_set(const struct rsa_public_key *key, in is_public_exponent_bit_set() argument
166 return key->exponent & (1ULL << pos); in is_public_exponent_bit_set()
175 static int pow_mod(const struct rsa_public_key *key, uint32_t *inout) in pow_mod() argument
182 if (key->len > RSA_MAX_KEY_BITS / 32) { in pow_mod()
183 debug("RSA key words %u exceeds maximum %d\n", key->len, in pow_mod()
188 uint32_t val[key->len], acc[key->len], tmp[key->len]; in pow_mod()
189 uint32_t a_scaled[key->len]; in pow_mod()
193 for (i = 0, ptr = inout + key->len - 1; i < key->len; i++, ptr--) in pow_mod()
196 if (0 != num_public_exponent_bits(key, &k)) in pow_mod()
205 if (!is_public_exponent_bit_set(key, 0)) { in pow_mod()
211 montgomery_mul(key, acc, val, key->rr); /* acc = a * RR / R mod n */ in pow_mod()
213 memcpy(a_scaled, acc, key->len * sizeof(a_scaled[0])); in pow_mod()
216 montgomery_mul(key, tmp, acc, acc); /* tmp = acc^2 / R mod n */ in pow_mod()
218 if (is_public_exponent_bit_set(key, j)) { in pow_mod()
220 montgomery_mul(key, acc, tmp, a_scaled); in pow_mod()
223 memcpy(acc, tmp, key->len * sizeof(acc[0])); in pow_mod()
228 montgomery_mul(key, tmp, acc, acc); /* tmp = acc^2 / R mod n */ in pow_mod()
229 montgomery_mul(key, acc, tmp, val); /* acc = tmp * a / R mod M */ in pow_mod()
230 memcpy(result, acc, key->len * sizeof(result[0])); in pow_mod()
233 if (greater_equal_modulus(key, result)) in pow_mod()
234 subtract_modulus(key, result); in pow_mod()
237 for (i = key->len - 1, ptr = inout; (int)i >= 0; i--, ptr++) in pow_mod()
258 struct rsa_public_key key; in rsa_mod_exp_sw() local
265 key.n0inv = prop->n0inv; in rsa_mod_exp_sw()
266 key.len = prop->num_bits; in rsa_mod_exp_sw()
269 key.exponent = RSA_DEFAULT_PUBEXP; in rsa_mod_exp_sw()
279 key.exponent = fdt64_to_cpu(tmp); in rsa_mod_exp_sw()
282 if (!key.len || !prop->modulus || !prop->rr) { in rsa_mod_exp_sw()
288 if (key.len > RSA_MAX_KEY_BITS || key.len < RSA_MIN_KEY_BITS) { in rsa_mod_exp_sw()
290 key.len, RSA_MIN_KEY_BITS, RSA_MAX_KEY_BITS); in rsa_mod_exp_sw()
293 key.len /= sizeof(uint32_t) * 8; in rsa_mod_exp_sw()
294 uint32_t key1[key.len], key2[key.len]; in rsa_mod_exp_sw()
296 key.modulus = key1; in rsa_mod_exp_sw()
297 key.rr = key2; in rsa_mod_exp_sw()
298 rsa_convert_big_endian(key.modulus, (uint32_t *)prop->modulus, key.len); in rsa_mod_exp_sw()
299 rsa_convert_big_endian(key.rr, (uint32_t *)prop->rr, key.len); in rsa_mod_exp_sw()
300 if (!key.modulus || !key.rr) { in rsa_mod_exp_sw()
309 ret = pow_mod(&key, buf); in rsa_mod_exp_sw()