Skip to content

Commit

Permalink
Merge pull request tronprotocol#2874 from alberto-zhang/feature/sm2sm3
Browse files Browse the repository at this point in the history
fix base58check for consistency
  • Loading branch information
alberto-zhang authored Jan 14, 2020
2 parents fbc6fe6 + ada03a5 commit 814be8e
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 23 deletions.
6 changes: 4 additions & 2 deletions actuator/src/main/java/org/tron/core/vm/utils/MUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ public static byte[] convertToTronAddress(byte[] address) {
}

public static String encode58Check(byte[] input) {
byte[] hash0 = Sha256Hash.hash(true, input);
byte[] hash1 = Sha256Hash.hash(true, hash0);
byte[] hash0 = Sha256Hash.hash(CommonParameter
.getInstance().isECKeyCryptoEngine(), input);
byte[] hash1 = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(),
hash0);
byte[] inputCheck = new byte[input.length + 4];
System.arraycopy(input, 0, inputCheck, 0, input.length);
System.arraycopy(hash1, 0, inputCheck, input.length, 4);
Expand Down
6 changes: 3 additions & 3 deletions chainbase/src/main/java/org/tron/common/utils/Commons.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ private static byte[] decode58Check(String input) {
}
byte[] decodeData = new byte[decodeCheck.length - 4];
System.arraycopy(decodeCheck, 0, decodeData, 0, decodeData.length);
// shoud be "true" for consistency
byte[] hash0 = Sha256Hash.hash(true,
byte[] hash0 = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(),
decodeData);
byte[] hash1 = Sha256Hash.hash(true, hash0);
byte[] hash1 = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(),
hash0);
if (hash1[0] == decodeCheck[decodeData.length] &&
hash1[1] == decodeCheck[decodeData.length + 1] &&
hash1[2] == decodeCheck[decodeData.length + 2] &&
Expand Down
4 changes: 2 additions & 2 deletions chainbase/src/main/java/org/tron/common/utils/WalletUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public static byte[] generateContractAddress(byte[] transactionRootId, long nonc


public static String encode58Check(byte[] input) {
byte[] hash0 = Sha256Hash.hash(true, input);
byte[] hash1 = Sha256Hash.hash(true, hash0);
byte[] hash0 = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), input);
byte[] hash1 = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), hash0);
byte[] inputCheck = new byte[input.length + 4];
System.arraycopy(input, 0, inputCheck, 0, input.length);
System.arraycopy(hash1, 0, inputCheck, input.length, 4);
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/java/org/tron/common/utils/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public static String createReadableString(byte[] bytes) {
}

public static String encode58Check(byte[] input) {
byte[] hash0 = Sha256Hash.hash(true, input);
byte[] hash1 = Sha256Hash.hash(true, hash0);
byte[] hash0 = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), input);
byte[] hash1 = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), hash0);
byte[] inputCheck = new byte[input.length + 4];
System.arraycopy(input, 0, inputCheck, 0, input.length);
System.arraycopy(hash1, 0, inputCheck, input.length, 4);
Expand Down
4 changes: 2 additions & 2 deletions framework/src/main/java/org/tron/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ public static void setAddressPreFixByte(byte addressPreFixByte) {
}

