win_crypto_ng/
property.rs

1//! Named properties support for CNG objects.
2
3use crate::helpers::{FromBytes, Pod};
4
5use winapi::shared::bcrypt;
6use winapi::shared::minwindef::DWORD;
7use winapi::shared::ntdef::WCHAR;
8
9// Marker trait for any type that can be used as the CNG property.
10pub trait Property {
11    const IDENTIFIER: &'static str;
12    type Value: FromBytes + ?Sized;
13}
14
15/// [**BCRYPT_ALGORITHM_NAME**](https://docs.microsoft.com/windows/win32/seccng/cng-property-identifiers#BCRYPT_ALGORITHM_NAME)
16///
17/// `L"AlgorithmName"`
18///
19/// A null-terminated Unicode string that contains the name of the algorithm.
20pub enum AlgorithmName {}
21impl Property for AlgorithmName {
22    const IDENTIFIER: &'static str = bcrypt::BCRYPT_ALGORITHM_NAME;
23    type Value = [WCHAR];
24}
25
26/// [**BCRYPT_BLOCK_LENGTH**](https://docs.microsoft.com/windows/win32/seccng/cng-property-identifiers#BCRYPT_BLOCK_LENGTH)
27///
28/// `L"BlockLength"`
29///
30/// The size, in bytes, of a cipher block for the algorithm. This property only
31/// applies to block cipher algorithms. This data type is a **DWORD**.
32pub enum BlockLength {}
33impl Property for BlockLength {
34    const IDENTIFIER: &'static str = bcrypt::BCRYPT_BLOCK_LENGTH;
35    type Value = DWORD;
36}
37
38/// [**BCRYPT_CHAINING_MODE**](https://docs.microsoft.com/windows/win32/seccng/cng-property-identifiers#BCRYPT_CHAINING_MODE)
39///
40/// `L"ChainingMode"`
41///
42/// A pointer to a null-terminated Unicode string that represents the chaining
43/// mode of the encryption algorithm. This property can be set on an algorithm
44/// handle or a key handle to one of the following values.
45///
46/// | Identifier            | Value              |  Description                                                                                                                                         |
47/// |-----------------------|--------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|
48/// | BCRYPT_CHAIN_MODE_CBC | L"ChainingModeCBC" | Sets the algorithm's chaining mode to cipher block chaining.                                                                                         |
49/// | BCRYPT_CHAIN_MODE_CCM | L"ChainingModeCCM" | Sets the algorithm's chaining mode to counter with CBC-MAC mode (CCM).Windows Vista:  This value is supported beginning with Windows Vista with SP1. |
50/// | BCRYPT_CHAIN_MODE_CFB | L"ChainingModeCFB" | Sets the algorithm's chaining mode to cipher feedback.                                                                                               |
51/// | BCRYPT_CHAIN_MODE_ECB | L"ChainingModeECB" | Sets the algorithm's chaining mode to electronic codebook.                                                                                           |
52/// | BCRYPT_CHAIN_MODE_GCM | L"ChainingModeGCM" | Sets the algorithm's chaining mode to Galois/counter mode (GCM).Windows Vista:  This value is supported beginning with Windows Vista with SP1.       |
53/// | BCRYPT_CHAIN_MODE_NA  | L"ChainingModeN/A" | The algorithm does not support chaining.                                                                                                             |
54pub enum ChainingMode {}
55impl Property for ChainingMode {
56    const IDENTIFIER: &'static str = bcrypt::BCRYPT_CHAINING_MODE;
57    type Value = [WCHAR];
58}
59
60/// [**BCRYPT_ECC_CURVE_NAME**](https://docs.microsoft.com/en-us/windows/win32/seccng/cng-named-elliptic-curves)
61///
62/// `L"ECCCurveName"`
63///
64/// A pointer to a null-terminated Unicode string that represents a named curve.
65/// This property can be set to specify which named curve should be used
66/// together with the *BCRYPT_ECDSA_ALGORITHM* or *BCRYPT_ECDH_ALGORITHM*.
67///
68/// See [CNG Named Elliptic Curves] or invoke the `certutil -displayEccCurve`
69/// command locally for the list of supported named curves.
70///
71/// [CNG Named Elliptic Curves]: https://docs.microsoft.com/en-us/windows/win32/seccng/cng-named-elliptic-curves
72pub enum EccCurveName {}
73impl Property for EccCurveName {
74    const IDENTIFIER: &'static str = bcrypt::BCRYPT_ECC_CURVE_NAME;
75    type Value = [WCHAR];
76}
77
78/// [**BCRYPT_HASH_LENGTH**](https://docs.microsoft.com/windows/win32/seccng/cng-property-identifiers#BCRYPT_HASH_LENGTH)
79///
80/// `L"HashDigestLength"`
81///
82/// The size, in bytes, of the hash value of a hash provider. This data type is
83/// a **DWORD**.
84pub enum HashLength {}
85impl Property for HashLength {
86    const IDENTIFIER: &'static str = bcrypt::BCRYPT_HASH_LENGTH;
87    type Value = DWORD;
88}
89
90/// [**BCRYPT_INITIALIZATION_VECTOR**](https://docs.microsoft.com/pl-pl/windows/win32/seccng/cng-property-identifiers#BCRYPT_INITIALIZATION_VECTOR)
91///
92/// L"IV"
93///
94/// Contains the initialization vector (IV) for a key. This property only applies to keys.
95pub enum InitializationVector {}
96impl Property for InitializationVector {
97    const IDENTIFIER: &'static str = bcrypt::BCRYPT_INITIALIZATION_VECTOR;
98    type Value = [u8];
99}
100
101/// [**BCRYPT_KEY_LENGTH**](https://docs.microsoft.com/windows/win32/seccng/cng-property-identifiers#BCRYPT_KEY_LENGTH)
102///
103/// `L"KeyLength"`
104///
105/// The size, in bits, of the key value of a symmetric key provider. This data
106/// type is a **DWORD**.
107pub enum KeyLength {}
108impl Property for KeyLength {
109    const IDENTIFIER: &'static str = bcrypt::BCRYPT_KEY_LENGTH;
110    type Value = DWORD;
111}
112
113/// [**BCRYPT_KEY_LENGTHS**](https://docs.microsoft.com/windows/win32/seccng/cng-property-identifiers#BCRYPT_KEY_LENGTHS)
114///
115/// `L"KeyLengths"`
116///
117/// The key lengths that are supported by the algorithm. This property is a
118/// [BCRYPT_KEY_LENGTHS_STRUCT] structure. This property only applies to
119/// algorithms.
120///
121/// [BCRYPT_KEY_LENGTHS_STRUCT]: https://docs.microsoft.com/windows/desktop/api/Bcrypt/ns-bcrypt-bcrypt_key_lengths_struct
122pub enum KeyLengths {}
123impl Property for KeyLengths {
124    const IDENTIFIER: &'static str = bcrypt::BCRYPT_KEY_LENGTHS;
125    type Value = bcrypt::BCRYPT_KEY_LENGTHS_STRUCT;
126}
127
128unsafe impl Pod for bcrypt::BCRYPT_KEY_LENGTHS_STRUCT {}
129
130/// [**BCRYPT_MESSAGE_BLOCK_LENGTH**](https://docs.microsoft.com/windows/win32/seccng/cng-property-identifiers#BCRYPT_MESSAGE_BLOCK_LENGTH)
131///
132/// `L"MessageBlockLength"`
133///
134/// This can be set on any key handle that has the CFB chaining mode set. By
135/// default, this property is set to 1 for 8-bit CFB. Setting it to the block
136/// size in bytes causes full-block CFB to be used. For XTS keys it is used to
137/// set the size, in bytes, of the XTS Data Unit (commonly 512 or 4096).
138pub enum MessageBlockLength {}
139impl Property for MessageBlockLength {
140    const IDENTIFIER: &'static str = bcrypt::BCRYPT_MESSAGE_BLOCK_LENGTH;
141    type Value = DWORD;
142}
143
144/// [**BCRYPT_OBJECT_LENGTH**](https://docs.microsoft.com/windows/win32/seccng/cng-property-identifiers#BCRYPT_OBJECT_LENGTH)
145///
146/// `L"ObjectLength"`
147///
148/// The size, in bytes, of the subobject of a provider. This data type is a
149/// **DWORD**. Currently, the hash and symmetric cipher algorithm providers use
150/// caller-allocated buffers to store their subobjects. For example, the hash
151/// provider requires you to allocate memory for the hash object obtained with
152/// the [`BCryptCreateHash`] function. This property provides the buffer size for a
153/// provider's object so you can allocate memory for the object created by the
154/// provider.
155///
156/// [`BCryptCreateHash`]: <https://docs.microsoft.com/windows/desktop/api/Bcrypt/nf-bcrypt-bcryptcreatehash>
157pub enum ObjectLength {}
158impl Property for ObjectLength {
159    const IDENTIFIER: &'static str = bcrypt::BCRYPT_OBJECT_LENGTH;
160    type Value = DWORD;
161}
162
163/// [**BCRYPT_DSA_PARAMETERS**](https://docs.microsoft.com/windows/win32/seccng/cng-property-identifiers#BCRYPT_DSA_PARAMETERS)
164///
165/// `L"DSAParameters"`
166///
167/// Specifies parameters to use with a DSA key. This property is a
168/// `BCRYPT_DSA_PARAMETER_HEADER` or a `BCRYPT_DSA_PARAMETER_HEADER_V2` structure.
169/// This property can only be set and must be set for the key before the key is
170/// completed.
171///
172/// Windows 8: Beginning with Windows 8, this property can be
173/// a `BCRYPT_DSA_PARAMETER_HEADER_V2` structure. Use this structure if the key
174/// size exceeds 1024 bits and is less than or equal to 3072 bits. If the key
175/// size is greater than or equal to 512 but less than or equal to 1024 bits,
176/// use the `BCRYPT_DSA_PARAMETER_HEADER` structure.
177pub enum DsaParameters {}
178impl Property for DsaParameters {
179    const IDENTIFIER: &'static str = bcrypt::BCRYPT_DSA_PARAMETERS;
180    // FIXME: Can we somehow use unsized unions?... We need to dynamically pass
181    // or receive V1/V2 structs.
182    type Value = [u8];
183}
184
185/// [**BCRYPT_DH_PARAMETERS**](https://docs.microsoft.com/windows/win32/seccng/cng-property-identifiers#BCRYPT_DH_PARAMETERS)
186///
187/// `L"DHParameters"`
188///
189/// Specifies parameters to use with a Diffie-Hellman key. This data type is a
190/// pointer to a `BCRYPT_DH_PARAMETER_HEADER` structure. This property can only be
191/// set and must be set for the key before the key is completed.
192pub enum DhParameters {}
193impl Property for DhParameters {
194    const IDENTIFIER: &'static str = bcrypt::BCRYPT_DH_PARAMETERS;
195    // TODO: Replace with appropriate blob type
196    type Value = [u8];
197}