Skip to content

Commit fde8306

Browse files
committed
Unifying spacing.
Signed-off-by: Tyler Anthony Romeo <[email protected]>
1 parent f4ec763 commit fde8306

File tree

9 files changed

+1345
-1345
lines changed

9 files changed

+1345
-1345
lines changed

crypto/crypto_scrypt-nosse.c

100755100644
Lines changed: 154 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@ static void smix(uint8_t *, size_t, uint64_t, uint8_t *, uint8_t *);
5252
static void
5353
blkcpy(uint8_t * dest, uint8_t * src, size_t len)
5454
{
55-
size_t i;
55+
size_t i;
5656

57-
for (i = 0; i < len; i++)
58-
dest[i] = src[i];
57+
for (i = 0; i < len; i++)
58+
dest[i] = src[i];
5959
}
6060

6161
static void
6262
blkxor(uint8_t * dest, uint8_t * src, size_t len)
6363
{
64-
size_t i;
64+
size_t i;
6565

66-
for (i = 0; i < len; i++)
67-
dest[i] ^= src[i];
66+
for (i = 0; i < len; i++)
67+
dest[i] ^= src[i];
6868
}
6969

7070
/**
@@ -74,54 +74,54 @@ blkxor(uint8_t * dest, uint8_t * src, size_t len)
7474
static void
7575
salsa20_8(uint8_t B[64])
7676
{
77-
uint32_t B32[16];
78-
uint32_t x[16];
79-
size_t i;
80-
81-
/* Convert little-endian values in. */
82-
for (i = 0; i < 16; i++)
83-
B32[i] = le32dec(&B[i * 4]);
84-
85-
/* Compute x = doubleround^4(B32). */
86-
for (i = 0; i < 16; i++)
87-
x[i] = B32[i];
88-
for (i = 0; i < 8; i += 2) {
77+
uint32_t B32[16];
78+
uint32_t x[16];
79+
size_t i;
80+
81+
/* Convert little-endian values in. */
82+
for (i = 0; i < 16; i++)
83+
B32[i] = le32dec(&B[i * 4]);
84+
85+
/* Compute x = doubleround^4(B32). */
86+
for (i = 0; i < 16; i++)
87+
x[i] = B32[i];
88+
for (i = 0; i < 8; i += 2) {
8989
#define R(a,b) (((a) << (b)) | ((a) >> (32 - (b))))
90-
/* Operate on columns. */
91-
x[ 4] ^= R(x[ 0]+x[12], 7); x[ 8] ^= R(x[ 4]+x[ 0], 9);
92-
x[12] ^= R(x[ 8]+x[ 4],13); x[ 0] ^= R(x[12]+x[ 8],18);
90+
/* Operate on columns. */
91+
x[ 4] ^= R(x[ 0]+x[12], 7); x[ 8] ^= R(x[ 4]+x[ 0], 9);
92+
x[12] ^= R(x[ 8]+x[ 4],13); x[ 0] ^= R(x[12]+x[ 8],18);
9393

94-
x[ 9] ^= R(x[ 5]+x[ 1], 7); x[13] ^= R(x[ 9]+x[ 5], 9);
95-
x[ 1] ^= R(x[13]+x[ 9],13); x[ 5] ^= R(x[ 1]+x[13],18);
94+
x[ 9] ^= R(x[ 5]+x[ 1], 7); x[13] ^= R(x[ 9]+x[ 5], 9);
95+
x[ 1] ^= R(x[13]+x[ 9],13); x[ 5] ^= R(x[ 1]+x[13],18);
9696

97-
x[14] ^= R(x[10]+x[ 6], 7); x[ 2] ^= R(x[14]+x[10], 9);
98-
x[ 6] ^= R(x[ 2]+x[14],13); x[10] ^= R(x[ 6]+x[ 2],18);
97+
x[14] ^= R(x[10]+x[ 6], 7); x[ 2] ^= R(x[14]+x[10], 9);
98+
x[ 6] ^= R(x[ 2]+x[14],13); x[10] ^= R(x[ 6]+x[ 2],18);
9999

100-
x[ 3] ^= R(x[15]+x[11], 7); x[ 7] ^= R(x[ 3]+x[15], 9);
101-
x[11] ^= R(x[ 7]+x[ 3],13); x[15] ^= R(x[11]+x[ 7],18);
100+
x[ 3] ^= R(x[15]+x[11], 7); x[ 7] ^= R(x[ 3]+x[15], 9);
101+
x[11] ^= R(x[ 7]+x[ 3],13); x[15] ^= R(x[11]+x[ 7],18);
102102

103-
/* Operate on rows. */
104-
x[ 1] ^= R(x[ 0]+x[ 3], 7); x[ 2] ^= R(x[ 1]+x[ 0], 9);
105-
x[ 3] ^= R(x[ 2]+x[ 1],13); x[ 0] ^= R(x[ 3]+x[ 2],18);
103+
/* Operate on rows. */
104+
x[ 1] ^= R(x[ 0]+x[ 3], 7); x[ 2] ^= R(x[ 1]+x[ 0], 9);
105+
x[ 3] ^= R(x[ 2]+x[ 1],13); x[ 0] ^= R(x[ 3]+x[ 2],18);
106106

107-
x[ 6] ^= R(x[ 5]+x[ 4], 7); x[ 7] ^= R(x[ 6]+x[ 5], 9);
108-
x[ 4] ^= R(x[ 7]+x[ 6],13); x[ 5] ^= R(x[ 4]+x[ 7],18);
107+
x[ 6] ^= R(x[ 5]+x[ 4], 7); x[ 7] ^= R(x[ 6]+x[ 5], 9);
108+
x[ 4] ^= R(x[ 7]+x[ 6],13); x[ 5] ^= R(x[ 4]+x[ 7],18);
109109

110-
x[11] ^= R(x[10]+x[ 9], 7); x[ 8] ^= R(x[11]+x[10], 9);
111-
x[ 9] ^= R(x[ 8]+x[11],13); x[10] ^= R(x[ 9]+x[ 8],18);
110+
x[11] ^= R(x[10]+x[ 9], 7); x[ 8] ^= R(x[11]+x[10], 9);
111+
x[ 9] ^= R(x[ 8]+x[11],13); x[10] ^= R(x[ 9]+x[ 8],18);
112112

113-
x[12] ^= R(x[15]+x[14], 7); x[13] ^= R(x[12]+x[15], 9);
114-
x[14] ^= R(x[13]+x[12],13); x[15] ^= R(x[14]+x[13],18);
113+
x[12] ^= R(x[15]+x[14], 7); x[13] ^= R(x[12]+x[15], 9);
114+
x[14] ^= R(x[13]+x[12],13); x[15] ^= R(x[14]+x[13],18);
115115
#undef R
116-
}
116+
}
117117

