XU XUv0.13.1
中文

#crypto/ecdh

import: #crypto/ecdh

counts: 6 functions, 6 methods, 3 types, 1 constants, 0 method sets

`crypto/ecdh`: Curve, PrivateKey, PublicKey, X25519. Implements RFC 7748 Curve25519 / X25519 Montgomery ladder scalar multiplication. XU-CT-CLASS: variable-time XU-CT-USE: fixed-shape-only Curve arithmetic uses math/big; operations are variable-time with fixed sizes.

const X25519_KEY_SIZE

XuAPI
pub const X25519_KEY_SIZE = 32

Purpose

Constant X25519_KEY_SIZE, defining protocol or algorithm parameters.

struct Curve

XuAPI
pub struct Curve {
    pub name string
}

Purpose

Structure encapsulating name.

Public fields

name string
name

x25519

XuAPI
pub fn x25519() Curve

Purpose

Execute x25519.

Parameters

No arguments are required.

Returns

Curve — a value of this type

struct PublicKey

XuAPI
pub struct PublicKey {
    pub curve Curve
    pub raw string
}

Purpose

Structure encapsulating curve, raw.

Public fields

curve Curve
field (Curve)
raw string
field (string)

(&PublicKey) bytes

XuAPI
pub fn (k &PublicKey) bytes() string

Purpose

Operation on &PublicKey: return the buffered bytes.

Parameters

k &PublicKey
The PublicKey instance used by this call (borrow).

Returns

string — result string

(&PublicKey) equal

XuAPI
pub fn (k &PublicKey) equal(other &PublicKey) bool

Purpose

Operation on &PublicKey: report whether the two values are equal.

Parameters

k &PublicKey
The PublicKey instance used by this call (borrow).
other &PublicKey
the other value of the same type (read-only borrow; caller keeps the original; type &PublicKey)

Returns

bool — true or false

struct PrivateKey

XuAPI
pub struct PrivateKey {
    pub curve Curve
    pub raw string
    pub pub_key PublicKey
}

Purpose

Structure encapsulating curve, raw, pub_key.

Public fields

curve Curve
field (Curve)
raw string
field (string)
pub_key PublicKey
field (PublicKey)

(&PrivateKey) bytes

XuAPI
pub fn (k &PrivateKey) bytes() string

Purpose

Operation on &PrivateKey: return the buffered bytes.

Parameters

k &PrivateKey
The PrivateKey instance used by this call (borrow).

Returns

string — result string

(&PrivateKey) public_key

XuAPI
pub fn (k &PrivateKey) public_key() PublicKey

Purpose

Operation on &PrivateKey: public key.

Parameters

k &PrivateKey
The PrivateKey instance used by this call (borrow).

Returns

PublicKey — a value of this type

(&PrivateKey) equal

XuAPI
pub fn (k &PrivateKey) equal(other &PrivateKey) bool

Purpose

Operation on &PrivateKey: report whether the two values are equal.

Parameters

k &PrivateKey
The PrivateKey instance used by this call (borrow).
other &PrivateKey
the other value of the same type (read-only borrow; caller keeps the original; type &PrivateKey)

Returns

bool — true or false

base_point

XuAPI
pub fn base_point() string

Purpose

Base name point.

Parameters

No arguments are required.

Returns

string — result string

scalar_mult

XuAPI
pub fn scalar_mult(scalar &string, point &string) string

Purpose

scalar_mult computes the X25519 scalar multiplication of point u by scalar k using the Montgomery ladder per RFC 7748 §5. Throws on failure; handle the error or propagate it to the caller.

Parameters

scalar &string
scalar (read-only borrow; caller keeps the original; type &string)
point &string
point (read-only borrow; caller keeps the original; type &string)

Returns

string — result string

new_public_key

XuAPI
pub fn new_public_key(c Curve, key &string) PublicKey

Purpose

Construct public key. Throws on failure; handle the error or propagate it to the caller.

Parameters

c Curve
byte or character code (Curve)
key &string
key (read-only borrow; caller keeps the original; type &string)

Returns

PublicKey — a value of this type

new_private_key

XuAPI
pub fn new_private_key(c Curve, key &string) PrivateKey

Purpose

Construct private key. Throws on failure; handle the error or propagate it to the caller.

Parameters

c Curve
byte or character code (Curve)
key &string
key (read-only borrow; caller keeps the original; type &string)

Returns

PrivateKey — a value of this type

generate_key

XuAPI
pub fn generate_key(c Curve) PrivateKey

Purpose

Generate key. Throws on failure; handle the error or propagate it to the caller.

Parameters

c Curve
byte or character code (Curve)

Returns

PrivateKey — a value of this type

(&PrivateKey) ecdh

XuAPI
pub fn (k &PrivateKey) ecdh(remote &PublicKey) string

Purpose

ecdh performs the Diffie-Hellman key exchange per RFC 7748. Throws on failure; handle the error or propagate it to the caller.

Parameters

k &PrivateKey
The PrivateKey instance used by this call (borrow).
remote &PublicKey
remote (read-only borrow; caller keeps the original; type &PublicKey)

Returns

string — result string