Skip to content

Commit af941f3

Browse files
committed
Cleanup tls.crypto domain classes
1 parent 7f1ca8b commit af941f3

File tree

5 files changed

+12
-18
lines changed

5 files changed

+12
-18
lines changed

tls/src/main/java/org/bouncycastle/tls/crypto/impl/bc/BcTlsDHDomain.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,20 @@ public static DHParameters getDomainParameters(TlsDHConfig dhConfig)
5757
return new DHParameters(dhGroup.getP(), dhGroup.getG(), dhGroup.getQ(), dhGroup.getL());
5858
}
5959

60-
protected BcTlsCrypto crypto;
61-
protected TlsDHConfig config;
62-
protected DHParameters domainParameters;
60+
protected final BcTlsCrypto crypto;
61+
protected final DHParameters domainParameters;
62+
protected final boolean isPadded;
6363

6464
public BcTlsDHDomain(BcTlsCrypto crypto, TlsDHConfig dhConfig)
6565
{
6666
this.crypto = crypto;
67-
this.config = dhConfig;
6867
this.domainParameters = getDomainParameters(dhConfig);
68+
this.isPadded = dhConfig.isPadded();
6969
}
7070

7171
public BcTlsSecret calculateDHAgreement(DHPrivateKeyParameters privateKey, DHPublicKeyParameters publicKey)
7272
{
73-
return calculateDHAgreement(crypto, privateKey, publicKey, config.isPadded());
73+
return calculateDHAgreement(crypto, privateKey, publicKey, isPadded);
7474
}
7575

7676
public TlsAgreement createDH()
@@ -80,7 +80,7 @@ public TlsAgreement createDH()
8080

8181
public BigInteger decodeParameter(byte[] encoding) throws IOException
8282
{
83-
if (config.isPadded() && getValueLength(domainParameters) != encoding.length)
83+
if (isPadded && getValueLength(domainParameters) != encoding.length)
8484
{
8585
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
8686
}
@@ -109,7 +109,7 @@ public DHPublicKeyParameters decodePublicKey(byte[] encoding) throws IOException
109109

110110
public byte[] encodeParameter(BigInteger x)
111111
{
112-
return encodeValue(domainParameters, config.isPadded(), x);
112+
return encodeValue(domainParameters, isPadded, x);
113113
}
114114

115115
public byte[] encodePublicKey(DHPublicKeyParameters publicKey)

tls/src/main/java/org/bouncycastle/tls/crypto/impl/bc/BcTlsECDomain.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,11 @@ public static ECDomainParameters getDomainParameters(int namedGroup)
7979
}
8080

8181
protected final BcTlsCrypto crypto;
82-
protected final TlsECConfig config;
8382
protected final ECDomainParameters domainParameters;
8483

8584
public BcTlsECDomain(BcTlsCrypto crypto, TlsECConfig ecConfig)
8685
{
8786
this.crypto = crypto;
88-
this.config = ecConfig;
8987
this.domainParameters = getDomainParameters(ecConfig);
9088
}
9189

tls/src/main/java/org/bouncycastle/tls/crypto/impl/bc/BcTlsMLKemDomain.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,12 @@ public static MLKEMParameters getDomainParameters(TlsKemConfig kemConfig)
3535
}
3636

3737
protected final BcTlsCrypto crypto;
38-
protected final TlsKemConfig config;
3938
protected final MLKEMParameters domainParameters;
4039
protected final boolean isServer;
4140

4241
public BcTlsMLKemDomain(BcTlsCrypto crypto, TlsKemConfig kemConfig)
4342
{
4443
this.crypto = crypto;
45-
this.config = kemConfig;
4644
this.domainParameters = getDomainParameters(kemConfig);
4745
this.isServer = kemConfig.isServer();
4846
}

tls/src/main/java/org/bouncycastle/tls/crypto/impl/jcajce/JceTlsDHDomain.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ public static JceTlsSecret calculateDHAgreement(JcaTlsCrypto crypto, DHPrivateKe
7171
}
7272

7373
protected final JcaTlsCrypto crypto;
74-
protected final TlsDHConfig dhConfig;
7574
protected final DHParameterSpec dhSpec;
75+
protected final boolean isPadded;
7676

7777
public JceTlsDHDomain(JcaTlsCrypto crypto, TlsDHConfig dhConfig)
7878
{
@@ -83,8 +83,8 @@ public JceTlsDHDomain(JcaTlsCrypto crypto, TlsDHConfig dhConfig)
8383
if (null != spec)
8484
{
8585
this.crypto = crypto;
86-
this.dhConfig = dhConfig;
8786
this.dhSpec = spec;
87+
this.isPadded = dhConfig.isPadded();
8888
return;
8989
}
9090
}
@@ -95,7 +95,7 @@ public JceTlsDHDomain(JcaTlsCrypto crypto, TlsDHConfig dhConfig)
9595
public JceTlsSecret calculateDHAgreement(DHPrivateKey privateKey, DHPublicKey publicKey)
9696
throws IOException
9797
{
98-
return calculateDHAgreement(crypto, privateKey, publicKey, dhConfig.isPadded());
98+
return calculateDHAgreement(crypto, privateKey, publicKey, isPadded);
9999
}
100100

101101
public TlsAgreement createDH()
@@ -105,7 +105,7 @@ public TlsAgreement createDH()
105105

106106
public BigInteger decodeParameter(byte[] encoding) throws IOException
107107
{
108-
if (dhConfig.isPadded() && getValueLength(dhSpec) != encoding.length)
108+
if (isPadded && getValueLength(dhSpec) != encoding.length)
109109
{
110110
throw new TlsFatalAlert(AlertDescription.illegal_parameter);
111111
}
@@ -140,7 +140,7 @@ public DHPublicKey decodePublicKey(byte[] encoding) throws IOException
140140

141141
public byte[] encodeParameter(BigInteger x) throws IOException
142142
{
143-
return encodeValue(dhSpec, dhConfig.isPadded(), x);
143+
return encodeValue(dhSpec, isPadded, x);
144144
}
145145

146146
public byte[] encodePublicKey(DHPublicKey publicKey) throws IOException

tls/src/main/java/org/bouncycastle/tls/crypto/impl/jcajce/JceTlsECDomain.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public class JceTlsECDomain
2929
implements TlsECDomain
3030
{
3131
protected final JcaTlsCrypto crypto;
32-
protected final TlsECConfig ecConfig;
3332
protected final ECParameterSpec ecSpec;
3433
protected final ECCurve ecCurve;
3534

@@ -42,7 +41,6 @@ public JceTlsECDomain(JcaTlsCrypto crypto, TlsECConfig ecConfig)
4241
if (null != spec)
4342
{
4443
this.crypto = crypto;
45-
this.ecConfig = ecConfig;
4644
this.ecSpec = spec;
4745
this.ecCurve = ECUtil.convertCurve(spec.getCurve(), spec.getOrder(), spec.getCofactor());
4846
return;

0 commit comments

Comments
 (0)