Skip to content

Commit f932db1

Browse files
committed
newtypes support
1 parent 137cda7 commit f932db1

File tree

21 files changed

+173
-133
lines changed

21 files changed

+173
-133
lines changed

Cargo.lock

Lines changed: 3 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ members = [
2727

2828
[profile.dev]
2929
opt-level = 2
30+
31+
[patch.crates-io]
32+
digest = { path = "../traits/digest" }
33+
#digest = { git = "https://github.com/baloo/traits.git", branch = "baloo/digest/new-type" }

ascon-hash/src/lib.rs

Lines changed: 61 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -381,55 +381,68 @@ impl AlgorithmName for AsconAXofCore {
381381
}
382382
}
383383

384-
/// Ascon hash
385-
///
386-
/// ```
387-
/// use ascon_hash::{AsconHash, Digest};
388-
///
389-
/// let mut hasher = AsconHash::new();
390-
/// hasher.update(b"some bytes");
391-
/// let digest = hasher.finalize();
392-
/// assert_eq!(&digest[..], b"\xb7\x42\xca\x75\xe5\x70\x38\x75\x70\x59\xcc\xcc\x68\x74\x71\x4f\x9d\xbd\x7f\xc5\x92\x4a\x7d\xf4\xe3\x16\x59\x4f\xd1\x42\x6c\xa8");
393-
/// ```
394-
pub type AsconHash = CoreWrapper<AsconCore>;
395-
/// AsconA hash
396-
///
397-
/// ```
398-
/// use ascon_hash::{AsconAHash, Digest};
399-
///
400-
/// let mut hasher = AsconAHash::new();
401-
/// hasher.update(b"some bytes");
402-
/// let digest = hasher.finalize();
403-
/// assert_eq!(&digest[..], b"\x1d\x1a\xc8\x74\x4a\x4a\x05\x81\x33\x7d\x5a\xf2\x78\xc2\x55\x88\xe1\xa3\xdd\x2d\x86\x73\x07\x64\x26\x53\xdc\xa4\x45\xf5\x5c\x2a");
404-
/// ```
405-
pub type AsconAHash = CoreWrapper<AsconACore>;
406-
/// AsconXof
407-
///
408-
/// ```
409-
/// use ascon_hash::{AsconXof, ExtendableOutput, Update, XofReader};
410-
///
411-
/// let mut xof = AsconXof::default();
412-
/// xof.update(b"some bytes");
413-
/// let mut reader = xof.finalize_xof();
414-
/// let mut dst = [0u8; 5];
415-
/// reader.read(&mut dst);
416-
/// assert_eq!(&dst, b"\xc2\x19\x72\xfd\xe9");
417-
/// ```
418-
pub type AsconXof = CoreWrapper<AsconXofCore>;
384+
digest::newtype!(
385+
r#"Ascon hash
386+
387+
```
388+
use ascon_hash::{AsconHash, Digest};
389+
390+
let mut hasher = AsconHash::new();
391+
hasher.update(b"some bytes");
392+
let digest = hasher.finalize();
393+
assert_eq!(&digest[..], b"\xb7\x42\xca\x75\xe5\x70\x38\x75\x70\x59\xcc\xcc\x68\x74\x71\x4f\x9d\xbd\x7f\xc5\x92\x4a\x7d\xf4\xe3\x16\x59\x4f\xd1\x42\x6c\xa8");
394+
```"#,
395+
AsconHash = CoreWrapper<AsconCore>
396+
);
397+
398+
digest::newtype!(
399+
r#"AsconA hash
400+
401+
```
402+
use ascon_hash::{AsconAHash, Digest};
403+
404+
let mut hasher = AsconAHash::new();
405+
hasher.update(b"some bytes");
406+
let digest = hasher.finalize();
407+
assert_eq!(&digest[..], b"\x1d\x1a\xc8\x74\x4a\x4a\x05\x81\x33\x7d\x5a\xf2\x78\xc2\x55\x88\xe1\xa3\xdd\x2d\x86\x73\x07\x64\x26\x53\xdc\xa4\x45\xf5\x5c\x2a");
408+
```"#,
409+
AsconAHash = CoreWrapper<AsconACore>
410+
);
411+
412+
digest::newtype!(
413+
r#"AsconXof
414+
415+
```
416+
use ascon_hash::{AsconXof, ExtendableOutput, Update, XofReader};
417+
418+
let mut xof = AsconXof::default();
419+
xof.update(b"some bytes");
420+
let mut reader = xof.finalize_xof();
421+
let mut dst = [0u8; 5];
422+
reader.read(&mut dst);
423+
assert_eq!(&dst, b"\xc2\x19\x72\xfd\xe9");
424+
```"#,
425+
AsconXof = CoreWrapper<AsconXofCore>
426+
);
427+
419428
/// Reader for AsconXof output
420429
pub type AsconXofReader = XofReaderCoreWrapper<AsconXofReaderCore>;
421-
/// AsconAXof
422-
///
423-
/// ```
424-
/// use ascon_hash::{AsconAXof, ExtendableOutput, Update, XofReader};
425-
///
426-
/// let mut xof = AsconAXof::default();
427-
/// xof.update(b"some bytes");
428-
/// let mut reader = xof.finalize_xof();
429-
/// let mut dst = [0u8; 5];
430-
/// reader.read(&mut dst);
431-
/// assert_eq!(&dst, b"\xb8\xd6\xbd\xf0\xa7");
432-
/// ```
433-
pub type AsconAXof = CoreWrapper<AsconAXofCore>;
430+
431+
digest::newtype!(
432+
r#"AsconAXof
433+
434+
```
435+
use ascon_hash::{AsconAXof, ExtendableOutput, Update, XofReader};
436+
437+
let mut xof = AsconAXof::default();
438+
xof.update(b"some bytes");
439+
let mut reader = xof.finalize_xof();
440+
let mut dst = [0u8; 5];
441+
reader.read(&mut dst);
442+
assert_eq!(&dst, b"\xb8\xd6\xbd\xf0\xa7");
443+
```"#,
444+
AsconAXof = CoreWrapper<AsconAXofCore>
445+
);
446+
434447
/// Reader for AsconAXof output
435448
pub type AsconAXofReader = XofReaderCoreWrapper<AsconAXofReaderCore>;

