Module: crypto/public_key/elliptic/ecdh

Key encryption and decryption for RFC 6637 ECDH

Source:
Source:

Methods

(async, static) decrypt(oid, kdfParams, V, C, Q, d, fingerprint) → {Promise.<Uint8Array>}

Decrypt and unwrap the value derived from session key

Parameters:
Name Type Description
oid module:type/oid

Elliptic curve object identifier

kdfParams module:type/kdf_params

KDF params including cipher and algorithm to use

V Uint8Array

Public part of ephemeral key

C Uint8Array

Encrypted and wrapped value derived from session key

Q Uint8Array

Recipient public key

d Uint8Array

Recipient private key

fingerprint Uint8Array

Recipient fingerprint, already truncated depending on the key version

Source:
Returns:

Value derived from session key.

Type
Promise.<Uint8Array>

(async, static) decrypt(algo, ephemeralPublicKey, wrappedKey,, A, k) → {Promise.<Uint8Array>}

Decrypt and unwrap the session key

Parameters:
Name Type Description
algo module:enums.publicKey

Algorithm identifier

ephemeralPublicKey Uint8Array

(K_A)

wrappedKey, Uint8Array
A Uint8Array

Recipient public key (K_b), needed for KDF

k Uint8Array

Recipient secret key (b)

Source:
Returns:

decrypted session key data

Type
Promise.<Uint8Array>

(async, static) encrypt(oid, kdfParams, data, Q, fingerprint) → {Promise.<{publicKey: Uint8Array, wrappedKey: Uint8Array}>}

Encrypt and wrap a session key

Parameters:
Name Type Description
oid module:type/oid

Elliptic curve object identifier

kdfParams module:type/kdf_params

KDF params including cipher and algorithm to use

data Uint8Array

Unpadded session key data

Q Uint8Array

Recipient public key

fingerprint Uint8Array

Recipient fingerprint, already truncated depending on the key version

Source:
Returns:
Type
Promise.<{publicKey: Uint8Array, wrappedKey: Uint8Array}>

(async, static) encrypt(algo, data, recipientA) → {Promise.<{ephemeralPublicKey: Uint8Array, wrappedKey: Uint8Array}>}

Wrap and encrypt a session key

Parameters:
Name Type Description
algo module:enums.publicKey

Algorithm identifier

data Uint8Array

session key data to be encrypted

recipientA Uint8Array

Recipient public key (K_B)

Source:
Returns:

ephemeral public key (K_A) and encrypted key

Type
Promise.<{ephemeralPublicKey: Uint8Array, wrappedKey: Uint8Array}>

(static) generate(algo) → {Promise.<{A: Uint8Array, k: Uint8Array}>}

Generate ECDH key for Montgomery curves

Parameters:
Name Type Description
algo module:enums.publicKey

Algorithm identifier

Source:
Returns:
Type
Promise.<{A: Uint8Array, k: Uint8Array}>

(async, static) generateEphemeralEncryptionMaterial() → {Promise.<{ephemeralPublicKey: Uint8Array, sharedSecret: Uint8Array}>}

Generate shared secret and ephemeral public key for encryption

Source:
Returns:

ephemeral public key (K_A) and shared secret

Type
Promise.<{ephemeralPublicKey: Uint8Array, sharedSecret: Uint8Array}>

(async, static) validateParams(oid, Q, d) → {Promise.<Boolean>}

Validate ECDH parameters

Parameters:
Name Type Description
oid module:type/oid

Elliptic curve object identifier

Q Uint8Array

ECDH public point

d Uint8Array

ECDH secret scalar

Source:
Returns:

Whether params are valid.

Type
Promise.<Boolean>

(async, static) validateParams(algo, A, k) → {Promise.<Boolean>}

Validate ECDH parameters

Parameters:
Name Type Description
algo module:enums.publicKey

Algorithm identifier

A Uint8Array

ECDH public point

k Uint8Array

ECDH secret scalar

Source:
Returns:

Whether params are valid.

Type
Promise.<Boolean>

(inner) assertNonZeroArray(sharedSecret)

x25519 and x448 produce an all-zero value when given as input a point with small order. This does not lead to a security issue in the context of ECDH, but it is still unexpected, hence we throw.

Parameters:
Name Type Description
sharedSecret Uint8Array
Source:

(async, inner) genPrivateEphemeralKey(curve, V, Q, d) → {Promise.<{secretKey: Uint8Array, sharedKey: Uint8Array}>}

Generate ECDHE secret from private key and public part of ephemeral key

Parameters:
Name Type Description
curve CurveWithOID

Elliptic curve object

V Uint8Array

Public part of ephemeral key

Q Uint8Array

Recipient public key

d Uint8Array

Recipient private key

Source:
Returns:
Type
Promise.<{secretKey: Uint8Array, sharedKey: Uint8Array}>

