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

An Ed25519 secret key.

Fields

bytes: [encoded_length]u8

Values

Constantencoded_length[src]

Length (in bytes) of a raw secret key.

Source Code

Source code
pub const encoded_length = 64

Functions

Functionseed[src]

pub fn seed(self: SecretKey) [KeyPair.seed_length]u8

Return the seed used to generate this secret key.

Parameters

self: SecretKey

Source Code

Source code
pub fn seed(self: SecretKey) [KeyPair.seed_length]u8 {
    return self.bytes[0..KeyPair.seed_length].*;
}

FunctionpublicKeyBytes[src]

pub fn publicKeyBytes(self: SecretKey) [PublicKey.encoded_length]u8

Return the raw public key bytes corresponding to this secret key.

Parameters

self: SecretKey

Source Code

Source code
pub fn publicKeyBytes(self: SecretKey) [PublicKey.encoded_length]u8 {
    return self.bytes[KeyPair.seed_length..].*;
}

FunctionfromBytes[src]

pub fn fromBytes(bytes: [encoded_length]u8) !SecretKey

Create a secret key from raw bytes.

Parameters

bytes: [encoded_length]u8

Source Code

Source code
pub fn fromBytes(bytes: [encoded_length]u8) !SecretKey {
    return SecretKey{ .bytes = bytes };
}

FunctiontoBytes[src]

pub fn toBytes(sk: SecretKey) [encoded_length]u8

Return the secret key as raw bytes.

Parameters

Source Code

Source code
pub fn toBytes(sk: SecretKey) [encoded_length]u8 {
    return sk.bytes;
}

Source Code

Source code
pub const SecretKey = struct {
    /// Length (in bytes) of a raw secret key.
    pub const encoded_length = 64;

    bytes: [encoded_length]u8,

    /// Return the seed used to generate this secret key.
    pub fn seed(self: SecretKey) [KeyPair.seed_length]u8 {
        return self.bytes[0..KeyPair.seed_length].*;
    }

    /// Return the raw public key bytes corresponding to this secret key.
    pub fn publicKeyBytes(self: SecretKey) [PublicKey.encoded_length]u8 {
        return self.bytes[KeyPair.seed_length..].*;
    }

    /// Create a secret key from raw bytes.
    pub fn fromBytes(bytes: [encoded_length]u8) !SecretKey {
        return SecretKey{ .bytes = bytes };
    }

    /// Return the secret key as raw bytes.
    pub fn toBytes(sk: SecretKey) [encoded_length]u8 {
        return sk.bytes;
    }

    // Return the clamped secret scalar and prefix for this secret key
    fn scalarAndPrefix(self: SecretKey) struct { scalar: CompressedScalar, prefix: [32]u8 } {
        var az: [Sha512.digest_length]u8 = undefined;
        var h = Sha512.init(.{});
        h.update(&self.seed());
        h.final(&az);

        var s = az[0..32].*;
        Curve.scalar.clamp(&s);

        return .{ .scalar = s, .prefix = az[32..].* };
    }
}