Skip to content

Commit 9968ec3

Browse files
committed
---
yaml --- r: 79211 b: refs/heads/auto c: 6e3b2ab h: refs/heads/master i: 79209: a75c2be 79207: 396cb1f v: v3
1 parent a22f47a commit 9968ec3

File tree

2 files changed

+41
-23
lines changed

2 files changed

+41
-23
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: d39cec65b025ad4c6de50e778ffd1177279b5b3d
16+
refs/heads/auto: 6e3b2ab44d9c03fb7aa8e8b94e711c197de3d337
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/libextra/crypto/sha2.rs

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,8 @@ use cryptoutil::{write_u64_be, write_u32_be, read_u64v_be, read_u32v_be, add_byt
1414
add_bytes_to_bits_tuple, FixedBuffer, FixedBuffer128, FixedBuffer64, StandardPadding};
1515
use digest::Digest;
1616

17-
18-
// Sha-512 and Sha-256 use basically the same calculations which are implemented by these macros.
19-
// Inlining the calculations seems to result in better generated code.
20-
macro_rules! schedule_round( ($t:expr) => (
21-
W[$t] = sigma1(W[$t - 2]) + W[$t - 7] + sigma0(W[$t - 15]) + W[$t - 16];
22-
)
23-
)
24-
25-
macro_rules! sha2_round(
26-
($A:ident, $B:ident, $C:ident, $D:ident,
27-
$E:ident, $F:ident, $G:ident, $H:ident, $K:ident, $t:expr) => (
28-
{
29-
$H += sum1($E) + ch($E, $F, $G) + $K[$t] + W[$t];
30-
$D += $H;
31-
$H += sum0($A) + maj($A, $B, $C);
32-
}
33-
)
34-
)
35-
36-
37-
// A structure that represents that state of a digest computation for the SHA-2 512 family of digest
38-
// functions
17+
// A structure that represents that state of a digest computation for the SHA-2 512 family
18+
// of digest functions
3919
struct Engine512State {
4020
H0: u64,
4121
H1: u64,
@@ -108,6 +88,25 @@ impl Engine512State {
10888

10989
let mut W = [0u64, ..80];
11090

91+
// Sha-512 and Sha-256 use basically the same calculations which are implemented by
92+
// these macros. Inlining the calculations seems to result in better generated code.
93+
macro_rules! schedule_round( ($t:expr) => (
94+
W[$t] = sigma1(W[$t - 2]) + W[$t - 7] + sigma0(W[$t - 15]) + W[$t - 16];
95+
)
96+
)
97+
98+
macro_rules! sha2_round(
99+
($A:ident, $B:ident, $C:ident, $D:ident,
100+
$E:ident, $F:ident, $G:ident, $H:ident, $K:ident, $t:expr) => (
101+
{
102+
$H += sum1($E) + ch($E, $F, $G) + $K[$t] + W[$t];
103+
$D += $H;
104+
$H += sum0($A) + maj($A, $B, $C);
105+
}
106+
)
107+
)
108+
109+
111110
read_u64v_be(W.mut_slice(0, 16), data);
112111

113112
// Putting the message schedule inside the same loop as the round calculations allows for
@@ -505,6 +504,25 @@ impl Engine256State {
505504

506505
let mut W = [0u32, ..64];
507506

507+
// Sha-512 and Sha-256 use basically the same calculations which are implemented
508+
// by these macros. Inlining the calculations seems to result in better generated code.
509+
macro_rules! schedule_round( ($t:expr) => (
510+
W[$t] = sigma1(W[$t - 2]) + W[$t - 7] + sigma0(W[$t - 15]) + W[$t - 16];
511+
)
512+
)
513+
514+
macro_rules! sha2_round(
515+
($A:ident, $B:ident, $C:ident, $D:ident,
516+
$E:ident, $F:ident, $G:ident, $H:ident, $K:ident, $t:expr) => (
517+
{
518+
$H += sum1($E) + ch($E, $F, $G) + $K[$t] + W[$t];
519+
$D += $H;
520+
$H += sum0($A) + maj($A, $B, $C);
521+
}
522+
)
523+
)
524+
525+
508526
read_u32v_be(W.mut_slice(0, 16), data);
509527

510528
// Putting the message schedule inside the same loop as the round calculations allows for

0 commit comments

Comments
 (0)