Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions crypto/src/main/java/org/tron/common/crypto/ECKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,30 +245,6 @@ private static PrivateKey privateKeyFromBigInteger(BigInteger priv) {
}
}

/**
* Utility for compressing an elliptic curve point. Returns the same point if it's already
* compressed. See the ECKey class docs for a discussion of point compression.
*
* @param uncompressed -
* @return -
* @deprecated per-point compression property will be removed in Bouncy Castle
*/
public static ECPoint compressPoint(ECPoint uncompressed) {
return CURVE.getCurve().decodePoint(uncompressed.getEncoded(true));
}

/**
* Utility for decompressing an elliptic curve point. Returns the same point if it's already
* compressed. See the ECKey class docs for a discussion of point compression.
*
* @param compressed -
* @return -
* @deprecated per-point compression property will be removed in Bouncy Castle
*/
public static ECPoint decompressPoint(ECPoint compressed) {
return CURVE.getCurve().decodePoint(compressed.getEncoded(false));
}

/**
* Creates an ECKey given the private key only.
*
Expand Down
12 changes: 12 additions & 0 deletions crypto/src/main/java/org/tron/common/crypto/SignUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,20 @@ public static byte[] signatureToAddress(
byte[] messageHash, SignatureInterface signatureInterface, boolean isECKeyCryptoEngine)
throws SignatureException {
if (isECKeyCryptoEngine) {
if (!(signatureInterface instanceof ECDSASignature)) {
throw new IllegalArgumentException(
"Expected ECDSASignature for ECKey engine, got: "
+ (signatureInterface == null ? "null"
: signatureInterface.getClass().getName()));
}
return ECKey.signatureToAddress(messageHash, (ECDSASignature) signatureInterface);
}
if (!(signatureInterface instanceof SM2Signature)) {
throw new IllegalArgumentException(
"Expected SM2Signature for SM2 engine, got: "
+ (signatureInterface == null ? "null"
: signatureInterface.getClass().getName()));
}
return SM2.signatureToAddress(messageHash, (SM2Signature) signatureInterface);
}
}
36 changes: 6 additions & 30 deletions crypto/src/main/java/org/tron/common/crypto/sm2/SM2.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@
@Slf4j(topic = "crypto")
public class SM2 implements Serializable, SignInterface {

private static BigInteger SM2_N = new BigInteger(
private static final BigInteger SM2_N = new BigInteger(
"FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123", 16);
private static BigInteger SM2_P = new BigInteger(
private static final BigInteger SM2_P = new BigInteger(
"FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF", 16);
private static BigInteger SM2_A = new BigInteger(
private static final BigInteger SM2_A = new BigInteger(
"FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC", 16);
private static BigInteger SM2_B = new BigInteger(
private static final BigInteger SM2_B = new BigInteger(
"28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93", 16);
private static BigInteger SM2_GX = new BigInteger(
private static final BigInteger SM2_GX = new BigInteger(
"32C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7", 16);
private static BigInteger SM2_GY = new BigInteger(
private static final BigInteger SM2_GY = new BigInteger(
"BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0", 16);

private static ECDomainParameters ecc_param;
Expand Down Expand Up @@ -207,30 +207,6 @@ private static ECPoint extractPublicKey(final ECPublicKey ecPublicKey) {
}


/**
* Utility for compressing an elliptic curve point. Returns the same point if it's already
* compressed. See the ECKey class docs for a discussion of point compression.
*
* @param uncompressed -
* @return -
* @deprecated per-point compression property will be removed in Bouncy Castle
*/
public static ECPoint compressPoint(ECPoint uncompressed) {
return ecc_param.getCurve().decodePoint(uncompressed.getEncoded(true));
}

/**
* Utility for decompressing an elliptic curve point. Returns the same point if it's already
* compressed. See the ECKey class docs for a discussion of point compression.
*
* @param compressed -
* @return -
* @deprecated per-point compression property will be removed in Bouncy Castle
*/
public static ECPoint decompressPoint(ECPoint compressed) {
return ecc_param.getCurve().decodePoint(compressed.getEncoded(false));
}

/**
* Creates an SM2 given the private key only.
*
Expand Down
Loading