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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
use prost::Message;
use tink_proto::KeyTemplate;
pub fn hmac_sha256_prf_key_template() -> KeyTemplate {
create_hmac_prf_key_template(32, tink_proto::HashType::Sha256)
}
pub fn hmac_sha512_prf_key_template() -> KeyTemplate {
create_hmac_prf_key_template(64, tink_proto::HashType::Sha512)
}
pub fn hkdf_sha256_prf_key_template() -> KeyTemplate {
create_hkdf_prf_key_template(32, tink_proto::HashType::Sha256, &[])
}
pub fn aes_cmac_prf_key_template() -> KeyTemplate {
create_aes_cmac_prf_key_template(32)
}
fn create_hmac_prf_key_template(key_size: u32, hash_type: tink_proto::HashType) -> KeyTemplate {
let params = tink_proto::HmacPrfParams {
hash: hash_type as i32,
};
let format = tink_proto::HmacPrfKeyFormat {
params: Some(params),
key_size,
version: super::HMAC_PRF_KEY_VERSION,
};
let mut serialized_format = Vec::new();
format.encode(&mut serialized_format).unwrap();
KeyTemplate {
type_url: super::HMAC_PRF_TYPE_URL.to_string(),
output_prefix_type: tink_proto::OutputPrefixType::Raw as i32,
value: serialized_format,
}
}
fn create_hkdf_prf_key_template(
key_size: u32,
hash_type: tink_proto::HashType,
salt: &[u8],
) -> KeyTemplate {
let params = tink_proto::HkdfPrfParams {
hash: hash_type as i32,
salt: salt.to_vec(),
};
let format = tink_proto::HkdfPrfKeyFormat {
params: Some(params),
key_size,
version: super::HKDF_PRF_KEY_VERSION,
};
let mut serialized_format = Vec::new();
format.encode(&mut serialized_format).unwrap();
KeyTemplate {
type_url: super::HKDF_PRF_TYPE_URL.to_string(),
output_prefix_type: tink_proto::OutputPrefixType::Raw as i32,
value: serialized_format,
}
}
fn create_aes_cmac_prf_key_template(key_size: u32) -> KeyTemplate {
let format = tink_proto::AesCmacPrfKeyFormat {
key_size,
version: super::AES_CMAC_PRF_KEY_VERSION,
};
let mut serialized_format = Vec::new();
format.encode(&mut serialized_format).unwrap();
KeyTemplate {
type_url: super::AES_CMAC_PRF_TYPE_URL.to_string(),
output_prefix_type: tink_proto::OutputPrefixType::Raw as i32,
value: serialized_format,
}
}