118-
/* Compute B32 = B32 + x. */
119-
for (i = 0; i < 16; i++)
120-
B32[i] += x[i];
118+
/* Compute B32 = B32 + x. */
119+
for (i = 0; i < 16; i++)
120+
B32[i] += x[i];
121121

122-
/* Convert little-endian values out. */
123-
for (i = 0; i < 16; i++)
124-
le32enc(&B[4 * i], B32[i]);
122+
/* Convert little-endian values out. */
123+
for (i = 0; i < 16; i++)
124+
le32enc(&B[4 * i], B32[i]);
125125
}
126126

127127
/**
@@ -132,27 +132,27 @@ salsa20_8(uint8_t B[64])
132132
static void
133133
blockmix_salsa8(uint8_t * B, uint8_t * Y, size_t r)
134134
{
135-
uint8_t X[64];
136-
size_t i;
137-
138-
/* 1: X <-- B_{2r - 1} */
139-
blkcpy(X, &B[(2 * r - 1) * 64], 64);
140-
141-
/* 2: for i = 0 to 2r - 1 do */
142-
for (i = 0; i < 2 * r; i++) {
143-
/* 3: X <-- H(X \xor B_i) */
144-
blkxor(X, &B[i * 64], 64);
145-
salsa20_8(X);
146-
147-
/* 4: Y_i <-- X */
148-
blkcpy(&Y[i * 64], X, 64);
149-
}
150-
151-
/* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */
152-
for (i = 0; i < r; i++)
153-
blkcpy(&B[i * 64], &Y[(i * 2) * 64], 64);
154-
for (i = 0; i < r; i++)
155-
blkcpy(&B[(i + r) * 64], &Y[(i * 2 + 1) * 64], 64);
135+
uint8_t X[64];
136+
size_t i;
137+
138+
/* 1: X <-- B_{2r - 1} */
139+
blkcpy(X, &B[(2 * r - 1) * 64], 64);
140+
141+
/* 2: for i = 0 to 2r - 1 do */
142+
for (i = 0; i < 2 * r; i++) {
143+
/* 3: X <-- H(X \xor B_i) */
144+
blkxor(X, &B[i * 64], 64);
145+
salsa20_8(X);
146+
147+
/* 4: Y_i <-- X */
148+
blkcpy(&Y[i * 64], X, 64);
149+
}
150+
151+
/* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */
152+
for (i = 0; i < r; i++)
153+
blkcpy(&B[i * 64], &Y[(i * 2) * 64], 64);
154+
for (i = 0; i < r; i++)
155+
blkcpy(&B[(i + r) * 64], &Y[(i * 2 + 1) * 64], 64);
156156
}
157157

