@@ -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