Skip to content

Commit bee6734

Browse files
committed
Refactoring in tls.crypto.impl
1 parent 4ed7d13 commit bee6734

File tree

7 files changed

+15
-60
lines changed

7 files changed

+15
-60
lines changed

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

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,6 @@ public static ASN1ObjectIdentifier getMLDSAObjectidentifier(int signatureScheme)
2323
}
2424
}
2525

26-
public static ASN1ObjectIdentifier getMLDSAObjectidentifier(MLDSAParameters parameters)
27-
{
28-
if (MLDSAParameters.ml_dsa_44 == parameters)
29-
{
30-
return NISTObjectIdentifiers.id_ml_dsa_44;
31-
}
32-
if (MLDSAParameters.ml_dsa_65 == parameters)
33-
{
34-
return NISTObjectIdentifiers.id_ml_dsa_65;
35-
}
36-
if (MLDSAParameters.ml_dsa_87 == parameters)
37-
{
38-
return NISTObjectIdentifiers.id_ml_dsa_87;
39-
}
40-
throw new IllegalArgumentException();
41-
}
42-
4326
public static int getMLDSASignatureScheme(MLDSAParameters parameters)
4427
{
4528
if (MLDSAParameters.ml_dsa_44 == parameters)
@@ -57,9 +40,9 @@ public static int getMLDSASignatureScheme(MLDSAParameters parameters)
5740
throw new IllegalArgumentException();
5841
}
5942

60-
public static boolean supportsMLDSA(AlgorithmIdentifier pubKeyAlgID, ASN1ObjectIdentifier algorithm)
43+
public static boolean supportsMLDSA(AlgorithmIdentifier pubKeyAlgID, ASN1ObjectIdentifier mlDsaAlgOid)
6144
{
62-
return pubKeyAlgID.getAlgorithm().equals(algorithm)
45+
return pubKeyAlgID.getAlgorithm().equals(mlDsaAlgOid)
6346
&& pubKeyAlgID.getParameters() == null;
6447
}
6548
}

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

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

3-
import java.io.IOException;
4-
53
import org.bouncycastle.crypto.params.Ed25519PrivateKeyParameters;
64
import org.bouncycastle.crypto.signers.Ed25519Signer;
75
import org.bouncycastle.tls.SignatureAndHashAlgorithm;
@@ -16,11 +14,6 @@ public BcTlsEd25519Signer(BcTlsCrypto crypto, Ed25519PrivateKeyParameters privat
1614
super(crypto, privateKey);
1715
}
1816