158158
/**
@@ -162,9 +162,9 @@ blockmix_salsa8(uint8_t * B, uint8_t * Y, size_t r)
162162
static uint64_t
163163
integerify(uint8_t * B, size_t r)
164164
{
165-
uint8_t * X = &B[(2 * r - 1) * 64];
165+
uint8_t * X = &B[(2 * r - 1) * 64];
166166

167-
return (le64dec(X));
167+
return (le64dec(X));
168168
}
169169

170170
/**
@@ -176,35 +176,35 @@ integerify(uint8_t * B, size_t r)
176176
static void
177177
smix(uint8_t * B, size_t r, uint64_t N, uint8_t * V, uint8_t * XY)
178178
{
179-
uint8_t * X = XY;
180-
uint8_t * Y = &XY[128 * r];
181-
uint64_t i;
182-
uint64_t j;
183-
184-
/* 1: X <-- B */
185-
blkcpy(X, B, 128 * r);
186-
187-
/* 2: for i = 0 to N - 1 do */
188-
for (i = 0; i < N; i++) {
189-
/* 3: V_i <-- X */
190-
blkcpy(&V[i * (128 * r)], X, 128 * r);
191-
192-
/* 4: X <-- H(X) */
193-
blockmix_salsa8(X, Y, r);
194-
}
195-
196-
/* 6: for i = 0 to N - 1 do */
197-
for (i = 0; i < N; i++) {
198-
/* 7: j <-- Integerify(X) mod N */
199-
j = integerify(X, r) & (N - 1);
200-
201-
/* 8: X <-- H(X \xor V_j) */
202-
blkxor(X, &V[j * (128 * r)], 128 * r);
203-
blockmix_salsa8(X, Y, r);
204-
}
205-
206-
/* 10: B' <-- X */
207-
blkcpy(B, X, 128 * r);
179+
uint8_t * X = XY;
180+
uint8_t * Y = &XY[128 * r];
181+
uint64_t i;
182+
uint64_t j;
183+
184+
/* 1: X <-- B */
185+
blkcpy(X, B, 128 * r);
186+
187+
/* 2: for i = 0 to N - 1 do */
188+
for (i = 0; i < N; i++) {
189+
/* 3: V_i <-- X */
190+
blkcpy(&V[i * (128 * r)], X, 128 * r);
191+
192+
/* 4: X <-- H(X) */
193+
blockmix_salsa8(X, Y, r);
194+
}
195+
196+
/* 6: for i = 0 to N - 1 do */
197+
for (i = 0; i < N; i++) {
198+
/* 7: j <-- Integerify(X) mod N */
199+
j = integerify(X, r) & (N - 1);
200+
201+
/* 8: X <-- H(X \xor V_j) */
202+
blkxor(X, &V[j * (128 * r)], 128 * r);
203+
blockmix_salsa8(X, Y, r);
204+
}
205+
206+
/* 10: B' <-- X */
207+
blkcpy(B, X, 128 * r);
208208
}
209209

