digest.doFinal(resBuf, 0);
resStr = new String(Hex.encode(resBuf));
if (!resVec1.equals(resStr))
{
return new SimpleTestResult(false,
"SHA-256 failing standard vector test 1"
+ System.getProperty("line.separator")
+ " expected: " + resVec1
+ System.getProperty("line.separator")
+ " got : " + resStr);
}
//
// test 2
//
byte[] bytes = Hex.decode(testVec2);
digest.update(bytes, 0, bytes.length);
digest.doFinal(resBuf, 0);
resStr = new String(Hex.encode(resBuf));
if (!resVec2.equals(resStr))
{
return new SimpleTestResult(false,
"SHA-256 failing standard vector test 2"
+ System.getProperty("line.separator")
+ " expected: " + resVec2
+ System.getProperty("line.separator")
+ " got : " + resStr);
}
//
// test 3
//
bytes = Hex.decode(testVec3);
digest.update(bytes, 0, bytes.length);
digest.doFinal(resBuf, 0);
resStr = new String(Hex.encode(resBuf));
if (!resVec3.equals(resStr))
{
return new SimpleTestResult(false,
"SHA-256 failing standard vector test 3"
+ System.getProperty("line.separator")
+ " expected: " + resVec3
+ System.getProperty("line.separator")
+ " got : " + resStr);
}
//
// test 4
//
bytes = Hex.decode(testVec4);
digest.update(bytes, 0, bytes.length);
digest.doFinal(resBuf, 0);
resStr = new String(Hex.encode(resBuf));
if (!resVec4.equals(resStr))
{
return new SimpleTestResult(false,
"SHA-256 failing standard vector test 4"
+ System.getProperty("line.separator")
+ " expected: " + resVec4
+ System.getProperty("line.separator")
+ " got : " + resStr);
}
//
// test 5
//
bytes = Hex.decode(testVec4);
digest.update(bytes, 0, bytes.length/2);
// clone the Digest
Digest d = new SHA224Digest((SHA224Digest)digest);
digest.update(bytes, bytes.length/2, bytes.length - bytes.length/2);
digest.doFinal(resBuf, 0);
resStr = new String(Hex.encode(resBuf));
if (!resVec4.equals(resStr))
{
return new SimpleTestResult(false,
"SHA224 failing standard vector test 5"
+ System.getProperty("line.separator")
+ " expected: " + resVec4
+ System.getProperty("line.separator")
+ " got : " + resStr);
}
d.update(bytes, bytes.length/2, bytes.length - bytes.length/2);
d.doFinal(resBuf, 0);
resStr = new String(Hex.encode(resBuf));
if (!resVec4.equals(resStr))
{
return new SimpleTestResult(false,
"SHA224 failing standard vector test 5"
+ System.getProperty("line.separator")
+ " expected: " + resVec4
+ System.getProperty("line.separator")
+ " got : " + resStr);
}
// test 6
bytes = Hex.decode(testVec5);
for ( int i = 0; i < 100000; i++ )
{
digest.update(bytes, 0, bytes.length);
}
digest.doFinal(resBuf, 0);
resStr = new String(Hex.encode(resBuf));
if (!resVec5.equals(resStr))
{
return new SimpleTestResult(false,
"SHA-256 failing standard vector test 5"
+ System.getProperty("line.separator")
+ " expected: " + resVec5
+ System.getProperty("line.separator")
+ " got : " + resStr);
}
return new SimpleTestResult(true, getName() + ": Okay");
}