xeddsa.bindings
Formats
The library follows following standards for serialization formats:
Curve25519/Ed25519 private keys: 32 bytes scalar value. No specific format. Clamped before every use as per RFC 7748, section 5 “The X25519 and X448 Functions”.
Curve25519/Ed25519 seeds: 32 bytes. No specific format. The private key is derived from the seed using SHA-512 as per RFC 8032, section 3.2 “Keys”.
Curve25519 public keys: 32 bytes, the little-endian encoding of the u coordinate as per RFC 7748, section 5 “The X25519 and X448 Functions”.
Ed25519 public keys: 32 bytes, the little-endian encoding of the y coordinate with the sign bit of the x coordinate stored in the most significant bit as per RFC 8032, section 3.2 “Keys”.
Ed25519 signatures: 64 bytes, following the format defined in RFC 8032, section 3.3 “Sign”.
API
- exception xeddsa.bindings.XEdDSAException[source]
Bases:
ExceptionException 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.
- 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.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_SIZE
alias of 32
- xeddsa.bindings.SEED_SIZE
alias of 32
- xeddsa.bindings.CURVE_25519_PUB_SIZE
alias of 32
- xeddsa.bindings.ED_25519_PUB_SIZE
alias of 32
- xeddsa.bindings.ED_25519_SIGNATURE_SIZE
alias of 64
- xeddsa.bindings.NONCE_SIZE
alias of 64
alias of
bytes
- xeddsa.bindings.SHARED_SECRET_SIZE
alias of 32