210210
/**
@@ -221,72 +221,72 @@ crypto_scrypt(const uint8_t * passwd, size_t passwdlen,
221221
const uint8_t * salt, size_t saltlen, uint64_t N, uint32_t r, uint32_t p,
222222
uint8_t * buf, size_t buflen)
223223
{
224-
uint8_t * B;
225-
uint8_t * V;
226-
uint8_t * XY;
227-
uint32_t i;
224+
uint8_t * B;
225+
uint8_t * V;
226+
uint8_t * XY;
227+
uint32_t i;
228228

229-
/* Sanity-check parameters. */
229+
/* Sanity-check parameters. */
230230
#if SIZE_MAX > UINT32_MAX
231-
if (buflen > (((uint64_t)(1) << 32) - 1) * 32) {
232-
php_error(1, "Invalid Parameters: $keyLength too big");
233-
errno = EFBIG;
234-
goto err0;
235-
}
231+
if (buflen > (((uint64_t)(1) << 32) - 1) * 32) {
232+
php_error(1, "Invalid Parameters: $keyLength too big");
233+
errno = EFBIG;
234+
goto err0;
235+
}
236236
#endif
237-
if ((uint64_t)(r) * (uint64_t)(p) >= (1 << 30)) {
238-
errno = EFBIG;
239-
php_error(1, "Invalid Parameters; $r * $p is >= 2^30");
240-
goto err0;
241-
}
242-
if (((N & (N - 1)) != 0) || (N == 0)) {
243-
errno = EINVAL;
244-
php_error(1, "Invalid Parameters; $N is not a power of two greater than 1");
245-
goto err0;
246-
}
247-
if ((r > SIZE_MAX / 128 / p) ||
237+
if ((uint64_t)(r) * (uint64_t)(p) >= (1 << 30)) {
238+
errno = EFBIG;
239+
php_error(1, "Invalid Parameters; $r * $p is >= 2^30");
240+
goto err0;
241+
}
242+
if (((N & (N - 1)) != 0) || (N == 0)) {
243+
errno = EINVAL;
244+
php_error(1, "Invalid Parameters; $N is not a power of two greater than 1");
245+
goto err0;
246+
}
247+
if ((r > SIZE_MAX / 128 / p) ||
248248
#if SIZE_MAX / 256 <= UINT32_MAX
249-
(r > SIZE_MAX / 256) ||
249+
(r > SIZE_MAX / 256) ||
250250
#endif
251-
(N > SIZE_MAX / 128 / r)) {
252-
errno = ENOMEM;
253-
php_error(1, "Invalid Parameters");
254-
goto err0;
255-
}
256-
257-
/* Allocate memory. */
258-
if ((B = emalloc(128 * r * p)) == NULL)
259-
goto err0;
260-
if ((XY = emalloc(256 * r)) == NULL)
261-
goto err1;
262-
if ((V = emalloc(128 * r * N)) == NULL)
263-
goto err2;
264-
265-
/* 1: (B_0 ... B_{p-1}) <-- PBKDF2(P, S, 1, p * MFLen) */
266-
PBKDF2_SHA256_SCRYPT(passwd, passwdlen, salt, saltlen, 1, B, p * 128 * r);
267-
268-
/* 2: for i = 0 to p - 1 do */
269-
for (i = 0; i < p; i++) {
270-
/* 3: B_i <-- MF(B_i, N) */
271-
smix(&B[i * 128 * r], r, N, V, XY);
272-
}
273-
274-
/* 5: DK <-- PBKDF2(P, B, 1, dkLen) */
275-
PBKDF2_SHA256_SCRYPT(passwd, passwdlen, B, p * 128 * r, 1, buf, buflen);
276-
277-
/* Free memory. */
278-
efree(V);
279-
efree(XY);
280-
efree(B);
281-
282-
/* Success! */
283-
return (0);
251+
(N > SIZE_MAX / 128 / r)) {
252+
errno = ENOMEM;
253+
php_error(1, "Invalid Parameters");
254+
goto err0;
255+
}
256+
257+
/* Allocate memory. */
258+
if ((B = emalloc(128 * r * p)) == NULL)
259+
goto err0;
260+
if ((XY = emalloc(256 * r)) == NULL)
261+
goto err1;
262+
if ((V = emalloc(128 * r * N)) == NULL)
263+
goto err2;
264+
265+
/* 1: (B_0 ... B_{p-1}) <-- PBKDF2(P, S, 1, p * MFLen) */
266+
PBKDF2_SHA256_SCRYPT(passwd, passwdlen, salt, saltlen, 1, B, p * 128 * r);
267+
268+
/* 2: for i = 0 to p - 1 do */
269+
for (i = 0; i < p; i++) {
270+
/* 3: B_i <-- MF(B_i, N) */
271+
smix(&B[i * 128 * r], r, N, V, XY);
272+
}
273+
274+
/* 5: DK <-- PBKDF2(P, B, 1, dkLen) */
275+
PBKDF2_SHA256_SCRYPT(passwd, passwdlen, B, p * 128 * r, 1, buf, buflen);
276+
277+
/* Free memory. */
278+
efree(V);
279+
efree(XY);
280+
efree(B);
281+
282+
/* Success! */
283+
return (0);
284284

285285
err2:
286-
efree(XY);
286+
efree(XY);
287287
err1:
288-
efree(B);
288+
efree(B);
289289
err0:
290-
/* Failure! */
291-
return (-1);
290+
/* Failure! */
291+
return (-1);
292292
}

0 commit comments

Comments
 (0)