Skip to content

Commit cc1fc9b

Browse files
committed
Better local variable names
1 parent f16cabc commit cc1fc9b

2 files changed

Lines changed: 52 additions & 52 deletions

File tree

src/main/java/org/apache/commons/codec/digest/Md5Crypt.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -299,34 +299,34 @@ public static String md5Crypt(final byte[] keyBytes, final String salt, final St
299299
}
300300
final byte[] saltBytes = saltString.getBytes(StandardCharsets.UTF_8);
301301

302-
final MessageDigest ctx = DigestUtils.getMd5Digest();
302+
final MessageDigest messageDigestMd5 = DigestUtils.getMd5Digest();
303303

304304
/*
305305
* The password first, since that is what is most unknown
306306
*/
307-
ctx.update(keyBytes);
307+
messageDigestMd5.update(keyBytes);
308308

309309
/*
310310
* Then our magic string
311311
*/
312-
ctx.update(prefix.getBytes(StandardCharsets.UTF_8));
312+
messageDigestMd5.update(prefix.getBytes(StandardCharsets.UTF_8));
313313

314314
/*
315315
* Then the raw salt
316316
*/
317-
ctx.update(saltBytes);
317+
messageDigestMd5.update(saltBytes);
318318

319319
/*
320320
* Then just as many characters of the MD5(pw,salt,pw)
321321
*/
322-
MessageDigest ctx1 = DigestUtils.getMd5Digest();
323-
ctx1.update(keyBytes);
324-
ctx1.update(saltBytes);
325-
ctx1.update(keyBytes);
326-
byte[] finalb = ctx1.digest();
322+
MessageDigest altMessageDigestMd5 = DigestUtils.getMd5Digest();
323+
altMessageDigestMd5.update(keyBytes);
324+
altMessageDigestMd5.update(saltBytes);
325+
altMessageDigestMd5.update(keyBytes);
326+
byte[] finalb = altMessageDigestMd5.digest();
327327
int ii = keyLen;
328328
while (ii > 0) {
329-
ctx.update(finalb, 0, Math.min(ii, 16));
329+
messageDigestMd5.update(finalb, 0, Math.min(ii, 16));
330330
ii -= 16;
331331
}
332332

