Merge pull request #165 from Boris-de/fix_bsize_bug

Fix bsize bug
This commit is contained in:
Jeroen van Erp
2015-01-12 09:51:06 +01:00
3 changed files with 11 additions and 6 deletions

View File

@@ -41,12 +41,12 @@ public class BaseMAC
@Override @Override
public byte[] doFinal() { public byte[] doFinal() {
return mac.doFinal(); return resizeToHashSize(mac.doFinal());
} }
@Override @Override
public byte[] doFinal(byte[] input) { public byte[] doFinal(byte[] input) {
return mac.doFinal(input); return resizeToHashSize(mac.doFinal(input));
} }
@Override @Override
@@ -62,6 +62,15 @@ public class BaseMAC
} }
} }
private byte[] resizeToHashSize(byte[] buf) {
if (bsize == defbsize)
return buf;
byte[] result = new byte[bsize];
System.arraycopy(buf, 0, result, 0, bsize);
return result;
}
@Override @Override
public int getBlockSize() { public int getBlockSize() {
return bsize; return bsize;

View File

@@ -30,7 +30,6 @@ public class HMACMD596Test {
private static final String EXPECTED_HMAC = "dff33c507463f9cf088a5ce8"; private static final String EXPECTED_HMAC = "dff33c507463f9cf088a5ce8";
@Test @Test
@Ignore
public void testUpdateWithDoFinal() { public void testUpdateWithDoFinal() {
HMACMD596 hmac = initHmac(); HMACMD596 hmac = initHmac();
hmac.update(PLAIN_TEXT); hmac.update(PLAIN_TEXT);
@@ -38,7 +37,6 @@ public class HMACMD596Test {
} }
@Test @Test
@Ignore
public void testDoFinalWithInput() { public void testDoFinalWithInput() {
HMACMD596 hmac = initHmac(); HMACMD596 hmac = initHmac();
assertThat(Hex.toHexString(hmac.doFinal(PLAIN_TEXT)), assertThat(Hex.toHexString(hmac.doFinal(PLAIN_TEXT)),

View File

@@ -30,7 +30,6 @@ public class HMACSHA196Test {
private static final String EXPECTED_HMAC = "24ddeed57ad91465c5b59dce"; private static final String EXPECTED_HMAC = "24ddeed57ad91465c5b59dce";
@Test @Test
@Ignore
public void testUpdateWithDoFinal() { public void testUpdateWithDoFinal() {
HMACSHA196 hmac = initHmac(); HMACSHA196 hmac = initHmac();
hmac.update(PLAIN_TEXT); hmac.update(PLAIN_TEXT);
@@ -38,7 +37,6 @@ public class HMACSHA196Test {
} }
@Test @Test
@Ignore
public void testDoFinalWithInput() { public void testDoFinalWithInput() {
HMACSHA196 hmac = initHmac(); HMACSHA196 hmac = initHmac();
assertThat(Hex.toHexString(hmac.doFinal(PLAIN_TEXT)), is(EXPECTED_HMAC)); assertThat(Hex.toHexString(hmac.doFinal(PLAIN_TEXT)), is(EXPECTED_HMAC));