Mercurial > projects > dcrypt
comparison dcrypt/crypto/hashes/SHA256.d @ 23:4589f8c5eb3c
Replaced dcrypt.crypto.Util with dcrypt.misc.Bitwise and dcrypt.misc.ByteConverter. Altered all dependent files to reflect changes.
author | Thomas Dixon <reikon@reikon.us> |
---|---|
date | Sat, 14 Feb 2009 19:58:20 -0500 |
parents | 5cb17e09d685 |
children | 176c933827a8 |
comparison
equal
deleted
inserted
replaced
22:74303a717032 | 23:4589f8c5eb3c |
---|---|
55 } | 55 } |
56 | 56 |
57 void transform(ubyte[] input) { | 57 void transform(ubyte[] input) { |
58 uint[] w = new uint[64]; | 58 uint[] w = new uint[64]; |
59 | 59 |
60 for (int i = 0, j = 0; i < 16; i++,j+=4) | 60 for (int i = 0, j = 0; i < 16; i++,j+=int.sizeof) |
61 w[i] = Util.ubytesToUintBig(input, j); | 61 w[i] = ByteConverter.BigEndian.to!(uint)(input[j..j+int.sizeof]); |
62 | 62 |
63 for (int i = 16; i < 64; i++) | 63 for (int i = 16; i < 64; i++) |
64 w[i] = theta1(w[i-2]) + w[i-7] + theta0(w[i-15]) + w[i-16]; | 64 w[i] = theta1(w[i-2]) + w[i-7] + theta0(w[i-15]) + w[i-16]; |
65 | 65 |
66 uint a = h0, | 66 uint a = h0, |
102 private uint maj(uint x, uint y, uint z) { | 102 private uint maj(uint x, uint y, uint z) { |
103 return (x&y)^(x&z)^(y&z); | 103 return (x&y)^(x&z)^(y&z); |
104 } | 104 } |
105 | 105 |
106 private uint sum0(uint x) { | 106 private uint sum0(uint x) { |
107 return Util.rotateRight(x,2)^Util.rotateRight(x,13)^Util.rotateRight(x,22); | 107 return Bitwise.rotateRight(x,2)^Bitwise.rotateRight(x,13)^Bitwise.rotateRight(x,22); |
108 } | 108 } |
109 | 109 |
110 private uint sum1(uint x) { | 110 private uint sum1(uint x) { |
111 return Util.rotateRight(x,6)^Util.rotateRight(x,11)^Util.rotateRight(x,25); | 111 return Bitwise.rotateRight(x,6)^Bitwise.rotateRight(x,11)^Bitwise.rotateRight(x,25); |
112 } | 112 } |
113 | 113 |
114 private uint theta0(uint x) { | 114 private uint theta0(uint x) { |
115 return Util.rotateRight(x,7)^Util.rotateRight(x,18)^(x >> 3); | 115 return Bitwise.rotateRight(x,7)^Bitwise.rotateRight(x,18)^(x >> 3); |
116 } | 116 } |
117 | 117 |
118 private uint theta1(uint x) { | 118 private uint theta1(uint x) { |
119 return Util.rotateRight(x,17)^Util.rotateRight(x,19)^(x >> 10); | 119 return Bitwise.rotateRight(x,17)^Bitwise.rotateRight(x,19)^(x >> 10); |
120 } | 120 } |
121 | 121 |
122 ubyte[] digest() { | 122 ubyte[] digest() { |
123 padMessage(MODE_SHA); | 123 padMessage(MODE_SHA); |
124 ubyte[] result = new ubyte[digestSize]; | 124 ubyte[] result = new ubyte[digestSize]; |
125 | 125 |
126 Util.uintToUbytesBig(h0, result, 0); | 126 result[0..4] = ByteConverter.BigEndian.from!(uint)(h0); |
127 Util.uintToUbytesBig(h1, result, 4); | 127 result[4..8] = ByteConverter.BigEndian.from!(uint)(h1); |
128 Util.uintToUbytesBig(h2, result, 8); | 128 result[8..12] = ByteConverter.BigEndian.from!(uint)(h2); |
129 Util.uintToUbytesBig(h3, result, 12); | 129 result[12..16] = ByteConverter.BigEndian.from!(uint)(h3); |
130 Util.uintToUbytesBig(h4, result, 16); | 130 result[16..20] = ByteConverter.BigEndian.from!(uint)(h4); |
131 Util.uintToUbytesBig(h5, result, 20); | 131 result[20..24] = ByteConverter.BigEndian.from!(uint)(h5); |
132 Util.uintToUbytesBig(h6, result, 24); | 132 result[24..28] = ByteConverter.BigEndian.from!(uint)(h6); |
133 Util.uintToUbytesBig(h7, result, 28); | 133 result[28..32] = ByteConverter.BigEndian.from!(uint)(h7); |
134 | 134 |
135 reset(); | 135 reset(); |
136 return result; | 136 return result; |
137 } | 137 } |
138 | 138 |