13#include <config-kwalletbackend.h>
20#define Q_BYTE_ORDER Q_BIG_ENDIAN
24#include <sys/bitypes.h>
34#define rol(x,y) ((x << y) | (x >> (32-y)))
40#define F1(x,y,z) ( z ^ ( x & ( y ^ z ) ) )
41#define F2(x,y,z) ( x ^ y ^ z )
42#define F3(x,y,z) ( ( x & y ) | ( z & ( x | y ) ) )
43#define F4(x,y,z) ( x ^ y ^ z )
45#define M(i) ( tm = x[i&0x0f] ^ x[(i-14)&0x0f] \
46 ^ x[(i-8)&0x0f] ^ x[(i-3)&0x0f] \
47 , (x[i&0x0f] = (tm << 1) | (tm >> 31)))
49#define R(a,b,c,d,e,f,k,m) do { e += rol(a, 5) \
89void SHA1::transform(
void *data)
98 unsigned char *_data = (
unsigned char *)data;
106#if Q_BYTE_ORDER == Q_BIG_ENDIAN
107 memcpy(x, _data, 64);
111 for (i = 0, p2 = (
unsigned char *)x;
112 i < 16; i++, p2 += 4) {
120 R(a, b, c, d, e, F1, K1, x[ 0]);
121 R(e, a, b, c, d, F1, K1, x[ 1]);
122 R(d, e, a, b, c, F1, K1, x[ 2]);
123 R(c, d, e, a, b, F1, K1, x[ 3]);
124 R(b, c, d, e, a, F1, K1, x[ 4]);
125 R(a, b, c, d, e, F1, K1, x[ 5]);
126 R(e, a, b, c, d, F1, K1, x[ 6]);
127 R(d, e, a, b, c, F1, K1, x[ 7]);
128 R(c, d, e, a, b, F1, K1, x[ 8]);
129 R(b, c, d, e, a, F1, K1, x[ 9]);
130 R(a, b, c, d, e, F1, K1, x[10]);
131 R(e, a, b, c, d, F1, K1, x[11]);
132 R(d, e, a, b, c, F1, K1, x[12]);
133 R(c, d, e, a, b, F1, K1, x[13]);
134 R(b, c, d, e, a, F1, K1, x[14]);
135 R(a, b, c, d, e, F1, K1, x[15]);
136 R(e, a, b, c, d, F1, K1, M(16));
137 R(d, e, a, b, c, F1, K1, M(17));
138 R(c, d, e, a, b, F1, K1, M(18));
139 R(b, c, d, e, a, F1, K1, M(19));
140 R(a, b, c, d, e, F2, K2, M(20));
141 R(e, a, b, c, d, F2, K2, M(21));
142 R(d, e, a, b, c, F2, K2, M(22));
143 R(c, d, e, a, b, F2, K2, M(23));
144 R(b, c, d, e, a, F2, K2, M(24));
145 R(a, b, c, d, e, F2, K2, M(25));
146 R(e, a, b, c, d, F2, K2, M(26));
147 R(d, e, a, b, c, F2, K2, M(27));
148 R(c, d, e, a, b, F2, K2, M(28));
149 R(b, c, d, e, a, F2, K2, M(29));
150 R(a, b, c, d, e, F2, K2, M(30));
151 R(e, a, b, c, d, F2, K2, M(31));
152 R(d, e, a, b, c, F2, K2, M(32));
153 R(c, d, e, a, b, F2, K2, M(33));
154 R(b, c, d, e, a, F2, K2, M(34));
155 R(a, b, c, d, e, F2, K2, M(35));
156 R(e, a, b, c, d, F2, K2, M(36));
157 R(d, e, a, b, c, F2, K2, M(37));
158 R(c, d, e, a, b, F2, K2, M(38));
159 R(b, c, d, e, a, F2, K2, M(39));
160 R(a, b, c, d, e, F3, K3, M(40));
161 R(e, a, b, c, d, F3, K3, M(41));
162 R(d, e, a, b, c, F3, K3, M(42));
163 R(c, d, e, a, b, F3, K3, M(43));
164 R(b, c, d, e, a, F3, K3, M(44));
165 R(a, b, c, d, e, F3, K3, M(45));
166 R(e, a, b, c, d, F3, K3, M(46));
167 R(d, e, a, b, c, F3, K3, M(47));
168 R(c, d, e, a, b, F3, K3, M(48));
169 R(b, c, d, e, a, F3, K3, M(49));
170 R(a, b, c, d, e, F3, K3, M(50));
171 R(e, a, b, c, d, F3, K3, M(51));
172 R(d, e, a, b, c, F3, K3, M(52));
173 R(c, d, e, a, b, F3, K3, M(53));
174 R(b, c, d, e, a, F3, K3, M(54));
175 R(a, b, c, d, e, F3, K3, M(55));
176 R(e, a, b, c, d, F3, K3, M(56));
177 R(d, e, a, b, c, F3, K3, M(57));
178 R(c, d, e, a, b, F3, K3, M(58));
179 R(b, c, d, e, a, F3, K3, M(59));
180 R(a, b, c, d, e, F4, K4, M(60));
181 R(e, a, b, c, d, F4, K4, M(61));
182 R(d, e, a, b, c, F4, K4, M(62));
183 R(c, d, e, a, b, F4, K4, M(63));
184 R(b, c, d, e, a, F4, K4, M(64));
185 R(a, b, c, d, e, F4, K4, M(65));
186 R(e, a, b, c, d, F4, K4, M(66));
187 R(d, e, a, b, c, F4, K4, M(67));
188 R(c, d, e, a, b, F4, K4, M(68));
189 R(b, c, d, e, a, F4, K4, M(69));
190 R(a, b, c, d, e, F4, K4, M(70));
191 R(e, a, b, c, d, F4, K4, M(71));
192 R(d, e, a, b, c, F4, K4, M(72));
193 R(c, d, e, a, b, F4, K4, M(73));
194 R(b, c, d, e, a, F4, K4, M(74));
195 R(a, b, c, d, e, F4, K4, M(75));
196 R(e, a, b, c, d, F4, K4, M(76));
197 R(d, e, a, b, c, F4, K4, M(77));
198 R(c, d, e, a, b, F4, K4, M(78));
199 R(b, c, d, e, a, F4, K4, M(79));
209bool SHA1::readyToGo()
const
214int SHA1::process(
const void *block,
int len)
220 unsigned char *_block = (
unsigned char *)block;
235 for (; len && _count < 64; --len, ++cnt) {
236 _buf[_count++] = *_block++;
253 for (; len && _count < 64; --len, ++cnt) {
254 _buf[_count++] = *_block++;
260const unsigned char *SHA1::hash()
268 return (
unsigned char *)_buf;
276 if ((lsb = t << 6) < t) {
283 if ((lsb = t + _count) < t) {
289 if ((lsb = t << 3) < t) {
295 _buf[_count++] = 0x80;
298 while (_count < 56) {
302 while (_count < 64) {
309 _buf[56] = msb >> 24;
310 _buf[57] = msb >> 16;
313 _buf[60] = lsb >> 24;
314 _buf[61] = lsb >> 16;
322#if Q_BYTE_ORDER == Q_BIG_ENDIAN
323#define X(a) do { *(uint32_t *)p = _h##a; p += 4; } while (0)
325#define X(a) do { *p++ = _h##a >> 24; *p++ = _h##a >> 16; \
326 *p++ = _h##a >> 8; *p++ = _h##a; } while (0)
340 return (
unsigned char *)_buf;