Skip to content

Commit b2e8528

Browse files
committed
rm Hash.sha256 instead of SHA256Hash
1 parent 521fe5f commit b2e8528

2 files changed

Lines changed: 7 additions & 23 deletions

File tree

‎src/main/java/org/tron/common/crypto/Hash.java‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,11 @@ public class Hash {
3636
private static final String HASH_256_ALGORITHM_NAME;
3737
private static final String HASH_512_ALGORITHM_NAME;
3838

39-
private static final MessageDigest sha256digest;
40-
4139
static {
4240
Security.addProvider(TronCastleProvider.getInstance());
4341
CRYPTO_PROVIDER = Security.getProvider("SC");
4442
HASH_256_ALGORITHM_NAME = "TRON-KECCAK-256";
4543
HASH_512_ALGORITHM_NAME = "TRON-KECCAK-512";
46-
try {
47-
sha256digest = MessageDigest.getInstance("SHA-256");
48-
} catch (NoSuchAlgorithmException e) {
49-
logger.error("Can't initialize HashUtils", e);
50-
throw new RuntimeException(e); // Can't happen.
51-
}
52-
53-
}
54-
55-
/**
56-
* @param input - data for hashing
57-
* @return - sha256 hash of the data
58-
*/
59-
public static byte[] sha256(byte[] input) {
60-
return sha256digest.digest(input);
6144
}
6245

6346
public static byte[] sha3(byte[] input) {

‎src/main/java/org/tron/core/Wallet.java‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
import org.tron.api.GrpcAPI.Return.response_code;
3939
import org.tron.api.GrpcAPI.WitnessList;
4040
import org.tron.common.crypto.ECKey;
41-
import org.tron.common.crypto.Hash;
4241
import org.tron.common.overlay.message.Message;
4342
import org.tron.common.utils.Base58;
4443
import org.tron.common.utils.ByteArray;
44+
import org.tron.common.utils.Sha256Hash;
4545
import org.tron.common.utils.Utils;
4646
import org.tron.core.capsule.AccountCapsule;
4747
import org.tron.core.capsule.AssetIssueCapsule;
@@ -140,8 +140,8 @@ public static boolean addressValid(byte[] address) {
140140
}
141141

142142
public static String encode58Check(byte[] input) {
143-
byte[] hash0 = Hash.sha256(input);
144-
byte[] hash1 = Hash.sha256(hash0);
143+
byte[] hash0 = Sha256Hash.of(input).getBytes();
144+
byte[] hash1 = Sha256Hash.of(hash0).getBytes();
145145
byte[] inputCheck = new byte[input.length + 4];
146146
System.arraycopy(input, 0, inputCheck, 0, input.length);
147147
System.arraycopy(hash1, 0, inputCheck, input.length, 4);
@@ -155,8 +155,8 @@ private static byte[] decode58Check(String input) {
155155
}
156156
byte[] decodeData = new byte[decodeCheck.length - 4];
157157
System.arraycopy(decodeCheck, 0, decodeData, 0, decodeData.length);
158-
byte[] hash0 = Hash.sha256(decodeData);
159-
byte[] hash1 = Hash.sha256(hash0);
158+
byte[] hash0 = Sha256Hash.of(decodeData).getBytes();
159+
byte[] hash1 = Sha256Hash.of(hash0).getBytes();
160160
if (hash1[0] == decodeCheck[decodeData.length] &&
161161
hash1[1] == decodeCheck[decodeData.length + 1] &&
162162
hash1[2] == decodeCheck[decodeData.length + 2] &&
@@ -439,7 +439,8 @@ public Transaction getTransactionById(ByteString transactionId) {
439439
try {
440440
transactionCapsule = dbManager.getTransactionStore()
441441
.get(transactionId.toByteArray());
442-
} catch (BadItemException e) {}
442+
} catch (BadItemException e) {
443+
}
443444
if (transactionCapsule != null) {
444445
return transactionCapsule.getInstance();
445446
}

0 commit comments

Comments
 (0)