Skip to content

Commit 86f19ed

Browse files
SeungMin Leesgkim126
authored andcommitted
Replace hash crates to other crates
1 parent 33e8927 commit 86f19ed

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ ring = "0.14.6"
99
quick-error = "1.2"
1010
rust-crypto = "0.2.36"
1111
primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.4" }
12+
sha-1 = "0.8.2"
13+
sha2 = "0.8.1"
14+
sha3 = "0.8.2"
15+
ripemd160 = "0.8.0"
16+
digest = "0.8"
1217

1318
[dev-dependencies]
1419
rand = "0.6.1"

src/hash.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,55 +14,55 @@
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

17+
use digest::Digest;
1718
use primitives::{H160, H256};
18-
use rcrypto::digest::Digest;
19-
use rcrypto::ripemd160::Ripemd160;
20-
use rcrypto::sha1::Sha1;
21-
use rcrypto::sha2::Sha256;
22-
use rcrypto::sha3::Sha3;
19+
use ripemd160::Ripemd160;
20+
use sha1::Sha1;
21+
use sha2::Sha256;
22+
use sha3::Keccak256;
2323

2424
/// RIPEMD160
2525
#[inline]
2626
pub fn ripemd160<T: AsRef<[u8]>>(s: T) -> H160 {
2727
let input = s.as_ref();
28-
let mut result = H160::default();
2928
let mut hasher = Ripemd160::new();
3029
hasher.input(input);
31-
hasher.result(&mut *result);
32-
result
30+
let mut array: [u8; 20] = [0; 20];
31+
array.copy_from_slice(&hasher.result());
32+
H160(array)
3333
}
3434

3535
/// SHA-1
3636
#[inline]
3737
pub fn sha1<T: AsRef<[u8]>>(s: T) -> H160 {
3838
let input = s.as_ref();
39-
let mut result = H160::default();
4039
let mut hasher = Sha1::new();
4140
hasher.input(input);
42-
hasher.result(&mut *result);
43-
result
41+
let mut array: [u8; 20] = [0; 20];
42+
array.copy_from_slice(&hasher.result());
43+
H160(array)
4444
}
4545

4646
/// SHA-256
4747
#[inline]
4848
pub fn sha256<T: AsRef<[u8]>>(s: T) -> H256 {
4949
let input = s.as_ref();
50-
let mut result = H256::default();
5150
let mut hasher = Sha256::new();
5251
hasher.input(input);
53-
hasher.result(&mut *result);
54-
result
52+
let mut array: [u8; 32] = [0; 32];
53+
array.copy_from_slice(&hasher.result());
54+
H256(array)
5555
}
5656

5757
/// KECCAK256
5858
#[inline]
5959
pub fn keccak256<T: AsRef<[u8]>>(s: T) -> H256 {
6060
let input = s.as_ref();
61-
let mut result = H256::default();
62-
let mut hasher = Sha3::keccak256();
61+
let mut hasher = Keccak256::new();
6362
hasher.input(input);
64-
hasher.result(&mut result);
65-
result
63+
let mut array: [u8; 32] = [0; 32];
64+
array.copy_from_slice(&hasher.result());
65+
H256(array)
6666
}
6767

6868
#[cfg(test)]

0 commit comments

Comments
 (0)