@@ -342,9 +342,9 @@ public static String md5Crypt(final byte[] keyBytes, final String salt, final St
342342
final int j = 0;
343343
while (ii > 0) {
344344
if ((ii & 1) == 1) {
345-
ctx.update(finalb[j]);
345+
messageDigestMd5.update(finalb[j]);
346346
} else {
347-
ctx.update(keyBytes[j]);
347+
messageDigestMd5.update(keyBytes[j]);
348348
}
349349
ii >>= 1;
350350
}
@@ -353,34 +353,34 @@ public static String md5Crypt(final byte[] keyBytes, final String salt, final St
353353
* Now make the output string
354354
*/
355355
final StringBuilder passwd = new StringBuilder(prefix + saltString + "$");
356-
finalb = ctx.digest();
356+
finalb = messageDigestMd5.digest();
357357

358358
/*
359359
* and now, just to make sure things don't run too fast On a 60 Mhz Pentium this takes 34 milliseconds, so you
360360
* would need 30 seconds to build a 1000 entry dictionary...
361361
*/
362362
for (int i = 0; i < ROUNDS; i++) {
363-
ctx1 = DigestUtils.getMd5Digest();
363+
altMessageDigestMd5 = DigestUtils.getMd5Digest();
364364
if ((i & 1) != 0) {
365-
ctx1.update(keyBytes);
365+
altMessageDigestMd5.update(keyBytes);
366366
} else {
367-
ctx1.update(finalb, 0, BLOCKSIZE);
367+
altMessageDigestMd5.update(finalb, 0, BLOCKSIZE);
368368
}
369369

370370
if (i % 3 != 0) {
371-
ctx1.update(saltBytes);
371+
altMessageDigestMd5.update(saltBytes);
372372
}
373373

374374
if (i % 7 != 0) {
375-
ctx1.update(keyBytes);
375+
altMessageDigestMd5.update(keyBytes);
376376
}
377377

378378
if ((i & 1) != 0) {
379-
ctx1.update(finalb, 0, BLOCKSIZE);
379+
altMessageDigestMd5.update(finalb, 0, BLOCKSIZE);
380380
} else {
381-
ctx1.update(keyBytes);
381+
altMessageDigestMd5.update(keyBytes);
382382
}
383-
finalb = ctx1.digest();
383+
finalb = altMessageDigestMd5.digest();
384384
}
385385

386386
// The following was nearly identical to the Sha2Crypt code.
@@ -397,8 +397,8 @@ public static String md5Crypt(final byte[] keyBytes, final String salt, final St
397397
* Don't leave anything around in JVM they could use.
398398
*/
399399
// Is there a better way to do this with the JVM?
400-
ctx.reset();
401-
ctx1.reset();
400+
messageDigestMd5.reset();
401+
altMessageDigestMd5.reset();
402402
Arrays.fill(keyBytes, (byte) 0);
403403
Arrays.fill(saltBytes, (byte) 0);
404404
Arrays.fill(finalb, (byte) 0);

src/main/java/org/apache/commons/codec/digest/Sha2Crypt.java

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,13 @@ private static String sha2Crypt(final byte[] keyBytes, final String salt, final
177177

178178
// 1. start digest A
179179
// Prepare for the real work.
180-
MessageDigest ctx = DigestUtils.getDigest(algorithm);
180+
MessageDigest messageDigest = DigestUtils.getDigest(algorithm);
181181

182182
// 2. the password string is added to digest A
183183
/*
184184
* Add the key string.
185185
*/
186-
ctx.update(keyBytes);
186+
messageDigest.update(keyBytes);
187187

188188
// 3. the salt string is added to digest A. This is just the salt string
189189
// itself without the enclosing '$', without the magic salt_prefix $5$ and
@@ -198,38 +198,38 @@ private static String sha2Crypt(final byte[] keyBytes, final String salt, final
198198
* The last part is the salt string. This must be at most 16 characters and it ends at the first `$' character
199199
* (for compatibility with existing implementations).
200200
*/
201-
ctx.update(saltBytes);
201+
messageDigest.update(saltBytes);
202202

203203
// 4. start digest B
204204
/*
205205
* Compute alternate sha512 sum with input KEY, SALT, and KEY. The final result will be added to the first
206206
* context.
207207
*/
208-
MessageDigest altCtx = DigestUtils.getDigest(algorithm);
208+
MessageDigest altMessageDigestMd5 = DigestUtils.getDigest(algorithm);
209209

210210
// 5. add the password to digest B
211211
/*
212212
* Add key.
213213
*/
214-
altCtx.update(keyBytes);
214+
altMessageDigestMd5.update(keyBytes);
215215

216216
// 6. add the salt string to digest B
217217
/*
218218
* Add salt.
219219
*/
220-
altCtx.update(saltBytes);
220+
altMessageDigestMd5.update(saltBytes);
221221

222222
// 7. add the password again to digest B
223223
/*
224224
* Add key again.
225225
*/
226-
altCtx.update(keyBytes);
226+
altMessageDigestMd5.update(keyBytes);
227227

228228
// 8. finish digest B
229229
/*
230230
* Now get result of this (32 bytes) and add it to the other context.
231231
*/
232-
byte[] altResult = altCtx.digest();
232+
byte[] altResult = altMessageDigestMd5.digest();
233233

234234
// 9. For each block of 32 or 64 bytes in the password string (excluding
235235
// the terminating NUL in the C representation), add digest B to digest A
@@ -241,13 +241,13 @@ private static String sha2Crypt(final byte[] keyBytes, final String salt, final
241241
*/
242242
int cnt = keyBytes.length;
243243
while (cnt > blocksize) {
244-
ctx.update(altResult, 0, blocksize);
244+
messageDigest.update(altResult, 0, blocksize);
245245
cnt -= blocksize;
246246
}
247247

248248
// 10. For the remaining N bytes of the password string add the first
249249
// N bytes of digest B to digest A
250-
ctx.update(altResult, 0, cnt);
250+
messageDigest.update(altResult, 0, cnt);
251251

252252
// 11. For each bit of the binary representation of the length of the
253253
// password string up to and including the highest 1-digit, starting
@@ -266,9 +266,9 @@ private static String sha2Crypt(final byte[] keyBytes, final String salt, final
266266
cnt = keyBytes.length;
267267
while (cnt > 0) {
268268
if ((cnt & 1) != 0) {
269-
ctx.update(altResult, 0, blocksize);
269+
messageDigest.update(altResult, 0, blocksize);
270270
} else {
271-
ctx.update(keyBytes);
271+
messageDigest.update(keyBytes);
272272
}
273273
cnt >>= 1;
274274
}
@@ -277,13 +277,13 @@ private static String sha2Crypt(final byte[] keyBytes, final String salt, final
277277
/*
278278
* Create intermediate result.
279279
*/
280-
altResult = ctx.digest();
280+
altResult = messageDigest.digest();
281281

282282
// 13. start digest DP
283283
/*
284284
* Start computation of P byte sequence.
285285
*/
286-
altCtx = DigestUtils.getDigest(algorithm);
286+
altMessageDigestMd5 = DigestUtils.getDigest(algorithm);
287287

288288
// 14. for every byte in the password (excluding the terminating NUL byte
289289
// in the C representation of the string)
@@ -293,14 +293,14 @@ private static String sha2Crypt(final byte[] keyBytes, final String salt, final
293293
* For every character in the password add the entire password.
294294
*/
295295
for (int i = 1; i <= keyLen; i++) {
296-
altCtx.update(keyBytes);
296+
altMessageDigestMd5.update(keyBytes);
297297
}
298298

299299
// 15. finish digest DP
300300
/*
301301
* Finish the digest.
302302
*/
303-
byte[] tempResult = altCtx.digest();
303+
byte[] tempResult = altMessageDigestMd5.digest();
304304

305305
// 16. produce byte sequence P of the same length as the password where
306306
//
@@ -324,7 +324,7 @@ private static String sha2Crypt(final byte[] keyBytes, final String salt, final
324324
/*
325325
* Start computation of S byte sequence.
326326
*/
327-
altCtx = DigestUtils.getDigest(algorithm);
327+
altMessageDigestMd5 = DigestUtils.getDigest(algorithm);
328328

329329
// 18. repeat the following 16+A[0] times, where A[0] represents the first
330330
// byte in digest A interpreted as an 8-bit unsigned value
@@ -334,14 +334,14 @@ private static String sha2Crypt(final byte[] keyBytes, final String salt, final
334334
* For every character in the password add the entire password.
335335
*/
336336
for (int i = 1; i <= 16 + (altResult[0] & 0xff); i++) {
337-
altCtx.update(saltBytes);
337+
altMessageDigestMd5.update(saltBytes);
338338
}
339339

340340
// 19. finish digest DS
341341
/*
342342
* Finish the digest.
343343
*/
344-
tempResult = altCtx.digest();
344+
tempResult = altMessageDigestMd5.digest();
345345

346346
// 20. produce byte sequence S of the same length as the salt string where
347347
//
@@ -378,33 +378,33 @@ private static String sha2Crypt(final byte[] keyBytes, final String salt, final
378378
/*
379379
* New context.
380380
*/
381-
ctx = DigestUtils.getDigest(algorithm);
381+
messageDigest = DigestUtils.getDigest(algorithm);
382382

383383
// b) for odd round numbers add the byte sequence P to digest C
384384
// c) for even round numbers add digest A/C
385385
/*
386386
* Add key or last result.
387387
*/
388388
if ((i & 1) != 0) {
389-
ctx.update(bytes, 0, keyLen);
389+
messageDigest.update(bytes, 0, keyLen);
390390
} else {
391-
ctx.update(altResult, 0, blocksize);
391+
messageDigest.update(altResult, 0, blocksize);
392392
}
393393

394394
// d) for all round numbers not divisible by 3 add the byte sequence S
395395
/*
396396
* Add salt for numbers not divisible by 3.
397397
*/
398398
if (i % 3 != 0) {
399-
ctx.update(sBytes, 0, saltLen);
399+
messageDigest.update(sBytes, 0, saltLen);
400400
}
401401

402402
// e) for all round numbers not divisible by 7 add the byte sequence P
403403
/*
404404
* Add key for numbers not divisible by 7.
405405
*/
406406
if (i % 7 != 0) {
407-
ctx.update(bytes, 0, keyLen);
407+
messageDigest.update(bytes, 0, keyLen);
408408
}
409409

410410
// f) for odd round numbers add digest A/C
@@ -413,16 +413,16 @@ private static String sha2Crypt(final byte[] keyBytes, final String salt, final
413413
* Add key or last result.
414414
*/
415415
if ((i & 1) != 0) {
416-
ctx.update(altResult, 0, blocksize);
416+
messageDigest.update(altResult, 0, blocksize);
417417
} else {
418-
ctx.update(bytes, 0, keyLen);
418+
messageDigest.update(bytes, 0, keyLen);
419419
}
420420

421421
// h) finish digest C.
422422
/*
423423
* Create intermediate result.
424424
*/
425-
altResult = ctx.digest();
425+
altResult = messageDigest.digest();
426426
}
427427

428428
// 22. Produce the output string. This is an ASCII string of the maximum
@@ -518,8 +518,8 @@ private static String sha2Crypt(final byte[] keyBytes, final String salt, final
518518
Arrays.fill(tempResult, (byte) 0);
519519
Arrays.fill(bytes, (byte) 0);
520520
Arrays.fill(sBytes, (byte) 0);
521-
ctx.reset();
522-
altCtx.reset();
521+
messageDigest.reset();
522+
altMessageDigestMd5.reset();
523523
Arrays.fill(keyBytes, (byte) 0);
524524
Arrays.fill(saltBytes, (byte) 0);
525525

0 commit comments

Comments
 (0)