Lines Matching refs:ndigits
70 u64 *out, unsigned int ndigits) in ecc_digits_from_bytes() argument
72 int diff = ndigits - DIV_ROUND_UP(nbytes, sizeof(u64)); in ecc_digits_from_bytes()
78 ndigits -= diff; in ecc_digits_from_bytes()
79 memset(&out[ndigits - 1], 0, diff * sizeof(u64)); in ecc_digits_from_bytes()
84 out[--ndigits] = be64_to_cpu(msd); in ecc_digits_from_bytes()
87 ecc_swap_digits(in, out, ndigits); in ecc_digits_from_bytes()
91 static u64 *ecc_alloc_digits_space(unsigned int ndigits) in ecc_alloc_digits_space() argument
93 size_t len = ndigits * sizeof(u64); in ecc_alloc_digits_space()
106 struct ecc_point *ecc_alloc_point(unsigned int ndigits) in ecc_alloc_point() argument
113 p->x = ecc_alloc_digits_space(ndigits); in ecc_alloc_point()
117 p->y = ecc_alloc_digits_space(ndigits); in ecc_alloc_point()
121 p->ndigits = ndigits; in ecc_alloc_point()
144 static void vli_clear(u64 *vli, unsigned int ndigits) in vli_clear() argument
148 for (i = 0; i < ndigits; i++) in vli_clear()
153 bool vli_is_zero(const u64 *vli, unsigned int ndigits) in vli_is_zero() argument
157 for (i = 0; i < ndigits; i++) { in vli_is_zero()
172 static bool vli_is_negative(const u64 *vli, unsigned int ndigits) in vli_is_negative() argument
174 return vli_test_bit(vli, ndigits * 64 - 1); in vli_is_negative()
178 static unsigned int vli_num_digits(const u64 *vli, unsigned int ndigits) in vli_num_digits() argument
186 for (i = ndigits - 1; i >= 0 && vli[i] == 0; i--); in vli_num_digits()
192 unsigned int vli_num_bits(const u64 *vli, unsigned int ndigits) in vli_num_bits() argument
197 num_digits = vli_num_digits(vli, ndigits); in vli_num_bits()
210 void vli_from_be64(u64 *dest, const void *src, unsigned int ndigits) in vli_from_be64() argument
215 for (i = 0; i < ndigits; i++) in vli_from_be64()
216 dest[i] = get_unaligned_be64(&from[ndigits - 1 - i]); in vli_from_be64()
220 void vli_from_le64(u64 *dest, const void *src, unsigned int ndigits) in vli_from_le64() argument
225 for (i = 0; i < ndigits; i++) in vli_from_le64()
231 static void vli_set(u64 *dest, const u64 *src, unsigned int ndigits) in vli_set() argument
235 for (i = 0; i < ndigits; i++) in vli_set()
240 int vli_cmp(const u64 *left, const u64 *right, unsigned int ndigits) in vli_cmp() argument
244 for (i = ndigits - 1; i >= 0; i--) { in vli_cmp()
259 unsigned int ndigits) in vli_lshift() argument
264 for (i = 0; i < ndigits; i++) { in vli_lshift()
275 static void vli_rshift1(u64 *vli, unsigned int ndigits) in vli_rshift1() argument
280 vli += ndigits; in vli_rshift1()
291 unsigned int ndigits) in vli_add() argument
296 for (i = 0; i < ndigits; i++) { in vli_add()
311 unsigned int ndigits) in vli_uadd() argument
316 for (i = 0; i < ndigits; i++) { in vli_uadd()
333 unsigned int ndigits) in vli_sub() argument
338 for (i = 0; i < ndigits; i++) { in vli_sub()
354 unsigned int ndigits) in vli_usub() argument
359 for (i = 0; i < ndigits; i++) { in vli_usub()
414 unsigned int ndigits) in vli_mult() argument
423 for (k = 0; k < ndigits * 2 - 1; k++) { in vli_mult()
426 if (k < ndigits) in vli_mult()
429 min = (k + 1) - ndigits; in vli_mult()
431 for (i = min; i <= k && i < ndigits; i++) { in vli_mult()
446 result[ndigits * 2 - 1] = r01.m_low; in vli_mult()
451 unsigned int ndigits) in vli_umult() argument
456 for (k = 0; k < ndigits; k++) { in vli_umult()
467 for (++k; k < ndigits * 2; k++) in vli_umult()
471 static void vli_square(u64 *result, const u64 *left, unsigned int ndigits) in vli_square() argument
477 for (k = 0; k < ndigits * 2 - 1; k++) { in vli_square()
480 if (k < ndigits) in vli_square()
483 min = (k + 1) - ndigits; in vli_square()
507 result[ndigits * 2 - 1] = r01.m_low; in vli_square()
514 const u64 *mod, unsigned int ndigits) in vli_mod_add() argument
518 carry = vli_add(result, left, right, ndigits); in vli_mod_add()
523 if (carry || vli_cmp(result, mod, ndigits) >= 0) in vli_mod_add()
524 vli_sub(result, result, mod, ndigits); in vli_mod_add()
531 const u64 *mod, unsigned int ndigits) in vli_mod_sub() argument
533 u64 borrow = vli_sub(result, left, right, ndigits); in vli_mod_sub()
540 vli_add(result, result, mod, ndigits); in vli_mod_sub()
553 const u64 *mod, unsigned int ndigits) in vli_mmod_special() argument
559 vli_set(r, product, ndigits * 2); in vli_mmod_special()
560 while (!vli_is_zero(r + ndigits, ndigits)) { in vli_mmod_special()
561 vli_umult(t, r + ndigits, c, ndigits); in vli_mmod_special()
562 vli_clear(r + ndigits, ndigits); in vli_mmod_special()
563 vli_add(r, r, t, ndigits * 2); in vli_mmod_special()
565 vli_set(t, mod, ndigits); in vli_mmod_special()
566 vli_clear(t + ndigits, ndigits); in vli_mmod_special()
567 while (vli_cmp(r, t, ndigits * 2) >= 0) in vli_mmod_special()
568 vli_sub(r, r, t, ndigits * 2); in vli_mmod_special()
569 vli_set(result, r, ndigits); in vli_mmod_special()
587 const u64 *mod, unsigned int ndigits) in vli_mmod_special2() argument
596 vli_set(m, mod, ndigits); in vli_mmod_special2()
597 vli_clear(m + ndigits, ndigits); in vli_mmod_special2()
599 vli_set(r, product, ndigits); in vli_mmod_special2()
601 vli_set(q, product + ndigits, ndigits); in vli_mmod_special2()
602 vli_clear(r + ndigits, ndigits); in vli_mmod_special2()
603 carry = vli_is_negative(r, ndigits); in vli_mmod_special2()
605 r[ndigits - 1] &= (1ull << 63) - 1; in vli_mmod_special2()
606 for (i = 1; carry || !vli_is_zero(q, ndigits); i++) { in vli_mmod_special2()
609 vli_umult(qc, q, c2, ndigits); in vli_mmod_special2()
611 vli_uadd(qc, qc, mod[0], ndigits * 2); in vli_mmod_special2()
612 vli_set(q, qc + ndigits, ndigits); in vli_mmod_special2()
613 vli_clear(qc + ndigits, ndigits); in vli_mmod_special2()
614 carry = vli_is_negative(qc, ndigits); in vli_mmod_special2()
616 qc[ndigits - 1] &= (1ull << 63) - 1; in vli_mmod_special2()
618 vli_sub(r, r, qc, ndigits * 2); in vli_mmod_special2()
620 vli_add(r, r, qc, ndigits * 2); in vli_mmod_special2()
622 while (vli_is_negative(r, ndigits * 2)) in vli_mmod_special2()
623 vli_add(r, r, m, ndigits * 2); in vli_mmod_special2()
624 while (vli_cmp(r, m, ndigits * 2) >= 0) in vli_mmod_special2()
625 vli_sub(r, r, m, ndigits * 2); in vli_mmod_special2()
627 vli_set(result, r, ndigits); in vli_mmod_special2()
636 unsigned int ndigits) in vli_mmod_slow() argument
644 int shift = (ndigits * 2 * 64) - vli_num_bits(mod, ndigits); in vli_mmod_slow()
650 for (i = 0; i < ndigits; ++i) { in vli_mmod_slow()
655 vli_set(mod_m + word_shift, mod, ndigits); in vli_mmod_slow()
661 for (j = 0; j < ndigits * 2; ++j) { in vli_mmod_slow()
669 vli_rshift1(mod_m, ndigits); in vli_mmod_slow()
670 mod_m[ndigits - 1] |= mod_m[ndigits] << (64 - 1); in vli_mmod_slow()
671 vli_rshift1(mod_m + ndigits, ndigits); in vli_mmod_slow()
673 vli_set(result, v[i], ndigits); in vli_mmod_slow()
686 unsigned int ndigits) in vli_mmod_barrett() argument
690 const u64 *mu = mod + ndigits; in vli_mmod_barrett()
692 vli_mult(q, product + ndigits, mu, ndigits); in vli_mmod_barrett()
693 if (mu[ndigits]) in vli_mmod_barrett()
694 vli_add(q + ndigits, q + ndigits, product + ndigits, ndigits); in vli_mmod_barrett()
695 vli_mult(r, mod, q + ndigits, ndigits); in vli_mmod_barrett()
696 vli_sub(r, product, r, ndigits * 2); in vli_mmod_barrett()
697 while (!vli_is_zero(r + ndigits, ndigits) || in vli_mmod_barrett()
698 vli_cmp(r, mod, ndigits) != -1) { in vli_mmod_barrett()
701 carry = vli_sub(r, r, mod, ndigits); in vli_mmod_barrett()
702 vli_usub(r + ndigits, r + ndigits, carry, ndigits); in vli_mmod_barrett()
704 vli_set(result, r, ndigits); in vli_mmod_barrett()
714 const unsigned int ndigits = 3; in vli_mmod_fast_192() local
717 vli_set(result, product, ndigits); in vli_mmod_fast_192()
719 vli_set(tmp, &product[3], ndigits); in vli_mmod_fast_192()
720 carry = vli_add(result, result, tmp, ndigits); in vli_mmod_fast_192()
725 carry += vli_add(result, result, tmp, ndigits); in vli_mmod_fast_192()
729 carry += vli_add(result, result, tmp, ndigits); in vli_mmod_fast_192()
731 while (carry || vli_cmp(curve_prime, result, ndigits) != 1) in vli_mmod_fast_192()
732 carry -= vli_sub(result, result, curve_prime, ndigits); in vli_mmod_fast_192()
742 const unsigned int ndigits = 4; in vli_mmod_fast_256() local
745 vli_set(result, product, ndigits); in vli_mmod_fast_256()
752 carry = vli_lshift(tmp, tmp, 1, ndigits); in vli_mmod_fast_256()
753 carry += vli_add(result, result, tmp, ndigits); in vli_mmod_fast_256()
759 carry += vli_lshift(tmp, tmp, 1, ndigits); in vli_mmod_fast_256()
760 carry += vli_add(result, result, tmp, ndigits); in vli_mmod_fast_256()
767 carry += vli_add(result, result, tmp, ndigits); in vli_mmod_fast_256()
774 carry += vli_add(result, result, tmp, ndigits); in vli_mmod_fast_256()
781 carry -= vli_sub(result, result, tmp, ndigits); in vli_mmod_fast_256()
788 carry -= vli_sub(result, result, tmp, ndigits); in vli_mmod_fast_256()
795 carry -= vli_sub(result, result, tmp, ndigits); in vli_mmod_fast_256()
802 carry -= vli_sub(result, result, tmp, ndigits); in vli_mmod_fast_256()
806 carry += vli_add(result, result, curve_prime, ndigits); in vli_mmod_fast_256()
809 while (carry || vli_cmp(curve_prime, result, ndigits) != 1) in vli_mmod_fast_256()
810 carry -= vli_sub(result, result, curve_prime, ndigits); in vli_mmod_fast_256()
825 const unsigned int ndigits = 6; in vli_mmod_fast_384() local
828 vli_set(result, product, ndigits); in vli_mmod_fast_384()
837 carry = vli_lshift(tmp, tmp, 1, ndigits); in vli_mmod_fast_384()
838 carry += vli_add(result, result, tmp, ndigits); in vli_mmod_fast_384()
847 carry += vli_add(result, result, tmp, ndigits); in vli_mmod_fast_384()
856 carry += vli_add(result, result, tmp, ndigits); in vli_mmod_fast_384()
865 carry += vli_add(result, result, tmp, ndigits); in vli_mmod_fast_384()
874 carry += vli_add(result, result, tmp, ndigits); in vli_mmod_fast_384()
883 carry += vli_add(result, result, tmp, ndigits); in vli_mmod_fast_384()
892 carry -= vli_sub(result, result, tmp, ndigits); in vli_mmod_fast_384()
901 carry -= vli_sub(result, result, tmp, ndigits); in vli_mmod_fast_384()
910 carry -= vli_sub(result, result, tmp, ndigits); in vli_mmod_fast_384()
914 carry += vli_add(result, result, curve_prime, ndigits); in vli_mmod_fast_384()
917 while (carry || vli_cmp(curve_prime, result, ndigits) != 1) in vli_mmod_fast_384()
918 carry -= vli_sub(result, result, curve_prime, ndigits); in vli_mmod_fast_384()
937 const unsigned int ndigits = curve->g.ndigits; in vli_mmod_fast() local
942 if (curve_prime[ndigits - 1] == -1ull) { in vli_mmod_fast()
944 ndigits); in vli_mmod_fast()
946 } else if (curve_prime[ndigits - 1] == 1ull << 63 && in vli_mmod_fast()
947 curve_prime[ndigits - 2] == 0) { in vli_mmod_fast()
949 ndigits); in vli_mmod_fast()
952 vli_mmod_barrett(result, product, curve_prime, ndigits); in vli_mmod_fast()
956 switch (ndigits) { in vli_mmod_fast()
978 const u64 *mod, unsigned int ndigits) in vli_mod_mult_slow() argument
982 vli_mult(product, left, right, ndigits); in vli_mod_mult_slow()
983 vli_mmod_slow(result, product, mod, ndigits); in vli_mod_mult_slow()
993 vli_mult(product, left, right, curve->g.ndigits); in vli_mod_mult_fast()
1003 vli_square(product, left, curve->g.ndigits); in vli_mod_square_fast()
1013 unsigned int ndigits) in vli_mod_inv() argument
1020 if (vli_is_zero(input, ndigits)) { in vli_mod_inv()
1021 vli_clear(result, ndigits); in vli_mod_inv()
1025 vli_set(a, input, ndigits); in vli_mod_inv()
1026 vli_set(b, mod, ndigits); in vli_mod_inv()
1027 vli_clear(u, ndigits); in vli_mod_inv()
1029 vli_clear(v, ndigits); in vli_mod_inv()
1031 while ((cmp_result = vli_cmp(a, b, ndigits)) != 0) { in vli_mod_inv()
1035 vli_rshift1(a, ndigits); in vli_mod_inv()
1038 carry = vli_add(u, u, mod, ndigits); in vli_mod_inv()
1040 vli_rshift1(u, ndigits); in vli_mod_inv()
1042 u[ndigits - 1] |= 0x8000000000000000ull; in vli_mod_inv()
1044 vli_rshift1(b, ndigits); in vli_mod_inv()
1047 carry = vli_add(v, v, mod, ndigits); in vli_mod_inv()
1049 vli_rshift1(v, ndigits); in vli_mod_inv()
1051 v[ndigits - 1] |= 0x8000000000000000ull; in vli_mod_inv()
1053 vli_sub(a, a, b, ndigits); in vli_mod_inv()
1054 vli_rshift1(a, ndigits); in vli_mod_inv()
1056 if (vli_cmp(u, v, ndigits) < 0) in vli_mod_inv()
1057 vli_add(u, u, mod, ndigits); in vli_mod_inv()
1059 vli_sub(u, u, v, ndigits); in vli_mod_inv()
1061 carry = vli_add(u, u, mod, ndigits); in vli_mod_inv()
1063 vli_rshift1(u, ndigits); in vli_mod_inv()
1065 u[ndigits - 1] |= 0x8000000000000000ull; in vli_mod_inv()
1067 vli_sub(b, b, a, ndigits); in vli_mod_inv()
1068 vli_rshift1(b, ndigits); in vli_mod_inv()
1070 if (vli_cmp(v, u, ndigits) < 0) in vli_mod_inv()
1071 vli_add(v, v, mod, ndigits); in vli_mod_inv()
1073 vli_sub(v, v, u, ndigits); in vli_mod_inv()
1075 carry = vli_add(v, v, mod, ndigits); in vli_mod_inv()
1077 vli_rshift1(v, ndigits); in vli_mod_inv()
1079 v[ndigits - 1] |= 0x8000000000000000ull; in vli_mod_inv()
1083 vli_set(result, u, ndigits); in vli_mod_inv()
1092 return (vli_is_zero(point->x, point->ndigits) && in ecc_point_is_zero()
1093 vli_is_zero(point->y, point->ndigits)); in ecc_point_is_zero()
1109 const unsigned int ndigits = curve->g.ndigits; in ecc_point_double_jacobian() local
1111 if (vli_is_zero(z1, ndigits)) in ecc_point_double_jacobian()
1126 vli_mod_add(x1, x1, z1, curve_prime, ndigits); in ecc_point_double_jacobian()
1128 vli_mod_add(z1, z1, z1, curve_prime, ndigits); in ecc_point_double_jacobian()
1130 vli_mod_sub(z1, x1, z1, curve_prime, ndigits); in ecc_point_double_jacobian()
1135 vli_mod_add(z1, x1, x1, curve_prime, ndigits); in ecc_point_double_jacobian()
1137 vli_mod_add(x1, x1, z1, curve_prime, ndigits); in ecc_point_double_jacobian()
1139 u64 carry = vli_add(x1, x1, curve_prime, ndigits); in ecc_point_double_jacobian()
1141 vli_rshift1(x1, ndigits); in ecc_point_double_jacobian()
1142 x1[ndigits - 1] |= carry << 63; in ecc_point_double_jacobian()
1144 vli_rshift1(x1, ndigits); in ecc_point_double_jacobian()
1151 vli_mod_sub(z1, z1, t5, curve_prime, ndigits); in ecc_point_double_jacobian()
1153 vli_mod_sub(z1, z1, t5, curve_prime, ndigits); in ecc_point_double_jacobian()
1155 vli_mod_sub(t5, t5, z1, curve_prime, ndigits); in ecc_point_double_jacobian()
1159 vli_mod_sub(t4, x1, t4, curve_prime, ndigits); in ecc_point_double_jacobian()
1161 vli_set(x1, z1, ndigits); in ecc_point_double_jacobian()
1162 vli_set(z1, y1, ndigits); in ecc_point_double_jacobian()
1163 vli_set(y1, t4, ndigits); in ecc_point_double_jacobian()
1182 const unsigned int ndigits = curve->g.ndigits; in xycz_initial_double() local
1184 vli_set(x2, x1, ndigits); in xycz_initial_double()
1185 vli_set(y2, y1, ndigits); in xycz_initial_double()
1187 vli_clear(z, ndigits); in xycz_initial_double()
1191 vli_set(z, p_initial_z, ndigits); in xycz_initial_double()
1210 const unsigned int ndigits = curve->g.ndigits; in xycz_add() local
1213 vli_mod_sub(t5, x2, x1, curve_prime, ndigits); in xycz_add()
1221 vli_mod_sub(y2, y2, y1, curve_prime, ndigits); in xycz_add()
1226 vli_mod_sub(t5, t5, x1, curve_prime, ndigits); in xycz_add()
1228 vli_mod_sub(t5, t5, x2, curve_prime, ndigits); in xycz_add()
1230 vli_mod_sub(x2, x2, x1, curve_prime, ndigits); in xycz_add()
1234 vli_mod_sub(x2, x1, t5, curve_prime, ndigits); in xycz_add()
1238 vli_mod_sub(y2, y2, y1, curve_prime, ndigits); in xycz_add()
1240 vli_set(x2, t5, ndigits); in xycz_add()
1255 const unsigned int ndigits = curve->g.ndigits; in xycz_add_c() local
1258 vli_mod_sub(t5, x2, x1, curve_prime, ndigits); in xycz_add_c()
1266 vli_mod_add(t5, y2, y1, curve_prime, ndigits); in xycz_add_c()
1268 vli_mod_sub(y2, y2, y1, curve_prime, ndigits); in xycz_add_c()
1271 vli_mod_sub(t6, x2, x1, curve_prime, ndigits); in xycz_add_c()
1275 vli_mod_add(t6, x1, x2, curve_prime, ndigits); in xycz_add_c()
1279 vli_mod_sub(x2, x2, t6, curve_prime, ndigits); in xycz_add_c()
1282 vli_mod_sub(t7, x1, x2, curve_prime, ndigits); in xycz_add_c()
1286 vli_mod_sub(y2, y2, y1, curve_prime, ndigits); in xycz_add_c()
1291 vli_mod_sub(t7, t7, t6, curve_prime, ndigits); in xycz_add_c()
1293 vli_mod_sub(t6, t7, x1, curve_prime, ndigits); in xycz_add_c()
1297 vli_mod_sub(y1, t6, y1, curve_prime, ndigits); in xycz_add_c()
1299 vli_set(x1, t7, ndigits); in xycz_add_c()
1305 unsigned int ndigits) in ecc_point_mult() argument
1317 carry = vli_add(sk[0], scalar, curve->n, ndigits); in ecc_point_mult()
1318 vli_add(sk[1], sk[0], curve->n, ndigits); in ecc_point_mult()
1320 num_bits = sizeof(u64) * ndigits * 8 + 1; in ecc_point_mult()
1322 vli_set(rx[1], point->x, ndigits); in ecc_point_mult()
1323 vli_set(ry[1], point->y, ndigits); in ecc_point_mult()
1338 vli_mod_sub(z, rx[1], rx[0], curve_prime, ndigits); in ecc_point_mult()
1345 vli_mod_inv(z, z, curve_prime, point->ndigits); in ecc_point_mult()
1357 vli_set(result->x, rx[0], ndigits); in ecc_point_mult()
1358 vli_set(result->y, ry[0], ndigits); in ecc_point_mult()
1369 unsigned int ndigits = curve->g.ndigits; in ecc_point_add() local
1371 vli_set(result->x, q->x, ndigits); in ecc_point_add()
1372 vli_set(result->y, q->y, ndigits); in ecc_point_add()
1373 vli_mod_sub(z, result->x, p->x, curve->p, ndigits); in ecc_point_add()
1374 vli_set(px, p->x, ndigits); in ecc_point_add()
1375 vli_set(py, p->y, ndigits); in ecc_point_add()
1377 vli_mod_inv(z, z, curve->p, ndigits); in ecc_point_add()
1393 unsigned int ndigits = curve->g.ndigits; in ecc_point_mult_shamir() local
1395 struct ecc_point sum = ECC_POINT_INIT(sump[0], sump[1], ndigits); in ecc_point_mult_shamir()
1407 num_bits = max(vli_num_bits(u1, ndigits), vli_num_bits(u2, ndigits)); in ecc_point_mult_shamir()
1413 vli_set(rx, point->x, ndigits); in ecc_point_mult_shamir()
1414 vli_set(ry, point->y, ndigits); in ecc_point_mult_shamir()
1415 vli_clear(z + 1, ndigits - 1); in ecc_point_mult_shamir()
1428 vli_set(tx, point->x, ndigits); in ecc_point_mult_shamir()
1429 vli_set(ty, point->y, ndigits); in ecc_point_mult_shamir()
1431 vli_mod_sub(tz, rx, tx, curve->p, ndigits); in ecc_point_mult_shamir()
1436 vli_mod_inv(z, z, curve->p, ndigits); in ecc_point_mult_shamir()
1442 const u64 *private_key, unsigned int ndigits) in __ecc_is_key_valid() argument
1450 if (curve->g.ndigits != ndigits) in __ecc_is_key_valid()
1454 if (vli_cmp(one, private_key, ndigits) != -1) in __ecc_is_key_valid()
1456 vli_sub(res, curve->n, one, ndigits); in __ecc_is_key_valid()
1457 vli_sub(res, res, one, ndigits); in __ecc_is_key_valid()
1458 if (vli_cmp(res, private_key, ndigits) != 1) in __ecc_is_key_valid()
1464 int ecc_is_key_valid(unsigned int curve_id, unsigned int ndigits, in ecc_is_key_valid() argument
1470 nbytes = ndigits << ECC_DIGITS_TO_BYTES_SHIFT; in ecc_is_key_valid()
1475 return __ecc_is_key_valid(curve, private_key, ndigits); in ecc_is_key_valid()
1491 int ecc_gen_privkey(unsigned int curve_id, unsigned int ndigits, u64 *privkey) in ecc_gen_privkey() argument
1495 unsigned int nbytes = ndigits << ECC_DIGITS_TO_BYTES_SHIFT; in ecc_gen_privkey()
1496 unsigned int nbits = vli_num_bits(curve->n, ndigits); in ecc_gen_privkey()
1500 if (nbits < 160 || ndigits > ARRAY_SIZE(priv)) in ecc_gen_privkey()
1523 if (__ecc_is_key_valid(curve, priv, ndigits)) in ecc_gen_privkey()
1526 ecc_swap_digits(priv, privkey, ndigits); in ecc_gen_privkey()
1532 int ecc_make_pub_key(unsigned int curve_id, unsigned int ndigits, in ecc_make_pub_key() argument
1540 if (!private_key || !curve || ndigits > ARRAY_SIZE(priv)) { in ecc_make_pub_key()
1545 ecc_swap_digits(private_key, priv, ndigits); in ecc_make_pub_key()
1547 pk = ecc_alloc_point(ndigits); in ecc_make_pub_key()
1553 ecc_point_mult(pk, &curve->g, priv, NULL, curve, ndigits); in ecc_make_pub_key()
1561 ecc_swap_digits(pk->x, public_key, ndigits); in ecc_make_pub_key()
1562 ecc_swap_digits(pk->y, &public_key[ndigits], ndigits); in ecc_make_pub_key()
1577 if (WARN_ON(pk->ndigits != curve->g.ndigits)) in ecc_is_pubkey_valid_partial()
1585 if (vli_cmp(curve->p, pk->x, pk->ndigits) != 1) in ecc_is_pubkey_valid_partial()
1587 if (vli_cmp(curve->p, pk->y, pk->ndigits) != 1) in ecc_is_pubkey_valid_partial()
1595 vli_mod_add(w, w, curve->b, curve->p, pk->ndigits); /* a·x + b */ in ecc_is_pubkey_valid_partial()
1596 vli_mod_add(w, w, xxx, curve->p, pk->ndigits); /* x^3 + a·x + b */ in ecc_is_pubkey_valid_partial()
1597 if (vli_cmp(yy, w, pk->ndigits) != 0) /* Equation */ in ecc_is_pubkey_valid_partial()
1617 nQ = ecc_alloc_point(pk->ndigits); in ecc_is_pubkey_valid_full()
1621 ecc_point_mult(nQ, pk, curve->n, NULL, curve, pk->ndigits); in ecc_is_pubkey_valid_full()
1631 int crypto_ecdh_shared_secret(unsigned int curve_id, unsigned int ndigits, in crypto_ecdh_shared_secret() argument
1643 ndigits > ARRAY_SIZE(priv) || ndigits > ARRAY_SIZE(rand_z)) { in crypto_ecdh_shared_secret()
1648 nbytes = ndigits << ECC_DIGITS_TO_BYTES_SHIFT; in crypto_ecdh_shared_secret()
1652 pk = ecc_alloc_point(ndigits); in crypto_ecdh_shared_secret()
1658 ecc_swap_digits(public_key, pk->x, ndigits); in crypto_ecdh_shared_secret()
1659 ecc_swap_digits(&public_key[ndigits], pk->y, ndigits); in crypto_ecdh_shared_secret()
1664 ecc_swap_digits(private_key, priv, ndigits); in crypto_ecdh_shared_secret()
1666 product = ecc_alloc_point(ndigits); in crypto_ecdh_shared_secret()
1672 ecc_point_mult(product, pk, priv, rand_z, curve, ndigits); in crypto_ecdh_shared_secret()
1679 ecc_swap_digits(product->x, secret, ndigits); in crypto_ecdh_shared_secret()