/rust/registry/src/index.crates.io-1949cf8c6b5b557f/sha1-0.10.6/src/compress/soft.rs
Line | Count | Source |
1 | | #![allow(clippy::many_single_char_names)] |
2 | | use super::BLOCK_SIZE; |
3 | | use core::convert::TryInto; |
4 | | |
5 | | const K: [u32; 4] = [0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6]; |
6 | | |
7 | | #[inline(always)] |
8 | 3.68G | fn add(a: [u32; 4], b: [u32; 4]) -> [u32; 4] { |
9 | 3.68G | [ |
10 | 3.68G | a[0].wrapping_add(b[0]), |
11 | 3.68G | a[1].wrapping_add(b[1]), |
12 | 3.68G | a[2].wrapping_add(b[2]), |
13 | 3.68G | a[3].wrapping_add(b[3]), |
14 | 3.68G | ] |
15 | 3.68G | } sha1::compress::soft::add Line | Count | Source | 8 | 2.92G | fn add(a: [u32; 4], b: [u32; 4]) -> [u32; 4] { | 9 | 2.92G | [ | 10 | 2.92G | a[0].wrapping_add(b[0]), | 11 | 2.92G | a[1].wrapping_add(b[1]), | 12 | 2.92G | a[2].wrapping_add(b[2]), | 13 | 2.92G | a[3].wrapping_add(b[3]), | 14 | 2.92G | ] | 15 | 2.92G | } |
sha1::compress::soft::add Line | Count | Source | 8 | 757M | fn add(a: [u32; 4], b: [u32; 4]) -> [u32; 4] { | 9 | 757M | [ | 10 | 757M | a[0].wrapping_add(b[0]), | 11 | 757M | a[1].wrapping_add(b[1]), | 12 | 757M | a[2].wrapping_add(b[2]), | 13 | 757M | a[3].wrapping_add(b[3]), | 14 | 757M | ] | 15 | 757M | } |
|
16 | | |
17 | | #[inline(always)] |
18 | 2.94G | fn xor(a: [u32; 4], b: [u32; 4]) -> [u32; 4] { |
19 | 2.94G | [a[0] ^ b[0], a[1] ^ b[1], a[2] ^ b[2], a[3] ^ b[3]] |
20 | 2.94G | } sha1::compress::soft::xor Line | Count | Source | 18 | 2.34G | fn xor(a: [u32; 4], b: [u32; 4]) -> [u32; 4] { | 19 | 2.34G | [a[0] ^ b[0], a[1] ^ b[1], a[2] ^ b[2], a[3] ^ b[3]] | 20 | 2.34G | } |
sha1::compress::soft::xor Line | Count | Source | 18 | 606M | fn xor(a: [u32; 4], b: [u32; 4]) -> [u32; 4] { | 19 | 606M | [a[0] ^ b[0], a[1] ^ b[1], a[2] ^ b[2], a[3] ^ b[3]] | 20 | 606M | } |
|
21 | | |
22 | | #[inline] |
23 | 3.68G | pub fn sha1_first_add(e: u32, w0: [u32; 4]) -> [u32; 4] { |
24 | 3.68G | let [a, b, c, d] = w0; |
25 | 3.68G | [e.wrapping_add(a), b, c, d] |
26 | 3.68G | } sha1::compress::soft::sha1_first_add Line | Count | Source | 23 | 2.92G | pub fn sha1_first_add(e: u32, w0: [u32; 4]) -> [u32; 4] { | 24 | 2.92G | let [a, b, c, d] = w0; | 25 | 2.92G | [e.wrapping_add(a), b, c, d] | 26 | 2.92G | } |
sha1::compress::soft::sha1_first_add Line | Count | Source | 23 | 757M | pub fn sha1_first_add(e: u32, w0: [u32; 4]) -> [u32; 4] { | 24 | 757M | let [a, b, c, d] = w0; | 25 | 757M | [e.wrapping_add(a), b, c, d] | 26 | 757M | } |
|
27 | | |
28 | 2.94G | fn sha1msg1(a: [u32; 4], b: [u32; 4]) -> [u32; 4] { |
29 | 2.94G | let [_, _, w2, w3] = a; |
30 | 2.94G | let [w4, w5, _, _] = b; |
31 | 2.94G | [a[0] ^ w2, a[1] ^ w3, a[2] ^ w4, a[3] ^ w5] |
32 | 2.94G | } sha1::compress::soft::sha1msg1 Line | Count | Source | 28 | 2.34G | fn sha1msg1(a: [u32; 4], b: [u32; 4]) -> [u32; 4] { | 29 | 2.34G | let [_, _, w2, w3] = a; | 30 | 2.34G | let [w4, w5, _, _] = b; | 31 | 2.34G | [a[0] ^ w2, a[1] ^ w3, a[2] ^ w4, a[3] ^ w5] | 32 | 2.34G | } |
sha1::compress::soft::sha1msg1 Line | Count | Source | 28 | 606M | fn sha1msg1(a: [u32; 4], b: [u32; 4]) -> [u32; 4] { | 29 | 606M | let [_, _, w2, w3] = a; | 30 | 606M | let [w4, w5, _, _] = b; | 31 | 606M | [a[0] ^ w2, a[1] ^ w3, a[2] ^ w4, a[3] ^ w5] | 32 | 606M | } |
|
33 | | |
34 | 2.94G | fn sha1msg2(a: [u32; 4], b: [u32; 4]) -> [u32; 4] { |
35 | 2.94G | let [x0, x1, x2, x3] = a; |
36 | 2.94G | let [_, w13, w14, w15] = b; |
37 | | |
38 | 2.94G | let w16 = (x0 ^ w13).rotate_left(1); |
39 | 2.94G | let w17 = (x1 ^ w14).rotate_left(1); |
40 | 2.94G | let w18 = (x2 ^ w15).rotate_left(1); |
41 | 2.94G | let w19 = (x3 ^ w16).rotate_left(1); |
42 | | |
43 | 2.94G | [w16, w17, w18, w19] |
44 | 2.94G | } sha1::compress::soft::sha1msg2 Line | Count | Source | 34 | 2.34G | fn sha1msg2(a: [u32; 4], b: [u32; 4]) -> [u32; 4] { | 35 | 2.34G | let [x0, x1, x2, x3] = a; | 36 | 2.34G | let [_, w13, w14, w15] = b; | 37 | | | 38 | 2.34G | let w16 = (x0 ^ w13).rotate_left(1); | 39 | 2.34G | let w17 = (x1 ^ w14).rotate_left(1); | 40 | 2.34G | let w18 = (x2 ^ w15).rotate_left(1); | 41 | 2.34G | let w19 = (x3 ^ w16).rotate_left(1); | 42 | | | 43 | 2.34G | [w16, w17, w18, w19] | 44 | 2.34G | } |
sha1::compress::soft::sha1msg2 Line | Count | Source | 34 | 606M | fn sha1msg2(a: [u32; 4], b: [u32; 4]) -> [u32; 4] { | 35 | 606M | let [x0, x1, x2, x3] = a; | 36 | 606M | let [_, w13, w14, w15] = b; | 37 | | | 38 | 606M | let w16 = (x0 ^ w13).rotate_left(1); | 39 | 606M | let w17 = (x1 ^ w14).rotate_left(1); | 40 | 606M | let w18 = (x2 ^ w15).rotate_left(1); | 41 | 606M | let w19 = (x3 ^ w16).rotate_left(1); | 42 | | | 43 | 606M | [w16, w17, w18, w19] | 44 | 606M | } |
|
45 | | |
46 | | #[inline] |
47 | 3.50G | fn sha1_first_half(abcd: [u32; 4], msg: [u32; 4]) -> [u32; 4] { |
48 | 3.50G | sha1_first_add(abcd[0].rotate_left(30), msg) |
49 | 3.50G | } sha1::compress::soft::sha1_first_half Line | Count | Source | 47 | 2.78G | fn sha1_first_half(abcd: [u32; 4], msg: [u32; 4]) -> [u32; 4] { | 48 | 2.78G | sha1_first_add(abcd[0].rotate_left(30), msg) | 49 | 2.78G | } |
sha1::compress::soft::sha1_first_half Line | Count | Source | 47 | 719M | fn sha1_first_half(abcd: [u32; 4], msg: [u32; 4]) -> [u32; 4] { | 48 | 719M | sha1_first_add(abcd[0].rotate_left(30), msg) | 49 | 719M | } |
|
50 | | |
51 | 3.68G | fn sha1_digest_round_x4(abcd: [u32; 4], work: [u32; 4], i: i8) -> [u32; 4] { |
52 | 3.68G | match i { |
53 | 921M | 0 => sha1rnds4c(abcd, add(work, [K[0]; 4])), |
54 | 921M | 1 => sha1rnds4p(abcd, add(work, [K[1]; 4])), |
55 | 921M | 2 => sha1rnds4m(abcd, add(work, [K[2]; 4])), |
56 | 921M | 3 => sha1rnds4p(abcd, add(work, [K[3]; 4])), |
57 | 0 | _ => unreachable!("unknown icosaround index"), |
58 | | } |
59 | 3.68G | } sha1::compress::soft::sha1_digest_round_x4 Line | Count | Source | 51 | 2.92G | fn sha1_digest_round_x4(abcd: [u32; 4], work: [u32; 4], i: i8) -> [u32; 4] { | 52 | 2.92G | match i { | 53 | 731M | 0 => sha1rnds4c(abcd, add(work, [K[0]; 4])), | 54 | 731M | 1 => sha1rnds4p(abcd, add(work, [K[1]; 4])), | 55 | 731M | 2 => sha1rnds4m(abcd, add(work, [K[2]; 4])), | 56 | 731M | 3 => sha1rnds4p(abcd, add(work, [K[3]; 4])), | 57 | 0 | _ => unreachable!("unknown icosaround index"), | 58 | | } | 59 | 2.92G | } |
sha1::compress::soft::sha1_digest_round_x4 Line | Count | Source | 51 | 757M | fn sha1_digest_round_x4(abcd: [u32; 4], work: [u32; 4], i: i8) -> [u32; 4] { | 52 | 757M | match i { | 53 | 189M | 0 => sha1rnds4c(abcd, add(work, [K[0]; 4])), | 54 | 189M | 1 => sha1rnds4p(abcd, add(work, [K[1]; 4])), | 55 | 189M | 2 => sha1rnds4m(abcd, add(work, [K[2]; 4])), | 56 | 189M | 3 => sha1rnds4p(abcd, add(work, [K[3]; 4])), | 57 | 0 | _ => unreachable!("unknown icosaround index"), | 58 | | } | 59 | 757M | } |
|
60 | | |
61 | 921M | fn sha1rnds4c(abcd: [u32; 4], msg: [u32; 4]) -> [u32; 4] { |
62 | 921M | let [mut a, mut b, mut c, mut d] = abcd; |
63 | 921M | let [t, u, v, w] = msg; |
64 | 921M | let mut e = 0u32; |
65 | | |
66 | | macro_rules! bool3ary_202 { |
67 | | ($a:expr, $b:expr, $c:expr) => { |
68 | | $c ^ ($a & ($b ^ $c)) |
69 | | }; |
70 | | } // Choose, MD5F, SHA1C |
71 | | |
72 | 921M | e = e |
73 | 921M | .wrapping_add(a.rotate_left(5)) |
74 | 921M | .wrapping_add(bool3ary_202!(b, c, d)) |
75 | 921M | .wrapping_add(t); |
76 | 921M | b = b.rotate_left(30); |
77 | | |
78 | 921M | d = d |
79 | 921M | .wrapping_add(e.rotate_left(5)) |
80 | 921M | .wrapping_add(bool3ary_202!(a, b, c)) |
81 | 921M | .wrapping_add(u); |
82 | 921M | a = a.rotate_left(30); |
83 | | |
84 | 921M | c = c |
85 | 921M | .wrapping_add(d.rotate_left(5)) |
86 | 921M | .wrapping_add(bool3ary_202!(e, a, b)) |
87 | 921M | .wrapping_add(v); |
88 | 921M | e = e.rotate_left(30); |
89 | | |
90 | 921M | b = b |
91 | 921M | .wrapping_add(c.rotate_left(5)) |
92 | 921M | .wrapping_add(bool3ary_202!(d, e, a)) |
93 | 921M | .wrapping_add(w); |
94 | 921M | d = d.rotate_left(30); |
95 | | |
96 | 921M | [b, c, d, e] |
97 | 921M | } sha1::compress::soft::sha1rnds4c Line | Count | Source | 61 | 731M | fn sha1rnds4c(abcd: [u32; 4], msg: [u32; 4]) -> [u32; 4] { | 62 | 731M | let [mut a, mut b, mut c, mut d] = abcd; | 63 | 731M | let [t, u, v, w] = msg; | 64 | 731M | let mut e = 0u32; | 65 | | | 66 | | macro_rules! bool3ary_202 { | 67 | | ($a:expr, $b:expr, $c:expr) => { | 68 | | $c ^ ($a & ($b ^ $c)) | 69 | | }; | 70 | | } // Choose, MD5F, SHA1C | 71 | | | 72 | 731M | e = e | 73 | 731M | .wrapping_add(a.rotate_left(5)) | 74 | 731M | .wrapping_add(bool3ary_202!(b, c, d)) | 75 | 731M | .wrapping_add(t); | 76 | 731M | b = b.rotate_left(30); | 77 | | | 78 | 731M | d = d | 79 | 731M | .wrapping_add(e.rotate_left(5)) | 80 | 731M | .wrapping_add(bool3ary_202!(a, b, c)) | 81 | 731M | .wrapping_add(u); | 82 | 731M | a = a.rotate_left(30); | 83 | | | 84 | 731M | c = c | 85 | 731M | .wrapping_add(d.rotate_left(5)) | 86 | 731M | .wrapping_add(bool3ary_202!(e, a, b)) | 87 | 731M | .wrapping_add(v); | 88 | 731M | e = e.rotate_left(30); | 89 | | | 90 | 731M | b = b | 91 | 731M | .wrapping_add(c.rotate_left(5)) | 92 | 731M | .wrapping_add(bool3ary_202!(d, e, a)) | 93 | 731M | .wrapping_add(w); | 94 | 731M | d = d.rotate_left(30); | 95 | | | 96 | 731M | [b, c, d, e] | 97 | 731M | } |
sha1::compress::soft::sha1rnds4c Line | Count | Source | 61 | 189M | fn sha1rnds4c(abcd: [u32; 4], msg: [u32; 4]) -> [u32; 4] { | 62 | 189M | let [mut a, mut b, mut c, mut d] = abcd; | 63 | 189M | let [t, u, v, w] = msg; | 64 | 189M | let mut e = 0u32; | 65 | | | 66 | | macro_rules! bool3ary_202 { | 67 | | ($a:expr, $b:expr, $c:expr) => { | 68 | | $c ^ ($a & ($b ^ $c)) | 69 | | }; | 70 | | } // Choose, MD5F, SHA1C | 71 | | | 72 | 189M | e = e | 73 | 189M | .wrapping_add(a.rotate_left(5)) | 74 | 189M | .wrapping_add(bool3ary_202!(b, c, d)) | 75 | 189M | .wrapping_add(t); | 76 | 189M | b = b.rotate_left(30); | 77 | | | 78 | 189M | d = d | 79 | 189M | .wrapping_add(e.rotate_left(5)) | 80 | 189M | .wrapping_add(bool3ary_202!(a, b, c)) | 81 | 189M | .wrapping_add(u); | 82 | 189M | a = a.rotate_left(30); | 83 | | | 84 | 189M | c = c | 85 | 189M | .wrapping_add(d.rotate_left(5)) | 86 | 189M | .wrapping_add(bool3ary_202!(e, a, b)) | 87 | 189M | .wrapping_add(v); | 88 | 189M | e = e.rotate_left(30); | 89 | | | 90 | 189M | b = b | 91 | 189M | .wrapping_add(c.rotate_left(5)) | 92 | 189M | .wrapping_add(bool3ary_202!(d, e, a)) | 93 | 189M | .wrapping_add(w); | 94 | 189M | d = d.rotate_left(30); | 95 | | | 96 | 189M | [b, c, d, e] | 97 | 189M | } |
|
98 | | |
99 | 1.84G | fn sha1rnds4p(abcd: [u32; 4], msg: [u32; 4]) -> [u32; 4] { |
100 | 1.84G | let [mut a, mut b, mut c, mut d] = abcd; |
101 | 1.84G | let [t, u, v, w] = msg; |
102 | 1.84G | let mut e = 0u32; |
103 | | |
104 | | macro_rules! bool3ary_150 { |
105 | | ($a:expr, $b:expr, $c:expr) => { |
106 | | $a ^ $b ^ $c |
107 | | }; |
108 | | } // Parity, XOR, MD5H, SHA1P |
109 | | |
110 | 1.84G | e = e |
111 | 1.84G | .wrapping_add(a.rotate_left(5)) |
112 | 1.84G | .wrapping_add(bool3ary_150!(b, c, d)) |
113 | 1.84G | .wrapping_add(t); |
114 | 1.84G | b = b.rotate_left(30); |
115 | | |
116 | 1.84G | d = d |
117 | 1.84G | .wrapping_add(e.rotate_left(5)) |
118 | 1.84G | .wrapping_add(bool3ary_150!(a, b, c)) |
119 | 1.84G | .wrapping_add(u); |
120 | 1.84G | a = a.rotate_left(30); |
121 | | |
122 | 1.84G | c = c |
123 | 1.84G | .wrapping_add(d.rotate_left(5)) |
124 | 1.84G | .wrapping_add(bool3ary_150!(e, a, b)) |
125 | 1.84G | .wrapping_add(v); |
126 | 1.84G | e = e.rotate_left(30); |
127 | | |
128 | 1.84G | b = b |
129 | 1.84G | .wrapping_add(c.rotate_left(5)) |
130 | 1.84G | .wrapping_add(bool3ary_150!(d, e, a)) |
131 | 1.84G | .wrapping_add(w); |
132 | 1.84G | d = d.rotate_left(30); |
133 | | |
134 | 1.84G | [b, c, d, e] |
135 | 1.84G | } sha1::compress::soft::sha1rnds4p Line | Count | Source | 99 | 1.46G | fn sha1rnds4p(abcd: [u32; 4], msg: [u32; 4]) -> [u32; 4] { | 100 | 1.46G | let [mut a, mut b, mut c, mut d] = abcd; | 101 | 1.46G | let [t, u, v, w] = msg; | 102 | 1.46G | let mut e = 0u32; | 103 | | | 104 | | macro_rules! bool3ary_150 { | 105 | | ($a:expr, $b:expr, $c:expr) => { | 106 | | $a ^ $b ^ $c | 107 | | }; | 108 | | } // Parity, XOR, MD5H, SHA1P | 109 | | | 110 | 1.46G | e = e | 111 | 1.46G | .wrapping_add(a.rotate_left(5)) | 112 | 1.46G | .wrapping_add(bool3ary_150!(b, c, d)) | 113 | 1.46G | .wrapping_add(t); | 114 | 1.46G | b = b.rotate_left(30); | 115 | | | 116 | 1.46G | d = d | 117 | 1.46G | .wrapping_add(e.rotate_left(5)) | 118 | 1.46G | .wrapping_add(bool3ary_150!(a, b, c)) | 119 | 1.46G | .wrapping_add(u); | 120 | 1.46G | a = a.rotate_left(30); | 121 | | | 122 | 1.46G | c = c | 123 | 1.46G | .wrapping_add(d.rotate_left(5)) | 124 | 1.46G | .wrapping_add(bool3ary_150!(e, a, b)) | 125 | 1.46G | .wrapping_add(v); | 126 | 1.46G | e = e.rotate_left(30); | 127 | | | 128 | 1.46G | b = b | 129 | 1.46G | .wrapping_add(c.rotate_left(5)) | 130 | 1.46G | .wrapping_add(bool3ary_150!(d, e, a)) | 131 | 1.46G | .wrapping_add(w); | 132 | 1.46G | d = d.rotate_left(30); | 133 | | | 134 | 1.46G | [b, c, d, e] | 135 | 1.46G | } |
sha1::compress::soft::sha1rnds4p Line | Count | Source | 99 | 378M | fn sha1rnds4p(abcd: [u32; 4], msg: [u32; 4]) -> [u32; 4] { | 100 | 378M | let [mut a, mut b, mut c, mut d] = abcd; | 101 | 378M | let [t, u, v, w] = msg; | 102 | 378M | let mut e = 0u32; | 103 | | | 104 | | macro_rules! bool3ary_150 { | 105 | | ($a:expr, $b:expr, $c:expr) => { | 106 | | $a ^ $b ^ $c | 107 | | }; | 108 | | } // Parity, XOR, MD5H, SHA1P | 109 | | | 110 | 378M | e = e | 111 | 378M | .wrapping_add(a.rotate_left(5)) | 112 | 378M | .wrapping_add(bool3ary_150!(b, c, d)) | 113 | 378M | .wrapping_add(t); | 114 | 378M | b = b.rotate_left(30); | 115 | | | 116 | 378M | d = d | 117 | 378M | .wrapping_add(e.rotate_left(5)) | 118 | 378M | .wrapping_add(bool3ary_150!(a, b, c)) | 119 | 378M | .wrapping_add(u); | 120 | 378M | a = a.rotate_left(30); | 121 | | | 122 | 378M | c = c | 123 | 378M | .wrapping_add(d.rotate_left(5)) | 124 | 378M | .wrapping_add(bool3ary_150!(e, a, b)) | 125 | 378M | .wrapping_add(v); | 126 | 378M | e = e.rotate_left(30); | 127 | | | 128 | 378M | b = b | 129 | 378M | .wrapping_add(c.rotate_left(5)) | 130 | 378M | .wrapping_add(bool3ary_150!(d, e, a)) | 131 | 378M | .wrapping_add(w); | 132 | 378M | d = d.rotate_left(30); | 133 | | | 134 | 378M | [b, c, d, e] | 135 | 378M | } |
|
136 | | |
137 | 921M | fn sha1rnds4m(abcd: [u32; 4], msg: [u32; 4]) -> [u32; 4] { |
138 | 921M | let [mut a, mut b, mut c, mut d] = abcd; |
139 | 921M | let [t, u, v, w] = msg; |
140 | 921M | let mut e = 0u32; |
141 | | |
142 | | macro_rules! bool3ary_232 { |
143 | | ($a:expr, $b:expr, $c:expr) => { |
144 | | ($a & $b) ^ ($a & $c) ^ ($b & $c) |
145 | | }; |
146 | | } // Majority, SHA1M |
147 | | |
148 | 921M | e = e |
149 | 921M | .wrapping_add(a.rotate_left(5)) |
150 | 921M | .wrapping_add(bool3ary_232!(b, c, d)) |
151 | 921M | .wrapping_add(t); |
152 | 921M | b = b.rotate_left(30); |
153 | | |
154 | 921M | d = d |
155 | 921M | .wrapping_add(e.rotate_left(5)) |
156 | 921M | .wrapping_add(bool3ary_232!(a, b, c)) |
157 | 921M | .wrapping_add(u); |
158 | 921M | a = a.rotate_left(30); |
159 | | |
160 | 921M | c = c |
161 | 921M | .wrapping_add(d.rotate_left(5)) |
162 | 921M | .wrapping_add(bool3ary_232!(e, a, b)) |
163 | 921M | .wrapping_add(v); |
164 | 921M | e = e.rotate_left(30); |
165 | | |
166 | 921M | b = b |
167 | 921M | .wrapping_add(c.rotate_left(5)) |
168 | 921M | .wrapping_add(bool3ary_232!(d, e, a)) |
169 | 921M | .wrapping_add(w); |
170 | 921M | d = d.rotate_left(30); |
171 | | |
172 | 921M | [b, c, d, e] |
173 | 921M | } sha1::compress::soft::sha1rnds4m Line | Count | Source | 137 | 731M | fn sha1rnds4m(abcd: [u32; 4], msg: [u32; 4]) -> [u32; 4] { | 138 | 731M | let [mut a, mut b, mut c, mut d] = abcd; | 139 | 731M | let [t, u, v, w] = msg; | 140 | 731M | let mut e = 0u32; | 141 | | | 142 | | macro_rules! bool3ary_232 { | 143 | | ($a:expr, $b:expr, $c:expr) => { | 144 | | ($a & $b) ^ ($a & $c) ^ ($b & $c) | 145 | | }; | 146 | | } // Majority, SHA1M | 147 | | | 148 | 731M | e = e | 149 | 731M | .wrapping_add(a.rotate_left(5)) | 150 | 731M | .wrapping_add(bool3ary_232!(b, c, d)) | 151 | 731M | .wrapping_add(t); | 152 | 731M | b = b.rotate_left(30); | 153 | | | 154 | 731M | d = d | 155 | 731M | .wrapping_add(e.rotate_left(5)) | 156 | 731M | .wrapping_add(bool3ary_232!(a, b, c)) | 157 | 731M | .wrapping_add(u); | 158 | 731M | a = a.rotate_left(30); | 159 | | | 160 | 731M | c = c | 161 | 731M | .wrapping_add(d.rotate_left(5)) | 162 | 731M | .wrapping_add(bool3ary_232!(e, a, b)) | 163 | 731M | .wrapping_add(v); | 164 | 731M | e = e.rotate_left(30); | 165 | | | 166 | 731M | b = b | 167 | 731M | .wrapping_add(c.rotate_left(5)) | 168 | 731M | .wrapping_add(bool3ary_232!(d, e, a)) | 169 | 731M | .wrapping_add(w); | 170 | 731M | d = d.rotate_left(30); | 171 | | | 172 | 731M | [b, c, d, e] | 173 | 731M | } |
sha1::compress::soft::sha1rnds4m Line | Count | Source | 137 | 189M | fn sha1rnds4m(abcd: [u32; 4], msg: [u32; 4]) -> [u32; 4] { | 138 | 189M | let [mut a, mut b, mut c, mut d] = abcd; | 139 | 189M | let [t, u, v, w] = msg; | 140 | 189M | let mut e = 0u32; | 141 | | | 142 | | macro_rules! bool3ary_232 { | 143 | | ($a:expr, $b:expr, $c:expr) => { | 144 | | ($a & $b) ^ ($a & $c) ^ ($b & $c) | 145 | | }; | 146 | | } // Majority, SHA1M | 147 | | | 148 | 189M | e = e | 149 | 189M | .wrapping_add(a.rotate_left(5)) | 150 | 189M | .wrapping_add(bool3ary_232!(b, c, d)) | 151 | 189M | .wrapping_add(t); | 152 | 189M | b = b.rotate_left(30); | 153 | | | 154 | 189M | d = d | 155 | 189M | .wrapping_add(e.rotate_left(5)) | 156 | 189M | .wrapping_add(bool3ary_232!(a, b, c)) | 157 | 189M | .wrapping_add(u); | 158 | 189M | a = a.rotate_left(30); | 159 | | | 160 | 189M | c = c | 161 | 189M | .wrapping_add(d.rotate_left(5)) | 162 | 189M | .wrapping_add(bool3ary_232!(e, a, b)) | 163 | 189M | .wrapping_add(v); | 164 | 189M | e = e.rotate_left(30); | 165 | | | 166 | 189M | b = b | 167 | 189M | .wrapping_add(c.rotate_left(5)) | 168 | 189M | .wrapping_add(bool3ary_232!(d, e, a)) | 169 | 189M | .wrapping_add(w); | 170 | 189M | d = d.rotate_left(30); | 171 | | | 172 | 189M | [b, c, d, e] | 173 | 189M | } |
|
174 | | |
175 | | macro_rules! rounds4 { |
176 | | ($h0:ident, $h1:ident, $wk:expr, $i:expr) => { |
177 | | sha1_digest_round_x4($h0, sha1_first_half($h1, $wk), $i) |
178 | | }; |
179 | | } |
180 | | |
181 | | macro_rules! schedule { |
182 | | ($v0:expr, $v1:expr, $v2:expr, $v3:expr) => { |
183 | | sha1msg2(xor(sha1msg1($v0, $v1), $v2), $v3) |
184 | | }; |
185 | | } |
186 | | |
187 | | macro_rules! schedule_rounds4 { |
188 | | ( |
189 | | $h0:ident, $h1:ident, |
190 | | $w0:expr, $w1:expr, $w2:expr, $w3:expr, $w4:expr, |
191 | | $i:expr |
192 | | ) => { |
193 | | $w4 = schedule!($w0, $w1, $w2, $w3); |
194 | | $h1 = rounds4!($h0, $h1, $w4, $i); |
195 | | }; |
196 | | } |
197 | | |
198 | | #[inline(always)] |
199 | 184M | fn sha1_digest_block_u32(state: &mut [u32; 5], block: &[u32; 16]) { |
200 | 184M | let mut w0 = [block[0], block[1], block[2], block[3]]; |
201 | 184M | let mut w1 = [block[4], block[5], block[6], block[7]]; |
202 | 184M | let mut w2 = [block[8], block[9], block[10], block[11]]; |
203 | 184M | let mut w3 = [block[12], block[13], block[14], block[15]]; |
204 | | #[allow(clippy::needless_late_init)] |
205 | | let mut w4; |
206 | | |
207 | 184M | let mut h0 = [state[0], state[1], state[2], state[3]]; |
208 | 184M | let mut h1 = sha1_first_add(state[4], w0); |
209 | | |
210 | | // Rounds 0..20 |
211 | 184M | h1 = sha1_digest_round_x4(h0, h1, 0); |
212 | 184M | h0 = rounds4!(h1, h0, w1, 0); |
213 | 184M | h1 = rounds4!(h0, h1, w2, 0); |
214 | 184M | h0 = rounds4!(h1, h0, w3, 0); |
215 | 184M | schedule_rounds4!(h0, h1, w0, w1, w2, w3, w4, 0); |
216 | | |
217 | | // Rounds 20..40 |
218 | 184M | schedule_rounds4!(h1, h0, w1, w2, w3, w4, w0, 1); |
219 | 184M | schedule_rounds4!(h0, h1, w2, w3, w4, w0, w1, 1); |
220 | 184M | schedule_rounds4!(h1, h0, w3, w4, w0, w1, w2, 1); |
221 | 184M | schedule_rounds4!(h0, h1, w4, w0, w1, w2, w3, 1); |
222 | 184M | schedule_rounds4!(h1, h0, w0, w1, w2, w3, w4, 1); |
223 | | |
224 | | // Rounds 40..60 |
225 | 184M | schedule_rounds4!(h0, h1, w1, w2, w3, w4, w0, 2); |
226 | 184M | schedule_rounds4!(h1, h0, w2, w3, w4, w0, w1, 2); |
227 | 184M | schedule_rounds4!(h0, h1, w3, w4, w0, w1, w2, 2); |
228 | 184M | schedule_rounds4!(h1, h0, w4, w0, w1, w2, w3, 2); |
229 | 184M | schedule_rounds4!(h0, h1, w0, w1, w2, w3, w4, 2); |
230 | | |
231 | | // Rounds 60..80 |
232 | 184M | schedule_rounds4!(h1, h0, w1, w2, w3, w4, w0, 3); |
233 | 184M | schedule_rounds4!(h0, h1, w2, w3, w4, w0, w1, 3); |
234 | 184M | schedule_rounds4!(h1, h0, w3, w4, w0, w1, w2, 3); |
235 | 184M | schedule_rounds4!(h0, h1, w4, w0, w1, w2, w3, 3); |
236 | 184M | schedule_rounds4!(h1, h0, w0, w1, w2, w3, w4, 3); |
237 | | |
238 | 184M | let e = h1[0].rotate_left(30); |
239 | 184M | let [a, b, c, d] = h0; |
240 | | |
241 | 184M | state[0] = state[0].wrapping_add(a); |
242 | 184M | state[1] = state[1].wrapping_add(b); |
243 | 184M | state[2] = state[2].wrapping_add(c); |
244 | 184M | state[3] = state[3].wrapping_add(d); |
245 | 184M | state[4] = state[4].wrapping_add(e); |
246 | 184M | } sha1::compress::soft::sha1_digest_block_u32 Line | Count | Source | 199 | 146M | fn sha1_digest_block_u32(state: &mut [u32; 5], block: &[u32; 16]) { | 200 | 146M | let mut w0 = [block[0], block[1], block[2], block[3]]; | 201 | 146M | let mut w1 = [block[4], block[5], block[6], block[7]]; | 202 | 146M | let mut w2 = [block[8], block[9], block[10], block[11]]; | 203 | 146M | let mut w3 = [block[12], block[13], block[14], block[15]]; | 204 | | #[allow(clippy::needless_late_init)] | 205 | | let mut w4; | 206 | | | 207 | 146M | let mut h0 = [state[0], state[1], state[2], state[3]]; | 208 | 146M | let mut h1 = sha1_first_add(state[4], w0); | 209 | | | 210 | | // Rounds 0..20 | 211 | 146M | h1 = sha1_digest_round_x4(h0, h1, 0); | 212 | 146M | h0 = rounds4!(h1, h0, w1, 0); | 213 | 146M | h1 = rounds4!(h0, h1, w2, 0); | 214 | 146M | h0 = rounds4!(h1, h0, w3, 0); | 215 | 146M | schedule_rounds4!(h0, h1, w0, w1, w2, w3, w4, 0); | 216 | | | 217 | | // Rounds 20..40 | 218 | 146M | schedule_rounds4!(h1, h0, w1, w2, w3, w4, w0, 1); | 219 | 146M | schedule_rounds4!(h0, h1, w2, w3, w4, w0, w1, 1); | 220 | 146M | schedule_rounds4!(h1, h0, w3, w4, w0, w1, w2, 1); | 221 | 146M | schedule_rounds4!(h0, h1, w4, w0, w1, w2, w3, 1); | 222 | 146M | schedule_rounds4!(h1, h0, w0, w1, w2, w3, w4, 1); | 223 | | | 224 | | // Rounds 40..60 | 225 | 146M | schedule_rounds4!(h0, h1, w1, w2, w3, w4, w0, 2); | 226 | 146M | schedule_rounds4!(h1, h0, w2, w3, w4, w0, w1, 2); | 227 | 146M | schedule_rounds4!(h0, h1, w3, w4, w0, w1, w2, 2); | 228 | 146M | schedule_rounds4!(h1, h0, w4, w0, w1, w2, w3, 2); | 229 | 146M | schedule_rounds4!(h0, h1, w0, w1, w2, w3, w4, 2); | 230 | | | 231 | | // Rounds 60..80 | 232 | 146M | schedule_rounds4!(h1, h0, w1, w2, w3, w4, w0, 3); | 233 | 146M | schedule_rounds4!(h0, h1, w2, w3, w4, w0, w1, 3); | 234 | 146M | schedule_rounds4!(h1, h0, w3, w4, w0, w1, w2, 3); | 235 | 146M | schedule_rounds4!(h0, h1, w4, w0, w1, w2, w3, 3); | 236 | 146M | schedule_rounds4!(h1, h0, w0, w1, w2, w3, w4, 3); | 237 | | | 238 | 146M | let e = h1[0].rotate_left(30); | 239 | 146M | let [a, b, c, d] = h0; | 240 | | | 241 | 146M | state[0] = state[0].wrapping_add(a); | 242 | 146M | state[1] = state[1].wrapping_add(b); | 243 | 146M | state[2] = state[2].wrapping_add(c); | 244 | 146M | state[3] = state[3].wrapping_add(d); | 245 | 146M | state[4] = state[4].wrapping_add(e); | 246 | 146M | } |
sha1::compress::soft::sha1_digest_block_u32 Line | Count | Source | 199 | 37.8M | fn sha1_digest_block_u32(state: &mut [u32; 5], block: &[u32; 16]) { | 200 | 37.8M | let mut w0 = [block[0], block[1], block[2], block[3]]; | 201 | 37.8M | let mut w1 = [block[4], block[5], block[6], block[7]]; | 202 | 37.8M | let mut w2 = [block[8], block[9], block[10], block[11]]; | 203 | 37.8M | let mut w3 = [block[12], block[13], block[14], block[15]]; | 204 | | #[allow(clippy::needless_late_init)] | 205 | | let mut w4; | 206 | | | 207 | 37.8M | let mut h0 = [state[0], state[1], state[2], state[3]]; | 208 | 37.8M | let mut h1 = sha1_first_add(state[4], w0); | 209 | | | 210 | | // Rounds 0..20 | 211 | 37.8M | h1 = sha1_digest_round_x4(h0, h1, 0); | 212 | 37.8M | h0 = rounds4!(h1, h0, w1, 0); | 213 | 37.8M | h1 = rounds4!(h0, h1, w2, 0); | 214 | 37.8M | h0 = rounds4!(h1, h0, w3, 0); | 215 | 37.8M | schedule_rounds4!(h0, h1, w0, w1, w2, w3, w4, 0); | 216 | | | 217 | | // Rounds 20..40 | 218 | 37.8M | schedule_rounds4!(h1, h0, w1, w2, w3, w4, w0, 1); | 219 | 37.8M | schedule_rounds4!(h0, h1, w2, w3, w4, w0, w1, 1); | 220 | 37.8M | schedule_rounds4!(h1, h0, w3, w4, w0, w1, w2, 1); | 221 | 37.8M | schedule_rounds4!(h0, h1, w4, w0, w1, w2, w3, 1); | 222 | 37.8M | schedule_rounds4!(h1, h0, w0, w1, w2, w3, w4, 1); | 223 | | | 224 | | // Rounds 40..60 | 225 | 37.8M | schedule_rounds4!(h0, h1, w1, w2, w3, w4, w0, 2); | 226 | 37.8M | schedule_rounds4!(h1, h0, w2, w3, w4, w0, w1, 2); | 227 | 37.8M | schedule_rounds4!(h0, h1, w3, w4, w0, w1, w2, 2); | 228 | 37.8M | schedule_rounds4!(h1, h0, w4, w0, w1, w2, w3, 2); | 229 | 37.8M | schedule_rounds4!(h0, h1, w0, w1, w2, w3, w4, 2); | 230 | | | 231 | | // Rounds 60..80 | 232 | 37.8M | schedule_rounds4!(h1, h0, w1, w2, w3, w4, w0, 3); | 233 | 37.8M | schedule_rounds4!(h0, h1, w2, w3, w4, w0, w1, 3); | 234 | 37.8M | schedule_rounds4!(h1, h0, w3, w4, w0, w1, w2, 3); | 235 | 37.8M | schedule_rounds4!(h0, h1, w4, w0, w1, w2, w3, 3); | 236 | 37.8M | schedule_rounds4!(h1, h0, w0, w1, w2, w3, w4, 3); | 237 | | | 238 | 37.8M | let e = h1[0].rotate_left(30); | 239 | 37.8M | let [a, b, c, d] = h0; | 240 | | | 241 | 37.8M | state[0] = state[0].wrapping_add(a); | 242 | 37.8M | state[1] = state[1].wrapping_add(b); | 243 | 37.8M | state[2] = state[2].wrapping_add(c); | 244 | 37.8M | state[3] = state[3].wrapping_add(d); | 245 | 37.8M | state[4] = state[4].wrapping_add(e); | 246 | 37.8M | } |
|
247 | | |
248 | 2.43M | pub fn compress(state: &mut [u32; 5], blocks: &[[u8; BLOCK_SIZE]]) { |
249 | 2.43M | let mut block_u32 = [0u32; BLOCK_SIZE / 4]; |
250 | | // since LLVM can't properly use aliasing yet it will make |
251 | | // unnecessary state stores without this copy |
252 | 2.43M | let mut state_cpy = *state; |
253 | 184M | for block in blocks.iter() { |
254 | 2.94G | for (o, chunk) in block_u32.iter_mut().zip(block.chunks_exact(4)) { |
255 | 2.94G | *o = u32::from_be_bytes(chunk.try_into().unwrap()); |
256 | 2.94G | } |
257 | 184M | sha1_digest_block_u32(&mut state_cpy, &block_u32); |
258 | | } |
259 | 2.43M | *state = state_cpy; |
260 | 2.43M | } sha1::compress::soft::compress Line | Count | Source | 248 | 1.76M | pub fn compress(state: &mut [u32; 5], blocks: &[[u8; BLOCK_SIZE]]) { | 249 | 1.76M | let mut block_u32 = [0u32; BLOCK_SIZE / 4]; | 250 | | // since LLVM can't properly use aliasing yet it will make | 251 | | // unnecessary state stores without this copy | 252 | 1.76M | let mut state_cpy = *state; | 253 | 146M | for block in blocks.iter() { | 254 | 2.34G | for (o, chunk) in block_u32.iter_mut().zip(block.chunks_exact(4)) { | 255 | 2.34G | *o = u32::from_be_bytes(chunk.try_into().unwrap()); | 256 | 2.34G | } | 257 | 146M | sha1_digest_block_u32(&mut state_cpy, &block_u32); | 258 | | } | 259 | 1.76M | *state = state_cpy; | 260 | 1.76M | } |
sha1::compress::soft::compress Line | Count | Source | 248 | 670k | pub fn compress(state: &mut [u32; 5], blocks: &[[u8; BLOCK_SIZE]]) { | 249 | 670k | let mut block_u32 = [0u32; BLOCK_SIZE / 4]; | 250 | | // since LLVM can't properly use aliasing yet it will make | 251 | | // unnecessary state stores without this copy | 252 | 670k | let mut state_cpy = *state; | 253 | 37.8M | for block in blocks.iter() { | 254 | 606M | for (o, chunk) in block_u32.iter_mut().zip(block.chunks_exact(4)) { | 255 | 606M | *o = u32::from_be_bytes(chunk.try_into().unwrap()); | 256 | 606M | } | 257 | 37.8M | sha1_digest_block_u32(&mut state_cpy, &block_u32); | 258 | | } | 259 | 670k | *state = state_cpy; | 260 | 670k | } |
|