19-
public byte[] generateRawSignature(SignatureAndHashAlgorithm algorithm, byte[] hash) throws IOException
20-
{
21-
throw new UnsupportedOperationException();
22-
}
23-
2417
public TlsStreamSigner getStreamSigner(SignatureAndHashAlgorithm algorithm)
2518
{
2619
if (algorithm == null || SignatureScheme.from(algorithm) != SignatureScheme.ed25519)

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

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

3-
import java.io.IOException;
4-
53
import org.bouncycastle.crypto.params.Ed448PrivateKeyParameters;
64
import org.bouncycastle.crypto.signers.Ed448Signer;
75
import org.bouncycastle.tls.SignatureAndHashAlgorithm;
@@ -17,11 +15,6 @@ public BcTlsEd448Signer(BcTlsCrypto crypto, Ed448PrivateKeyParameters privateKey
1715
super(crypto, privateKey);
1816
}
1917

20-
public byte[] generateRawSignature(SignatureAndHashAlgorithm algorithm, byte[] hash) throws IOException
21-
{
22-
throw new UnsupportedOperationException();
23-
}
24-
2518
public TlsStreamSigner getStreamSigner(SignatureAndHashAlgorithm algorithm)
2619
{
2720
if (algorithm == null || SignatureScheme.from(algorithm) != SignatureScheme.ed448)

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

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

3-
import java.io.IOException;
4-
53
import org.bouncycastle.crypto.params.ParametersWithRandom;
64
import org.bouncycastle.pqc.crypto.mldsa.MLDSAPrivateKeyParameters;
75
import org.bouncycastle.pqc.crypto.mldsa.MLDSASigner;
@@ -32,11 +30,6 @@ private BcTlsMLDSASigner(BcTlsCrypto crypto, MLDSAPrivateKeyParameters privateKe
3230
this.signatureScheme = signatureScheme;
3331
}
3432

35-
public byte[] generateRawSignature(SignatureAndHashAlgorithm algorithm, byte[] hash) throws IOException
36-
{
37-
throw new UnsupportedOperationException();
38-
}
39-
4033
public TlsStreamSigner getStreamSigner(SignatureAndHashAlgorithm algorithm)
4134
{
4235
if (algorithm == null || SignatureScheme.from(algorithm) != signatureScheme)

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.bouncycastle.crypto.signers.PSSSigner;
2727
import org.bouncycastle.crypto.signers.RSADigestSigner;
2828
import org.bouncycastle.crypto.util.PublicKeyFactory;
29-
import org.bouncycastle.pqc.crypto.mldsa.MLDSAParameters;
3029
import org.bouncycastle.pqc.crypto.mldsa.MLDSAPublicKeyParameters;
3130
import org.bouncycastle.pqc.crypto.mldsa.MLDSASigner;
3231
import org.bouncycastle.tls.AlertDescription;
@@ -255,16 +254,10 @@ public Tls13Verifier createVerifier(int signatureScheme) throws IOException
255254
case SignatureScheme.DRAFT_mldsa65:
256255
case SignatureScheme.DRAFT_mldsa87:
257256
{
258-
ASN1ObjectIdentifier algorithm = PQCUtil.getMLDSAObjectidentifier(signatureScheme);
259-
validateMLDSA(algorithm);
257+
ASN1ObjectIdentifier mlDsaAlgOid = PQCUtil.getMLDSAObjectidentifier(signatureScheme);
258+
validateMLDSA(mlDsaAlgOid);
260259

261260
MLDSAPublicKeyParameters publicKey = getPubKeyMLDSA();
262-
MLDSAParameters parameters = publicKey.getParameters();
263-
if (!PQCUtil.getMLDSAObjectidentifier(parameters).equals(algorithm))
264-
{
265-
throw new TlsFatalAlert(AlertDescription.certificate_unknown,
266-
"ML-DSA public key not for " + SignatureScheme.getText(signatureScheme));
267-
}
268261

269262
MLDSASigner verifier = new MLDSASigner();
270263
verifier.init(false, publicKey);
@@ -485,10 +478,10 @@ protected boolean supportsKeyUsage(int keyUsageBit)
485478
return true;
486479
}
487480

488-
protected boolean supportsMLDSA(ASN1ObjectIdentifier algorithm)
481+
protected boolean supportsMLDSA(ASN1ObjectIdentifier mlDsaAlgOid)
489482
{
490483
AlgorithmIdentifier pubKeyAlgID = keyInfo.getAlgorithm();
491-
return PQCUtil.supportsMLDSA(pubKeyAlgID, algorithm);
484+
return PQCUtil.supportsMLDSA(pubKeyAlgID, mlDsaAlgOid);
492485
}
493486

494487
protected boolean supportsRSA_PKCS1()
@@ -582,10 +575,10 @@ public void validateKeyUsage(int keyUsageBit)
582575
}
583576
}
584577

585-
protected void validateMLDSA(ASN1ObjectIdentifier algorithm)
578+
protected void validateMLDSA(ASN1ObjectIdentifier mlDsaAlgOid)
586579
throws IOException
587580
{
588-
if (!supportsMLDSA(algorithm))
581+
if (!supportsMLDSA(mlDsaAlgOid))
589582
{
590583
throw new TlsFatalAlert(AlertDescription.certificate_unknown, "No support for ML-DSA signature scheme");
591584
}

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

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

3-
import java.io.IOException;
4-
53
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
64
import org.bouncycastle.crypto.params.ParametersWithID;
75
import org.bouncycastle.crypto.params.ParametersWithRandom;
@@ -22,11 +20,6 @@ public BcTlsSM2Signer(BcTlsCrypto crypto, ECPrivateKeyParameters privateKey, byt
2220
this.identifier = Arrays.clone(identifier);
2321
}
2422

25-
public byte[] generateRawSignature(SignatureAndHashAlgorithm algorithm, byte[] hash) throws IOException
26-
{
27-
throw new UnsupportedOperationException();
28-
}
29-
3023
public TlsStreamSigner getStreamSigner(SignatureAndHashAlgorithm algorithm)
3124
{
3225
if (algorithm == null

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

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

3+
import java.io.IOException;
4+
35
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
46
import org.bouncycastle.tls.SignatureAndHashAlgorithm;
57
import org.bouncycastle.tls.crypto.TlsSigner;
@@ -30,6 +32,11 @@ protected BcTlsSigner(BcTlsCrypto crypto, AsymmetricKeyParameter privateKey)
3032
this.privateKey = privateKey;
3133
}
3234

35+
public byte[] generateRawSignature(SignatureAndHashAlgorithm algorithm, byte[] hash) throws IOException
36+
{
37+
throw new UnsupportedOperationException();
38+
}
39+
3340
public TlsStreamSigner getStreamSigner(SignatureAndHashAlgorithm algorithm)
3441
{
3542
return null;

0 commit comments

Comments
 (0)