arcium-primitives 0.4.2

Arcium primitives
Documentation
use std::ops::Add;

use crate::{algebra::field::FieldExtension, ciphers::BlockCipher};

/// Correlation-resistant hash function built from a block cipher.
///
/// ** Note: ** This function implements the MMO hash from
/// Guo et al "Efficient and Secure Multiparty Computation from Fixed-Key Block Ciphers"
#[inline]
pub fn hash_cr<C: BlockCipher>(enc: &C, msg: &C::Block) -> C::Block
where
    C::Block: Add<C::Block, Output = C::Block>,
{
    // π(msg) ^ msg
    enc.encrypt(msg) + *msg
}

/// Circular correlation-resistant hash function built from a block cipher.
///
/// ** Note: ** This function implements the \hat{MMO} hash from
/// Guo et al "Efficient and Secure Multiparty Computation from Fixed-Key Block Ciphers"
#[inline]
pub fn hash_ccr<C>(enc: &C, msg: &C::Block) -> C::Block
where
    C: BlockCipher,
    C::Block: FieldExtension,
{
    // π(σ(msg)) ^ σ(msg)
    let t = msg.linear_orthomorphism();
    enc.encrypt(&t) + t
}