blob: 07c3d64f61f0f7166a436628564404e30df409f5 [file] [log] [blame]
Hasini Gunasingheb7142972021-02-20 03:11:27 +00001// Copyright 2021, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! This module provides convenience functions for keystore2 logging.
16use crate::error::get_error_code;
Pavel Grafov94243c22021-04-21 18:03:11 +010017use crate::globals::{DB, LOGS_HANDLER};
Hasini Gunasingheb7142972021-02-20 03:11:27 +000018use crate::key_parameter::KeyParameterValue as KsKeyParamValue;
Hasini Gunasinghe0aba68a2021-03-19 00:43:52 +000019use crate::operation::Outcome;
Hasini Gunasingheb7142972021-02-20 03:11:27 +000020use android_hardware_security_keymint::aidl::android::hardware::security::keymint::{
21 Algorithm::Algorithm, BlockMode::BlockMode, Digest::Digest, EcCurve::EcCurve,
22 HardwareAuthenticatorType::HardwareAuthenticatorType, KeyOrigin::KeyOrigin,
23 KeyParameter::KeyParameter, KeyPurpose::KeyPurpose, PaddingMode::PaddingMode,
Hasini Gunasinghe9617fd92021-04-01 22:27:07 +000024 SecurityLevel::SecurityLevel,
Hasini Gunasingheb7142972021-02-20 03:11:27 +000025};
Seth Moore78c091f2021-04-09 21:38:30 +000026use anyhow::Result;
27use keystore2_system_property::PropertyWatcher;
28use statslog_rust::{
29 keystore2_key_creation_event_reported::{
30 Algorithm as StatsdAlgorithm, EcCurve as StatsdEcCurve, KeyOrigin as StatsdKeyOrigin,
31 Keystore2KeyCreationEventReported, SecurityLevel as StatsdKeyCreationSecurityLevel,
32 UserAuthType as StatsdUserAuthType,
33 },
34 keystore2_key_operation_event_reported::{
35 Keystore2KeyOperationEventReported, Outcome as StatsdOutcome, Purpose as StatsdKeyPurpose,
36 SecurityLevel as StatsdKeyOperationSecurityLevel,
37 },
38 keystore2_storage_stats::StorageType as StatsdStorageType,
Hasini Gunasingheb7142972021-02-20 03:11:27 +000039};
Seth Moore78c091f2021-04-09 21:38:30 +000040use statslog_rust_header::Atoms;
41use statspull_rust::{set_pull_atom_callback, StatsPullResult};
Hasini Gunasinghe0aba68a2021-03-19 00:43:52 +000042
Hasini Gunasingheb7142972021-02-20 03:11:27 +000043fn create_default_key_creation_atom() -> Keystore2KeyCreationEventReported {
44 // If a value is not present, fields represented by bitmaps and i32 fields
45 // will take 0, except error_code which defaults to 1 indicating NO_ERROR and key_size,
46 // and auth_time_out which default to -1.
47 // The boolean fields are set to false by default.
48 // Some keymint enums do have 0 as an enum variant value. In such cases, the corresponding
49 // enum variant value in atoms.proto is incremented by 1, in order to have 0 as the reserved
50 // value for unspecified fields.
51 Keystore2KeyCreationEventReported {
52 algorithm: StatsdAlgorithm::AlgorithmUnspecified,
53 key_size: -1,
54 key_origin: StatsdKeyOrigin::OriginUnspecified,
55 user_auth_type: StatsdUserAuthType::AuthTypeUnspecified,
56 user_auth_key_timeout_seconds: -1,
57 padding_mode_bitmap: 0,
58 digest_bitmap: 0,
59 block_mode_bitmap: 0,
60 purpose_bitmap: 0,
61 ec_curve: StatsdEcCurve::EcCurveUnspecified,
62 // as per keystore2/ResponseCode.aidl, 1 is reserved for NO_ERROR
63 error_code: 1,
64 attestation_requested: false,
Hasini Gunasinghe9617fd92021-04-01 22:27:07 +000065 security_level: StatsdKeyCreationSecurityLevel::SecurityLevelUnspecified,
Hasini Gunasingheb7142972021-02-20 03:11:27 +000066 }
67}
68
Hasini Gunasinghe0aba68a2021-03-19 00:43:52 +000069fn create_default_key_operation_atom() -> Keystore2KeyOperationEventReported {
70 Keystore2KeyOperationEventReported {
71 purpose: StatsdKeyPurpose::KeyPurposeUnspecified,
72 padding_mode_bitmap: 0,
73 digest_bitmap: 0,
74 block_mode_bitmap: 0,
75 outcome: StatsdOutcome::OutcomeUnspecified,
76 error_code: 1,
77 key_upgraded: false,
Hasini Gunasinghe9617fd92021-04-01 22:27:07 +000078 security_level: StatsdKeyOperationSecurityLevel::SecurityLevelUnspecified,
Hasini Gunasinghe0aba68a2021-03-19 00:43:52 +000079 }
80}
81
82/// Log key creation events via statsd API.
Hasini Gunasinghe9617fd92021-04-01 22:27:07 +000083pub fn log_key_creation_event_stats<U>(
84 sec_level: SecurityLevel,
85 key_params: &[KeyParameter],
Seth Moore78c091f2021-04-09 21:38:30 +000086 result: &Result<U>,
Hasini Gunasinghe9617fd92021-04-01 22:27:07 +000087) {
88 let key_creation_event_stats =
89 construct_key_creation_event_stats(sec_level, key_params, result);
Hasini Gunasingheb7142972021-02-20 03:11:27 +000090
Pavel Grafov94243c22021-04-21 18:03:11 +010091 LOGS_HANDLER.queue_lo(move |_| {
Hasini Gunasinghe19022812021-04-19 21:31:30 +000092 let logging_result = key_creation_event_stats.stats_write();
Hasini Gunasingheb7142972021-02-20 03:11:27 +000093
Hasini Gunasinghe19022812021-04-19 21:31:30 +000094 if let Err(e) = logging_result {
95 log::error!("Error in logging key creation event in the async task. {:?}", e);
96 }
97 });
Hasini Gunasingheb7142972021-02-20 03:11:27 +000098}
99
Hasini Gunasinghe0aba68a2021-03-19 00:43:52 +0000100/// Log key operation events via statsd API.
101pub fn log_key_operation_event_stats(
Hasini Gunasinghe9617fd92021-04-01 22:27:07 +0000102 sec_level: SecurityLevel,
Hasini Gunasinghe0aba68a2021-03-19 00:43:52 +0000103 key_purpose: KeyPurpose,
104 op_params: &[KeyParameter],
105 op_outcome: &Outcome,
106 key_upgraded: bool,
107) {
Hasini Gunasinghe9617fd92021-04-01 22:27:07 +0000108 let key_operation_event_stats = construct_key_operation_event_stats(
109 sec_level,
110 key_purpose,
111 op_params,
112 op_outcome,
113 key_upgraded,
114 );
Hasini Gunasinghe0aba68a2021-03-19 00:43:52 +0000115
Pavel Grafov94243c22021-04-21 18:03:11 +0100116 LOGS_HANDLER.queue_lo(move |_| {
Hasini Gunasinghe19022812021-04-19 21:31:30 +0000117 let logging_result = key_operation_event_stats.stats_write();
Hasini Gunasinghe0aba68a2021-03-19 00:43:52 +0000118
Hasini Gunasinghe19022812021-04-19 21:31:30 +0000119 if let Err(e) = logging_result {
120 log::error!("Error in logging key operation event in the async task. {:?}", e);
121 }
122 });
Hasini Gunasinghe0aba68a2021-03-19 00:43:52 +0000123}
124
Hasini Gunasingheb7142972021-02-20 03:11:27 +0000125fn construct_key_creation_event_stats<U>(
Hasini Gunasinghe9617fd92021-04-01 22:27:07 +0000126 sec_level: SecurityLevel,
Hasini Gunasingheb7142972021-02-20 03:11:27 +0000127 key_params: &[KeyParameter],
Seth Moore78c091f2021-04-09 21:38:30 +0000128 result: &Result<U>,
Hasini Gunasingheb7142972021-02-20 03:11:27 +0000129) -> Keystore2KeyCreationEventReported {
130 let mut key_creation_event_atom = create_default_key_creation_atom();
131
132 if let Err(ref e) = result {
133 key_creation_event_atom.error_code = get_error_code(e);
134 }
135
Hasini Gunasinghe9617fd92021-04-01 22:27:07 +0000136 key_creation_event_atom.security_level = match sec_level {
137 SecurityLevel::SOFTWARE => StatsdKeyCreationSecurityLevel::SecurityLevelSoftware,
138 SecurityLevel::TRUSTED_ENVIRONMENT => {
139 StatsdKeyCreationSecurityLevel::SecurityLevelTrustedEnvironment
140 }
141 SecurityLevel::STRONGBOX => StatsdKeyCreationSecurityLevel::SecurityLevelStrongbox,
142 //KEYSTORE is not a valid variant here
143 _ => StatsdKeyCreationSecurityLevel::SecurityLevelUnspecified,
144 };
145
Hasini Gunasingheb7142972021-02-20 03:11:27 +0000146 for key_param in key_params.iter().map(KsKeyParamValue::from) {
147 match key_param {
148 KsKeyParamValue::Algorithm(a) => {
149 key_creation_event_atom.algorithm = match a {
150 Algorithm::RSA => StatsdAlgorithm::Rsa,
151 Algorithm::EC => StatsdAlgorithm::Ec,
152 Algorithm::AES => StatsdAlgorithm::Aes,
153 Algorithm::TRIPLE_DES => StatsdAlgorithm::TripleDes,
154 Algorithm::HMAC => StatsdAlgorithm::Hmac,
155 _ => StatsdAlgorithm::AlgorithmUnspecified,
156 }
157 }
158 KsKeyParamValue::KeySize(s) => {
159 key_creation_event_atom.key_size = s;
160 }
161 KsKeyParamValue::KeyOrigin(o) => {
162 key_creation_event_atom.key_origin = match o {
163 KeyOrigin::GENERATED => StatsdKeyOrigin::Generated,
164 KeyOrigin::DERIVED => StatsdKeyOrigin::Derived,
165 KeyOrigin::IMPORTED => StatsdKeyOrigin::Imported,
166 KeyOrigin::RESERVED => StatsdKeyOrigin::Reserved,
167 KeyOrigin::SECURELY_IMPORTED => StatsdKeyOrigin::SecurelyImported,
168 _ => StatsdKeyOrigin::OriginUnspecified,
169 }
170 }
171 KsKeyParamValue::HardwareAuthenticatorType(a) => {
172 key_creation_event_atom.user_auth_type = match a {
173 HardwareAuthenticatorType::NONE => StatsdUserAuthType::None,
174 HardwareAuthenticatorType::PASSWORD => StatsdUserAuthType::Password,
175 HardwareAuthenticatorType::FINGERPRINT => StatsdUserAuthType::Fingerprint,
176 HardwareAuthenticatorType::ANY => StatsdUserAuthType::Any,
177 _ => StatsdUserAuthType::AuthTypeUnspecified,
178 }
179 }
180 KsKeyParamValue::AuthTimeout(t) => {
181 key_creation_event_atom.user_auth_key_timeout_seconds = t;
182 }
183 KsKeyParamValue::PaddingMode(p) => {
184 key_creation_event_atom.padding_mode_bitmap =
185 compute_padding_mode_bitmap(&key_creation_event_atom.padding_mode_bitmap, p);
186 }
187 KsKeyParamValue::Digest(d) => {
188 key_creation_event_atom.digest_bitmap =
189 compute_digest_bitmap(&key_creation_event_atom.digest_bitmap, d);
190 }
191 KsKeyParamValue::BlockMode(b) => {
192 key_creation_event_atom.block_mode_bitmap =
193 compute_block_mode_bitmap(&key_creation_event_atom.block_mode_bitmap, b);
194 }
195 KsKeyParamValue::KeyPurpose(k) => {
196 key_creation_event_atom.purpose_bitmap =
197 compute_purpose_bitmap(&key_creation_event_atom.purpose_bitmap, k);
198 }
199 KsKeyParamValue::EcCurve(e) => {
200 key_creation_event_atom.ec_curve = match e {
201 EcCurve::P_224 => StatsdEcCurve::P224,
202 EcCurve::P_256 => StatsdEcCurve::P256,
203 EcCurve::P_384 => StatsdEcCurve::P384,
204 EcCurve::P_521 => StatsdEcCurve::P521,
205 _ => StatsdEcCurve::EcCurveUnspecified,
206 }
207 }
208 KsKeyParamValue::AttestationChallenge(_) => {
209 key_creation_event_atom.attestation_requested = true;
210 }
211 _ => {}
212 }
213 }
214 key_creation_event_atom
215}
216
Hasini Gunasinghe0aba68a2021-03-19 00:43:52 +0000217fn construct_key_operation_event_stats(
Hasini Gunasinghe9617fd92021-04-01 22:27:07 +0000218 sec_level: SecurityLevel,
Hasini Gunasinghe0aba68a2021-03-19 00:43:52 +0000219 key_purpose: KeyPurpose,
220 op_params: &[KeyParameter],
221 op_outcome: &Outcome,
222 key_upgraded: bool,
223) -> Keystore2KeyOperationEventReported {
224 let mut key_operation_event_atom = create_default_key_operation_atom();
225
Hasini Gunasinghe9617fd92021-04-01 22:27:07 +0000226 key_operation_event_atom.security_level = match sec_level {
227 SecurityLevel::SOFTWARE => StatsdKeyOperationSecurityLevel::SecurityLevelSoftware,
228 SecurityLevel::TRUSTED_ENVIRONMENT => {
229 StatsdKeyOperationSecurityLevel::SecurityLevelTrustedEnvironment
230 }
231 SecurityLevel::STRONGBOX => StatsdKeyOperationSecurityLevel::SecurityLevelStrongbox,
232 //KEYSTORE is not a valid variant here
233 _ => StatsdKeyOperationSecurityLevel::SecurityLevelUnspecified,
234 };
235
Hasini Gunasinghe0aba68a2021-03-19 00:43:52 +0000236 key_operation_event_atom.key_upgraded = key_upgraded;
237
238 key_operation_event_atom.purpose = match key_purpose {
239 KeyPurpose::ENCRYPT => StatsdKeyPurpose::Encrypt,
240 KeyPurpose::DECRYPT => StatsdKeyPurpose::Decrypt,
241 KeyPurpose::SIGN => StatsdKeyPurpose::Sign,
242 KeyPurpose::VERIFY => StatsdKeyPurpose::Verify,
243 KeyPurpose::WRAP_KEY => StatsdKeyPurpose::WrapKey,
244 KeyPurpose::AGREE_KEY => StatsdKeyPurpose::AgreeKey,
245 KeyPurpose::ATTEST_KEY => StatsdKeyPurpose::AttestKey,
246 _ => StatsdKeyPurpose::KeyPurposeUnspecified,
247 };
248
249 key_operation_event_atom.outcome = match op_outcome {
250 Outcome::Unknown | Outcome::Dropped => StatsdOutcome::Dropped,
251 Outcome::Success => StatsdOutcome::Success,
252 Outcome::Abort => StatsdOutcome::Abort,
253 Outcome::Pruned => StatsdOutcome::Pruned,
254 Outcome::ErrorCode(e) => {
255 key_operation_event_atom.error_code = e.0;
256 StatsdOutcome::Error
257 }
258 };
259
260 for key_param in op_params.iter().map(KsKeyParamValue::from) {
261 match key_param {
262 KsKeyParamValue::PaddingMode(p) => {
263 key_operation_event_atom.padding_mode_bitmap =
264 compute_padding_mode_bitmap(&key_operation_event_atom.padding_mode_bitmap, p);
265 }
266 KsKeyParamValue::Digest(d) => {
267 key_operation_event_atom.digest_bitmap =
268 compute_digest_bitmap(&key_operation_event_atom.digest_bitmap, d);
269 }
270 KsKeyParamValue::BlockMode(b) => {
271 key_operation_event_atom.block_mode_bitmap =
272 compute_block_mode_bitmap(&key_operation_event_atom.block_mode_bitmap, b);
273 }
274 _ => {}
275 }
276 }
277
278 key_operation_event_atom
279}
280
Hasini Gunasingheb7142972021-02-20 03:11:27 +0000281fn compute_purpose_bitmap(purpose_bitmap: &i32, purpose: KeyPurpose) -> i32 {
282 let mut bitmap = *purpose_bitmap;
283 match purpose {
284 KeyPurpose::ENCRYPT => {
285 bitmap |= 1 << KeyPurposeBitPosition::ENCRYPT_BIT_POS as i32;
286 }
287 KeyPurpose::DECRYPT => {
288 bitmap |= 1 << KeyPurposeBitPosition::DECRYPT_BIT_POS as i32;
289 }
290 KeyPurpose::SIGN => {
291 bitmap |= 1 << KeyPurposeBitPosition::SIGN_BIT_POS as i32;
292 }
293 KeyPurpose::VERIFY => {
294 bitmap |= 1 << KeyPurposeBitPosition::VERIFY_BIT_POS as i32;
295 }
296 KeyPurpose::WRAP_KEY => {
297 bitmap |= 1 << KeyPurposeBitPosition::WRAP_KEY_BIT_POS as i32;
298 }
299 KeyPurpose::AGREE_KEY => {
300 bitmap |= 1 << KeyPurposeBitPosition::AGREE_KEY_BIT_POS as i32;
301 }
302 KeyPurpose::ATTEST_KEY => {
303 bitmap |= 1 << KeyPurposeBitPosition::ATTEST_KEY_BIT_POS as i32;
304 }
305 _ => {}
306 }
307 bitmap
308}
309
310fn compute_padding_mode_bitmap(padding_mode_bitmap: &i32, padding_mode: PaddingMode) -> i32 {
311 let mut bitmap = *padding_mode_bitmap;
312 match padding_mode {
313 PaddingMode::NONE => {
314 bitmap |= 1 << PaddingModeBitPosition::NONE_BIT_POSITION as i32;
315 }
316 PaddingMode::RSA_OAEP => {
317 bitmap |= 1 << PaddingModeBitPosition::RSA_OAEP_BIT_POS as i32;
318 }
319 PaddingMode::RSA_PSS => {
320 bitmap |= 1 << PaddingModeBitPosition::RSA_PSS_BIT_POS as i32;
321 }
322 PaddingMode::RSA_PKCS1_1_5_ENCRYPT => {
323 bitmap |= 1 << PaddingModeBitPosition::RSA_PKCS1_1_5_ENCRYPT_BIT_POS as i32;
324 }
325 PaddingMode::RSA_PKCS1_1_5_SIGN => {
326 bitmap |= 1 << PaddingModeBitPosition::RSA_PKCS1_1_5_SIGN_BIT_POS as i32;
327 }
328 PaddingMode::PKCS7 => {
329 bitmap |= 1 << PaddingModeBitPosition::PKCS7_BIT_POS as i32;
330 }
331 _ => {}
332 }
333 bitmap
334}
335
336fn compute_digest_bitmap(digest_bitmap: &i32, digest: Digest) -> i32 {
337 let mut bitmap = *digest_bitmap;
338 match digest {
339 Digest::NONE => {
340 bitmap |= 1 << DigestBitPosition::NONE_BIT_POSITION as i32;
341 }
342 Digest::MD5 => {
343 bitmap |= 1 << DigestBitPosition::MD5_BIT_POS as i32;
344 }
345 Digest::SHA1 => {
346 bitmap |= 1 << DigestBitPosition::SHA_1_BIT_POS as i32;
347 }
348 Digest::SHA_2_224 => {
349 bitmap |= 1 << DigestBitPosition::SHA_2_224_BIT_POS as i32;
350 }
351 Digest::SHA_2_256 => {
352 bitmap |= 1 << DigestBitPosition::SHA_2_256_BIT_POS as i32;
353 }
354 Digest::SHA_2_384 => {
355 bitmap |= 1 << DigestBitPosition::SHA_2_384_BIT_POS as i32;
356 }
357 Digest::SHA_2_512 => {
358 bitmap |= 1 << DigestBitPosition::SHA_2_512_BIT_POS as i32;
359 }
360 _ => {}
361 }
362 bitmap
363}
364
365fn compute_block_mode_bitmap(block_mode_bitmap: &i32, block_mode: BlockMode) -> i32 {
366 let mut bitmap = *block_mode_bitmap;
367 match block_mode {
368 BlockMode::ECB => {
369 bitmap |= 1 << BlockModeBitPosition::ECB_BIT_POS as i32;
370 }
371 BlockMode::CBC => {
372 bitmap |= 1 << BlockModeBitPosition::CBC_BIT_POS as i32;
373 }
374 BlockMode::CTR => {
375 bitmap |= 1 << BlockModeBitPosition::CTR_BIT_POS as i32;
376 }
377 BlockMode::GCM => {
378 bitmap |= 1 << BlockModeBitPosition::GCM_BIT_POS as i32;
379 }
380 _ => {}
381 }
382 bitmap
383}
Seth Moore78c091f2021-04-09 21:38:30 +0000384
385/// Registers pull metrics callbacks
386pub fn register_pull_metrics_callbacks() -> Result<()> {
387 // Before registering the callbacks with statsd, we have to wait for the system to finish
388 // booting up. This avoids possible races that may occur at startup. For example, statsd
389 // depends on a companion service, and if registration happens too soon it will fail since
390 // the companion service isn't up yet.
391 let mut watcher = PropertyWatcher::new("sys.boot_completed")?;
392 loop {
393 watcher.wait()?;
394 let value = watcher.read(|_name, value| Ok(value.trim().to_string()));
395 if value? == "1" {
396 set_pull_atom_callback(Atoms::Keystore2StorageStats, None, pull_metrics_callback);
397 break;
398 }
399 }
400 Ok(())
401}
402
403fn pull_metrics_callback() -> StatsPullResult {
404 let mut result = StatsPullResult::new();
405 let mut append = |stat| {
406 match stat {
407 Ok(s) => result.push(Box::new(s)),
408 Err(error) => {
409 log::error!("pull_metrics_callback: Error getting storage stat: {}", error)
410 }
411 };
412 };
413 DB.with(|db| {
414 let mut db = db.borrow_mut();
415 append(db.get_storage_stat(StatsdStorageType::Database));
416 append(db.get_storage_stat(StatsdStorageType::KeyEntry));
417 append(db.get_storage_stat(StatsdStorageType::KeyEntryIdIndex));
418 append(db.get_storage_stat(StatsdStorageType::KeyEntryDomainNamespaceIndex));
419 append(db.get_storage_stat(StatsdStorageType::BlobEntry));
420 append(db.get_storage_stat(StatsdStorageType::BlobEntryKeyEntryIdIndex));
421 append(db.get_storage_stat(StatsdStorageType::KeyParameter));
422 append(db.get_storage_stat(StatsdStorageType::KeyParameterKeyEntryIdIndex));
423 append(db.get_storage_stat(StatsdStorageType::KeyMetadata));
424 append(db.get_storage_stat(StatsdStorageType::KeyMetadataKeyEntryIdIndex));
425 append(db.get_storage_stat(StatsdStorageType::Grant));
426 append(db.get_storage_stat(StatsdStorageType::AuthToken));
427 append(db.get_storage_stat(StatsdStorageType::BlobMetadata));
428 append(db.get_storage_stat(StatsdStorageType::BlobMetadataBlobEntryIdIndex));
429 });
430 result
431}
432
Hasini Gunasingheb7142972021-02-20 03:11:27 +0000433/// Enum defining the bit position for each padding mode. Since padding mode can be repeatable, it
434/// is represented using a bitmap.
435#[allow(non_camel_case_types)]
436#[repr(i32)]
437pub enum PaddingModeBitPosition {
438 ///Bit position in the PaddingMode bitmap for NONE.
439 NONE_BIT_POSITION = 0,
440 ///Bit position in the PaddingMode bitmap for RSA_OAEP.
441 RSA_OAEP_BIT_POS = 1,
442 ///Bit position in the PaddingMode bitmap for RSA_PSS.
443 RSA_PSS_BIT_POS = 2,
444 ///Bit position in the PaddingMode bitmap for RSA_PKCS1_1_5_ENCRYPT.
445 RSA_PKCS1_1_5_ENCRYPT_BIT_POS = 3,
446 ///Bit position in the PaddingMode bitmap for RSA_PKCS1_1_5_SIGN.
447 RSA_PKCS1_1_5_SIGN_BIT_POS = 4,
448 ///Bit position in the PaddingMode bitmap for RSA_PKCS7.
449 PKCS7_BIT_POS = 5,
450}
451
452/// Enum defining the bit position for each digest type. Since digest can be repeatable in
453/// key parameters, it is represented using a bitmap.
454#[allow(non_camel_case_types)]
455#[repr(i32)]
456pub enum DigestBitPosition {
457 ///Bit position in the Digest bitmap for NONE.
458 NONE_BIT_POSITION = 0,
459 ///Bit position in the Digest bitmap for MD5.
460 MD5_BIT_POS = 1,
461 ///Bit position in the Digest bitmap for SHA1.
462 SHA_1_BIT_POS = 2,
463 ///Bit position in the Digest bitmap for SHA_2_224.
464 SHA_2_224_BIT_POS = 3,
465 ///Bit position in the Digest bitmap for SHA_2_256.
466 SHA_2_256_BIT_POS = 4,
467 ///Bit position in the Digest bitmap for SHA_2_384.
468 SHA_2_384_BIT_POS = 5,
469 ///Bit position in the Digest bitmap for SHA_2_512.
470 SHA_2_512_BIT_POS = 6,
471}
472
473/// Enum defining the bit position for each block mode type. Since block mode can be repeatable in
474/// key parameters, it is represented using a bitmap.
475#[allow(non_camel_case_types)]
476#[repr(i32)]
477enum BlockModeBitPosition {
478 ///Bit position in the BlockMode bitmap for ECB.
479 ECB_BIT_POS = 1,
480 ///Bit position in the BlockMode bitmap for CBC.
481 CBC_BIT_POS = 2,
482 ///Bit position in the BlockMode bitmap for CTR.
483 CTR_BIT_POS = 3,
484 ///Bit position in the BlockMode bitmap for GCM.
485 GCM_BIT_POS = 4,
486}
487
488/// Enum defining the bit position for each key purpose. Since key purpose can be repeatable in
489/// key parameters, it is represented using a bitmap.
490#[allow(non_camel_case_types)]
491#[repr(i32)]
492enum KeyPurposeBitPosition {
493 ///Bit position in the KeyPurpose bitmap for Encrypt.
494 ENCRYPT_BIT_POS = 1,
495 ///Bit position in the KeyPurpose bitmap for Decrypt.
496 DECRYPT_BIT_POS = 2,
497 ///Bit position in the KeyPurpose bitmap for Sign.
498 SIGN_BIT_POS = 3,
499 ///Bit position in the KeyPurpose bitmap for Verify.
500 VERIFY_BIT_POS = 4,
501 ///Bit position in the KeyPurpose bitmap for Wrap Key.
502 WRAP_KEY_BIT_POS = 5,
503 ///Bit position in the KeyPurpose bitmap for Agree Key.
504 AGREE_KEY_BIT_POS = 6,
505 ///Bit position in the KeyPurpose bitmap for Attest Key.
506 ATTEST_KEY_BIT_POS = 7,
507}