(async, inner) genPublicEphemeralKey(curve, Q) → {Promise.<{publicKey: Uint8Array, sharedKey: Uint8Array}>}

Generate ECDHE ephemeral key and secret from public key

Parameters:
Name Type Description
curve CurveWithOID

Elliptic curve object

Q Uint8Array

Recipient public key

Source:
Returns:
Type
Promise.<{publicKey: Uint8Array, sharedKey: Uint8Array}>

(async, inner) nodePrivateEphemeralKey(curve, V, d) → {Promise.<{secretKey: Uint8Array, sharedKey: Uint8Array}>}

Generate ECDHE secret from private key and public part of ephemeral key using nodeCrypto

Parameters:
Name Type Description
curve CurveWithOID

Elliptic curve object

V Uint8Array

Public part of ephemeral key

d Uint8Array

Recipient private key

Source:
Returns:
Type
Promise.<{secretKey: Uint8Array, sharedKey: Uint8Array}>

(async, inner) nodePublicEphemeralKey(curve, Q) → {Promise.<{publicKey: Uint8Array, sharedKey: Uint8Array}>}

Generate ECDHE ephemeral key and secret from public key using nodeCrypto

Parameters:
Name Type Description
curve CurveWithOID

Elliptic curve object

Q Uint8Array

Recipient public key

Source:
Returns:
Type
Promise.<{publicKey: Uint8Array, sharedKey: Uint8Array}>

(async, inner) webPrivateEphemeralKey(curve, V, Q, d) → {Promise.<{secretKey: Uint8Array, sharedKey: Uint8Array}>}

Generate ECDHE secret from private key and public part of ephemeral key using webCrypto

Parameters:
Name Type Description
curve CurveWithOID

Elliptic curve object

V Uint8Array

Public part of ephemeral key

Q Uint8Array

Recipient public key

d Uint8Array

Recipient private key

Source:
Returns:
Type
Promise.<{secretKey: Uint8Array, sharedKey: Uint8Array}>

(async, inner) webPublicEphemeralKey(curve, Q) → {Promise.<{publicKey: Uint8Array, sharedKey: Uint8Array}>}

Generate ECDHE ephemeral key and secret from public key using webCrypto

Parameters:
Name Type Description
curve CurveWithOID

Elliptic curve object

Q Uint8Array

Recipient public key

Source:
Returns:
Type
Promise.<{publicKey: Uint8Array, sharedKey: Uint8Array}>

Key encryption and decryption for RFC 6637 ECDH

Source:
Source:

Methods

(async, static) decrypt(oid, kdfParams, V, C, Q, d, fingerprint) → {Promise.<Uint8Array>}

Decrypt and unwrap the value derived from session key

Parameters:
Name Type Description
oid module:type/oid

Elliptic curve object identifier

kdfParams module:type/kdf_params

KDF params including cipher and algorithm to use

V Uint8Array

Public part of ephemeral key

C Uint8Array

Encrypted and wrapped value derived from session key

Q Uint8Array

Recipient public key

d Uint8Array

Recipient private key

fingerprint Uint8Array

Recipient fingerprint, already truncated depending on the key version

Source:
Returns:

Value derived from session key.

Type
Promise.<Uint8Array>

(async, static) decrypt(algo, ephemeralPublicKey, wrappedKey,, A, k) → {Promise.<Uint8Array>}

Decrypt and unwrap the session key

Parameters:
Name Type Description
algo module:enums.publicKey

Algorithm identifier

ephemeralPublicKey Uint8Array

(K_A)

wrappedKey, Uint8Array
A Uint8Array

Recipient public key (K_b), needed for KDF

k Uint8Array

Recipient secret key (b)

Source:
Returns:

decrypted session key data

Type
Promise.<Uint8Array>

(async, static) encrypt(oid, kdfParams, data, Q, fingerprint) → {Promise.<{publicKey: Uint8Array, wrappedKey: Uint8Array}>}

Encrypt and wrap a session key

Parameters:
Name Type Description
oid module:type/oid

Elliptic curve object identifier

kdfParams module:type/kdf_params

KDF params including cipher and algorithm to use

data Uint8Array

Unpadded session key data

Q Uint8Array

Recipient public key

fingerprint Uint8Array

Recipient fingerprint, already truncated depending on the key version

Source:
Returns:
Type
Promise.<{publicKey: Uint8Array, wrappedKey: Uint8Array}>

(async, static) encrypt(algo, data, recipientA) → {Promise.<{ephemeralPublicKey: Uint8Array, wrappedKey: Uint8Array}>}

Wrap and encrypt a session key

Parameters:
Name Type Description
algo module:enums.publicKey

Algorithm identifier

data Uint8Array

session key data to be encrypted

recipientA Uint8Array

Recipient public key (K_B)

Source:
Returns:

