anubis-wormhole 1.0.0

A post-quantum secure file transfer tool based on the Magic Wormhole protocol.
Documentation
#![cfg(feature = "providers-pqclean")]
use crate::traits::Signature as SigTrait;
use pqcrypto_dilithium::dilithium5;
use pqcrypto_traits::sign::{PublicKey as _, SecretKey as _, DetachedSignature as _};

#[derive(Clone, Copy, Debug, Default)]
pub struct MlDsa87;

impl SigTrait for MlDsa87 {
    type PublicKey = Vec<u8>;
    type SecretKey = Vec<u8>;
    type Signature = Vec<u8>;

    fn keypair(&self) -> (Self::PublicKey, Self::SecretKey) {
        let (pk, sk) = dilithium5::keypair();
        (pk.as_bytes().to_vec(), sk.as_bytes().to_vec())
    }

    fn sign(&self, sk: &Self::SecretKey, msg: &[u8]) -> Self::Signature {
        let sk = dilithium5::SecretKey::from_bytes(sk).expect("valid dilithium sk");
        let sig = dilithium5::detached_sign(msg, &sk);
        sig.as_bytes().to_vec()
    }

    fn verify(&self, pk: &Self::PublicKey, msg: &[u8], sig: &Self::Signature) -> bool {
        let pk = match dilithium5::PublicKey::from_bytes(pk) { Ok(v) => v, Err(_) => return false };
        let sig = match dilithium5::DetachedSignature::from_bytes(sig) { Ok(v) => v, Err(_) => return false };
        dilithium5::verify_detached_signature(&sig, msg, &pk).is_ok()
    }
}