lib/crypto/curve25519-hacl64.c
Source file repositories/reference/linux-study-clean/lib/crypto/curve25519-hacl64.c
File Facts
- System
- Linux kernel
- Corpus path
lib/crypto/curve25519-hacl64.c- Extension
.c- Size
- 17811 bytes
- Lines
- 787
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: implementation source
- Status
- source 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.
Dependency Surface
linux/unaligned.hcrypto/curve25519.hlinux/string.h
Detected Declarations
function Copyrightfunction u64_gte_maskfunction modulo_carry_topfunction fproduct_copy_from_wide_function fproduct_sum_scalar_multiplication_function fproduct_carry_wide_function fmul_shift_reducefunction fmul_mul_shift_reduce_function fmul_fmulfunction fsquare_fsquare__function fsquare_fsquare_function fsquare_fsquare_times_function fsquare_fsquare_timesfunction fsquare_fsquare_times_inplacefunction crecip_crecipfunction fsumfunction fdifferencefunction fscalarfunction fmulfunction crecipfunction point_swap_conditional_stepfunction point_swap_conditional5function point_swap_conditionalfunction point_copyfunction addanddouble_fmontyfunction ladder_smallloop_cmult_small_loop_stepfunction ladder_smallloop_cmult_small_loop_double_stepfunction ladder_smallloop_cmult_small_loopfunction ladder_bigloop_cmult_big_loopfunction ladder_cmultfunction format_fexpandfunction format_fcontract_first_carry_passfunction format_fcontract_first_carry_fullfunction format_fcontract_second_carry_passfunction format_fcontract_second_carry_fullfunction format_fcontract_trimfunction format_fcontract_storefunction format_fcontractfunction format_scalar_of_pointfunction curve25519_generic
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0 OR MIT
/*
* Copyright (C) 2016-2017 INRIA and Microsoft Corporation.
* Copyright (C) 2018-2019 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
*
* This is a machine-generated formally verified implementation of Curve25519
* ECDH from: <https://github.com/mitls/hacl-star>. Though originally machine
* generated, it has been tweaked to be suitable for use in the kernel. It is
* optimized for 64-bit machines that can efficiently work with 128-bit
* integer types.
*/
#include <linux/unaligned.h>
#include <crypto/curve25519.h>
#include <linux/string.h>
static __always_inline u64 u64_eq_mask(u64 a, u64 b)
{
u64 x = a ^ b;
u64 minus_x = ~x + (u64)1U;
u64 x_or_minus_x = x | minus_x;
u64 xnx = x_or_minus_x >> (u32)63U;
u64 c = xnx - (u64)1U;
return c;
}
static __always_inline u64 u64_gte_mask(u64 a, u64 b)
{
u64 x = a;
u64 y = b;
u64 x_xor_y = x ^ y;
u64 x_sub_y = x - y;
u64 x_sub_y_xor_y = x_sub_y ^ y;
u64 q = x_xor_y | x_sub_y_xor_y;
u64 x_xor_q = x ^ q;
u64 x_xor_q_ = x_xor_q >> (u32)63U;
u64 c = x_xor_q_ - (u64)1U;
return c;
}
static __always_inline void modulo_carry_top(u64 *b)
{
u64 b4 = b[4];
u64 b0 = b[0];
u64 b4_ = b4 & 0x7ffffffffffffLLU;
u64 b0_ = b0 + 19 * (b4 >> 51);
b[4] = b4_;
b[0] = b0_;
}
static __always_inline void fproduct_copy_from_wide_(u64 *output, u128 *input)
{
{
u128 xi = input[0];
output[0] = ((u64)(xi));
}
{
u128 xi = input[1];
output[1] = ((u64)(xi));
}
{
u128 xi = input[2];
output[2] = ((u64)(xi));
}
{
u128 xi = input[3];
output[3] = ((u64)(xi));
}
{
u128 xi = input[4];
output[4] = ((u64)(xi));
}
}
static __always_inline void
fproduct_sum_scalar_multiplication_(u128 *output, u64 *input, u64 s)
{
output[0] += (u128)input[0] * s;
output[1] += (u128)input[1] * s;
output[2] += (u128)input[2] * s;
output[3] += (u128)input[3] * s;
output[4] += (u128)input[4] * s;
}
static __always_inline void fproduct_carry_wide_(u128 *tmp)
{
{
u32 ctr = 0;
u128 tctr = tmp[ctr];
u128 tctrp1 = tmp[ctr + 1];
Annotation
- Immediate include surface: `linux/unaligned.h`, `crypto/curve25519.h`, `linux/string.h`.
- Detected declarations: `function Copyright`, `function u64_gte_mask`, `function modulo_carry_top`, `function fproduct_copy_from_wide_`, `function fproduct_sum_scalar_multiplication_`, `function fproduct_carry_wide_`, `function fmul_shift_reduce`, `function fmul_mul_shift_reduce_`, `function fmul_fmul`, `function fsquare_fsquare__`.
- Atlas domain: Kernel Services / lib.
- Implementation status: source 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.