Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Removed superfluous long->int bit mask operations and added one more …
…test.
  • Loading branch information
Christian Hammers committed Aug 31, 2012
commit 704e046a60e344add510c4ee0de004f09cd46889
16 changes: 8 additions & 8 deletions src/main/java/org/apache/commons/codec/digest/UnixCrypt.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* <p>
* This class is immutable and thread-safe.
*
* @version $Id$
* @version $Id: UnixCrypt.java 1375781 2012-08-21 20:49:40Z tn $
* @since 1.7
*/
public class UnixCrypt {
Expand Down Expand Up @@ -337,8 +337,8 @@ private static int[] body(int schedule[], int eSwap0, int eSwap1) {
t = right;
right = left >>> 1 | left << 31;
left = t >>> 1 | t << 31;
left &= 0xffffffff;
right &= 0xffffffff;
// left &= 0xffffffff;
// right &= 0xffffffff;
int results[] = new int[2];
permOp(right, left, 1, 0x55555555, results);
right = results[0];
Expand Down Expand Up @@ -399,7 +399,7 @@ private static int[] desSetKey(byte key[]) {
d = results[0];
c = results[1];
d = (d & 0xff) << 16 | d & 0xff00 | (d & 0xff0000) >>> 16 | (c & 0xf0000000) >>> 4;
c &= 0xfffffff;
// c &= 0xfffffff;
int j = 0;
for (int i = 0; i < 16; i++) {
if (SHIFT2[i]) {
Expand All @@ -409,14 +409,14 @@ private static int[] desSetKey(byte key[]) {
c = c >>> 1 | c << 27;
d = d >>> 1 | d << 27;
}
c &= 0xfffffff;
d &= 0xfffffff;
// c &= 0xfffffff;
// d &= 0xfffffff;
int s = SKB[0][c & 0x3f] | SKB[1][c >>> 6 & 0x3 | c >>> 7 & 0x3c] | SKB[2][c >>> 13 & 0xf | c >>> 14 & 0x30] | SKB[3][c >>> 20 & 0x1 | c >>> 21 & 0x6 | c >>> 22 & 0x38];
int t = SKB[4][d & 0x3f] | SKB[5][d >>> 7 & 0x3 | d >>> 8 & 0x3c] | SKB[6][d >>> 15 & 0x3f] | SKB[7][d >>> 21 & 0xf | d >>> 22 & 0x30];
schedule[j++] = (t << 16 | s & 0xffff) & 0xffffffff;
schedule[j++] = (t << 16 | s & 0xffff) /* & 0xffffffff */;
s = s >>> 16 | t & 0xffff0000;
s = s << 4 | s >>> 28;
schedule[j++] = s & 0xffffffff;
schedule[j++] = s /* & 0xffffffff */;
}

return schedule;
Expand Down
11 changes: 9 additions & 2 deletions src/test/java/org/apache/commons/codec/digest/CryptTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
*/
package org.apache.commons.codec.digest;

import static org.junit.Assert.assertTrue;

import java.security.NoSuchAlgorithmException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;

public class CryptTest {
Expand All @@ -31,6 +31,13 @@ public void testDefaultCryptVariant() throws NoSuchAlgorithmException {
assertTrue(Crypt.crypt("secret", null).startsWith("$6$"));
}

@Test
public void testCryptWithBytes() throws NoSuchAlgorithmException {
byte[] keyBytes = new byte[] { 'b', 'y', 't', 'e' };
String hash = Crypt.crypt(keyBytes);
assertEquals(hash, Crypt.crypt("byte", hash));
}

/**
* An empty string as salt is invalid.
*
Expand Down