public static String encode58Check(byte[] input) {
byte[] hash0 = Sha256Hash.hash(true, input);
byte[] hash1 = Sha256Hash.hash(true, hash0);
byte[] hash0 = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), input);
byte[] hash1 = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(), hash0);
byte[] inputCheck = new byte[input.length + 4];
System.arraycopy(input, 0, inputCheck, 0, input.length);
System.arraycopy(hash1, 0, inputCheck, input.length, 4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,10 @@ public static boolean addressValid(byte[] address) {
*/

public static String encode58Check(byte[] input) {
byte[] hash0 = Sha256Hash.hash(true, input);
byte[] hash1 = Sha256Hash.hash(true, hash0);
byte[] hash0 = Sha256Hash.hash(CommonParameter
.getInstance().isECKeyCryptoEngine(), input);
byte[] hash1 = Sha256Hash.hash(CommonParameter
.getInstance().isECKeyCryptoEngine(), hash0);
byte[] inputCheck = new byte[input.length + 4];
System.arraycopy(input, 0, inputCheck, 0, input.length);
System.arraycopy(hash1, 0, inputCheck, input.length, 4);
Expand All @@ -630,8 +632,10 @@ private static byte[] decode58Check(String input) {
}
byte[] decodeData = new byte[decodeCheck.length - 4];
System.arraycopy(decodeCheck, 0, decodeData, 0, decodeData.length);
byte[] hash0 = Sha256Hash.hash(true, decodeData);
byte[] hash1 = Sha256Hash.hash(true, hash0);
byte[] hash0 = Sha256Hash.hash(CommonParameter
.getInstance().isECKeyCryptoEngine(), decodeData);
byte[] hash1 = Sha256Hash.hash(CommonParameter
.getInstance().isECKeyCryptoEngine(), hash0);
if (hash1[0] == decodeCheck[decodeData.length]
&& hash1[1] == decodeCheck[decodeData.length + 1]
&& hash1[2] == decodeCheck[decodeData.length + 2]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,10 @@ private static byte[] decode58Check(String input) {
}
byte[] decodeData = new byte[decodeCheck.length - 4];
System.arraycopy(decodeCheck, 0, decodeData, 0, decodeData.length);
byte[] hash0 = Sha256Hash.hash(true, decodeData);
byte[] hash1 = Sha256Hash.hash(true, hash0);
byte[] hash0 = Sha256Hash.hash(CommonParameter
.getInstance().isECKeyCryptoEngine(), decodeData);
byte[] hash1 = Sha256Hash.hash(CommonParameter
.getInstance().isECKeyCryptoEngine(), hash0);
if (hash1[0] == decodeCheck[decodeData.length]
&& hash1[1] == decodeCheck[decodeData.length + 1]
&& hash1[2] == decodeCheck[decodeData.length + 2]
Expand Down Expand Up @@ -228,8 +230,10 @@ public static boolean addressValid(byte[] address) {
*/

public static String encode58Check(byte[] input) {
byte[] hash0 = Sha256Hash.hash(true, input);
byte[] hash1 = Sha256Hash.hash(true, hash0);
byte[] hash0 = Sha256Hash.hash(CommonParameter
.getInstance().isECKeyCryptoEngine(), input);
byte[] hash1 = Sha256Hash.hash(CommonParameter
.getInstance().isECKeyCryptoEngine(), hash0);
byte[] inputCheck = new byte[input.length + 4];
System.arraycopy(input, 0, inputCheck, 0, input.length);
System.arraycopy(hash1, 0, inputCheck, input.length, 4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6018,8 +6018,10 @@ public static byte[] decode58Check(String input) {
}
byte[] decodeData = new byte[decodeCheck.length - 4];
System.arraycopy(decodeCheck, 0, decodeData, 0, decodeData.length);
byte[] hash0 = Sha256Hash.hash(true, decodeData);
byte[] hash1 = Sha256Hash.hash(true, hash0);
byte[] hash0 = Sha256Hash.hash(CommonParameter.getInstance()
.isECKeyCryptoEngine(), decodeData);
byte[] hash1 = Sha256Hash.hash(CommonParameter.getInstance()
.isECKeyCryptoEngine(), hash0);
if (hash1[0] == decodeCheck[decodeData.length]
&& hash1[1] == decodeCheck[decodeData.length + 1]
&& hash1[2] == decodeCheck[decodeData.length + 2]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3083,8 +3083,10 @@ public static String printKey(Key key) {
* constructor.
*/
public static String encode58Check(byte[] input) {
byte[] hash0 = Sha256Hash.hash(true, input);
byte[] hash1 = Sha256Hash.hash(true, hash0);
byte[] hash0 = Sha256Hash.hash(CommonParameter.getInstance()
.isECKeyCryptoEngine(), input);
byte[] hash1 = Sha256Hash.hash(CommonParameter.getInstance()
.isECKeyCryptoEngine(), hash0);
byte[] inputCheck = new byte[input.length + 4];
System.arraycopy(input, 0, inputCheck, 0, input.length);
System.arraycopy(hash1, 0, inputCheck, input.length, 4);
Expand Down

0 comments on commit 814be8e

Please sign in to comment.