core/crypto/mldsa
mldsa
Types
3Parameters
Parameters :: enum int {
Invalid = 0,
ML_DSA_44 = 1,
ML_DSA_65 = 2,
ML_DSA_87 = 3,
}SourceParameters are the supported ML-DSA parameter sets.
Private_Key
Private_Key :: Private_KeySourcePrivate_Key is a ML-DSA private key.
Public_Key
Public_Key :: Public_KeySourcePublic_Key is a ML-DSA public key.
Constants
2MAX_CTX_SIZE
MAX_CTX_SIZE :: CTXBYTES_MAXSourceMAX_CTX_SIZE is the maximum size of the signature context (domain separation tag) in bytes.
PRIVATE_KEY_SEED_SIZE
PRIVATE_KEY_SEED_SIZE :: SEEDBYTESSourcePRIVATE_KEY_SEED_SIZE is the size of a private key in bytes.
Variables
2PUBLIC_KEY_SIZES
PUBLIC_KEY_SIZES :: [4]int = [Parameters]int {
.Invalid = 0,
.ML_DSA_44 = 1312,
.ML_DSA_65 = 1952,
.ML_DSA_87 = 2592,
}SourcePUBLIC_KEY_SIZES are the per-parameter sizes of a public key in bytes.
SIGNATURE_SIZES
SIGNATURE_SIZES :: [4]int = [Parameters]int {
.Invalid = 0,
.ML_DSA_44 = 2420,
.ML_DSA_65 = 3309,
.ML_DSA_87 = 4627,
}SourceSIGNATURE_SIZES are the per-parameter sizes of a signature in byte.
Procedures
18key_size
key_size :: proc(k: ^T) -> (int)Sourcekey_size returns the key size of a Private_Key or Public_Key in bytes.
params
params :: proc(k: ^T) -> (Parameters)Sourceparams returns the Parameters used by a Private_Key or Public_Key instance.
private_key_bytes
private_key_bytes :: proc(priv_key: ^Private_Key, dst: []u8)Sourceprivate_key_bytes sets dst to byte-encoding of priv_key in the "seed" format.
private_key_clear
private_key_clear :: proc(priv_key: ^Private_Key)Sourceprivate_key_clear clears priv_key to the uninitialized state.
private_key_equal
private_key_equal :: proc(p: ^Private_Key, q: ^Private_Key) -> (bool)Sourceprivate_key_equal returns true if and only if (⟺) the private keys are equal, in constant time.
private_key_generate
private_key_generate :: proc(priv_key: ^Private_Key, params: Parameters) -> (bool)Sourceprivate_key_generate uses the system entropy source to generate a new Private_Key. This will only fail if and only if (⟺) the system entropy source is missing or broken.
private_key_public_bytes
private_key_public_bytes :: proc(priv_key: ^Private_Key, dst: []u8)Sourceprivate_key_public_bytes sets dst to the byte-encoding of the public key corresponding to priv_key.
private_key_set
private_key_set :: proc(priv_key: ^Private_Key, src: ^Private_Key)Sourceprivate_key_set sets priv_key to src.
private_key_set_bytes
private_key_set_bytes :: proc(priv_key: ^Private_Key, params: Parameters, b: []u8) -> (bool)Sourceprivate_key_set_bytes decodes a byte-encoded private key in "seed" format, and returns true if and only if (⟺) the operation was successful.
public_key_bytes
public_key_bytes :: proc(pub_key: ^Public_Key, dst: []u8)Sourcepublic_key_bytes sets dst to byte-encoding of pub_key.
public_key_clear
public_key_clear :: proc(pub_key: ^Public_Key)Sourcepublic_key_clear clears pub_key to the uninitialized state.
public_key_equal
public_key_equal :: proc(p: ^Public_Key, q: ^Public_Key) -> (bool)Sourcepublic_key_equal returns true if and only if (⟺) the public keys are equal, in constant time.
public_key_set
public_key_set :: proc(pub_key: ^Public_Key, src: ^Public_Key)Sourcepublic_key_set sets pub_key to src.
public_key_set_bytes
public_key_set_bytes :: proc(pub_key: ^Public_Key, params: Parameters, b: []u8) -> (bool)Sourcepublic_key_set_bytes decodes a byte-encoded public key, and returns true if and only if (⟺) the operation was successful.
public_key_set_priv
public_key_set_priv :: proc(pub_key: ^Public_Key, priv_key: ^Private_Key)Sourcepublic_key_set_priv sets pub_key to the public component of priv_key.
sign
sign :: proc(priv_key: ^Private_Key, ctx: []u8, msg: []u8, sig: []u8, deterministic = !crypto.HAS_RAND_BYTES) -> (bool)Sourcesign writes the signature by priv_key over (ctx, msg) to sig and returns true if and only if (⟺) the signing succeeded.
ctx is an optional domain separation tag and may be omitted (nil).
signature_size
signature_size :: proc(k: ^T) -> (int)Sourcesignature_size returns the key size of a signature in bytes.
verify
verify :: proc(pub_key: ^Public_Key, ctx: []u8, msg: []u8, sig: []u8) -> (bool)Sourceverify returns true if and only if (⟺) sig is a valid signature by pub_key over (ctx, msg).