Skip to content

Commit b002007

Browse files
committed
---
yaml --- r: 2461 b: refs/heads/master c: 7e7d134 h: refs/heads/master i: 2459: 2152dd2 v: v3
1 parent 5ec89e0 commit b002007

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: e35984b6c67f2adf1c12d84c48fdf4f01be020e5
2+
refs/heads/master: 7e7d134e3c2f7b99dd9c8cd02d7288a3cd7571c3

trunk/src/lib/SHA1.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ state type sha1 = state obj {
3131
const uint digest_buf_len = 5;
3232
const uint msg_block_len = 64;
3333

34+
const u32 k0 = 0x5A827999u32;
35+
const u32 k1 = 0x6ED9EBA1u32;
36+
const u32 k2 = 0x8F1BBCDCu32;
37+
const u32 k3 = 0xCA62C1D6u32;
38+
3439
// Builds a sha1 object
3540
fn mk_sha1() -> sha1 {
3641

@@ -69,22 +74,18 @@ fn mk_sha1() -> sha1 {
6974
// FIXME: Make precondition
7075
assert (Vec.len(st.h) == digest_buf_len);
7176

72-
// Constants
73-
auto k = vec(0x5A827999u32,
74-
0x6ED9EBA1u32,
75-
0x8F1BBCDCu32,
76-
0xCA62C1D6u32);
77-
7877
let int t; // Loop counter
7978
let vec[mutable u32] w = Vec.init_elt_mut[u32](0u32, 80u);
8079

8180
// Initialize the first 16 words of the vector w
8281
t = 0;
8382
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;
8889
t += 1;
8990
}
9091

@@ -106,7 +107,7 @@ fn mk_sha1() -> sha1 {
106107
t = 0;
107108
while (t < 20) {
108109
temp = circular_shift(5u32, a)
109-
+ ((b & c) | ((~b) & d)) + e + w.(t) + k.(0);
110+
+ ((b & c) | ((~b) & d)) + e + w.(t) + k0;
110111
e = d;
111112
d = c;
112113
c = circular_shift(30u32, b);
@@ -117,7 +118,7 @@ fn mk_sha1() -> sha1 {
117118

118119
while (t < 40) {
119120
temp = circular_shift(5u32, a)
120-
+ (b ^ c ^ d) + e + w.(t) + k.(1);
121+
+ (b ^ c ^ d) + e + w.(t) + k1;
121122
e = d;
122123
d = c;
123124
c = circular_shift(30u32, b);
@@ -128,7 +129,7 @@ fn mk_sha1() -> sha1 {
128129

129130
while (t < 60) {
130131
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;
132133
e = d;
133134
d = c;
134135
c = circular_shift(30u32, b);
@@ -139,7 +140,7 @@ fn mk_sha1() -> sha1 {
139140

140141
while (t < 80) {
141142
temp = circular_shift(5u32, a)
142-
+ (b ^ c ^ d) + e + w.(t) + k.(3);
143+
+ (b ^ c ^ d) + e + w.(t) + k3;
143144
e = d;
144145
d = c;
145146
c = circular_shift(30u32, b);

0 commit comments

Comments
 (0)