-
Notifications
You must be signed in to change notification settings - Fork 167
Expand file tree
/
Copy pathecdsa.rs
More file actions
77 lines (71 loc) · 2.02 KB
/
Copy pathecdsa.rs
File metadata and controls
77 lines (71 loc) · 2.02 KB
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
use crate::wycheproof;
use crate::wycheproof::{case_result, description, hex_string};
use crate::TestInfo;
use serde::Deserialize;
#[derive(Debug, Deserialize)]
struct TestSuite {
#[serde(flatten)]
pub suite: wycheproof::Suite,
#[serde(rename = "testGroups")]
pub test_groups: Vec<TestGroup>,
}
#[derive(Debug, Deserialize)]
struct TestGroup {
#[allow(dead_code)]
#[serde(flatten)]
pub group: wycheproof::Group,
#[allow(dead_code)]
#[serde(rename = "keyDer")]
pub key_der: String,
#[allow(dead_code)]
#[serde(rename = "keyPem")]
pub key_pem: String,
pub sha: String,
pub key: TestKey,
pub tests: Vec<TestCase>,
}
#[derive(Debug, Deserialize)]
struct TestKey {
curve: String,
#[allow(dead_code)]
#[serde(rename = "type")]
key_type: String,
#[serde(with = "hex_string")]
wx: Vec<u8>,
#[serde(with = "hex_string")]
wy: Vec<u8>,
}
#[derive(Debug, Deserialize)]
struct TestCase {
#[serde(flatten)]
pub case: wycheproof::Case,
#[serde(with = "hex_string")]
pub msg: Vec<u8>,
#[serde(with = "hex_string")]
pub sig: Vec<u8>,
}
pub fn generator(data: &[u8], algorithm: &str, _key_size: u32) -> Vec<TestInfo> {
let suite: TestSuite = serde_json::from_slice(data).unwrap();
let mut infos = vec![];
for g in &suite.test_groups {
assert_eq!(g.key.curve, algorithm);
assert_eq!(g.sha, "SHA-256");
for tc in &g.tests {
if tc.case.result == crate::wycheproof::CaseResult::Acceptable {
// TODO: figure out what to do with test cases that pass but which have weak params
continue;
}
infos.push(TestInfo {
data: vec![
g.key.wx.clone(),
g.key.wy.clone(),
tc.msg.clone(),
tc.sig.clone(),
vec![case_result(&tc.case)],
],
desc: description(&suite.suite, &tc.case),
});
}
}
infos
}