提交 bb6d78b5 编写于 作者: A ascarpino

8001284: Buffer problems with SunPKCS11-Solaris and CKM_AES_CTR

Summary: Changed output length calculation to include incomplete blocks for CTR mode.
Reviewed-by: valeriep
上级 0e6dd1da
/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -460,7 +460,7 @@ final class P11Cipher extends CipherSpi {
}
int result = inLen + bytesBuffered;
if (blockSize != 0) {
if (blockSize != 0 && blockMode != MODE_CTR) {
// minus the number of bytes in the last incomplete block.
result -= (result & (blockSize - 1));
}
......
/*
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -23,7 +23,7 @@
/**
* @test
* @bug 4898484 6604496
* @bug 4898484 6604496 8001284
* @summary basic test for symmetric ciphers with no padding
* @author Valerie Peng
* @library ..
......@@ -60,7 +60,8 @@ public class TestSymmCiphersNoPad extends PKCS11Test {
new CI("DESede/CBC/NoPadding", "DESede", 160),
new CI("AES/CBC/NoPadding", "AES", 4800),
new CI("Blowfish/CBC/NoPadding", "Blowfish", 24),
new CI("AES/CTR/NoPadding", "AES", 1600)
new CI("AES/CTR/NoPadding", "AES", 1600),
new CI("AES/CTR/NoPadding", "AES", 65)
};
private static StringBuffer debugBuf;
......@@ -182,6 +183,29 @@ public class TestSymmCiphersNoPad extends PKCS11Test {
debugBuf.append("(post) outputBuf: " + outDirectBuf + "\n");
match(outDirectBuf, answer);
// test#6: Streams
debugBuf.append("Test#6: Streaming\n");
outBuf.position(0);
InputStream stream =
new CipherInputStream(new ByteArrayInputStream(in), cipher);
byte[] data = new byte[1024];
int bytesRead = 0;
try {
while (bytesRead >= 0) {
bytesRead = stream.read(data);
if (bytesRead == -1)
break;
debugBuf.append("bytesRead: " + bytesRead);
debugBuf.append("\toutBuf.position(): " + outBuf.position() +
"\n");
outBuf.put(data, 0 , bytesRead);
}
} catch (Exception ex) {
debugBuf.append("Caught Exception during stream reading\n");
throw ex;
}
match(outBuf, answer);
debugBuf = null;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册