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;