bugfix: BaseMac would not use bsize in certain cases

The implementation of BaseMac would only take the bsize (size of the
hash) into account if the #doFinal(byte[], int) method was called.
Both other #doFinal methods would behave as if bsize==defbsize and
not cut the hash to the right size.
This commit is contained in:
Boris Wachtmeister
2015-01-11 21:00:16 +01:00
parent 665cbf078a
commit 73de5b7b08
3 changed files with 11 additions and 6 deletions

View File

@@ -41,12 +41,12 @@ public class BaseMAC
@Override
public byte[] doFinal() {
return mac.doFinal();
return resizeToHashSize(mac.doFinal());
}
@Override
public byte[] doFinal(byte[] input) {
return mac.doFinal(input);
return resizeToHashSize(mac.doFinal(input));
}
@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
public int getBlockSize() {
return bsize;

View File

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

View File

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