@@ -14,28 +14,8 @@ use cryptoutil::{write_u64_be, write_u32_be, read_u64v_be, read_u32v_be, add_byt
14
14
add_bytes_to_bits_tuple, FixedBuffer , FixedBuffer128 , FixedBuffer64 , StandardPadding } ;
15
15
use digest:: Digest ;
16
16
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
39
19
struct Engine512State {
40
20
H0 : u64 ,
41
21
H1 : u64 ,
@@ -108,6 +88,25 @@ impl Engine512State {
108
88
109
89
let mut W = [ 0u64 , ..80 ] ;
110
90
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
+
111
110
read_u64v_be( W . mut_slice( 0 , 16 ) , data) ;
112
111
113
112
// Putting the message schedule inside the same loop as the round calculations allows for
@@ -505,6 +504,25 @@ impl Engine256State {
505
504
506
505
let mut W = [ 0u32 , ..64 ] ;
507
506
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
+
508
526
read_u32v_be( W . mut_slice( 0 , 16 ) , data) ;
509
527
510
528
// Putting the message schedule inside the same loop as the round calculations allows for
0 commit comments