Skip to content

Commit

Permalink
feat: support ripemd160 hash
Browse files Browse the repository at this point in the history
  • Loading branch information
djm07073 committed Oct 29, 2024
1 parent 683ed0e commit 56a2091
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions move_stdlib/sources/hash.move
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,31 @@
module std::hash {
native public fun sha2_256(data: vector<u8>): vector<u8>;
native public fun sha3_256(data: vector<u8>): vector<u8>;
native public fun ripemd160(data: vector<u8>): vector<u8>;

#[test]
fun ripemd160_test() {
let inputs = vector[
b"testing",
b"",
];

// From https://www.browserling.com/tools/ripemd160-hash
let outputs = vector[
x"b89ba156b40bed29a5965684b7d244c49a3a769b",
x"9c1185a5c5e9fc54612808977ee8f548b2258d31",
];

let i = 0;
while (i < std::vector::length(&inputs)) {
let input = *std::vector::borrow(&inputs, i);
let hash_expected = *std::vector::borrow(&outputs, i);
let hash = ripemd160(input);

assert!(hash_expected == hash, 1);

i = i + 1;
};
}
}

0 comments on commit 56a2091

Please sign in to comment.