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
107
108
109
110
use winapi::shared::bcrypt::*;
pub trait Curve {
fn as_curve(&self) -> NamedCurve;
fn key_bits(&self) -> u32;
}
pub struct NistP256;
impl Curve for NistP256 {
fn as_curve(&self) -> NamedCurve {
NamedCurve::NistP256
}
fn key_bits(&self) -> u32 {
256
}
}
pub struct NistP384;
impl Curve for NistP384 {
fn as_curve(&self) -> NamedCurve {
NamedCurve::NistP384
}
fn key_bits(&self) -> u32 {
384
}
}
pub struct NistP521;
impl Curve for NistP521 {
fn as_curve(&self) -> NamedCurve {
NamedCurve::NistP521
}
fn key_bits(&self) -> u32 {
521
}
}
pub struct Curve25519;
impl Curve for Curve25519 {
fn as_curve(&self) -> NamedCurve {
NamedCurve::Curve25519
}
fn key_bits(&self) -> u32 {
255
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum NamedCurve {
NistP256,
NistP384,
NistP521,
Curve25519,
}
impl NamedCurve {
pub fn to_str(self) -> &'static str {
match self {
Self::NistP256 => BCRYPT_ECC_CURVE_NISTP256,
Self::NistP384 => BCRYPT_ECC_CURVE_NISTP384,
Self::NistP521 => BCRYPT_ECC_CURVE_NISTP521,
Self::Curve25519 => BCRYPT_ECC_CURVE_25519,
}
}
pub fn key_bits(self) -> u32 {
match self {
Self::NistP256 => NistP256.key_bits(),
Self::NistP384 => NistP384.key_bits(),
Self::NistP521 => NistP521.key_bits(),
Self::Curve25519 => Curve25519.key_bits(),
}
}
}