Skip to content

Commit 2120772

Browse files
committed
Merge branch 'main' of gitlab.cryptoworkshop.com:root/bc-java
2 parents a38c09f + e73dbc5 commit 2120772

3 files changed

Lines changed: 69 additions & 2 deletions

File tree

core/src/main/java/org/bouncycastle/crypto/modes/CCMBlockCipher.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,19 @@ public int processPacket(byte[] in, int inOff, int inLen, byte[] output, int out
261261
if (q < 4)
262262
{
263263
int limitLen = 1 << (8 * q);
264-
if (inLen >= limitLen)
264+
265+
// no input length adjustment for encryption
266+
int inputAdjustment = 0;
267+
268+
if (!forEncryption)
269+
{
270+
// input includes 16 additional bytes: CCM flags and n+q values.
271+
inputAdjustment = 1 /* flags */ + 15 /* n + q */;
272+
}
273+
274+
if ((inLen-inputAdjustment) >= limitLen)
265275
{
266-
throw new IllegalStateException("CCM packet too large for choice of q.");
276+
throw new IllegalStateException("CCM packet too large for choice of q");
267277
}
268278
}
269279

core/src/test/java/org/bouncycastle/crypto/test/CCMTest.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.bouncycastle.crypto.params.AEADParameters;
88
import org.bouncycastle.crypto.params.KeyParameter;
99
import org.bouncycastle.crypto.params.ParametersWithIV;
10+
import org.bouncycastle.util.Arrays;
1011
import org.bouncycastle.util.Strings;
1112
import org.bouncycastle.util.encoders.Hex;
1213
import org.bouncycastle.util.test.SimpleTest;
@@ -150,6 +151,51 @@ public void performTest()
150151
// expected
151152
}
152153

154+
// For small number of allowed blocks, validate boundary
155+
// conditions are properly handled. Zero and greater will
156+
// fail as size bound is a strict inequality.
157+
int[] offsets = new int[]{-10, -2, -1, 0, 1, 10};
158+
int[] ns = new int[]{13, 12};
159+
for (int n_len : ns)
160+
{
161+
for (int offset : offsets)
162+
{
163+
try
164+
{
165+
ccm.init(true, new AEADParameters(new KeyParameter(K1), 128, new byte[n_len]));
166+
167+
// Encrypt up to 2^(8q) + offset. Note that message length
168+
// must be strictly less than 2^(8q) so offset=0 will not
169+
// work (per SP 800-38C Section A.1 Length Requirements).
170+
int q = 15 - n_len;
171+
int size = 1 << (8*q);
172+
inBuf = new byte[size + offset];
173+
174+
outBuf = new byte[ccm.getOutputSize(inBuf.length)];
175+
len = ccm.processPacket(inBuf, 0, inBuf.length, outBuf, 0);
176+
177+
if (offset >= 0) {
178+
fail("expected to fail to encrypt boundary bytes n=" + n_len + "size=" + size + " offset=" + offset);
179+
} else {
180+
// Decrypt should also succeed if encryption succeeded.
181+
ccm.init(false, new AEADParameters(new KeyParameter(K1), 128, new byte[n_len]));
182+
out = ccm.processPacket(outBuf, 0, outBuf.length);
183+
184+
if (out.length != inBuf.length || !Arrays.areEqual(inBuf, out))
185+
{
186+
fail("encryption output incorrect");
187+
}
188+
}
189+
}
190+
catch (Exception e)
191+
{
192+
if (offset < 0) {
193+
fail("unexpected failure to encrypt boundary bytes n=" + n_len + " offset=" + offset + " msg=" + e.getMessage());
194+
}
195+
}
196+
}
197+
}
198+
153199
AEADTestUtil.testReset(this, new CCMBlockCipher(AESEngine.newInstance()), new CCMBlockCipher(AESEngine.newInstance()), new AEADParameters(new KeyParameter(K1), 32, N2));
154200
AEADTestUtil.testTampering(this, ccm, new AEADParameters(new KeyParameter(K1), 32, N2));
155201
AEADTestUtil.testOutputSizes(this, new CCMBlockCipher(AESEngine.newInstance()), new AEADParameters(

docs/releasenotes.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,29 @@ <h2>2.0 Release History</h2>
2424
<h3>2.1.2 Defects Fixed</h3>
2525
<ul>
2626
<li>Issues with a dangling weak reference causing intermittent NullPointerExceptions in the OcspCache have been fixed.</li>
27+
<li>Issues with non-constant time RSA operations in TLS handshakes have been fixed.</li>
28+
<li>Issue with Ed25519, Ed448 signature verification causing intermittent infinite loop have been fixed.</li>
29+
<li>Issues with non-constant time ML-KEM implementation ("Kyber Slash") have been fixed.</li>
30+
<li>Align ML-KEM input validation with FIPS 203 IPD requirements.</li>
31+
<li>Make PEM parsing more forgiving of whitespace to align with RFC 7468 - Textual Encodings of PKIX, PKCS, and CMS Structures.</li>
2732
</ul>
2833
<h3>2.1.3 Additional Features and Functionality</h3>
2934
<ul>
3035
<li>An implementation of MLS (RFC 9420 - The Messaging Layer Security Protocol) has been added as a new module.</li>
3136
<li>NTRU now supports NTRU-HPS4096-1229 and NTRU-HRSS-1373.</li>
37+
<li>Improvements to PGP support, including Curve25519, Curve448 key types.</li>
38+
<li>Add initial support for ML-KEM in TLS.</li>
39+
<li>Add XWing hybrid KEM construction (X25519 + ML-KEM-768).</li>
40+
<li>Introduce initial KEMSpi support (NTRU, SNTRU Prime) for JDK 21+.</li>
41+
<li>Introduce initial composite signature support for X509 Certificates.</li>
3242
</ul>
3343
<h3>2.1.4 Notes.</h3>
3444
<ul>
3545
<li>Both versions of NTRUPrime have been updated to produce 256 bit secrets in line with Kyber. This should also bring them into line with other implementations such as those used in OpenSSH now.</li>
3646
<li>BCJSSE: The boolean system property 'org.bouncycastle.jsse.fips.allowRSAKeyExchange" now defaults to false. All RSA
3747
key exchange cipher suites will therefore be disabled when the BCJSSE provider is used in FIPS mode, unless this system
3848
property is explicitly set to true.</li>
49+
<li>Improve OSGi compatibility.</li>
3950
</ul>
4051

4152
<a id="r1rv77"><h3>2.2.1 Version</h3></a>

0 commit comments

Comments
 (0)