|
10 | 10 | #![cfg_attr(feature = "simd", feature(platform_intrinsics, repr_simd))] |
11 | 11 | #![cfg_attr(feature = "simd", allow(incomplete_features))] |
12 | 12 |
|
13 | | -#[cfg(feature = "std")] |
14 | | -extern crate std; |
15 | | - |
16 | 13 | pub use digest::{self, Digest}; |
17 | 14 |
|
18 | 15 | use core::{fmt, marker::PhantomData, ops::Div}; |
19 | 16 | use digest::{ |
20 | | - FixedOutput, HashMarker, InvalidOutputSize, MacMarker, Output, Update, VarOutputCustomized, |
| 17 | + CustomizedInit, FixedOutput, HashMarker, InvalidOutputSize, MacMarker, Output, Update, |
| 18 | + VarOutputCustomized, |
21 | 19 | array::{Array, ArraySize}, |
22 | 20 | block_buffer::{Lazy, LazyBuffer}, |
23 | 21 | consts::{U4, U16, U32, U64, U128}, |
24 | 22 | core_api::{ |
25 | | - AlgorithmName, Block, BlockSizeUser, Buffer, BufferKindUser, CoreWrapper, CtOutWrapper, |
26 | | - OutputSizeUser, RtVariableCoreWrapper, TruncSide, UpdateCore, VariableOutputCore, |
| 23 | + AlgorithmName, Block, BlockSizeUser, Buffer, BufferKindUser, OutputSizeUser, TruncSide, |
| 24 | + UpdateCore, VariableOutputCore, |
27 | 25 | }, |
28 | 26 | crypto_common::{InvalidLength, Key, KeyInit, KeySizeUser}, |
29 | | - typenum::{IsLessOrEqual, LeEq, NonZero, Unsigned}, |
| 27 | + typenum::{IsLessOrEqual, LeEq, NonZero, True, Unsigned}, |
30 | 28 | }; |
31 | 29 | #[cfg(feature = "reset")] |
32 | 30 | use digest::{FixedOutputReset, Reset}; |
@@ -62,12 +60,32 @@ blake2_impl!( |
62 | 60 | "Blake2b instance with a fixed output.", |
63 | 61 | ); |
64 | 62 |
|
65 | | -/// BLAKE2b which allows to choose output size at runtime. |
66 | | -pub type Blake2bVar = RtVariableCoreWrapper<Blake2bVarCore>; |
67 | | -/// Core hasher state of BLAKE2b generic over output size. |
68 | | -pub type Blake2bCore<OutSize> = CtOutWrapper<Blake2bVarCore, OutSize>; |
69 | | -/// BLAKE2b generic over output size. |
70 | | -pub type Blake2b<OutSize> = CoreWrapper<Blake2bCore<OutSize>>; |
| 63 | +digest::newtype_ct_variable_hash!( |
| 64 | + /// BLAKE2b generic over output size. |
| 65 | + pub struct Blake2b<OutSize>(Blake2bVarCore); |
| 66 | + exclude: SerializableState; |
| 67 | + max_size: U64; |
| 68 | +); |
| 69 | + |
| 70 | +// TODO: impl in the macro |
| 71 | +impl<OutSize> CustomizedInit for Blake2b<OutSize> |
| 72 | +where |
| 73 | + OutSize: ArraySize + IsLessOrEqual<U64, Output = True>, |
| 74 | +{ |
| 75 | + fn new_customized(customization: &[u8]) -> Self { |
| 76 | + Self { |
| 77 | + core: CustomizedInit::new_customized(customization), |
| 78 | + buffer: Default::default(), |
| 79 | + } |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +digest::newtype_rt_variable_hash!( |
| 84 | + /// BLAKE2b which allows to choose output size at runtime. |
| 85 | + pub struct Blake2bVar(Blake2bVarCore); |
| 86 | + exclude: SerializableState; |
| 87 | +); |
| 88 | + |
71 | 89 | /// BLAKE2b-128 hasher state. |
72 | 90 | pub type Blake2b128 = Blake2b<U16>; |
73 | 91 | /// BLAKE2b-256 hasher state. |
@@ -96,12 +114,32 @@ blake2_impl!( |
96 | 114 | "Blake2s instance with a fixed output.", |
97 | 115 | ); |
98 | 116 |
|
99 | | -/// BLAKE2s which allows to choose output size at runtime. |
100 | | -pub type Blake2sVar = RtVariableCoreWrapper<Blake2sVarCore>; |
101 | | -/// Core hasher state of BLAKE2s generic over output size. |
102 | | -pub type Blake2sCore<OutSize> = CtOutWrapper<Blake2sVarCore, OutSize>; |
103 | | -/// BLAKE2s generic over output size. |
104 | | -pub type Blake2s<OutSize> = CoreWrapper<Blake2sCore<OutSize>>; |
| 117 | +digest::newtype_ct_variable_hash!( |
| 118 | + /// BLAKE2s generic over output size. |
| 119 | + pub struct Blake2s<OutSize>(Blake2sVarCore); |
| 120 | + exclude: SerializableState; |
| 121 | + max_size: U32; |
| 122 | +); |
| 123 | + |
| 124 | +// TODO: impl in the macro |
| 125 | +impl<OutSize> CustomizedInit for Blake2s<OutSize> |
| 126 | +where |
| 127 | + OutSize: ArraySize + IsLessOrEqual<U32, Output = True>, |
| 128 | +{ |
| 129 | + fn new_customized(customization: &[u8]) -> Self { |
| 130 | + Self { |
| 131 | + core: CustomizedInit::new_customized(customization), |
| 132 | + buffer: Default::default(), |
| 133 | + } |
| 134 | + } |
| 135 | +} |
| 136 | + |
| 137 | +digest::newtype_rt_variable_hash!( |
| 138 | + /// BLAKE2s which allows to choose output size at runtime. |
| 139 | + pub struct Blake2sVar(Blake2sVarCore); |
| 140 | + exclude: SerializableState; |
| 141 | +); |
| 142 | + |
105 | 143 | /// BLAKE2s-128 hasher state. |
106 | 144 | pub type Blake2s128 = Blake2s<U16>; |
107 | 145 | /// BLAKE2s-256 hasher state. |
|
0 commit comments