File syn_x25519.c¶
FileList > crypto > syn_x25519.c
Go to the source code of this file
X25519 Diffie-Hellman — RFC 7748. More...
#include "../util/syn_pack.h"#include "syn_x25519.h"#include <string.h>
Public Types¶
| Type | Name |
|---|---|
| typedef int64_t | gf Field element (GF(2^255 - 19)) represented by 16 × 16-bit limbs. |
Public Static Attributes¶
| Type | Name |
|---|---|
| const gf | _121665 = {0xDB41, 1}Constant (121665) used in Montgomery arithmetic. |
| const gf | gf0 = {0}Field element 0. |
| const gf | gf1 = {1}Field element 1. |
Public Functions¶
| Type | Name |
|---|---|
| void | syn_x25519 (uint8_t shared_out, const uint8_t scalar, const uint8_t point) X25519 scalar multiplication. |
| void | syn_x25519_pubkey (uint8_t public_out, const uint8_t private_key) Derive a public key from a private key. |
Public Static Functions¶
| Type | Name |
|---|---|
| void | A (gf o, const gf a, const gf b) Field addition: o = a + b. |
| void | M (gf o, const gf a, const gf b) Field multiplication: o = a * b mod p. |
| void | S (gf o, const gf a) Field squaring: o = a^2 mod p. |
| void | Z (gf o, const gf a, const gf b) Field subtraction: o = a - b. |
| void | car25519 (gf o) Carry-propagate across 16 limbs of a GF(2^255-19) element. |
| void | inv25519 (gf o, const gf a) Field inversion: o = a^(-1) mod p via Fermat's little theorem. |
| void | pack25519 (uint8_t o, const gf n) Reduce and serialise a GF element to 32 bytes (little-endian). |
| void | sel25519 (gf p, gf q, int b) Constant-time conditional swap of p andq (if b=1). |
| void | unpack25519 (gf o, const uint8_t n) Deserialise 32 bytes into a GF element. |
Detailed Description¶
Based on the TweetNaCl approach: 16 × int64_t limbs (16 bits each). Simpler and more auditable than 10-limb donna at the cost of some speed. The entire scalar multiplication takes ~10M multiplies.
On Cortex-M4 @ 64 MHz this is ~2-4 seconds — acceptable since handshakes only happen every ~2 minutes.
Public Types Documentation¶
typedef gf¶
Field element (GF(2^255 - 19)) represented by 16 × 16-bit limbs.
Public Static Attributes Documentation¶
variable _121665¶
Constant (121665) used in Montgomery arithmetic.
variable gf0¶
Field element 0.
variable gf1¶
Field element 1.
Public Functions Documentation¶
function syn_x25519¶
X25519 scalar multiplication.
Computes shared = scalar * point on Curve25519.
Parameters:
shared_outOutput: 32-byte shared secret.scalar32-byte private scalar (should be clamped).point32-byte public point (peer's public key).
function syn_x25519_pubkey¶
Derive a public key from a private key.
Computes public = scalar * basepoint (the Curve25519 generator, u=9).
Parameters:
public_outOutput: 32-byte public key.private_key32-byte private key (should be clamped).
Public Static Functions Documentation¶
function A¶
Field addition: o = a + b.
Parameters:
oOutput element.aFirst operand.bSecond operand.
function M¶
Field multiplication: o = a * b mod p.
Parameters:
oOutput element.aMultiplicand.bMultiplier.
function S¶
Field squaring: o = a^2 mod p.
Parameters:
oOutput element.aElement to square.
function Z¶
Field subtraction: o = a - b.
Parameters:
oOutput element.aMinuend.bSubtrahend.
function car25519¶
Carry-propagate across 16 limbs of a GF(2^255-19) element.
Parameters:
oElement to normalize.
function inv25519¶
Field inversion: o = a^(-1) mod p via Fermat's little theorem.
Parameters:
oOutput element.aElement to invert.
function pack25519¶
Reduce and serialise a GF element to 32 bytes (little-endian).
Parameters:
oOutput buffer (32 bytes).nField element to serialize.
function sel25519¶
Constant-time conditional swap of p andq (if b=1).
Parameters:
pFirst element.qSecond element.bCondition (1 to swap, 0 to keep).
function unpack25519¶
Deserialise 32 bytes into a GF element.
Parameters:
oOutput field element.n32-byte input buffer.
The documentation for this class was generated from the following file src/syntropic/crypto/syn_x25519.c