Skip to content

Commit 9dd15a0

Browse files
committed
Deprecate redundant ECGOST3410_2012Signer class
1 parent 00d9899 commit 9dd15a0

File tree

5 files changed

+10
-161
lines changed

5 files changed

+10
-161
lines changed
Lines changed: 3 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -1,160 +1,11 @@
11
package org.bouncycastle.crypto.signers;
22

3-
import java.math.BigInteger;
4-
import java.security.SecureRandom;
5-
6-
import org.bouncycastle.crypto.CipherParameters;
7-
import org.bouncycastle.crypto.CryptoServicesRegistrar;
8-
import org.bouncycastle.crypto.DSAExt;
9-
import org.bouncycastle.crypto.params.ECDomainParameters;
10-
import org.bouncycastle.crypto.params.ECKeyParameters;
11-
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
12-
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
13-
import org.bouncycastle.crypto.params.ParametersWithRandom;
14-
import org.bouncycastle.math.ec.ECAlgorithms;
15-
import org.bouncycastle.math.ec.ECConstants;
16-
import org.bouncycastle.math.ec.ECMultiplier;
17-
import org.bouncycastle.math.ec.ECPoint;
18-
import org.bouncycastle.math.ec.FixedPointCombMultiplier;
19-
import org.bouncycastle.util.Arrays;
20-
import org.bouncycastle.util.BigIntegers;
21-
223
/**
234
* GOST R 34.10-2012 Signature Algorithm
5+
*
6+
* @deprecated Use {@link ECGOST3410Signer} instead.
247
*/
258
public class ECGOST3410_2012Signer
26-
implements DSAExt
9+
extends ECGOST3410Signer
2710
{
28-
ECKeyParameters key;
29-
30-
SecureRandom random;
31-
32-
public void init(
33-
boolean forSigning,
34-
CipherParameters param)
35-
{
36-
if (forSigning)
37-
{
38-
if (param instanceof ParametersWithRandom)
39-
{
40-
ParametersWithRandom rParam = (ParametersWithRandom)param;
41-
42-
this.random = rParam.getRandom();
43-
this.key = (ECPrivateKeyParameters)rParam.getParameters();
44-
}
45-
else
46-
{
47-
this.random = CryptoServicesRegistrar.getSecureRandom();
48-
this.key = (ECPrivateKeyParameters)param;
49-
}
50-
}
51-
else
52-
{
53-
this.key = (ECPublicKeyParameters)param;
54-
}
55-
56-
CryptoServicesRegistrar.checkConstraints(Utils.getDefaultProperties("ECGOST3410_2012", key, forSigning));
57-
}
58-
59-
public BigInteger getOrder()
60-
{
61-
return key.getParameters().getN();
62-
}
63-
64-
/**
65-
* generate a signature for the given message using the key we were
66-
* initialised with. For conventional GOST3410 2012 the message should be a GOST3411 2012
67-
* hash of the message of interest.
68-
*
69-
* @param message the message that will be verified later.
70-
*/
71-
public BigInteger[] generateSignature(
72-
byte[] message)
73-
{
74-
byte[] mRev = Arrays.reverse(message); // conversion is little-endian
75-
BigInteger e = new BigInteger(1, mRev);
76-
77-
ECDomainParameters ec = key.getParameters();
78-
BigInteger n = ec.getN();
79-
BigInteger d = ((ECPrivateKeyParameters)key).getD();
80-
81-
BigInteger r, s;
82-
83-
ECMultiplier basePointMultiplier = createBasePointMultiplier();
84-
85-
do // generate s
86-
{
87-
BigInteger k;
88-
do // generate r
89-
{
90-
do
91-
{
92-
k = BigIntegers.createRandomBigInteger(n.bitLength(), random);
93-
}
94-
while (k.equals(ECConstants.ZERO));
95-
96-
ECPoint p = basePointMultiplier.multiply(ec.getG(), k).normalize();
97-
98-
r = p.getAffineXCoord().toBigInteger().mod(n);
99-
}
100-
while (r.equals(ECConstants.ZERO));
101-
102-
s = (k.multiply(e)).add(d.multiply(r)).mod(n);
103-
}
104-
while (s.equals(ECConstants.ZERO));
105-
106-
return new BigInteger[]{ r, s };
107-
}
108-
109-
/**
110-
* return true if the value r and s represent a GOST3410 2012 signature for
111-
* the passed in message (for standard GOST3410 2012 the message should be
112-
* a GOST3411 2012 hash of the real message to be verified).
113-
*/
114-
public boolean verifySignature(
115-
byte[] message,
116-
BigInteger r,
117-
BigInteger s)
118-
{
119-
byte[] mRev = Arrays.reverse(message); // conversion is little-endian
120-
BigInteger e = new BigInteger(1, mRev);
121-
BigInteger n = key.getParameters().getN();
122-
123-
// r in the range [1,n-1]
124-
if (r.compareTo(ECConstants.ONE) < 0 || r.compareTo(n) >= 0)
125-
{
126-
return false;
127-
}
128-
129-
// s in the range [1,n-1]
130-
if (s.compareTo(ECConstants.ONE) < 0 || s.compareTo(n) >= 0)
131-
{
132-
return false;
133-
}
134-
135-
BigInteger v = BigIntegers.modOddInverseVar(n, e);
136-
137-
BigInteger z1 = s.multiply(v).mod(n);
138-
BigInteger z2 = (n.subtract(r)).multiply(v).mod(n);
139-
140-
ECPoint G = key.getParameters().getG(); // P
141-
ECPoint Q = ((ECPublicKeyParameters)key).getQ();
142-
143-
ECPoint point = ECAlgorithms.sumOfTwoMultiplies(G, z1, Q, z2).normalize();
144-
145-
// components must be bogus.
146-
if (point.isInfinity())
147-
{
148-
return false;
149-
}
150-
151-
BigInteger R = point.getAffineXCoord().toBigInteger().mod(n);
152-
153-
return R.equals(r);
154-
}
155-
156-
protected ECMultiplier createBasePointMultiplier()
157-
{
158-
return new FixedPointCombMultiplier();
159-
}
16011
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@
9595
import org.bouncycastle.crypto.signers.DSTU4145Signer;
9696
import org.bouncycastle.crypto.signers.ECDSASigner;
9797
import org.bouncycastle.crypto.signers.ECGOST3410Signer;
98-
import org.bouncycastle.crypto.signers.ECGOST3410_2012Signer;
9998
import org.bouncycastle.crypto.signers.Ed25519Signer;
10099
import org.bouncycastle.crypto.signers.Ed25519ctxSigner;
101100
import org.bouncycastle.crypto.signers.Ed25519phSigner;
@@ -389,7 +388,6 @@ private void testEC()
389388
// first though.
390389
ecSignerTest(kp.getPublic(), kp.getPrivate(), new ECDSASigner());
391390
ecSignerTest(kp.getPublic(), kp.getPrivate(), new DSTU4145Signer());
392-
ecSignerTest(kp.getPublic(), kp.getPrivate(), new ECGOST3410_2012Signer());
393391
ecSignerTest(kp.getPublic(), kp.getPrivate(), new ECGOST3410Signer());
394392
ecSignerTest(kp.getPublic(), kp.getPrivate(), new SM2Signer());
395393

prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/ecgost12/ECGOST2012SignatureSpi256.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
1818
import org.bouncycastle.crypto.params.ECKeyParameters;
1919
import org.bouncycastle.crypto.params.ParametersWithRandom;
20-
import org.bouncycastle.crypto.signers.ECGOST3410_2012Signer;
20+
import org.bouncycastle.crypto.signers.ECGOST3410Signer;
2121
import org.bouncycastle.jcajce.provider.asymmetric.util.ECUtil;
2222
import org.bouncycastle.jce.interfaces.ECKey;
2323
import org.bouncycastle.jce.interfaces.ECPublicKey;
@@ -38,7 +38,7 @@ public class ECGOST2012SignatureSpi256
3838
public ECGOST2012SignatureSpi256()
3939
{
4040
this.digest = new GOST3411_2012_256Digest();
41-
this.signer = new ECGOST3410_2012Signer();
41+
this.signer = new ECGOST3410Signer();
4242
}
4343

4444
protected void engineInitVerify(

prov/src/main/java/org/bouncycastle/jcajce/provider/asymmetric/ecgost12/ECGOST2012SignatureSpi512.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
1818
import org.bouncycastle.crypto.params.ECKeyParameters;
1919
import org.bouncycastle.crypto.params.ParametersWithRandom;
20-
import org.bouncycastle.crypto.signers.ECGOST3410_2012Signer;
20+
import org.bouncycastle.crypto.signers.ECGOST3410Signer;
2121
import org.bouncycastle.jcajce.provider.asymmetric.util.ECUtil;
2222
import org.bouncycastle.jce.interfaces.ECKey;
2323
import org.bouncycastle.jce.interfaces.ECPublicKey;
@@ -40,7 +40,7 @@ public class ECGOST2012SignatureSpi512
4040
public ECGOST2012SignatureSpi512()
4141
{
4242
this.digest = new GOST3411_2012_512Digest();
43-
this.signer = new ECGOST3410_2012Signer();
43+
this.signer = new ECGOST3410Signer();
4444
}
4545

4646
protected void engineInitVerify(

prov/src/test/java/org/bouncycastle/jce/provider/test/GOST3410Test.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import org.bouncycastle.crypto.params.ECDomainParameters;
3939
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
4040
import org.bouncycastle.crypto.params.ParametersWithRandom;
41-
import org.bouncycastle.crypto.signers.ECGOST3410_2012Signer;
41+
import org.bouncycastle.crypto.signers.ECGOST3410Signer;
4242
import org.bouncycastle.jcajce.provider.asymmetric.util.ECUtil;
4343
import org.bouncycastle.jce.X509Principal;
4444
import org.bouncycastle.jce.interfaces.ECPrivateKey;
@@ -425,7 +425,7 @@ private void ecGOST34102012256Test()
425425
PrivateKey sKey = f.generatePrivate(priKey);
426426
PublicKey vKey = f.generatePublic(pubKey);
427427

428-
ECGOST3410_2012Signer signer = new ECGOST3410_2012Signer();
428+
ECGOST3410Signer signer = new ECGOST3410Signer();
429429
CipherParameters param = ECUtil.generatePrivateKeyParameter(sKey);
430430

431431
signer.init(true, new ParametersWithRandom(param, k));
@@ -583,7 +583,7 @@ private void ecGOST34102012512Test()
583583
PublicKey vKey = f.generatePublic(pubKey);
584584

585585

586-
ECGOST3410_2012Signer signer = new ECGOST3410_2012Signer();
586+
ECGOST3410Signer signer = new ECGOST3410Signer();
587587
CipherParameters param = ECUtil.generatePrivateKeyParameter(sKey);
588588

589589
signer.init(true, new ParametersWithRandom(param, k));

0 commit comments

Comments
 (0)