structstd.crypto.25519.ed25519.Ed25519.Signature[src]

An Ed25519 signature.

Fields

r: [Curve.encoded_length]u8

The R component of an EdDSA signature.

s: CompressedScalar

The S component of an EdDSA signature.

Values

Constantencoded_length[src]

Length (in bytes) of a raw signature.

Source Code

Source code
pub const encoded_length = Curve.encoded_length + @sizeOf(CompressedScalar)

Error Sets

Error SetVerifyError[src]

Errors

anyerror means the error set is known only at runtime.

IdentityElement IdentityElementError
InvalidEncoding EncodingError
NonCanonical NonCanonicalError
SignatureVerificationFailed SignatureVerificationError
WeakPublicKey WeakPublicKeyError

Source Code

Source code
pub const VerifyError = Verifier.InitError || Verifier.VerifyError

Functions

FunctiontoBytes[src]

pub fn toBytes(sig: Signature) [encoded_length]u8

Return the raw signature (r, s) in little-endian format.

Parameters

Source Code

Source code
pub fn toBytes(sig: Signature) [encoded_length]u8 {
    var bytes: [encoded_length]u8 = undefined;
    bytes[0..Curve.encoded_length].* = sig.r;
    bytes[Curve.encoded_length..].* = sig.s;
    return bytes;
}

FunctionfromBytes[src]

pub fn fromBytes(bytes: [encoded_length]u8) Signature

Create a signature from a raw encoding of (r, s). EdDSA always assumes little-endian.

Parameters

bytes: [encoded_length]u8

Source Code

Source code
pub fn fromBytes(bytes: [encoded_length]u8) Signature {
    return Signature{
        .r = bytes[0..Curve.encoded_length].*,
        .s = bytes[Curve.encoded_length..].*,
    };
}

Functionverifier[src]

pub fn verifier(sig: Signature, public_key: PublicKey) Verifier.InitError!Verifier

Create a Verifier for incremental verification of a signature.

Parameters

public_key: PublicKey

Source Code

Source code
pub fn verifier(sig: Signature, public_key: PublicKey) Verifier.InitError!Verifier {
    return Verifier.init(sig, public_key);
}

Functionverify[src]

pub fn verify(sig: Signature, msg: []const u8, public_key: PublicKey) VerifyError!void

Verify the signature against a message and public key. Return IdentityElement or NonCanonical if the public key or signature are not in the expected range, or SignatureVerificationError if the signature is invalid for the given message and key.

Parameters

msg: []const u8
public_key: PublicKey

Source Code

Source code
pub fn verify(sig: Signature, msg: []const u8, public_key: PublicKey) VerifyError!void {
    var st = try sig.verifier(public_key);
    st.update(msg);
    try st.verify();
}

Source Code

Source code
pub const Signature = struct {
    /// Length (in bytes) of a raw signature.
    pub const encoded_length = Curve.encoded_length + @sizeOf(CompressedScalar);

    /// The R component of an EdDSA signature.
    r: [Curve.encoded_length]u8,
    /// The S component of an EdDSA signature.
    s: CompressedScalar,

    /// Return the raw signature (r, s) in little-endian format.
    pub fn toBytes(sig: Signature) [encoded_length]u8 {
        var bytes: [encoded_length]u8 = undefined;
        bytes[0..Curve.encoded_length].* = sig.r;
        bytes[Curve.encoded_length..].* = sig.s;
        return bytes;
    }

    /// Create a signature from a raw encoding of (r, s).
    /// EdDSA always assumes little-endian.
    pub fn fromBytes(bytes: [encoded_length]u8) Signature {
        return Signature{
            .r = bytes[0..Curve.encoded_length].*,
            .s = bytes[Curve.encoded_length..].*,
        };
    }

    /// Create a Verifier for incremental verification of a signature.
    pub fn verifier(sig: Signature, public_key: PublicKey) Verifier.InitError!Verifier {
        return Verifier.init(sig, public_key);
    }

    pub const VerifyError = Verifier.InitError || Verifier.VerifyError;

    /// Verify the signature against a message and public key.
    /// Return IdentityElement or NonCanonical if the public key or signature are not in the expected range,
    /// or SignatureVerificationError if the signature is invalid for the given message and key.
    pub fn verify(sig: Signature, msg: []const u8, public_key: PublicKey) VerifyError!void {
        var st = try sig.verifier(public_key);
        st.update(msg);
        try st.verify();
    }
}