]> Repositorios git - scryer-prolog.git/commitdiff
ADDED: Support for BLAKE2 algorithms in crypto_data_hash/3.
authorMarkus Triska <[email protected]>
Tue, 19 May 2020 10:22:49 +0000 (12:22 +0200)
committerMarkus Triska <[email protected]>
Tue, 19 May 2020 10:44:10 +0000 (12:44 +0200)
Cargo.toml
src/prolog/lib/crypto.pl
src/prolog/machine/system_calls.rs

index 6e5c657eb8e725c5f314d82312579e47f3752e40..b869277c1433b5a2b04a0f92dc85b992339317ca 100644 (file)
@@ -37,3 +37,4 @@ unicode_reader = "1.0.0"
 ring = "0.16.13"
 ripemd160 = "0.8.0"
 sha3 = "0.8.2"
+blake2 = "0.8.1"
index 9881afba42b24ed2d7fe9785a46e2da2be19388c..0df0dbd7bdd124732c7cff37e7b243f763428bb8 100644 (file)
@@ -158,9 +158,9 @@ crypto_random_byte(B) :- '$crypto_random_byte'(B).
    Options is a list of:
 
      - algorithm(+A)
-       where A is one of ripemd160, sha256, sha384, sha512,
-       sha512_256, sha3_224, sha3_256, sha3_384, sha3_512, or a
-       variable. If A is a variable, then it is unified with the
+       where A is one of ripemd160, sha256, sha384, sha512, sha512_256,
+       sha3_224, sha3_256, sha3_384, sha3_512, blake2s256, blake2b512,
+       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 at the time of this writing.
      - encoding(+Encoding)
@@ -219,6 +219,8 @@ hash_algorithm(sha3_224).
 hash_algorithm(sha3_256).
 hash_algorithm(sha3_384).
 hash_algorithm(sha3_512).
+hash_algorithm(blake2s256).
+hash_algorithm(blake2b512).
 
 
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
index 9643aac5e9017a93c922dcd0d167cabfed9895e5..b3df3c78f7bc10b540ee1ab1aeb096d8705a5667 100644 (file)
@@ -43,6 +43,7 @@ use ring::rand::{SecureRandom, SystemRandom};
 use ring::{digest,hkdf,pbkdf2,aead,error};
 use ripemd160::{Ripemd160, Digest};
 use sha3::{Sha3_224, Sha3_256, Sha3_384, Sha3_512};
+use blake2::{Blake2s, Blake2b};
 
 pub fn get_key() -> KeyEvent {
     let key;
@@ -5236,6 +5237,14 @@ impl MachineState {
                              let mut context = Sha3_512::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 if algorithm_str == "blake2s256" {
+                             let mut context = Blake2s::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 if algorithm_str == "blake2b512" {
+                             let mut context = Blake2b::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 if algorithm_str == "ripemd160" {
                              let mut context = Ripemd160::new();
                              context.input(&bytes);