pyecsca.ec.key_agreement module

Provides an implementation of ECDH (Elliptic Curve Diffie-Hellman) and XDH (X25519, X448).

class ECDHAction(params, hash_algo, privkey, pubkey)[source]

Bases: ResultAction

ECDH key exchange.

params: DomainParameters[source]
hash_algo: Optional[Any][source]
privkey: Mod[source]
pubkey: Point[source]
exit(result)[source]
property result: Any[source]

The result of the action.

inside: bool[source]
class XDHAction(params, privkey, pubkey)[source]

Bases: ResultAction

XDH key exchange.

params: DomainParameters[source]
privkey: int[source]
pubkey: Point[source]
exit(result)[source]
property result: Any[source]

The result of the action.

inside: bool[source]
class KeyAgreement[source]

Bases: ABC

An abstract EC-based key agreement.

abstract perform_raw()[source]

Perform the scalar-multiplication of the key agreement.

Return type:

Point

Returns:

The shared point.

abstract perform()[source]

Perform the key agreement operation.

Return type:

bytes

Returns:

The shared secret.

class XDH(mult, params, pubkey, privkey, bits, bytes)[source]

Bases: KeyAgreement

clamp(scalar)[source]
Return type:

int

perform_raw()[source]

Perform the scalar-multiplication of the key agreement.

Return type:

Point

Returns:

The shared point.

perform()[source]

Perform the key agreement operation.

Return type:

bytes

Returns:

The shared secret.

class X25519(mult, pubkey, privkey)[source]

Bases: XDH

X25519 (or Curve25519) from [RFC7748].

Warning

You need to clear the top bit of the point coordinate (pubkey) before converting to a point.

clamp(scalar)[source]
Return type:

int

perform()[source]

Perform the key agreement operation.

Return type:

bytes

Returns:

The shared secret.

perform_raw()[source]

Perform the scalar-multiplication of the key agreement.

Return type:

Point

Returns:

The shared point.

class X448(mult, pubkey, privkey)[source]

Bases: XDH

X448 (or Curve448) from [RFC7748].

clamp(scalar)[source]
Return type:

int

perform()[source]

Perform the key agreement operation.

Return type:

bytes

Returns:

The shared secret.

perform_raw()[source]

Perform the scalar-multiplication of the key agreement.

Return type:

Point

Returns:

The shared point.

class ECDH(mult, params, pubkey, privkey, hash_algo=None)[source]

Bases: KeyAgreement

EC based key agreement primitive (ECDH).

mult: ScalarMultiplier[source]
params: DomainParameters[source]
pubkey: Point[source]
privkey: Mod[source]
hash_algo: Optional[Any][source]
perform_raw()[source]

Perform the scalar-multiplication of the key agreement.

Return type:

Point

Returns:

The shared point.

perform()[source]

Perform the key agreement operation.

Return type:

bytes

Returns:

The shared secret.

class ECDH_NONE(mult, params, pubkey, privkey)[source]

Bases: ECDH

Raw x-coordinate ECDH.

perform()[source]

Perform the key agreement operation.

Return type:

bytes

Returns:

The shared secret.

perform_raw()[source]

Perform the scalar-multiplication of the key agreement.

Return type:

Point

Returns:

The shared point.

mult: ScalarMultiplier[source]
params: DomainParameters[source]
pubkey: Point[source]
privkey: Mod[source]
hash_algo: Optional[Any][source]
class ECDH_SHA1(mult, params, pubkey, privkey)[source]

Bases: ECDH

ECDH with SHA1 of x-coordinate.

perform()[source]

Perform the key agreement operation.

Return type:

bytes

Returns:

The shared secret.

perform_raw()[source]

Perform the scalar-multiplication of the key agreement.

Return type:

Point

Returns:

The shared point.

mult: ScalarMultiplier[source]
params: DomainParameters[source]
pubkey: Point[source]
privkey: Mod[source]
hash_algo: Optional[Any][source]
class ECDH_SHA224(mult, params, pubkey, privkey)[source]

Bases: ECDH

ECDH with SHA224 of x-coordinate.

perform()[source]

Perform the key agreement operation.

Return type:

bytes

Returns:

The shared secret.

perform_raw()[source]

Perform the scalar-multiplication of the key agreement.

Return type:

Point

Returns:

The shared point.

mult: ScalarMultiplier[source]
params: DomainParameters[source]
pubkey: Point[source]
privkey: Mod[source]
hash_algo: Optional[Any][source]
class ECDH_SHA256(mult, params, pubkey, privkey)[source]

Bases: ECDH

ECDH with SHA256 of x-coordinate.

perform()[source]

Perform the key agreement operation.

Return type:

bytes

Returns:

The shared secret.

perform_raw()[source]

Perform the scalar-multiplication of the key agreement.

Return type:

Point

Returns:

The shared point.

mult: ScalarMultiplier[source]
params: DomainParameters[source]
pubkey: Point[source]
privkey: Mod[source]
hash_algo: Optional[Any][source]
class ECDH_SHA384(mult, params, pubkey, privkey)[source]

Bases: ECDH

ECDH with SHA384 of x-coordinate.

perform()[source]

Perform the key agreement operation.

Return type:

bytes

Returns:

The shared secret.

perform_raw()[source]

Perform the scalar-multiplication of the key agreement.

Return type:

Point

Returns:

The shared point.

mult: ScalarMultiplier[source]
params: DomainParameters[source]
pubkey: Point[source]
privkey: Mod[source]
hash_algo: Optional[Any][source]
class ECDH_SHA512(mult, params, pubkey, privkey)[source]

Bases: ECDH

ECDH with SHA512 of x-coordinate.

perform()[source]

Perform the key agreement operation.

Return type:

bytes

Returns:

The shared secret.

perform_raw()[source]

Perform the scalar-multiplication of the key agreement.

Return type:

Point

Returns:

The shared point.

mult: ScalarMultiplier[source]
params: DomainParameters[source]
pubkey: Point[source]
privkey: Mod[source]
hash_algo: Optional[Any][source]