Merge pull request #500 from triska/master
ADDED: ripemd160 digest algorithm
This commit is contained in:
@@ -35,3 +35,4 @@ rug = { version = "1.4.0", optional = true }
|
|||||||
rustyline = "6.0.0"
|
rustyline = "6.0.0"
|
||||||
unicode_reader = "1.0.0"
|
unicode_reader = "1.0.0"
|
||||||
ring = "0.16.13"
|
ring = "0.16.13"
|
||||||
|
ripemd160 = "0.8.0"
|
||||||
|
|||||||
@@ -138,7 +138,8 @@ crypto_random_byte(B) :- '$crypto_random_byte'(B).
|
|||||||
|
|
||||||
algorithm(A)
|
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,
|
If A is a variable, then it is unified with the default algorithm,
|
||||||
which is an algorithm that is considered cryptographically secure
|
which is an algorithm that is considered cryptographically secure
|
||||||
@@ -167,6 +168,7 @@ crypto_data_hash(Data, Hash, Options) :-
|
|||||||
'$crypto_data_hash'(Data, HashBytes, A),
|
'$crypto_data_hash'(Data, HashBytes, A),
|
||||||
hex_bytes(Hash, HashBytes).
|
hex_bytes(Hash, HashBytes).
|
||||||
|
|
||||||
|
hash_algorithm(ripemd160).
|
||||||
hash_algorithm(sha256).
|
hash_algorithm(sha256).
|
||||||
hash_algorithm(sha512).
|
hash_algorithm(sha512).
|
||||||
hash_algorithm(sha384).
|
hash_algorithm(sha384).
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ use crate::crossterm::terminal::{enable_raw_mode, disable_raw_mode};
|
|||||||
|
|
||||||
use ring::rand::{SecureRandom, SystemRandom};
|
use ring::rand::{SecureRandom, SystemRandom};
|
||||||
use ring::digest;
|
use ring::digest;
|
||||||
|
use ripemd160::{Ripemd160, Digest};
|
||||||
|
|
||||||
pub fn get_key() -> KeyEvent {
|
pub fn get_key() -> KeyEvent {
|
||||||
let key;
|
let key;
|
||||||
@@ -5255,18 +5256,23 @@ impl MachineState {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let hash = digest::digest(
|
let ints_list =
|
||||||
match algorithm_str {
|
if algorithm_str == "ripemd160" {
|
||||||
"sha256" => { &digest::SHA256 }
|
let mut context = Ripemd160::new();
|
||||||
"sha384" => { &digest::SHA384 }
|
context.input(&bytes);
|
||||||
"sha512" => { &digest::SHA512 }
|
Addr::HeapCell(self.heap.to_list(context.result().as_ref().iter().map(|b| HeapCellValue::Integer(Rc::new(Integer::from(*b))))))
|
||||||
"sha512_256" => { &digest::SHA512_256 }
|
} else {
|
||||||
_ => { unreachable!() }
|
let ints = digest::digest(
|
||||||
},
|
match algorithm_str {
|
||||||
&bytes);
|
"sha256" => { &digest::SHA256 }
|
||||||
|
"sha384" => { &digest::SHA384 }
|
||||||
let ints = hash.as_ref().iter().map(|b| HeapCellValue::Integer(Rc::new(Integer::from(*b))));
|
"sha512" => { &digest::SHA512 }
|
||||||
let ints_list = Addr::HeapCell(self.heap.to_list(ints));
|
"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);
|
self.unify(self[temp_v!(2)], ints_list);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user