crypto/ecc.c
Source file repositories/reference/linux-study-clean/crypto/ecc.c
File Facts
- System
- Linux kernel
- Corpus path
crypto/ecc.c- Extension
.c- Size
- 44609 bytes
- Lines
- 1715
- Domain
- Kernel Services
- Bucket
- crypto
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
crypto/ecc_curve.hlinux/module.hlinux/random.hlinux/slab.hlinux/swab.hlinux/fips.hcrypto/ecdh.hcrypto/rng.hcrypto/internal/ecc.hlinux/unaligned.hlinux/ratelimit.hecc_curve_defs.h
Detected Declarations
function ecc_digits_from_bytesfunction ecc_free_pointfunction vli_clearfunction vli_is_zerofunction vli_test_bitfunction vli_is_negativefunction vli_num_digitsfunction vli_num_bitsfunction vli_from_be64function vli_from_le64function vli_setfunction vli_cmpfunction vli_lshiftfunction vli_rshift1function vli_addfunction vli_uaddfunction vli_subfunction vli_usubfunction mul_64_64function check_add_128_128_overflowfunction vli_multfunction vli_umultfunction vli_squarefunction vli_mod_addfunction vli_mod_subfunction vli_mmod_specialfunction Referencesfunction vli_mmod_slowfunction vli_mmod_barrettfunction vli_cmpfunction vli_mmod_fast_192function vli_mmod_fast_256function vli_mmod_fast_384function vli_mmod_fast_521function vli_mmod_fastfunction vli_mod_mult_slowfunction vli_mod_mult_fastfunction vli_mod_square_fastfunction vli_mod_invfunction ecc_point_is_zerofunction ecc_point_double_jacobianfunction apply_zfunction xycz_initial_doublefunction xycz_addfunction xycz_add_cfunction ecc_point_multfunction ecc_point_addfunction ecc_point_mult_shamir
Annotated Snippet
if (i < k - i) {
r2 += product.m_high >> 63;
product.m_high = (product.m_high << 1) |
(product.m_low >> 63);
product.m_low <<= 1;
}
r2 += check_add_128_128_overflow(&r01, r01, product);
}
result[k] = r01.m_low;
r01.m_low = r01.m_high;
r01.m_high = r2;
r2 = 0;
}
result[ndigits * 2 - 1] = r01.m_low;
}
/* Computes result = (left + right) % mod.
* Assumes that left < mod and right < mod, result != mod.
*/
static void vli_mod_add(u64 *result, const u64 *left, const u64 *right,
const u64 *mod, unsigned int ndigits)
{
u64 carry;
carry = vli_add(result, left, right, ndigits);
/* result > mod (result = mod + remainder), so subtract mod to
* get remainder.
*/
if (carry || vli_cmp(result, mod, ndigits) >= 0)
vli_sub(result, result, mod, ndigits);
}
/* Computes result = (left - right) % mod.
* Assumes that left < mod and right < mod, result != mod.
*/
static void vli_mod_sub(u64 *result, const u64 *left, const u64 *right,
const u64 *mod, unsigned int ndigits)
{
u64 borrow = vli_sub(result, left, right, ndigits);
/* In this case, p_result == -diff == (max int) - diff.
* Since -x % d == d - x, we can get the correct result from
* result + mod (with overflow).
*/
if (borrow)
vli_add(result, result, mod, ndigits);
}
/*
* Computes result = product % mod
* for special form moduli: p = 2^k-c, for small c (note the minus sign)
*
* References:
* R. Crandall, C. Pomerance. Prime Numbers: A Computational Perspective.
* 9 Fast Algorithms for Large-Integer Arithmetic. 9.2.3 Moduli of special form
* Algorithm 9.2.13 (Fast mod operation for special-form moduli).
*/
static void vli_mmod_special(u64 *result, const u64 *product,
const u64 *mod, unsigned int ndigits)
{
u64 c = -mod[0];
u64 t[ECC_MAX_DIGITS * 2];
u64 r[ECC_MAX_DIGITS * 2];
vli_set(r, product, ndigits * 2);
while (!vli_is_zero(r + ndigits, ndigits)) {
vli_umult(t, r + ndigits, c, ndigits);
vli_clear(r + ndigits, ndigits);
vli_add(r, r, t, ndigits * 2);
}
vli_set(t, mod, ndigits);
vli_clear(t + ndigits, ndigits);
while (vli_cmp(r, t, ndigits * 2) >= 0)
vli_sub(r, r, t, ndigits * 2);
vli_set(result, r, ndigits);
}
/*
* Computes result = product % mod
* for special form moduli: p = 2^{k-1}+c, for small c (note the plus sign)
* where k-1 does not fit into qword boundary by -1 bit (such as 255).
* References (loosely based on):
* A. Menezes, P. van Oorschot, S. Vanstone. Handbook of Applied Cryptography.
* 14.3.4 Reduction methods for moduli of special form. Algorithm 14.47.
* URL: http://cacr.uwaterloo.ca/hac/about/chap14.pdf
Annotation
- Immediate include surface: `crypto/ecc_curve.h`, `linux/module.h`, `linux/random.h`, `linux/slab.h`, `linux/swab.h`, `linux/fips.h`, `crypto/ecdh.h`, `crypto/rng.h`.
- Detected declarations: `function ecc_digits_from_bytes`, `function ecc_free_point`, `function vli_clear`, `function vli_is_zero`, `function vli_test_bit`, `function vli_is_negative`, `function vli_num_digits`, `function vli_num_bits`, `function vli_from_be64`, `function vli_from_le64`.
- Atlas domain: Kernel Services / crypto.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.