belt-hash/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ pub struct BeltHashCore {
4040
h: [u32; 8],
4141
}
4242

43-
/// BelT hasher state.
44-
pub type BeltHash = CoreWrapper<BeltHashCore>;
43+
digest::newtype!("BelT hasher hasher", BeltHash = CoreWrapper<BeltHashCore>);
4544

4645
impl BeltHashCore {
4746
fn compress_block(&mut self, block: &Block<Self>) {

fsb/src/macros.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ macro_rules! fsb_impl {
1212
state: [u8; $r / 8],
1313
}
1414

15-
#[doc=$full_doc]
16-
pub type $full_state = CoreWrapper<$state>;
15+
digest::newtype!($full_doc, $full_state = CoreWrapper<$state>);
1716

1817
impl HashMarker for $state {}
1918

gost94/src/lib.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ impl AssociatedOid for Gost94Core<params::GOST28147UAParam> {
3434
const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.2.804.2.1.1.1.1.2.1");
3535
}
3636

37-
/// GOST94 hash function with CryptoPro parameters.
38-
pub type Gost94CryptoPro = CoreWrapper<Gost94Core<params::CryptoProParam>>;
39-
/// GOST94 hash function with S-box defined in GOST R 34.12-2015.
40-
pub type Gost94s2015 = CoreWrapper<Gost94Core<params::S2015Param>>;
41-
/// GOST94 hash function with test parameters.
42-
pub type Gost94Test = CoreWrapper<Gost94Core<params::TestParam>>;
43-
/// GOST94 hash function with UAPKI GOST 34.311-95 parameters
44-
/// (1.2.804.2.1.1.1.1.2.1 OID).
45-
pub type Gost94UA = CoreWrapper<Gost94Core<params::GOST28147UAParam>>;
37+
digest::newtype!("GOST94 hash function with CryptoPro parameters.", Gost94CryptoPro = CoreWrapper<Gost94Core<params::CryptoProParam>>);
38+
39+
digest::newtype!("GOST94 hash function with S-box defined in GOST R 34.12-2015.", Gost94s2015 = CoreWrapper<Gost94Core<params::S2015Param>>);
40+
41+
digest::newtype!("GOST94 hash function with test parameters.", Gost94Test = CoreWrapper<Gost94Core<params::TestParam>>);
42+
43+
digest::newtype!(
44+
r#"GOST94 hash function with UAPKI GOST 34.311-95 parameters
45+
(1.2.804.2.1.1.1.1.2.1 OID)."#,
46+
Gost94UA = CoreWrapper<Gost94Core<params::GOST28147UAParam>>
47+
);

groestl/src/lib.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ pub type GroestlShortCore<OutSize> = CtVariableCoreWrapper<GroestlShortVarCore,
4444
/// Hasher state of the short Groestl variant generic over output size.
4545
pub type GroestlShort<OutSize> = CoreWrapper<GroestlShortCore<OutSize>>;
4646

47-
/// Groestl-224 hasher state.
48-
pub type Groestl224 = CoreWrapper<GroestlShortCore<U28>>;
49-
/// Groestl-256 hasher state.
50-
pub type Groestl256 = CoreWrapper<GroestlShortCore<U32>>;
47+
digest::newtype!("Groestl-224 hasher state.", Groestl224 = CoreWrapper<GroestlShortCore<U28>>);
48+
digest::newtype!("Groestl-256 hasher state.", Groestl256 = CoreWrapper<GroestlShortCore<U32>>);
5149

5250
impl HashMarker for GroestlShortVarCore {}
5351

@@ -175,10 +173,8 @@ pub type GroestlLongCore<OutSize> = CtVariableCoreWrapper<GroestlLongVarCore, Ou
175173
/// Hasher state of the long Groestl variant generic over output size.
176174
pub type GroestlLong<OutSize> = CoreWrapper<GroestlLongCore<OutSize>>;
177175

178-
/// Groestl-384 hasher state.
179-
pub type Groestl384 = CoreWrapper<GroestlLongCore<U48>>;
180-
/// Groestl-512 hasher state.
181-
pub type Groestl512 = CoreWrapper<GroestlLongCore<U64>>;
176+
digest::newtype!("Groestl-384 hasher state.", Groestl384 = CoreWrapper<GroestlLongCore<U48>>);
177+
digest::newtype!("Groestl-512 hasher state.", Groestl512 = CoreWrapper<GroestlLongCore<U64>>);
182178

183179
impl HashMarker for GroestlLongVarCore {}
184180

jh/src/lib.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,22 @@ pub struct JhCore {
3838
block_len: u64,
3939
}
4040

41-
/// Jh-224 hasher state
42-
pub type Jh224 = CoreWrapper<CtVariableCoreWrapper<JhCore, U28>>;
43-
/// Jh-256 hasher state
44-
pub type Jh256 = CoreWrapper<CtVariableCoreWrapper<JhCore, U32>>;
45-
/// Jh-384 hasher state
46-
pub type Jh384 = CoreWrapper<CtVariableCoreWrapper<JhCore, U48>>;
47-
/// Jh-512 hasher state
48-
pub type Jh512 = CoreWrapper<CtVariableCoreWrapper<JhCore, U64>>;
41+
digest::newtype!(
42+
"Jh-224 hasher state",
43+
Jh224 = CoreWrapper<CtVariableCoreWrapper<JhCore, U28>>
44+
);
45+
digest::newtype!(
46+
"Jh-256 hasher state",
47+
Jh256 = CoreWrapper<CtVariableCoreWrapper<JhCore, U32>>
48+
);
49+
digest::newtype!(
50+
"Jh-384 hasher state",
51+
Jh384 = CoreWrapper<CtVariableCoreWrapper<JhCore, U48>>
52+
);
53+
digest::newtype!(
54+
"Jh-512 hasher state",
55+
Jh512 = CoreWrapper<CtVariableCoreWrapper<JhCore, U64>>
56+
);
4957

5058
impl HashMarker for JhCore {}
5159

md2/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ pub struct Md2Core {
3737
checksum: Block<Self>,
3838
}
3939

40-
/// MD2 hasher state.
41-
pub type Md2 = CoreWrapper<Md2Core>;
40+
digest::newtype!("MD2 hasher state.", Md2 = CoreWrapper<Md2Core>);
4241

4342
const STATE_LEN: usize = 48;
4443

md4/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ pub struct Md4Core {
4444
state: [Wu32; STATE_LEN],
4545
}
4646

47-
/// MD4 hasher state
48-
pub type Md4 = CoreWrapper<Md4Core>;
47+
digest::newtype!("MD4 hasher state", Md4 = CoreWrapper<Md4Core>);
4948

5049
const STATE_LEN: usize = 4;
5150

0 commit comments

Comments
 (0)