-
Notifications
You must be signed in to change notification settings - Fork 270
/
Copy pathmod.rs
163 lines (150 loc) · 3.95 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
use digest::dev::{feed_rand_16mib, fixed_reset_test};
use digest::{hash_serialization_test, new_test};
use hex_literal::hex;
use ripemd::{Digest, Ripemd128, Ripemd160, Ripemd256, Ripemd320};
// Test vectors from FIPS 180-1 and from the [RIPEMD webpage][1].
//
// [1] https://homes.esat.kuleuven.be/~bosselae/ripemd160.html
new_test!(ripemd128_main, "ripemd128", Ripemd128, fixed_reset_test);
new_test!(ripemd160_main, "ripemd160", Ripemd160, fixed_reset_test);
new_test!(ripemd256_main, "ripemd256", Ripemd256, fixed_reset_test);
new_test!(ripemd320_main, "ripemd320", Ripemd320, fixed_reset_test);
#[rustfmt::skip]
hash_serialization_test!(
ripemd128_serialization,
Ripemd128,
hex!("
4be201c3c174ca6a87dbc274d2a372eb
01000000000000000113000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
000000000000000000
")
);
#[rustfmt::skip]
hash_serialization_test!(
ripemd160_serialization,
Ripemd160,
hex!("
fe8fe28142dc4785457085ad85ac4a20
4127b66d010000000000000001130000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000
")
);
#[rustfmt::skip]
hash_serialization_test!(
ripemd256_serialization,
Ripemd256,
hex!("
adaa3eee80b1ebe8f5a2363a13ad15c6
1cac8a0942a88e8b075d9cdc788dd59e
01000000000000000113000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
000000000000000000
")
);
#[rustfmt::skip]
hash_serialization_test!(
ripemd320_serialization,
Ripemd320,
hex!("
b964693501716183244dc2f66453fe04
333677dadfc04919f1aa6b2e66684cce
665028f0f1253e090100000000000000
01130000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00
")
);
#[test]
fn ripemd128_1mil_a() {
let mut h = Ripemd128::new();
let buf = [b'a'; 1000];
for _ in 0..1000 {
h.update(&buf[..]);
}
assert_eq!(h.finalize(), hex!("4a7f5723f954eba1216c9d8f6320431f"));
}
#[test]
fn ripemd128_rand() {
let mut h = Ripemd128::new();
feed_rand_16mib(&mut h);
assert_eq!(h.finalize(), hex!("01eb52529bcec15bd0cb4040ec998632"));
}
#[test]
fn ripemd160_1mil_a() {
let mut h = Ripemd160::new();
let buf = [b'a'; 1000];
for _ in 0..1000 {
h.update(&buf[..]);
}
assert_eq!(
h.finalize(),
hex!("52783243c1697bdbe16d37f97f68f08325dc1528")
);
}
#[test]
fn ripemd160_rand() {
let mut h = Ripemd160::new();
feed_rand_16mib(&mut h);
assert_eq!(
h.finalize(),
hex!("bcd8c672932125776af3c60eeeb58bbaf206f386")
);
}
#[test]
fn ripemd256_1mil_a() {
let mut h = Ripemd256::new();
let buf = [b'a'; 1000];
for _ in 0..1000 {
h.update(&buf[..]);
}
assert_eq!(
h.finalize(),
hex!("ac953744e10e31514c150d4d8d7b677342e33399788296e43ae4850ce4f97978"),
);
}
#[test]
fn ripemd256_rand() {
let mut h = Ripemd256::new();
feed_rand_16mib(&mut h);
assert_eq!(
h.finalize(),
hex!("6492ffe075896441b737900bdf58fc960e77477e42a2a61bc02c66fd689b69d0"),
);
}
#[test]
fn ripemd320_1mil_a() {
let mut h = Ripemd320::new();
let buf = [b'a'; 1000];
for _ in 0..1000 {
h.update(&buf[..]);
}
assert_eq!(
h.finalize(),
hex!(
"bdee37f4371e20646b8b0d862dda16292ae36f40"
"965e8c8509e63d1dbddecc503e2b63eb9245bb66"
),
);
}
#[test]
fn ripemd320_rand() {
let mut h = Ripemd320::new();
feed_rand_16mib(&mut h);
assert_eq!(
h.finalize(),
hex!(
"3a905312162c5c173639f6cc1cdf51d14e8bda02"
"865767592e26d9343fbec348ce55ce39b4b4b56f"
),
);
}