summaryrefslogtreecommitdiffstats
path: root/src/demo_hash.rs
blob: 115a10fec270441df4bf76e1c5d4dddfdf09098a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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!();
}