summaryrefslogtreecommitdiffstats
path: root/src/demo_hash.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/demo_hash.rs')
-rw-r--r--src/demo_hash.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/demo_hash.rs b/src/demo_hash.rs
new file mode 100644
index 0000000..115a10f
--- /dev/null
+++ b/src/demo_hash.rs
@@ -0,0 +1,23 @@
+use sha2::Digest;
+
+pub fn hash_bigint(n: usize, i: &num::BigInt) -> Vec<u8>
+{
+ let (_, bytes) = i.to_bytes_be();
+ assert!(bytes.len() <= n);
+
+ let mut hash = sha2::Sha512::new();
+ hash.input(vec![0; n - bytes.len()]);
+ hash.input(bytes);
+
+ hash.result().to_vec()
+}
+
+pub fn show_hash(h: &Vec<u8>)
+{
+ for x in h
+ {
+ print!("{:02x}", x);
+ }
+
+ println!();
+}