Skip to content

Commit

Permalink
Merge pull request #445 from tronprotocol/release_4.3.0
Browse files Browse the repository at this point in the history
merge the release 4.3.0 into master branch
  • Loading branch information
renchenchang committed Aug 2, 2021
2 parents 9f211a9 + 8ca7ea2 commit 939f517
Show file tree
Hide file tree
Showing 22 changed files with 936 additions and 955 deletions.
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ task wrapper(type: Wrapper) {
}

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'junit', name: 'junit', version: '4.12'
compile group: 'com.beust', name: 'jcommander', version: '1.72'
//compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
compile group: 'org.slf4j', name: 'jcl-over-slf4j', version: '1.7.25'
Expand All @@ -76,8 +76,7 @@ dependencies {
compile group: 'io.grpc', name: 'grpc-stub', version: '1.9.0'

compile group: 'com.googlecode.protobuf-java-format', name: 'protobuf-java-format', version: '1.4'
compile "com.madgag.spongycastle:core:1.58.0.0"
compile "com.madgag.spongycastle:prov:1.58.0.0"
compile group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.69'
compile group: 'com.typesafe', name: 'config', version: '1.3.2'
compile "com.google.code.findbugs:jsr305:3.0.0"
compile "org.springframework.cloud:spring-cloud-starter-consul-discovery:${springCloudConsulVersion}"
Expand Down
161 changes: 88 additions & 73 deletions src/main/java/org/tron/common/crypto/ECKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,63 @@
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/

import lombok.extern.slf4j.Slf4j;
import org.spongycastle.asn1.ASN1InputStream;
import org.spongycastle.asn1.ASN1Integer;
import org.spongycastle.asn1.DLSequence;
import org.spongycastle.asn1.sec.SECNamedCurves;
import org.spongycastle.asn1.x9.X9ECParameters;
import org.spongycastle.asn1.x9.X9IntegerConverter;
import org.spongycastle.crypto.agreement.ECDHBasicAgreement;
import org.spongycastle.crypto.digests.SHA256Digest;
import org.spongycastle.crypto.engines.AESEngine;
import org.spongycastle.crypto.modes.SICBlockCipher;
import org.spongycastle.crypto.params.*;
import org.spongycastle.crypto.signers.ECDSASigner;
import org.spongycastle.crypto.signers.HMacDSAKCalculator;
import org.spongycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey;
import org.spongycastle.jcajce.provider.asymmetric.ec.BCECPublicKey;
import org.spongycastle.jce.spec.ECParameterSpec;
import org.spongycastle.jce.spec.ECPrivateKeySpec;
import org.spongycastle.jce.spec.ECPublicKeySpec;
import org.spongycastle.math.ec.ECAlgorithms;
import org.spongycastle.math.ec.ECCurve;
import org.spongycastle.math.ec.ECPoint;
import org.spongycastle.util.BigIntegers;
import org.spongycastle.util.encoders.Base64;
import org.spongycastle.util.encoders.Hex;
import org.tron.common.crypto.cryptohash.Keccak256;
import org.tron.common.crypto.jce.*;
import org.tron.common.utils.BIUtil;
import org.tron.common.utils.ByteUtil;
import org.tron.common.utils.Hash;

import javax.annotation.Nullable;
import javax.crypto.KeyAgreement;
import java.io.IOException;
import java.io.Serializable;
import java.math.BigInteger;
import java.nio.charset.Charset;
import java.security.*;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Signature;
import java.security.SignatureException;
import java.security.interfaces.ECPrivateKey;
import java.security.interfaces.ECPublicKey;
import java.security.spec.InvalidKeySpecException;
import java.util.Arrays;
import javax.annotation.Nullable;
import javax.crypto.KeyAgreement;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.DLSequence;
import org.bouncycastle.asn1.sec.SECNamedCurves;
import org.bouncycastle.asn1.x9.X9ECParameters;
import org.bouncycastle.asn1.x9.X9IntegerConverter;
import org.bouncycastle.crypto.agreement.ECDHBasicAgreement;
import org.bouncycastle.crypto.digests.SHA256Digest;
import org.bouncycastle.crypto.engines.AESEngine;
import org.bouncycastle.crypto.modes.SICBlockCipher;
import org.bouncycastle.crypto.params.ECDomainParameters;
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.crypto.params.ParametersWithIV;
import org.bouncycastle.crypto.signers.ECDSASigner;
import org.bouncycastle.crypto.signers.HMacDSAKCalculator;
import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey;
import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey;
import org.bouncycastle.jce.spec.ECParameterSpec;
import org.bouncycastle.jce.spec.ECPrivateKeySpec;
import org.bouncycastle.jce.spec.ECPublicKeySpec;
import org.bouncycastle.math.ec.ECAlgorithms;
import org.bouncycastle.math.ec.ECCurve;
import org.bouncycastle.math.ec.ECPoint;
import org.bouncycastle.util.BigIntegers;
import org.bouncycastle.util.encoders.Base64;
import org.bouncycastle.util.encoders.Hex;
import org.tron.common.crypto.cryptohash.Keccak256;
import org.tron.common.crypto.jce.ECKeyAgreement;
import org.tron.common.crypto.jce.ECKeyFactory;
import org.tron.common.crypto.jce.ECKeyPairGenerator;
import org.tron.common.crypto.jce.ECSignatureFactory;
import org.tron.common.crypto.jce.TronCastleProvider;
import org.tron.common.utils.BIUtil;
import org.tron.common.utils.ByteUtil;
import org.tron.common.utils.Hash;

@Slf4j(topic = "crypto")
public class ECKey implements Serializable, SignInterface {
Expand Down Expand Up @@ -680,30 +695,30 @@ private static void check(boolean test, String message) {
}
}

/**
* Returns a copy of this key, but with the public point represented in uncompressed form.
* Normally you would never need this: it's for specialised scenarios or when backwards
* compatibility in encoded form is necessary.
*
* @return -
* @deprecated per-point compression property will be removed in Bouncy Castle
*/
public ECKey decompress() {
if (!pub.isCompressed()) {
return this;
} else {
return new ECKey(this.provider, this.privKey, decompressPoint(pub));
}
}

/** @deprecated per-point compression property will be removed in Bouncy Castle */
public ECKey compress() {
if (pub.isCompressed()) {
return this;
} else {
return new ECKey(this.provider, this.privKey, compressPoint(pub));
}
}
// /**
// * Returns a copy of this key, but with the public point represented in uncompressed form.
// * Normally you would never need this: it's for specialised scenarios or when backwards
// * compatibility in encoded form is necessary.
// *
// * @return -
// * @deprecated per-point compression property will be removed in Bouncy Castle
// */
// public ECKey decompress() {
// if (!pub.isCompressed()) {
// return this;
// } else {
// return new ECKey(this.provider, this.privKey, decompressPoint(pub));
// }
// }
//
// /** @deprecated per-point compression property will be removed in Bouncy Castle */
// public ECKey compress() {
// if (pub.isCompressed()) {
// return this;
// } else {
// return new ECKey(this.provider, this.privKey, compressPoint(pub));
// }
// }

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

/**
* Returns whether this key is using the compressed form or not. Compressed pubkeys are only 33
* bytes, not 64.
*
* @return -
*/
public boolean isCompressed() {
return pub.isCompressed();
}

public String toString() {
StringBuilder b = new StringBuilder();
b.append("pub:").append(Hex.toHexString(pub.getEncoded(false)));
return b.toString();
}
// /**
// * Returns whether this key is using the compressed form or not. Compressed pubkeys are only 33
// * bytes, not 64.
// *
// * @return -
// */
// public boolean isCompressed() {
// return pub.isCompressed();
// }
//
// public String toString() {
// StringBuilder b = new StringBuilder();
// b.append("pub:").append(Hex.toHexString(pub.getEncoded(false)));
// return b.toString();
// }

/**
* Produce a string rendering of the ECKey INCLUDING the private key. Unless you absolutely need
Expand Down
Loading

0 comments on commit 939f517

Please sign in to comment.