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