/* SPDX-License-Identifier: GPL-2.0-or-later */1/*2* Support for verifying ML-DSA signatures3*4* Copyright 2025 Google LLC5*/6#ifndef _CRYPTO_MLDSA_H7#define _CRYPTO_MLDSA_H89#include <linux/types.h>1011/* Identifier for an ML-DSA parameter set */12enum mldsa_alg {13MLDSA44, /* ML-DSA-44 */14MLDSA65, /* ML-DSA-65 */15MLDSA87, /* ML-DSA-87 */16};1718/* Lengths of ML-DSA public keys and signatures in bytes */19#define MLDSA44_PUBLIC_KEY_SIZE 131220#define MLDSA65_PUBLIC_KEY_SIZE 195221#define MLDSA87_PUBLIC_KEY_SIZE 259222#define MLDSA44_SIGNATURE_SIZE 242023#define MLDSA65_SIGNATURE_SIZE 330924#define MLDSA87_SIGNATURE_SIZE 46272526/**27* mldsa_verify() - Verify an ML-DSA signature28* @alg: The ML-DSA parameter set to use29* @sig: The signature30* @sig_len: Length of the signature in bytes. Should match the31* MLDSA*_SIGNATURE_SIZE constant associated with @alg,32* otherwise -EBADMSG will be returned.33* @msg: The message34* @msg_len: Length of the message in bytes35* @pk: The public key36* @pk_len: Length of the public key in bytes. Should match the37* MLDSA*_PUBLIC_KEY_SIZE constant associated with @alg,38* otherwise -EBADMSG will be returned.39*40* This verifies a signature using pure ML-DSA with the specified parameter set.41* The context string is assumed to be empty. This corresponds to FIPS 20442* Algorithm 3 "ML-DSA.Verify" with the ctx parameter set to the empty string43* and the lengths of the signature and key given explicitly by the caller.44*45* Context: Might sleep46*47* Return:48* * 0 if the signature is valid49* * -EBADMSG if the signature and/or public key is malformed50* * -EKEYREJECTED if the signature is invalid but otherwise well-formed51* * -ENOMEM if out of memory so the validity of the signature is unknown52*/53int mldsa_verify(enum mldsa_alg alg, const u8 *sig, size_t sig_len,54const u8 *msg, size_t msg_len, const u8 *pk, size_t pk_len);5556#if IS_ENABLED(CONFIG_CRYPTO_LIB_MLDSA_KUNIT_TEST)57/* Internal function, exposed only for unit testing */58s32 mldsa_use_hint(u8 h, s32 r, s32 gamma2);59#endif6061#endif /* _CRYPTO_MLDSA_H */626364