Skip to content

Commit 6e86007

Browse files
committed
update the bouncy castle module
1 parent 676a278 commit 6e86007

File tree

16 files changed

+790
-770
lines changed

16 files changed

+790
-770
lines changed

build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ dependencies {
7676
compile group: 'io.grpc', name: 'grpc-stub', version: '1.9.0'
7777

7878
compile group: 'com.googlecode.protobuf-java-format', name: 'protobuf-java-format', version: '1.4'
79-
compile "com.madgag.spongycastle:core:1.58.0.0"
80-
compile "com.madgag.spongycastle:prov:1.58.0.0"
79+
// compile "com.madgag.spongycastle:core:1.58.0.0"
80+
// compile "com.madgag.spongycastle:prov:1.58.0.0"
81+
compile group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.68'
8182
compile group: 'com.typesafe', name: 'config', version: '1.3.2'
8283
compile "com.google.code.findbugs:jsr305:3.0.0"
8384
compile "org.springframework.cloud:spring-cloud-starter-consul-discovery:${springCloudConsulVersion}"

src/main/java/org/tron/common/crypto/ECKey.java

Lines changed: 88 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,63 @@
1717
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
1818
*/
1919

20-
import lombok.extern.slf4j.Slf4j;
21-
import org.spongycastle.asn1.ASN1InputStream;
22-
import org.spongycastle.asn1.ASN1Integer;
23-
import org.spongycastle.asn1.DLSequence;
24-
import org.spongycastle.asn1.sec.SECNamedCurves;
25-
import org.spongycastle.asn1.x9.X9ECParameters;
26-
import org.spongycastle.asn1.x9.X9IntegerConverter;
27-
import org.spongycastle.crypto.agreement.ECDHBasicAgreement;
28-
import org.spongycastle.crypto.digests.SHA256Digest;
29-
import org.spongycastle.crypto.engines.AESEngine;
30-
import org.spongycastle.crypto.modes.SICBlockCipher;
31-
import org.spongycastle.crypto.params.*;
32-
import org.spongycastle.crypto.signers.ECDSASigner;
33-
import org.spongycastle.crypto.signers.HMacDSAKCalculator;
34-
import org.spongycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey;
35-
import org.spongycastle.jcajce.provider.asymmetric.ec.BCECPublicKey;
36-
import org.spongycastle.jce.spec.ECParameterSpec;
37-
import org.spongycastle.jce.spec.ECPrivateKeySpec;
38-
import org.spongycastle.jce.spec.ECPublicKeySpec;
39-
import org.spongycastle.math.ec.ECAlgorithms;
40-
import org.spongycastle.math.ec.ECCurve;
41-
import org.spongycastle.math.ec.ECPoint;
42-
import org.spongycastle.util.BigIntegers;
43-
import org.spongycastle.util.encoders.Base64;
44-
import org.spongycastle.util.encoders.Hex;
45-
import org.tron.common.crypto.cryptohash.Keccak256;
46-
import org.tron.common.crypto.jce.*;
47-
import org.tron.common.utils.BIUtil;
48-
import org.tron.common.utils.ByteUtil;
49-
import org.tron.common.utils.Hash;
50-
51-
import javax.annotation.Nullable;
52-
import javax.crypto.KeyAgreement;
5320
import java.io.IOException;
5421
import java.io.Serializable;
5522
import java.math.BigInteger;
5623
import java.nio.charset.Charset;
57-
import java.security.*;
24+
import java.security.InvalidKeyException;
25+
import java.security.KeyPair;
26+
import java.security.KeyPairGenerator;
27+
import java.security.PrivateKey;
28+
import java.security.Provider;
29+
import java.security.PublicKey;
30+
import java.security.SecureRandom;
31+
import java.security.Signature;
32+
import java.security.SignatureException;
5833
import java.security.interfaces.ECPrivateKey;
5934
import java.security.interfaces.ECPublicKey;
6035
import java.security.spec.InvalidKeySpecException;
6136
import java.util.Arrays;
37+
import javax.annotation.Nullable;
38+
import javax.crypto.KeyAgreement;
39+
import lombok.extern.slf4j.Slf4j;
40+
import org.bouncycastle.asn1.ASN1InputStream;
41+
import org.bouncycastle.asn1.ASN1Integer;
42+
import org.bouncycastle.asn1.DLSequence;
43+
import org.bouncycastle.asn1.sec.SECNamedCurves;
44+
import org.bouncycastle.asn1.x9.X9ECParameters;
45+
import org.bouncycastle.asn1.x9.X9IntegerConverter;
46+
import org.bouncycastle.crypto.agreement.ECDHBasicAgreement;
47+
import org.bouncycastle.crypto.digests.SHA256Digest;
48+
import org.bouncycastle.crypto.engines.AESEngine;
49+
import org.bouncycastle.crypto.modes.SICBlockCipher;
50+
import org.bouncycastle.crypto.params.ECDomainParameters;
51+
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
52+
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
53+
import org.bouncycastle.crypto.params.KeyParameter;
54+
import org.bouncycastle.crypto.params.ParametersWithIV;
55+
import org.bouncycastle.crypto.signers.ECDSASigner;
56+
import org.bouncycastle.crypto.signers.HMacDSAKCalculator;
57+
import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey;
58+
import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey;
59+
import org.bouncycastle.jce.spec.ECParameterSpec;
60+
import org.bouncycastle.jce.spec.ECPrivateKeySpec;
61+
import org.bouncycastle.jce.spec.ECPublicKeySpec;
62+
import org.bouncycastle.math.ec.ECAlgorithms;
63+
import org.bouncycastle.math.ec.ECCurve;
64+
import org.bouncycastle.math.ec.ECPoint;
65+
import org.bouncycastle.util.BigIntegers;
66+
import org.bouncycastle.util.encoders.Base64;
67+
import org.bouncycastle.util.encoders.Hex;
68+
import org.tron.common.crypto.cryptohash.Keccak256;
69+
import org.tron.common.crypto.jce.ECKeyAgreement;
70+
import org.tron.common.crypto.jce.ECKeyFactory;
71+
import org.tron.common.crypto.jce.ECKeyPairGenerator;
72+
import org.tron.common.crypto.jce.ECSignatureFactory;
73+
import org.tron.common.crypto.jce.TronCastleProvider;
74+
import org.tron.common.utils.BIUtil;
75+
import org.tron.common.utils.ByteUtil;
76+
import org.tron.common.utils.Hash;
6277

6378
@Slf4j(topic = "crypto")
6479
public class ECKey implements Serializable, SignInterface {
@@ -680,30 +695,30 @@ private static void check(boolean test, String message) {
680695
}
681696
}
682697

683-
/**
684-
* Returns a copy of this key, but with the public point represented in uncompressed form.
685-
* Normally you would never need this: it's for specialised scenarios or when backwards
686-
* compatibility in encoded form is necessary.
687-
*
688-
* @return -
689-
* @deprecated per-point compression property will be removed in Bouncy Castle
690-
*/
691-
public ECKey decompress() {
692-
if (!pub.isCompressed()) {
693-
return this;
694-
} else {
695-
return new ECKey(this.provider, this.privKey, decompressPoint(pub));
696-
}
697-
}
698-
699-
/** @deprecated per-point compression property will be removed in Bouncy Castle */
700-
public ECKey compress() {
701-
if (pub.isCompressed()) {
702-
return this;
703-
} else {
704-
return new ECKey(this.provider, this.privKey, compressPoint(pub));
705-
}
706-
}
698+
// /**
699+
// * Returns a copy of this key, but with the public point represented in uncompressed form.
700+
// * Normally you would never need this: it's for specialised scenarios or when backwards
701+
// * compatibility in encoded form is necessary.
702+
// *
703+
// * @return -
704+
// * @deprecated per-point compression property will be removed in Bouncy Castle
705+
// */
706+
// public ECKey decompress() {
707+
// if (!pub.isCompressed()) {
708+
// return this;
709+
// } else {
710+
// return new ECKey(this.provider, this.privKey, decompressPoint(pub));
711+
// }
712+
// }
713+
//
714+
// /** @deprecated per-point compression property will be removed in Bouncy Castle */
715+
// public ECKey compress() {
716+
// if (pub.isCompressed()) {
717+
// return this;
718+
// } else {
719+
// return new ECKey(this.provider, this.privKey, compressPoint(pub));
720+
// }
721+
// }
707722

708723
/**
709724
* Returns true if this key doesn't have access to private key bytes. This may be because it was
@@ -809,21 +824,21 @@ public BigInteger getPrivKey() {
809824
}
810825
}
811826

812-
/**
813-
* Returns whether this key is using the compressed form or not. Compressed pubkeys are only 33
814-
* bytes, not 64.
815-
*
816-
* @return -
817-
*/
818-
public boolean isCompressed() {
819-
return pub.isCompressed();
820-
}
821-
822-
public String toString() {
823-
StringBuilder b = new StringBuilder();
824-
b.append("pub:").append(Hex.toHexString(pub.getEncoded(false)));
825-
return b.toString();
826-
}
827+
// /**
828+
// * Returns whether this key is using the compressed form or not. Compressed pubkeys are only 33
829+
// * bytes, not 64.
830+
// *
831+
// * @return -
832+
// */
833+
// public boolean isCompressed() {
834+
// return pub.isCompressed();
835+
// }
836+
//
837+
// public String toString() {
838+
// StringBuilder b = new StringBuilder();
839+
// b.append("pub:").append(Hex.toHexString(pub.getEncoded(false)));
840+
// return b.toString();
841+
// }
827842

828843
/**
829844
* Produce a string rendering of the ECKey INCLUDING the private key. Unless you absolutely need

src/main/java/org/tron/common/crypto/SM3Hash.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,20 @@
1717
* limitations under the License.
1818
*/
1919

20+
import static com.google.common.base.Preconditions.checkArgument;
21+
2022
import com.google.common.io.ByteStreams;
2123
import com.google.common.primitives.Ints;
2224
import com.google.common.primitives.Longs;
2325
import com.google.protobuf.ByteString;
24-
import org.spongycastle.crypto.digests.SM3Digest;
25-
import org.tron.common.utils.ByteArray;
26-
2726
import java.io.File;
2827
import java.io.FileInputStream;
2928
import java.io.IOException;
3029
import java.io.Serializable;
3130
import java.math.BigInteger;
3231
import java.util.Arrays;
33-
34-
import static com.google.common.base.Preconditions.checkArgument;
32+
import org.bouncycastle.crypto.digests.SM3Digest;
33+
import org.tron.common.utils.ByteArray;
3534

3635
/**
3736
* A SM3Hash just wraps a byte[] so that equals and hashcode work correctly, allowing it to be used

src/main/java/org/tron/common/crypto/Sha256Sm3Hash.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import com.google.common.primitives.Longs;
2525
import com.google.protobuf.ByteString;
2626
import com.typesafe.config.Config;
27-
import org.spongycastle.crypto.digests.SM3Digest;
28-
2927
import java.io.File;
3028
import java.io.FileInputStream;
3129
import java.io.IOException;
@@ -34,6 +32,7 @@
3432
import java.security.MessageDigest;
3533
import java.security.NoSuchAlgorithmException;
3634
import java.util.Arrays;
35+
import org.bouncycastle.crypto.digests.SM3Digest;
3736
import org.tron.common.utils.ByteArray;
3837
import org.tron.core.config.Configuration;
3938

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,45 @@
1-
/*
2-
* Copyright (c) [2016] [ <ether.camp> ]
3-
* This file is part of the ethereumJ library.
4-
*
5-
* The ethereumJ library is free software: you can redistribute it and/or modify
6-
* it under the terms of the GNU Lesser General Public License as published by
7-
* the Free Software Foundation, either version 3 of the License, or
8-
* (at your option) any later version.
9-
*
10-
* The ethereumJ library is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
* GNU Lesser General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU Lesser General Public License
16-
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
17-
*/
18-
19-
package org.tron.common.crypto.jce;
20-
21-
import org.spongycastle.jce.provider.BouncyCastleProvider;
22-
23-
import java.security.Provider;
24-
import java.security.Security;
25-
26-
public final class TronCastleProvider {
27-
28-
public static Provider getInstance() {
29-
return Holder.INSTANCE;
30-
}
31-
32-
private static class Holder {
33-
private static final Provider INSTANCE;
34-
35-
static {
36-
Provider p = Security.getProvider("SC");
37-
38-
INSTANCE = (p != null) ? p : new BouncyCastleProvider();
39-
40-
INSTANCE.put("MessageDigest.TRON-KECCAK-256", "org.tron.common.crypto" +
41-
".cryptohash.Keccak256");
42-
INSTANCE.put("MessageDigest.TRON-KECCAK-512", "org.tron.common.crypto" +
43-
".cryptohash.Keccak512");
44-
}
45-
}
46-
}
1+
/*
2+
* Copyright (c) [2016] [ <ether.camp> ]
3+
* This file is part of the ethereumJ library.
4+
*
5+
* The ethereumJ library is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* The ethereumJ library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
package org.tron.common.crypto.jce;
20+
21+
import java.security.Provider;
22+
import java.security.Security;
23+
import org.bouncycastle.jce.provider.BouncyCastleProvider;
24+
25+
public final class TronCastleProvider {
26+
27+
public static Provider getInstance() {
28+
return Holder.INSTANCE;
29+
}
30+
31+
private static class Holder {
32+
private static final Provider INSTANCE;
33+
34+
static {
35+
Provider p = Security.getProvider("BC");
36+
37+
INSTANCE = (p != null) ? p : new BouncyCastleProvider();
38+
39+
INSTANCE.put("MessageDigest.TRON-KECCAK-256", "org.tron.common.crypto" +
40+
".cryptohash.Keccak256");
41+
INSTANCE.put("MessageDigest.TRON-KECCAK-512", "org.tron.common.crypto" +
42+
".cryptohash.Keccak512");
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)