algorithm(A)
- where A is one of sha256, sha384, sha512, sha512_256, or a variable.
+ where A is one of ripemd160, sha256, sha384, sha512, sha512_256,
+ or a variable.
If A is a variable, then it is unified with the default algorithm,
which is an algorithm that is considered cryptographically secure
'$crypto_data_hash'(Data, HashBytes, A),
hex_bytes(Hash, HashBytes).
+hash_algorithm(ripemd160).
hash_algorithm(sha256).
hash_algorithm(sha512).
hash_algorithm(sha384).
use ring::rand::{SecureRandom, SystemRandom};
use ring::digest;
+use ripemd160::{Ripemd160, Digest};
pub fn get_key() -> KeyEvent {
let key;
}
};
- let hash = digest::digest(
- match algorithm_str {
- "sha256" => { &digest::SHA256 }
- "sha384" => { &digest::SHA384 }
- "sha512" => { &digest::SHA512 }
- "sha512_256" => { &digest::SHA512_256 }
- _ => { unreachable!() }
- },
- &bytes);
-
- let ints = hash.as_ref().iter().map(|b| HeapCellValue::Integer(Rc::new(Integer::from(*b))));
- let ints_list = Addr::HeapCell(self.heap.to_list(ints));
+ let ints_list =
+ if algorithm_str == "ripemd160" {
+ let mut context = Ripemd160::new();
+ context.input(&bytes);
+ Addr::HeapCell(self.heap.to_list(context.result().as_ref().iter().map(|b| HeapCellValue::Integer(Rc::new(Integer::from(*b))))))
+ } else {
+ let ints = digest::digest(
+ match algorithm_str {
+ "sha256" => { &digest::SHA256 }
+ "sha384" => { &digest::SHA384 }
+ "sha512" => { &digest::SHA512 }
+ "sha512_256" => { &digest::SHA512_256 }
+ _ => { unreachable!() }
+ },
+ &bytes);
+ Addr::HeapCell(self.heap.to_list(ints.as_ref().iter().map(|b| HeapCellValue::Integer(Rc::new(Integer::from(*b))))))
+ };
self.unify(self[temp_v!(2)], ints_list);
}