Skip to content

Commit

Permalink
V1.2.12
Browse files Browse the repository at this point in the history
Added a new macro `Verify` and the debugged the `Signature` macro + tests
  • Loading branch information
mm9942 authored Jun 25, 2024
1 parent d888dd3 commit 0ed72af
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
workspace = { members = ["crypt_guard_proc"] }
[package]
name = "crypt_guard"
version = "1.2.11"
version = "1.2.12"
edition = "2021"
description = "CryptGuardLib is a comprehensive Rust library designed for strong encryption and decryption, incorporating post-quantum cryptography to safeguard against quantum threats. It's geared towards developers who need to embed advanced cryptographic capabilities in their Rust applications."
license = "MIT"
repository = "https://github.com/mm9942/CryptGuardLib"
repository = "https://github.com/mm9942/crypt_guard"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
83 changes: 69 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
//! [crates-badge]: https://img.shields.io/badge/crates.io-v1.2-blue.svg?style=for-the-badge
//! [crates-url]: https://crates.io/crates/crypt_guard
//! [mit-badge]: https://img.shields.io/badge/license-MIT-green.svg?style=for-the-badge
//! [mit-url]: https://github.com/mm9942/CryptGuardLib/blob/main/LICENSE
//! [mit-url]: https://github.com/mm9942/crypt_guard/blob/main/LICENSE
//! [doc-badge]: https://img.shields.io/badge/docs-v1.2-yellow.svg?style=for-the-badge
//! [doc-url]: https://docs.rs/crypt_guard/
//! [lib-badge]: https://img.shields.io/badge/github-lib-black.svg?style=for-the-badge
//! [lib-link]: https://github.com/mm9942/CryptGuardLib
//! [lib-link]: https://github.com/mm9942/crypt_guard
//!
//! ## Introduction
//!
Expand Down Expand Up @@ -428,57 +428,112 @@ macro_rules! DecryptFile {

#[macro_export]
macro_rules! Signature {

// Falcon
// 1024
(Falcon, $key:expr, 1024, $content:expr, Message) => {{
let sign = Signature::<Falcon1024, Message>;
let sign = Signature::<Falcon1024, Message>::new();
sign.signature($content, $key).unwrap()
}};
(Falcon, $key:expr, 1024, $content:expr, Detached) => {{
let sign = Signature::<Falcon1024, Detached>;
let sign = Signature::<Falcon1024, Detached>::new();
sign.signature($content, $key).unwrap()
}};

// 512
(Falcon, $key:expr, 512, $content:expr, Message) => {{
let sign = Signature::<Falcon512, Message>;
sign.signature($content, key).unwrap()
let sign = Signature::<Falcon512, Message>::new();
sign.signature($content, $key).unwrap()
}};
(Falcon, $key:expr, 512, $content:expr, Detached) => {{
let sign = Signature::<Falcon512, Detached>;
let sign = Signature::<Falcon512, Detached>::new();
sign.signature($content, $key).unwrap()
}};

// Dilithium
// 5
(Dilithium, $key:expr, 5, $content:expr, Message) => {{
let sign = Signature::<Dilithium5, Message>;
let sign = Signature::<Dilithium5, Message>::new();
sign.signature($content, $key).unwrap()
}};
(Dilithium, $key:expr, 5, $content:expr, Detached) => {{
let sign = Signature::<Dilithium5, Detached>;
let sign = Signature::<Dilithium5, Detached>::new();
sign.signature($content, $key).unwrap()
}};

// 3
(Dilithium, $key:expr, 3, $content:expr, Message) => {{
let sign = Signature::<Dilithium3, Message>;
let sign = Signature::<Dilithium3, Message>::new();
sign.signature($content, $key).unwrap()
}};
(Dilithium, $key:expr, 3, $content:expr, Detached) => {{
let sign = Signature::<Dilithium3, Detached>;
let sign = Signature::<Dilithium3, Detached>::new();
sign.signature($content, $key).unwrap()
}};

// 2
(Dilithium, $key:expr, 2, $content:expr, Message) => {{
let sign = Signature::<Dilithium2, Message>;
let sign = Signature::<Dilithium2, Message>::new();
sign.signature($content, $key).unwrap()
}};
(Dilithium, $key:expr, 2, $content:expr, Detached) => {{
let sign = Signature::<Dilithium2, Detached>;
let sign = Signature::<Dilithium2, Detached>::new();
sign.signature($content, $key).unwrap()
}};

}

#[macro_export]
macro_rules! Verify {
// Falcon
// 1024
(Falcon, $key:expr, 1024, $content:expr, Message) => {{
let sign = Signature::<Falcon1024, Message>::new();
sign.open($content, $key).unwrap()
}};
(Falcon, $key:expr, 1024, $signature:expr, $content:expr, Detached) => {{
let sign = Signature::<Falcon1024, Detached>::new();
sign.verify($content, $signature, $key).unwrap()
}};

// 512
(Falcon, $key:expr, 512, $content:expr, Message) => {{
let sign = Signature::<Falcon512, Message>::new();
sign.open($content, $key).unwrap()
}};
(Falcon, $key:expr, 512, $signature:expr, $content:expr, Detached) => {{
let sign = Signature::<Falcon512, Detached>::new();
sign.verify($content, $signature, $key).unwrap()
}};

// Dilithium
// 5
(Dilithium, $key:expr, 5, $content:expr, Message) => {{
let sign = Signature::<Dilithium5, Message>::new();
sign.open($content, $key).unwrap()
}};
(Dilithium, $key:expr, 5, $signature:expr, $content:expr, Detached) => {{
let sign = Signature::<Dilithium5, Detached>::new();
sign.verify($content, $signature, $key).unwrap()
}};

// 3
(Dilithium, $key:expr, 3, $content:expr, Message) => {{
let sign = Signature::<Dilithium3, Message>::new();
sign.open($content, $key).unwrap()
}};
(Dilithium, $key:expr, 3, $signature:expr, $content:expr, Detached) => {{
let sign = Signature::<Dilithium3, Detached>::new();
sign.verify($content, $signature, $key).unwrap()
}};

// 2
(Dilithium, $key:expr, 2, $content:expr, Message) => {{
let sign = Signature::<Dilithium2, Message>::new();
sign.open($content, $key).unwrap()
}};
(Dilithium, $key:expr, 2, $signature:expr, $content:expr, Detached) => {{
let sign = Signature::<Dilithium2, Detached>::new();
sign.verify($content, $signature, $key).unwrap()
}};

}
25 changes: 23 additions & 2 deletions src/tests/SignatureTests.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@

use crate::KDF::*;
use crate::{KDF::*, error::*, FalconKeypair, Signature, Verify};
use std::{
fs,
path::{Path, PathBuf}
};


#[test]
fn test_falcon1024_signature_message_macro() -> Result<(), Box<dyn std::error::Error>> {
let data = b"hey, how are you?".to_vec();
let (public_key, secret_key) = FalconKeypair!(1024);
let sign = Signature!(Falcon, secret_key, 1024, data.clone(), Message);
let verified = Verify!(Falcon, public_key, 1024, sign.clone(), Message);
assert_eq!(data, verified);
Ok(())
}


#[test]
fn test_falcon1024_signature_detached_macro() -> Result<(), Box<dyn std::error::Error>> {
let data = b"hey, how are you?".to_vec();
let (public_key, secret_key) = FalconKeypair!(1024);
let sign = Signature!(Falcon, secret_key, 1024, data.clone(), Detached);
let verified = Verify!(Falcon, public_key, 1024, sign.clone(), data.clone(), Detached);
assert!(verified);
Ok(())
}

#[test]
fn test_save_Falcon1024_keys() -> Result<(), Box<dyn std::error::Error>> {
let (public_key, secret_key) = Falcon1024::keypair().unwrap();
Expand Down

0 comments on commit 0ed72af

Please sign in to comment.