0.0.1
commit
6fe6f715d9
|
@ -0,0 +1,2 @@
|
|||
/target
|
||||
/Cargo.lock
|
|
@ -0,0 +1,23 @@
|
|||
[package]
|
||||
name = "caead"
|
||||
version = "0.0.1"
|
||||
description = "Committing AEAD constructions from existing AEADs."
|
||||
authors = ["Aydin Mercan <aydin@mercan.dev>"]
|
||||
edition = "2021"
|
||||
license = "BSD-3-Clause"
|
||||
readme = "README.md"
|
||||
documentation = "https://docs.rs/caead"
|
||||
keywords = ["aead", "key-commitment"]
|
||||
categories = ["cryptography", "no-std"]
|
||||
rust-version = "1.68"
|
||||
|
||||
[dependencies]
|
||||
aead = { version = "0.5", default-features = false }
|
||||
digest = { version = "0.10", default-features = false }
|
||||
|
||||
[features]
|
||||
std = ["aead/std", "digest/std"]
|
||||
alloc = ["aead/alloc", "digest/alloc"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
|
@ -0,0 +1,11 @@
|
|||
Copyright 2023 Aydin Mercan <aydin@mercan.dev>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@ -0,0 +1,13 @@
|
|||
# cAEAD
|
||||
|
||||
![BSD-3-Clause][license-image]
|
||||
|
||||
Key committing AEAD constructions from existing AEADs.
|
||||
|
||||
## License
|
||||
|
||||
Licensed under the BSD-3-Clause.
|
||||
|
||||
[//]: # (badges)
|
||||
|
||||
[license-image]: https://img.shields.io/badge/license-BSD--3--Clause-blue
|
|
@ -0,0 +1,85 @@
|
|||
#![no_std]
|
||||
|
||||
//! Committing AEAD constructions. Allows one to construct key/fully committing AEAD constructions
|
||||
//! from [existing AEADs].
|
||||
//!
|
||||
//! [existing AEADS]: aead
|
||||
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use aead::generic_array::GenericArray;
|
||||
use aead::{AeadCore, AeadInPlace, Error, KeyInit, KeySizeUser, Nonce, Tag};
|
||||
use digest::Digest;
|
||||
|
||||
/// CTX key committing AEAD construction from [“On Committing Authenticated Encryption” by John Chan and Phillip Rogaway](https://eprint.iacr.org/2022/1260).
|
||||
pub struct CtxCommitment<A, H>
|
||||
where
|
||||
A: AeadCore + KeyInit,
|
||||
H: Digest,
|
||||
{
|
||||
key: GenericArray<u8, A::KeySize>,
|
||||
naead: A,
|
||||
_digest: PhantomData<H>,
|
||||
}
|
||||
|
||||
impl<A, H> AeadCore for CtxCommitment<A, H>
|
||||
where
|
||||
A: AeadCore + KeyInit,
|
||||
H: Digest,
|
||||
{
|
||||
type NonceSize = A::NonceSize;
|
||||
type TagSize = H::OutputSize;
|
||||
type CiphertextOverhead = A::CiphertextOverhead;
|
||||
}
|
||||
|
||||
impl<A, H> KeySizeUser for CtxCommitment<A, H>
|
||||
where
|
||||
A: AeadCore + KeyInit,
|
||||
H: Digest,
|
||||
{
|
||||
type KeySize = A::KeySize;
|
||||
}
|
||||
|
||||
impl<A, H> KeyInit for CtxCommitment<A, H>
|
||||
where
|
||||
A: AeadCore + KeyInit,
|
||||
H: Digest,
|
||||
{
|
||||
fn new(key: &GenericArray<u8, Self::KeySize>) -> Self {
|
||||
Self {
|
||||
key: key.clone(),
|
||||
naead: A::new(key),
|
||||
_digest: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<A, H> CtxCommitment<A, H>
|
||||
where
|
||||
A: AeadCore + KeyInit + AeadInPlace,
|
||||
H: Digest,
|
||||
{
|
||||
/// Currently not in [`AeadInPlace`] due to the inability to decrypt without verifying
|
||||
/// the tag.
|
||||
pub fn encrypt_in_place_detached(
|
||||
&self,
|
||||
nonce: &Nonce<Self>,
|
||||
associated_data: &[u8],
|
||||
buffer: &mut [u8],
|
||||
) -> Result<Tag<Self>, Error> {
|
||||
let mut tag = Tag::<Self>::default();
|
||||
|
||||
let ntag = self
|
||||
.naead
|
||||
.encrypt_in_place_detached(nonce, associated_data, buffer)?;
|
||||
|
||||
H::new()
|
||||
.chain_update(&self.key)
|
||||
.chain_update(nonce)
|
||||
.chain_update(associated_data)
|
||||
.chain_update(ntag)
|
||||
.finalize_into(&mut tag);
|
||||
|
||||
Ok(tag)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue