-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ghash+polyval: add
new_with_init_block
(#195)
Adds customization for init_block, needed for `belt-dwp` AEAD
- Loading branch information
Showing
6 changed files
with
99 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,11 @@ | |
//! | ||
//! Copyright (c) 2016 Thomas Pornin <[email protected]> | ||
use crate::{Block, Key, Tag}; | ||
use core::{ | ||
num::Wrapping, | ||
ops::{Add, Mul}, | ||
}; | ||
|
||
use universal_hash::{ | ||
consts::{U1, U16}, | ||
crypto_common::{BlockSizeUser, KeySizeUser, ParBlocksSizeUser}, | ||
|
@@ -19,6 +19,8 @@ use universal_hash::{ | |
#[cfg(feature = "zeroize")] | ||
use zeroize::Zeroize; | ||
|
||
use crate::{Block, Key, Tag}; | ||
|
||
/// **POLYVAL**: GHASH-like universal hash over GF(2^128). | ||
#[derive(Clone)] | ||
pub struct Polyval { | ||
|
@@ -29,17 +31,24 @@ pub struct Polyval { | |
s: U64x2, | ||
} | ||
|
||
impl Polyval { | ||
/// Initialize POLYVAL with the given `H` field element and initial block | ||
pub fn new_with_init_block(h: &Key, init_block: u128) -> Self { | ||
Self { | ||
h: h.into(), | ||
s: init_block.into(), | ||
} | ||
} | ||
} | ||
|
||
impl KeySizeUser for Polyval { | ||
type KeySize = U16; | ||
} | ||
|
||
impl KeyInit for Polyval { | ||
/// Initialize POLYVAL with the given `H` field element | ||
fn new(h: &Key) -> Self { | ||
Self { | ||
h: h.into(), | ||
s: U64x2::default(), | ||
} | ||
Self::new_with_init_block(h, 0) | ||
} | ||
} | ||
|
||
|
@@ -105,6 +114,12 @@ impl From<&Block> for U64x2 { | |
} | ||
} | ||
|
||
impl From<u128> for U64x2 { | ||
fn from(x: u128) -> Self { | ||
U64x2((x >> 64) as u64, (x) as u64) | ||
} | ||
} | ||
|
||
#[allow(clippy::suspicious_arithmetic_impl)] | ||
impl Add for U64x2 { | ||
type Output = Self; | ||
|