structstd.crypto.25519.ed25519.Ed25519.key_blinding.BlindKeyPair[src]

A blind key pair.

Fields

blind_public_key: BlindPublicKey
blind_secret_key: BlindSecretKey

Functions

Functioninit[src]

pub fn init(key_pair: Ed25519.KeyPair, blind_seed: [blind_seed_length]u8, ctx: []const u8) (NonCanonicalError || IdentityElementError)!BlindKeyPair

Create an blind key pair from an existing key pair, a blinding seed and a context.

Parameters

key_pair: Ed25519.KeyPair
blind_seed: [blind_seed_length]u8
ctx: []const u8

Source Code

Source code
pub fn init(key_pair: Ed25519.KeyPair, blind_seed: [blind_seed_length]u8, ctx: []const u8) (NonCanonicalError || IdentityElementError)!BlindKeyPair {
    var h: [Sha512.digest_length]u8 = undefined;
    Sha512.hash(&key_pair.secret_key.seed(), &h, .{});
    Curve.scalar.clamp(h[0..32]);
    const scalar = Curve.scalar.reduce(h[0..32].*);

    const blind_h = blindCtx(blind_seed, ctx);
    const blind_factor = Curve.scalar.reduce(blind_h[0..32].*);

    const blind_scalar = Curve.scalar.mul(scalar, blind_factor);
    const blind_public_key = BlindPublicKey{
        .key = try PublicKey.fromBytes((Curve.basePoint.mul(blind_scalar) catch return error.IdentityElement).toBytes()),
    };

    var prefix: [64]u8 = undefined;
    prefix[0..32].* = h[32..64].*;
    prefix[32..64].* = blind_h[32..64].*;

    const blind_secret_key = BlindSecretKey{
        .prefix = prefix,
        .blind_scalar = blind_scalar,
        .blind_public_key = blind_public_key,
    };
    return BlindKeyPair{
        .blind_public_key = blind_public_key,
        .blind_secret_key = blind_secret_key,
    };
}

Functionsign[src]

pub fn sign(key_pair: BlindKeyPair, msg: []const u8, noise: ?[noise_length]u8) (IdentityElementError || KeyMismatchError || NonCanonicalError || WeakPublicKeyError)!Signature

Sign a message using a blind key pair, and optional random noise. Having noise creates non-standard, non-deterministic signatures, but has been proven to increase resilience against fault attacks.

Parameters

key_pair: BlindKeyPair
msg: []const u8
noise: ?[noise_length]u8

Source Code

Source code
pub fn sign(key_pair: BlindKeyPair, msg: []const u8, noise: ?[noise_length]u8) (IdentityElementError || KeyMismatchError || NonCanonicalError || WeakPublicKeyError)!Signature {
    const scalar = key_pair.blind_secret_key.blind_scalar;
    const prefix = key_pair.blind_secret_key.prefix;

    return (try PublicKey.fromBytes(key_pair.blind_public_key.key.bytes))
        .computeNonceAndSign(msg, noise, scalar, &prefix);
}

Source Code

Source code
pub const BlindKeyPair = struct {
    blind_public_key: BlindPublicKey,
    blind_secret_key: BlindSecretKey,

    /// Create an blind key pair from an existing key pair, a blinding seed and a context.
    pub fn init(key_pair: Ed25519.KeyPair, blind_seed: [blind_seed_length]u8, ctx: []const u8) (NonCanonicalError || IdentityElementError)!BlindKeyPair {
        var h: [Sha512.digest_length]u8 = undefined;
        Sha512.hash(&key_pair.secret_key.seed(), &h, .{});
        Curve.scalar.clamp(h[0..32]);
        const scalar = Curve.scalar.reduce(h[0..32].*);

        const blind_h = blindCtx(blind_seed, ctx);
        const blind_factor = Curve.scalar.reduce(blind_h[0..32].*);

        const blind_scalar = Curve.scalar.mul(scalar, blind_factor);
        const blind_public_key = BlindPublicKey{
            .key = try PublicKey.fromBytes((Curve.basePoint.mul(blind_scalar) catch return error.IdentityElement).toBytes()),
        };

        var prefix: [64]u8 = undefined;
        prefix[0..32].* = h[32..64].*;
        prefix[32..64].* = blind_h[32..64].*;

        const blind_secret_key = BlindSecretKey{
            .prefix = prefix,
            .blind_scalar = blind_scalar,
            .blind_public_key = blind_public_key,
        };
        return BlindKeyPair{
            .blind_public_key = blind_public_key,
            .blind_secret_key = blind_secret_key,
        };
    }

    /// Sign a message using a blind key pair, and optional random noise.
    /// Having noise creates non-standard, non-deterministic signatures,
    /// but has been proven to increase resilience against fault attacks.
    pub fn sign(key_pair: BlindKeyPair, msg: []const u8, noise: ?[noise_length]u8) (IdentityElementError || KeyMismatchError || NonCanonicalError || WeakPublicKeyError)!Signature {
        const scalar = key_pair.blind_secret_key.blind_scalar;
        const prefix = key_pair.blind_secret_key.prefix;

        return (try PublicKey.fromBytes(key_pair.blind_public_key.key.bytes))
            .computeNonceAndSign(msg, noise, scalar, &prefix);
    }
}