Skip to content

Commit ced3d33

Browse files
author
gefeili
committed
Merge branch 'main' into 1958-aead-parameters
2 parents b530e83 + a912b69 commit ced3d33

24 files changed

+90
-102
lines changed

tls/src/main/java/org/bouncycastle/tls/NamedGroup.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public class NamedGroup
117117
public static final int MLKEM1024 = 0x1024;
118118

119119
/* Names of the actual underlying elliptic curves (not necessarily matching the NamedGroup names). */
120-
private static final String[] CURVE_NAMES = new String[] { "sect163k1", "sect163r1", "sect163r2", "sect193r1",
120+
private static final String[] CURVE_NAMES = new String[]{ "sect163k1", "sect163r1", "sect163r2", "sect193r1",
121121
"sect193r2", "sect233k1", "sect233r1", "sect239k1", "sect283k1", "sect283r1", "sect409k1", "sect409r1",
122122
"sect571k1", "sect571r1", "secp160k1", "secp160r1", "secp160r2", "secp192k1", "secp192r1", "secp224k1",
123123
"secp224r1", "secp256k1", "secp256r1", "secp384r1", "secp521r1", "brainpoolP256r1", "brainpoolP384r1",
@@ -126,7 +126,7 @@ public class NamedGroup
126126
"GostR3410-2001-CryptoPro-C", "Tc26-Gost-3410-12-512-paramSetA", "Tc26-Gost-3410-12-512-paramSetB",
127127
"Tc26-Gost-3410-12-512-paramSetC", "sm2p256v1" };
128128

129-
private static final String[] FINITE_FIELD_NAMES = new String[] { "ffdhe2048", "ffdhe3072", "ffdhe4096",
129+
private static final String[] FINITE_FIELD_NAMES = new String[]{ "ffdhe2048", "ffdhe3072", "ffdhe4096",
130130
"ffdhe6144", "ffdhe8192" };
131131

132132
public static boolean canBeNegotiated(int namedGroup, ProtocolVersion version)

tls/src/main/java/org/bouncycastle/tls/SimulatedTlsSRPIdentityManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static SimulatedTlsSRPIdentityManager getRFC5054Default(TlsCrypto crypto,
3636

3737
TlsSRPConfig srpConfig = new TlsSRPConfig();
3838

39-
srpConfig.setExplicitNG(new BigInteger[] { group.getN(), group.getG() });
39+
srpConfig.setExplicitNG(new BigInteger[]{ group.getN(), group.getG() });
4040

4141
return new SimulatedTlsSRPIdentityManager(group, crypto.createSRP6VerifierGenerator(srpConfig), mac);
4242
}

tls/src/main/java/org/bouncycastle/tls/TlsDHUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static int getNamedGroupForDHParameters(BigInteger p, BigInteger g)
101101

102102
public static DHGroup getStandardGroupForDHParameters(BigInteger p, BigInteger g)
103103
{
104-
DHGroup[] standardGroups = new DHGroup[] { DHStandardGroups.rfc7919_ffdhe2048,
104+
DHGroup[] standardGroups = new DHGroup[]{ DHStandardGroups.rfc7919_ffdhe2048,
105105
DHStandardGroups.rfc7919_ffdhe3072, DHStandardGroups.rfc7919_ffdhe4096, DHStandardGroups.rfc7919_ffdhe6144,
106106
DHStandardGroups.rfc7919_ffdhe8192, DHStandardGroups.rfc3526_1536, DHStandardGroups.rfc3526_2048,
107107
DHStandardGroups.rfc3526_3072, DHStandardGroups.rfc3526_4096, DHStandardGroups.rfc3526_6144,
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package org.bouncycastle.tls.crypto.impl;
22

3-
import org.bouncycastle.tls.TlsFatalAlert;
3+
import java.io.IOException;
44

55
public interface AEADNonceGenerator
66
{
7-
public void generateNonce(byte[] nonce)
8-
throws TlsFatalAlert;
7+
public void generateNonce(byte[] nonce) throws IOException;
98
}

tls/src/main/java/org/bouncycastle/tls/crypto/impl/AEADNonceGeneratorFactory.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package org.bouncycastle.tls.crypto.impl;
22

3-
import org.bouncycastle.tls.crypto.TlsNonceGenerator;
4-
53
public interface AEADNonceGeneratorFactory
64
{
75
AEADNonceGenerator create(byte[] baseNonce, int counterSizeInBits);
Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
package org.bouncycastle.tls.crypto.impl;
22

3-
import java.security.AccessController;
4-
import java.security.PrivilegedAction;
5-
6-
final public class GcmTls12NonceGeneratorUtil
3+
public final class GcmTls12NonceGeneratorUtil
74
{
8-
private static AEADNonceGeneratorFactory tlsNonceGeneratorFactory = null;
5+
private static volatile AEADNonceGeneratorFactory globalFactory = null;
96

10-
public static void setGcmTlsNonceGeneratorFactory(final AEADNonceGeneratorFactory factory)
7+
public static void setGcmTlsNonceGeneratorFactory(AEADNonceGeneratorFactory factory)
118
{
12-
tlsNonceGeneratorFactory = factory;
9+
globalFactory = factory;
1310
}
1411

1512
public static boolean isGcmFipsNonceGeneratorFactorySet()
1613
{
17-
return tlsNonceGeneratorFactory != null;
14+
return globalFactory != null;
1815
}
1916

20-
public static AEADNonceGenerator createGcmFipsNonceGenerator(final byte[] baseNonce, final int counterSizeInBits)
17+
public static AEADNonceGenerator createGcmFipsNonceGenerator(byte[] baseNonce, int counterSizeInBits)
2118
{
22-
return tlsNonceGeneratorFactory != null
23-
? tlsNonceGeneratorFactory.create(baseNonce, counterSizeInBits)
24-
: null;
19+
return globalFactory == null ? null : globalFactory.create(baseNonce, counterSizeInBits);
2520
}
2621
}

tls/src/main/java/org/bouncycastle/tls/crypto/impl/TlsAEADCipher.java

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.bouncycastle.tls.crypto.TlsCryptoUtils;
1414
import org.bouncycastle.tls.crypto.TlsDecodeResult;
1515
import org.bouncycastle.tls.crypto.TlsEncodeResult;
16-
import org.bouncycastle.tls.crypto.TlsNonceGenerator;
1716
import org.bouncycastle.tls.crypto.TlsSecret;
1817
import org.bouncycastle.util.Arrays;
1918

@@ -31,7 +30,7 @@ public final class TlsAEADCipher
3130
private static final int NONCE_RFC7905 = 2;
3231
private static final long SEQUENCE_NUMBER_PLACEHOLDER = -1L;
3332

34-
private static final byte[] EPOCH_1 = {0x00, 0x01};
33+
private static final byte[] EPOCH_1 = { 0x00, 0x01 };
3534

3635
private final TlsCryptoParameters cryptoParams;
3736
private final int keySize;
@@ -129,9 +128,9 @@ public TlsAEADCipher(TlsCryptoParameters cryptoParams, TlsAEADCipherImpl encrypt
129128

130129
if (AEAD_GCM == aeadType && GcmTls12NonceGeneratorUtil.isGcmFipsNonceGeneratorFactorySet())
131130
{
132-
final int nonceLength = fixed_iv_length + record_iv_length;
133-
final byte[] baseNonce = Arrays.copyOf(encryptNonce, nonceLength);
134-
final int counterSizeInBits;
131+
int nonceLength = fixed_iv_length + record_iv_length;
132+
byte[] baseNonce = Arrays.copyOf(encryptNonce, nonceLength);
133+
int counterSizeInBits;
135134
if (negotiatedVersion.isDTLS())
136135
{
137136
counterSizeInBits = (record_iv_length - 2) * 8; // 48
@@ -142,7 +141,8 @@ public TlsAEADCipher(TlsCryptoParameters cryptoParams, TlsAEADCipherImpl encrypt
142141
{
143142
counterSizeInBits = record_iv_length * 8; // 64
144143
}
145-
gcmFipsNonceGenerator = GcmTls12NonceGeneratorUtil.createGcmFipsNonceGenerator(baseNonce, counterSizeInBits);
144+
gcmFipsNonceGenerator = GcmTls12NonceGeneratorUtil.createGcmFipsNonceGenerator(baseNonce,
145+
counterSizeInBits);
146146
}
147147
else
148148
{
@@ -181,8 +181,7 @@ public int getPlaintextEncodeLimit(int ciphertextLimit)
181181
public TlsEncodeResult encodePlaintext(long seqNo, short contentType, ProtocolVersion recordVersion,
182182
int headerAllocation, byte[] plaintext, int plaintextOffset, int plaintextLength) throws IOException
183183
{
184-
final int nonceSize = encryptNonce.length + record_iv_length;
185-
final byte[] nonce = new byte[nonceSize];
184+
byte[] nonce = new byte[encryptNonce.length + record_iv_length];
186185

187186
if (null != gcmFipsNonceGenerator)
188187
{
@@ -192,20 +191,20 @@ public TlsEncodeResult encodePlaintext(long seqNo, short contentType, ProtocolVe
192191
{
193192
switch (nonceMode)
194193
{
195-
case NONCE_RFC5288:
196-
System.arraycopy(encryptNonce, 0, nonce, 0, encryptNonce.length);
197-
// RFC 5288/6655: The nonce_explicit MAY be the 64-bit sequence number.
198-
TlsUtils.writeUint64(seqNo, nonce, encryptNonce.length);
199-
break;
200-
case NONCE_RFC7905:
201-
TlsUtils.writeUint64(seqNo, nonce, nonce.length - 8);
202-
for (int i = 0; i < encryptNonce.length; ++i)
203-
{
204-
nonce[i] ^= encryptNonce[i];
205-
}
206-
break;
207-
default:
208-
throw new TlsFatalAlert(AlertDescription.internal_error);
194+
case NONCE_RFC5288:
195+
System.arraycopy(encryptNonce, 0, nonce, 0, encryptNonce.length);
196+
// RFC 5288/6655: The nonce_explicit MAY be the 64-bit sequence number.
197+
TlsUtils.writeUint64(seqNo, nonce, encryptNonce.length);
198+
break;
199+
case NONCE_RFC7905:
200+
TlsUtils.writeUint64(seqNo, nonce, nonce.length - 8);
201+
for (int i = 0; i < encryptNonce.length; ++i)
202+
{
203+
nonce[i] ^= encryptNonce[i];
204+
}
205+
break;
206+
default:
207+
throw new TlsFatalAlert(AlertDescription.internal_error);
209208
}
210209
}
211210

tls/src/main/java/org/bouncycastle/tls/crypto/impl/jcajce/srp/SRP6Util.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class SRP6Util
1010
{
11-
private static final byte[] colon = new byte[] { (byte)':' };
11+
private static final byte[] COLON = new byte[]{ (byte)':' };
1212

1313
private static BigInteger ZERO = BigInteger.valueOf(0);
1414
private static BigInteger ONE = BigInteger.valueOf(1);
@@ -26,7 +26,7 @@ public static BigInteger calculateU(TlsHash digest, BigInteger N, BigInteger A,
2626
public static BigInteger calculateX(TlsHash digest, BigInteger N, byte[] salt, byte[] identity, byte[] password)
2727
{
2828
digest.update(identity, 0, identity.length);
29-
digest.update(colon, 0, 1);
29+
digest.update(COLON, 0, 1);
3030
digest.update(password, 0, password.length);
3131

3232
byte[] output = digest.calculateHash();

tls/src/test/java/org/bouncycastle/jsse/provider/test/ECDSACredentialsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ private void implTestECDSACredentials(int port, String protocol, int namedGroup)
126126
X509Certificate caCert = TestUtils.generateRootCert(caKeyPair);
127127

128128
KeyStore serverKs = createKeyStore();
129-
serverKs.setKeyEntry("server", caKeyPair.getPrivate(), keyPass, new X509Certificate[] { caCert });
129+
serverKs.setKeyEntry("server", caKeyPair.getPrivate(), keyPass, new X509Certificate[]{ caCert });
130130

131131
KeyStore clientKs = createKeyStore();
132-
clientKs.setKeyEntry("client", caKeyPair.getPrivate(), keyPass, new X509Certificate[] { caCert });
132+
clientKs.setKeyEntry("client", caKeyPair.getPrivate(), keyPass, new X509Certificate[]{ caCert });
133133

134134
TestProtocolUtil.runClientAndServer(new ECDSAServer(port, protocol, serverKs, keyPass, caCert),
135135
new ECDSAClient(port, protocol, clientKs, keyPass, caCert));

tls/src/test/java/org/bouncycastle/jsse/provider/test/KeyManagerFactoryTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ private KeyStore getEcKeyStore(boolean agreement)
199199

200200
ks.load(null, PASSWORD);
201201

202-
ks.setKeyEntry("test", ePair.getPrivate(), PASSWORD, new Certificate[] { eCert, iCert });
202+
ks.setKeyEntry("test", ePair.getPrivate(), PASSWORD, new Certificate[]{ eCert, iCert });
203203

204204
ks.setCertificateEntry("root", rCert);
205205

@@ -230,7 +230,7 @@ private KeyStore getRsaKeyStore(boolean encryption)
230230

231231
ks.load(null, PASSWORD);
232232

233-
ks.setKeyEntry("test", ePair.getPrivate(), PASSWORD, new Certificate[] { eCert, iCert });
233+
ks.setKeyEntry("test", ePair.getPrivate(), PASSWORD, new Certificate[]{ eCert, iCert });
234234

235235
ks.setCertificateEntry("root", rCert);
236236

@@ -248,14 +248,14 @@ private void implTestKeyManager(BCX509ExtendedKeyManager manager, String keyType
248248
BCX509Key key = manager.chooseServerKeyBC(new String[]{ keyType }, null, null);
249249
assertNotNull(key);
250250

251-
alias = manager.chooseServerAlias(keyType, new Principal[] { new X500Principal("CN=TLS Test") }, null);
251+
alias = manager.chooseServerAlias(keyType, new Principal[]{ new X500Principal("CN=TLS Test") }, null);
252252
assertNull(alias);
253253

254-
key = manager.chooseServerKeyBC(new String[]{ keyType }, new Principal[] { new X500Principal("CN=TLS Test") },
254+
key = manager.chooseServerKeyBC(new String[]{ keyType }, new Principal[]{ new X500Principal("CN=TLS Test") },
255255
null);
256256
assertNull(key);
257257

258-
alias = manager.chooseServerAlias(keyType, new Principal[] { new X500Principal("CN=TLS Test CA") }, null);
258+
alias = manager.chooseServerAlias(keyType, new Principal[]{ new X500Principal("CN=TLS Test CA") }, null);
259259
assertNotNull(alias);
260260
assertNotNull(manager.getCertificateChain(alias));
261261
assertNotNull(manager.getPrivateKey(alias));

0 commit comments

Comments
 (0)