@@ -31,6 +31,11 @@ state type sha1 = state obj {
31
31
const uint digest_buf_len = 5 ;
32
32
const uint msg_block_len = 64 ;
33
33
34
+ const u32 k0 = 0x5A827999u32 ;
35
+ const u32 k1 = 0x6ED9EBA1u32 ;
36
+ const u32 k2 = 0x8F1BBCDCu32 ;
37
+ const u32 k3 = 0xCA62C1D6u32 ;
38
+
34
39
// Builds a sha1 object
35
40
fn mk_sha1( ) -> sha1 {
36
41
@@ -69,22 +74,18 @@ fn mk_sha1() -> sha1 {
69
74
// FIXME: Make precondition
70
75
assert ( Vec . len ( st. h ) == digest_buf_len) ;
71
76
72
- // Constants
73
- auto k = vec ( 0x5A827999u32 ,
74
- 0x6ED9EBA1u32 ,
75
- 0x8F1BBCDCu32 ,
76
- 0xCA62C1D6u32 ) ;
77
-
78
77
let int t; // Loop counter
79
78
let vec[ mutable u32] w = Vec . init_elt_mut [ u32] ( 0u32 , 80 u) ;
80
79
81
80
// Initialize the first 16 words of the vector w
82
81
t = 0 ;
83
82
while ( t < 16 ) {
84
- w. ( t) = ( st. msg_block . ( t * 4 ) as u32 ) << 24u32 ;
85
- w. ( t) = w. ( t) | ( ( st. msg_block . ( t * 4 + 1 ) as u32 ) << 16u32 ) ;
86
- w. ( t) = w. ( t) | ( ( st. msg_block . ( t * 4 + 2 ) as u32 ) << 8u32 ) ;
87
- w. ( t) = w. ( t) | ( st. msg_block . ( t * 4 + 3 ) as u32 ) ;
83
+ auto tmp;
84
+ tmp = ( st. msg_block . ( t * 4 ) as u32 ) << 24u32 ;
85
+ tmp = tmp | ( ( st. msg_block . ( t * 4 + 1 ) as u32 ) << 16u32 ) ;
86
+ tmp = tmp | ( ( st. msg_block . ( t * 4 + 2 ) as u32 ) << 8u32 ) ;
87
+ tmp = tmp | ( st. msg_block . ( t * 4 + 3 ) as u32 ) ;
88
+ w. ( t) = tmp;
88
89
t += 1 ;
89
90
}
90
91
@@ -106,7 +107,7 @@ fn mk_sha1() -> sha1 {
106
107
t = 0 ;
107
108
while ( t < 20 ) {
108
109
temp = circular_shift ( 5u32 , a)
109
- + ( ( b & c) | ( ( ~b) & d) ) + e + w. ( t) + k . ( 0 ) ;
110
+ + ( ( b & c) | ( ( ~b) & d) ) + e + w. ( t) + k0 ;
110
111
e = d;
111
112
d = c;
112
113
c = circular_shift ( 30u32 , b) ;
@@ -117,7 +118,7 @@ fn mk_sha1() -> sha1 {
117
118
118
119
while ( t < 40 ) {
119
120
temp = circular_shift ( 5u32 , a)
120
- + ( b ^ c ^ d) + e + w. ( t) + k . ( 1 ) ;
121
+ + ( b ^ c ^ d) + e + w. ( t) + k1 ;
121
122
e = d;
122
123
d = c;
123
124
c = circular_shift ( 30u32 , b) ;
@@ -128,7 +129,7 @@ fn mk_sha1() -> sha1 {
128
129
129
130
while ( t < 60 ) {
130
131
temp = circular_shift ( 5u32 , a)
131
- + ( ( b & c) | ( b & d) | ( c & d) ) + e + w. ( t) + k . ( 2 ) ;
132
+ + ( ( b & c) | ( b & d) | ( c & d) ) + e + w. ( t) + k2 ;
132
133
e = d;
133
134
d = c;
134
135
c = circular_shift ( 30u32 , b) ;
@@ -139,7 +140,7 @@ fn mk_sha1() -> sha1 {
139
140
140
141
while ( t < 80 ) {
141
142
temp = circular_shift ( 5u32 , a)
142
- + ( b ^ c ^ d) + e + w. ( t) + k . ( 3 ) ;
143
+ + ( b ^ c ^ d) + e + w. ( t) + k3 ;
143
144
e = d;
144
145
d = c;
145
146
c = circular_shift ( 30u32 , b) ;
0 commit comments