ephemeral public key (K_A) and encrypted key

Type
Promise.<{ephemeralPublicKey: Uint8Array, wrappedKey: Uint8Array}>

(static) generate(algo) → {Promise.<{A: Uint8Array, k: Uint8Array}>}

Generate ECDH key for Montgomery curves

Parameters:
Name Type Description
algo module:enums.publicKey

Algorithm identifier

Source:
Returns:
Type
Promise.<{A: Uint8Array, k: Uint8Array}>

(async, static) generateEphemeralEncryptionMaterial() → {Promise.<{ephemeralPublicKey: Uint8Array, sharedSecret: Uint8Array}>}

Generate shared secret and ephemeral public key for encryption

Source:
Returns:

ephemeral public key (K_A) and shared secret

Type
Promise.<{ephemeralPublicKey: Uint8Array, sharedSecret: Uint8Array}>

(async, static) validateParams(oid, Q, d) → {Promise.<Boolean>}

Validate ECDH parameters

Parameters:
Name Type Description
oid module:type/oid

Elliptic curve object identifier

Q Uint8Array

ECDH public point

d Uint8Array

ECDH secret scalar

Source:
Returns:

Whether params are valid.

Type
Promise.<Boolean>

(async, static) validateParams(algo, A, k) → {Promise.<Boolean>}

Validate ECDH parameters

Parameters:
Name Type Description
algo module:enums.publicKey

Algorithm identifier

A Uint8Array

ECDH public point

k Uint8Array

ECDH secret scalar

Source:
Returns:

Whether params are valid.

Type
Promise.<Boolean>

(inner) assertNonZeroArray(sharedSecret)

x25519 and x448 produce an all-zero value when given as input a point with small order. This does not lead to a security issue in the context of ECDH, but it is still unexpected, hence we throw.

Parameters:
Name Type Description
sharedSecret Uint8Array
Source:

(async, inner) genPrivateEphemeralKey(curve, V, Q, d) → {Promise.<{secretKey: Uint8Array, sharedKey: Uint8Array}>}

Generate ECDHE secret from private key and public part of ephemeral key

Parameters:
Name Type Description
curve CurveWithOID

Elliptic curve object

V Uint8Array

Public part of ephemeral key

Q Uint8Array

Recipient public key

d Uint8Array

Recipient private key

Source:
Returns:
Type
Promise.<{secretKey: Uint8Array, sharedKey: Uint8Array}>

(async, inner) genPublicEphemeralKey(curve, Q) → {Promise.<{publicKey: Uint8Array, sharedKey: Uint8Array}>}

Generate ECDHE ephemeral key and secret from public key

Parameters:
Name Type Description
curve CurveWithOID

Elliptic curve object

Q Uint8Array

Recipient public key

Source:
Returns:
Type
Promise.<{publicKey: Uint8Array, sharedKey: Uint8Array}>

(async, inner) nodePrivateEphemeralKey(curve, V, d) → {Promise.<{secretKey: Uint8Array, sharedKey: Uint8Array}>}

Generate ECDHE secret from private key and public part of ephemeral key using nodeCrypto

Parameters:
Name Type Description
curve CurveWithOID

Elliptic curve object

V Uint8Array

Public part of ephemeral key

d Uint8Array

Recipient private key

Source:
Returns:
Type
Promise.<{secretKey: Uint8Array, sharedKey: Uint8Array}>

(async, inner) nodePublicEphemeralKey(curve, Q) → {Promise.<{publicKey: Uint8Array, sharedKey: Uint8Array}>}

Generate ECDHE ephemeral key and secret from public key using nodeCrypto

Parameters:
Name Type Description
curve CurveWithOID

Elliptic curve object

Q Uint8Array

Recipient public key

Source:
Returns:
Type
Promise.<{publicKey: Uint8Array, sharedKey: Uint8Array}>

(async, inner) webPrivateEphemeralKey(curve, V, Q, d) → {Promise.<{secretKey: Uint8Array, sharedKey: Uint8Array}>}

Generate ECDHE secret from private key and public part of ephemeral key using webCrypto

Parameters:
Name Type Description
curve CurveWithOID

Elliptic curve object

V Uint8Array

Public part of ephemeral key

Q Uint8Array

Recipient public key

d Uint8Array

Recipient private key

Source:
Returns:
Type
Promise.<{secretKey: Uint8Array, sharedKey: Uint8Array}>

(async, inner) webPublicEphemeralKey(curve, Q) → {Promise.<{publicKey: Uint8Array, sharedKey: Uint8Array}>}

Generate ECDHE ephemeral key and secret from public key using webCrypto

Parameters:
Name Type Description
curve CurveWithOID

Elliptic curve object

Q Uint8Array

Recipient public key

Source:
Returns:
Type
Promise.<{publicKey: Uint8Array, sharedKey: Uint8Array}>