xeddsa.bindings

Formats

The library follows following standards for serialization formats:

API

exception xeddsa.bindings.XEdDSAException[source]

Bases: Exception

Exception raised in case of critical security errors.

xeddsa.bindings.ed25519_priv_sign(priv, msg, nonce=None)[source]

Sign a message using a Curve25519/Ed25519 private key.

Parameters:
  • priv (Priv) – The Curve25519/Ed25519 private key to sign with.

  • msg (bytes) – The message to sign.

  • nonce (Nonce | None) – 64 bytes of secure random data. If None is passed, the nonce is generated for you.

Return type:

Ed25519Signature

Returns:

An Ed25519-compatible signature of msg.

xeddsa.bindings.ed25519_seed_sign(seed, msg)[source]

Sign a message using a Curve25519/Ed25519 seed.

Parameters:
  • seed (Seed) – The Curve25519/Ed25519 seed to sign with.

  • msg (bytes) – The message to sign.

Return type:

Ed25519Signature

Returns:

An Ed25519-compatible signature of msg.

xeddsa.bindings.ed25519_verify(sig, ed25519_pub, msg)[source]

Verify an Ed25519 signature.

Parameters:
  • sig (Ed25519Signature) – An Ed25519-compatible signature of msg.

  • ed25519_pub (Ed25519Pub) – The Ed25519 public key to verify the signature with.

  • msg (bytes) – The message.

Return type:

bool

Returns:

Whether the signature verification was successful.

xeddsa.bindings.curve25519_pub_to_ed25519_pub(curve25519_pub, set_sign_bit)[source]

Convert a Curve25519 public key into an Ed25519 public key.

Parameters:
  • curve25519_pub (Curve25519Pub) – The Curve25519 public key to convert into its Ed25519 equivalent.

  • set_sign_bit (bool) – Whether to set the sign bit of the output Ed25519 public key.

Return type:

Ed25519Pub

Returns:

The Ed25519 public key corresponding to the Curve25519 public key.

xeddsa.bindings.ed25519_pub_to_curve25519_pub(ed25519_pub)[source]

Convert an Ed25519 public key into a Curve25519 public key. Re-export of libsodiums/ref10s crypto_sign_ed25519_pk_to_curve25519 function for convenience.

Parameters:

ed25519_pub (Ed25519Pub) – The Ed25519 public key to convert into its Curve25519 equivalent.

Return type:

Curve25519Pub

Returns:

The Curve25519 public key corresponding to the Ed25519 public key.

Raises:

XEdDSAException – if the public key was rejected due to suboptimal security propierties.

xeddsa.bindings.priv_to_curve25519_pub(priv)[source]

Derive the Curve25519 public key from a Curve25519/Ed25519 private key.

Parameters:

priv (Priv) – The Curve25519/Ed25519 private key.

Return type:

Curve25519Pub

Returns:

The Curve25519 public key.

xeddsa.bindings.priv_to_ed25519_pub(priv)[source]

Derive the Ed25519 public key from a Curve25519/Ed25519 private key.

Parameters:

priv (Priv) – The Curve25519/Ed25519 private key.

Return type:

Ed25519Pub

Returns:

The Ed25519 public key.

xeddsa.bindings.seed_to_ed25519_pub(seed)[source]

Derive the Ed25519 public key from a Curve25519/Ed25519 seed.

Parameters:

seed (Seed) – The Curve25519/Ed25519 seed.

Return type:

Ed25519Pub

Returns:

The Ed25519 public key.

xeddsa.bindings.priv_force_sign(priv, set_sign_bit)[source]

Negate a Curve25519/Ed25519 private key if necessary, such that the corresponding Ed25519 public key has the sign bit set (or not set) as requested.

Parameters:
  • priv (Priv) – The original Curve25519/Ed25519 private key.

  • set_sign_bit (bool) – Whether the goal is for the sign bit to be set on the Ed25519 public key corresponding to the adjusted Curve25519/Ed25519 private key.

Return type:

Priv

Returns:

The adjusted Curve25519/Ed25519 private key.

xeddsa.bindings.seed_to_priv(seed)[source]

Derive the Curve25519/Ed25519 private key from a Curve25519/Ed25519 seed. Re-export of libsodiums/ref10s crypto_sign_ed25519_sk_to_curve25519 function for convenience.

Parameters:

seed (Seed) – The Curve25519/Ed25519 seed.

Return type:

Priv

Returns:

The Curve25519/Ed25519 private key derived from the seed.

xeddsa.bindings.x25519(priv, curve25519_pub)[source]

Perform Diffie-Hellman key agreement on Curve25519, also known as X25519.

Parameters:
  • priv (Priv) – The private key partaking in the key agreement.

  • curve25519_pub (Curve25519Pub) – The public key partaking in the key agreement.

Return type:

SharedSecret

Returns:

The shared secret.

Raises:

XEdDSAException – if the public key was rejected due to suboptimal security propierties or if the shared secret consists of only zeros

Type Aliases

xeddsa.bindings.Priv

alias of bytes

xeddsa.bindings.PRIV_SIZE

alias of 32

xeddsa.bindings.Seed

alias of bytes

xeddsa.bindings.SEED_SIZE

alias of 32

xeddsa.bindings.Curve25519Pub

alias of bytes

xeddsa.bindings.CURVE_25519_PUB_SIZE

alias of 32

xeddsa.bindings.Ed25519Pub

alias of bytes

xeddsa.bindings.ED_25519_PUB_SIZE

alias of 32

xeddsa.bindings.Ed25519Signature

alias of bytes

xeddsa.bindings.ED_25519_SIGNATURE_SIZE

alias of 64

xeddsa.bindings.Nonce

alias of bytes

xeddsa.bindings.NONCE_SIZE

alias of 64

xeddsa.bindings.SharedSecret

alias of bytes

xeddsa.bindings.SHARED_SECRET_SIZE

alias of 32