diff --git a/Cargo.lock b/Cargo.lock index 98b8930..cfbead2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "ascon" -version = "0.1.4" +version = "0.2.0-pre" dependencies = [ "byteorder", ] diff --git a/ascon/Cargo.toml b/ascon/Cargo.toml index c973914..859901e 100644 --- a/ascon/Cargo.toml +++ b/ascon/Cargo.toml @@ -1,10 +1,18 @@ [package] name = "ascon" -version = "0.1.4" -authors = ["quininer kel "] -description = "A implementation of ASCON authenticated encryption." -repository = "https://github.com/quininer/ascon" +version = "0.2.0-pre" +description = """ +Pure Rust implementation of Ascon, a family of authenticated encryption and +hashing algorithms designed to be lightweight and easy to implement +""" +authors = ["quininer kel ", "RustCrypto Developers"] license = "Apache-2.0 OR MIT" +documentation = "https://docs.rs/ascon" +repository = "https://github.com/RustCrypto/sponges/tree/master/ascon" +keywords = ["crypto", "sponge"] +categories = ["cryptography", "no-std"] +readme = "README.md" +edition = "2018" [dependencies] byteorder = { version = "1.0", default-features = false } diff --git a/ascon/README.md b/ascon/README.md index bf10059..4b0908f 100644 --- a/ascon/README.md +++ b/ascon/README.md @@ -64,6 +64,7 @@ dual licensed as above, without any additional terms or conditions. [//]: # (links) [RustCrypto]: https://github.com/rustcrypto +[Ascon]: https://ascon.iaik.tugraz.at/ [New standard for lightweight cryptography]: https://www.nist.gov/news-events/news/2023/02/nist-selects-lightweight-cryptography-algorithms-protect-small-devices [NIST Lightweight Cryptography]: https://csrc.nist.gov/projects/lightweight-cryptography/finalists [CAESAR competition]: https://competitions.cr.yp.to/caesar-submissions.html diff --git a/ascon/src/lib.rs b/ascon/src/lib.rs index 2445a79..ac076b4 100644 --- a/ascon/src/lib.rs +++ b/ascon/src/lib.rs @@ -1,9 +1,42 @@ -extern crate byteorder; +//! Pure Rust implementation of [Ascon], a family of authenticated encryption and +//! hashing algorithms designed to be lightweight and easy to implement. +//! +//! ## About +//! +//! Ascon is a family of lightweight algorithms built on a core permutation +//! algorithm. These algorithms include: +//! +//! - Authenticated Encryption with Associated Data (AEAD) +//! - Hash functions (HASH) and extendible-output functions (XOF) +//! - Pseudo-random functions (PRF) and message authentication codes (MAC) +//! +//! Ascon has been selected as [new standard for lightweight cryptography] in the +//! [NIST Lightweight Cryptography] competition, and has also been selected as the +//! primary choice for lightweight authenticated encryption in the final +//! portfolio of the [CAESAR competition]. +//! +//! [Ascon]: https://ascon.iaik.tugraz.at/ +//! [New standard for lightweight cryptography]: https://www.nist.gov/news-events/news/2023/02/nist-selects-lightweight-cryptography-algorithms-protect-small-devices +//! [NIST Lightweight Cryptography]: https://csrc.nist.gov/projects/lightweight-cryptography/finalists +//! [CAESAR competition]: https://competitions.cr.yp.to/caesar-submissions.html + +#![doc( + html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg", + html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg" +)] +#![warn( + clippy::mod_module_files, + clippy::unwrap_used, + missing_docs, + rust_2018_idioms, + unused_lifetimes, + unused_qualifications +)] mod ops; mod util; -use ops::{finalization, initialization, permutation, process_aad}; +use crate::ops::{finalization, initialization, permutation, process_aad}; const KEY_LEN: usize = 16; const S_SIZE: usize = 320 / 8; @@ -11,12 +44,17 @@ const RATE: usize = 128 / 8; const A: usize = 12; const B: usize = 8; +/// Decryption errors. #[derive(Debug)] pub enum DecryptFail { + /// Invalid tag length. TagLengthError, + + /// Authentication failure (invalid tag). AuthenticationFail, } +/// AEAD encryption. pub fn aead_encrypt(key: &[u8], iv: &[u8], message: &[u8], aad: &[u8]) -> (Vec, [u8; KEY_LEN]) { let s = aad.len() / RATE + 1; let t = message.len() / RATE + 1; @@ -69,6 +107,7 @@ pub fn aead_encrypt(key: &[u8], iv: &[u8], message: &[u8], aad: &[u8]) -> (Vec