1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2020 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
//! # Hash operations
//!
//! See the PSA Crypto API for the format of the different parameters used in this module.
use crateinitialized;
use crateHash;
use crate;
/// Calculate hash of a message
///
/// # Example
///
/// ```
/// use psa_crypto::operations::hash::hash_compute;
/// use psa_crypto::types::algorithm::Hash;
/// # const MESSAGE: [u8; 32] = [
/// # 0x69, 0x3E, 0xDB, 0x1B, 0x22, 0x79, 0x03, 0xF4, 0xC0, 0xBF, 0xD6, 0x91, 0x76, 0x37, 0x84, 0xA2,
/// # 0x94, 0x8E, 0x92, 0x50, 0x35, 0xC2, 0x8C, 0x5C, 0x3C, 0xCA, 0xFE, 0x18, 0xE8, 0x81, 0x37, 0x78,
/// # ];
///
/// psa_crypto::init().unwrap();
/// let hash_alg = Hash::Sha256;
/// let mut hash = vec![0; hash_alg.hash_length()];
/// let size = hash_compute(hash_alg,
/// &MESSAGE,
/// &mut hash).unwrap();
/// ```
/// Calculate the hash of a message and compare it with a reference value
///
/// # Example
///
/// ```
/// use psa_crypto::operations::hash::{hash_compute, hash_compare};
/// use psa_crypto::types::algorithm::Hash;
/// # const MESSAGE: [u8; 3] = [0xb0, 0xbd, 0x69];
/// # const HASH: [u8; 32] = [0x40, 0x96, 0x80, 0x42, 0x21, 0x09, 0x3d, 0xdc, 0xcf, 0xbf, 0x46, 0x83, 0x14, 0x90, 0xea, 0x63, 0xe9, 0xe9, 0x94, 0x14, 0x85, 0x8f, 0x8d, 0x75, 0xff, 0x7f, 0x64, 0x2c, 0x7c, 0xa6, 0x18, 0x03];
/// psa_crypto::init().unwrap();
/// let hash_alg = Hash::Sha256;
/// hash_compare(hash_alg,
/// &MESSAGE,
/// &HASH).unwrap();
/// ```