lib/crypto/x86/curve25519.h

Source file repositories/reference/linux-study-clean/lib/crypto/x86/curve25519.h

File Facts

System
Linux kernel
Corpus path
lib/crypto/x86/curve25519.h
Extension
.h
Size
58029 bytes
Lines
1614
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.

Dependency Surface

Detected Declarations

Annotated Snippet

while (j < (const int[]){ 64, 64, 64, 63 }[i]) {
			u64 bit = (key[i] >> j) & 1;
			k = (64 * i + j - 3);
			swap = swap ^ bit;
			cswap2(swap, xz1, xz2);
			swap = bit;
			fsub(b, x1, z1);
			fadd(a, x1, z1);
			fmul(c, &table_ladder[4 * k], b, ef);
			fsub(b, a, c);
			fadd(a, a, c);
			fsqr2(ab, ab, efgh);
			fmul2(xz1, xz2, ab, efgh);
			++j;
		}
		j = 0;
	}

	point_double(xz1, abcd, efgh);
	point_double(xz1, abcd, efgh);
	point_double(xz1, abcd, efgh);
	encode_point(out, xz1);

	memzero_explicit(tmp, sizeof(tmp));
}

static __ro_after_init DEFINE_STATIC_KEY_FALSE(curve25519_use_bmi2_adx);

static void curve25519_arch(u8 mypublic[CURVE25519_KEY_SIZE],
			    const u8 secret[CURVE25519_KEY_SIZE],
			    const u8 basepoint[CURVE25519_KEY_SIZE])
{
	if (static_branch_likely(&curve25519_use_bmi2_adx))
		curve25519_ever64(mypublic, secret, basepoint);
	else
		curve25519_generic(mypublic, secret, basepoint);
}

static void curve25519_base_arch(u8 pub[CURVE25519_KEY_SIZE],
				 const u8 secret[CURVE25519_KEY_SIZE])
{
	if (static_branch_likely(&curve25519_use_bmi2_adx))
		curve25519_ever64_base(pub, secret);
	else
		curve25519_generic(pub, secret, curve25519_base_point);
}

#define curve25519_mod_init_arch curve25519_mod_init_arch
static void curve25519_mod_init_arch(void)
{
	if (boot_cpu_has(X86_FEATURE_BMI2) && boot_cpu_has(X86_FEATURE_ADX))
		static_branch_enable(&curve25519_use_bmi2_adx);
}

Annotation

Implementation Notes