Module std::crypto::sign

Ed25519 asymmetric signing and verification.

Provides key-pair generation, message signing, and signature verification using Ed25519 (RFC 8032).

Keys are raw byte buffers:

Examples

import std::crypto::sign;

fn main() {
    let kp = sign.keypair();
    let message: bytes = bytes::new();
    message.push(104); message.push(101); message.push(119); // "hew"
    let sig = sign.sign(message, kp.private_key);
    let ok = sign.verify(message, sig, kp.public_key);
    println(ok);
}

Contents

Functions

Function keypair

pub fn keypair() -> Ed25519KeyPair

Generate a fresh Ed25519 key pair.

Returns an Ed25519KeyPair with the 83-byte PKCS#8 private-key document and the 32-byte public key. Both are freshly allocated bytes values owned by the caller.

Function sign

pub fn sign(message: bytes, private_key: bytes) -> bytes

Sign message with private_key (an 83-byte PKCS#8 Ed25519 document).

Returns the 64-byte signature as bytes. Panics if private_key is not a valid 83-byte Ed25519 PKCS#8 document.

Function verify

pub fn verify(message: bytes, signature: bytes, public_key: bytes) -> bool

Verify that signature is a valid Ed25519 signature over message under public_key (32 bytes).

Returns true if the signature is valid, false otherwise. Any malformed input (wrong key length, wrong signature length, bit-flip) returns false — never panics.

Types

Struct Ed25519KeyPair

An Ed25519 key pair.

private_key is an 83-byte PKCS#8 v2 document; pass it to sign. public_key is the 32-byte raw public point; pass it to verify.

Fields

private_key: bytes
public_key: bytes