python-pkcs11 0.10.1__cp315-cp315-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pkcs11/constants.py ADDED
@@ -0,0 +1,559 @@
1
+ """
2
+ PKCS#11 constants.
3
+
4
+ See the Python :mod:`enum` documentation for more information on how to
5
+ use these classes.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from enum import IntEnum, IntFlag, unique
11
+ from typing import Final
12
+
13
+ DEFAULT: Final[object] = object()
14
+ """Sentinel value used in templates.
15
+
16
+ Not all pkcs11 attribute sets are accepted by HSMs.
17
+ Use this value to remove the attribute from the template
18
+ sent to the HSM or to use the HSM default value.
19
+ """
20
+
21
+
22
+ @unique
23
+ class UserType(IntEnum):
24
+ """PKCS#11 user types."""
25
+
26
+ NOBODY = 999
27
+ """
28
+ Not officially in the PKCS#11 spec. Used to represent a session that is not
29
+ logged in.
30
+ """
31
+ SO = 0
32
+ """Security officer."""
33
+ USER = 1
34
+
35
+
36
+ class ObjectClass(IntEnum):
37
+ """
38
+ PKCS#11 :class:`Object` class.
39
+
40
+ This is the type of object we have.
41
+ """
42
+
43
+ DATA = 0x00000000
44
+ CERTIFICATE = 0x00000001
45
+ """See :class:`pkcs11.Certificate`."""
46
+ PUBLIC_KEY = 0x00000002
47
+ """See :class:`pkcs11.PublicKey`."""
48
+ PRIVATE_KEY = 0x00000003
49
+ """See :class:`pkcs11.PrivateKey`."""
50
+ SECRET_KEY = 0x00000004
51
+ """See :class:`pkcs11.SecretKey`."""
52
+ HW_FEATURE = 0x00000005
53
+ DOMAIN_PARAMETERS = 0x00000006
54
+ """See :class:`pkcs11.DomainParameters`."""
55
+ MECHANISM = 0x00000007
56
+ OTP_KEY = 0x00000008
57
+ PROFILE = 0x00000009
58
+
59
+ _VENDOR_DEFINED = 0x80000000
60
+
61
+ def __repr__(self) -> str:
62
+ return f"<ObjectClass.{self.name}>"
63
+
64
+
65
+ _ARRAY_ATTRIBUTE: Final[int] = 0x40000000
66
+ """Attribute consists of an array of values."""
67
+
68
+
69
+ class Attribute(IntEnum):
70
+ """
71
+ PKCS#11 object attributes.
72
+
73
+ Not all attributes are relevant to all objects.
74
+ Relevant attributes for each object type are given in `PKCS #11
75
+ <http://docs.oasis-open.org/pkcs11/pkcs11-curr/v2.40/pkcs11-curr-v2.40.html>`_.
76
+ """
77
+
78
+ CLASS = 0x00000000
79
+ """Object type (:class:`ObjectClass`)."""
80
+ TOKEN = 0x00000001
81
+ """
82
+ If True object will be stored to token.
83
+ Otherwise has session lifetime (:class:`bool`).
84
+ """
85
+ PRIVATE = 0x00000002
86
+ """
87
+ True if user must be authenticated to access this object (:class:`bool`).
88
+ """
89
+ LABEL = 0x00000003
90
+ """Object label (:class:`str`)."""
91
+ UNIQUE_ID = 0x00000004
92
+ """Unique identifier (:class:`str`)."""
93
+ APPLICATION = 0x00000010
94
+ VALUE = 0x00000011
95
+ """
96
+ Object value. Usually represents a secret or private key.
97
+ For certificates this is the complete certificate in the certificate's
98
+ native format (e.g. BER-encoded X.509 or WTLS encoding).
99
+
100
+ May be `SENSITIVE` (:class:`bytes`).
101
+ """
102
+ OBJECT_ID = 0x00000012
103
+ CERTIFICATE_TYPE = 0x00000080
104
+ """
105
+ Certificate type (:class:`CertificateType`).
106
+ """
107
+ ISSUER = 0x00000081
108
+ """
109
+ Certificate issuer in certificate's native format
110
+ (e.g. X.509 DER-encoding or WTLS encoding) (:class:`bytes`).
111
+ """
112
+ SERIAL_NUMBER = 0x00000082
113
+ """
114
+ Certificate serial number in certificate's native format
115
+ (e.g. X.509 DER-encoding) (:class:`bytes`).
116
+ """
117
+ AC_ISSUER = 0x00000083
118
+ """
119
+ Attribute Certificate Issuer. Different from `ISSUER` because the
120
+ encoding is different (:class:`bytes`).
121
+ """
122
+ OWNER = 0x00000084
123
+ """
124
+ Attribute Certificate Owner. Different from `SUBJECT` because the
125
+ encoding is different (:class:`bytes`).
126
+ """
127
+ ATTR_TYPES = 0x00000085
128
+ """
129
+ BER-encoding of a sequence of object identifier values corresponding to the
130
+ attribute types contained in the certificate. When present, this field
131
+ offers an opportunity for applications to search for a particular attribute
132
+ certificate without fetching and parsing the certificate itself.
133
+ """
134
+ TRUSTED = 0x00000086
135
+ """
136
+ This key can be used to wrap keys with `WRAP_WITH_TRUSTED` set;
137
+ or this certificate can be trusted.
138
+ (:class:`bool`).
139
+ """
140
+ CERTIFICATE_CATEGORY = 0x00000087
141
+ """
142
+ Certificate category (:class:`CertificateCategory`).
143
+ """
144
+ JAVA_MIDP_SECURITY_DOMAIN = 0x00000088
145
+ URL = 0x00000089
146
+ """URL where the complete certificate can be obtained."""
147
+ HASH_OF_SUBJECT_PUBLIC_KEY = 0x0000008A
148
+ """Hash of the certificate subject's public key."""
149
+ HASH_OF_ISSUER_PUBLIC_KEY = 0x0000008B
150
+ """Hash of the certificate issuer's public key."""
151
+ CHECK_VALUE = 0x00000090
152
+ """`VALUE` checksum. Key Check Value (:class:`bytes`)."""
153
+
154
+ KEY_TYPE = 0x00000100
155
+ """Key type (:class:`KeyType`)."""
156
+ SUBJECT = 0x00000101
157
+ """
158
+ Certificate subject in certificate's native format
159
+ (e.g. X.509 DER-encoding or WTLS encoding) (:class:`bytes`).
160
+ """
161
+ ID = 0x00000102
162
+ """Key ID (bytes)."""
163
+ SENSITIVE = 0x00000103
164
+ """
165
+ Sensitive attributes cannot be retrieved from the HSM
166
+ (e.g. `VALUE` or `PRIVATE_EXPONENT`) (:class:`bool`).
167
+ """
168
+ ENCRYPT = 0x00000104
169
+ """Key supports encryption (:class:`bool`)."""
170
+ DECRYPT = 0x00000105
171
+ """Key supports decryption (:class:`bool`)."""
172
+ WRAP = 0x00000106
173
+ """Key supports wrapping (:class:`bool`)."""
174
+ UNWRAP = 0x00000107
175
+ """Key supports unwrapping (:class:`bool`)."""
176
+ SIGN = 0x00000108
177
+ """Key supports signing (:class:`bool`)."""
178
+ SIGN_RECOVER = 0x00000109
179
+ VERIFY = 0x0000010A
180
+ """Key supports signature verification (:class:`bool`)."""
181
+ VERIFY_RECOVER = 0x0000010B
182
+ DERIVE = 0x0000010C
183
+ """Key supports key derivation (:class:`bool`)."""
184
+ START_DATE = 0x00000110
185
+ """Start date for the object's validity (:class:`datetime.date`)."""
186
+ END_DATE = 0x00000111
187
+ """End date for the object's validity (:class:`datetime.date`)."""
188
+ MODULUS = 0x00000120
189
+ """RSA private key modulus (n) (`biginteger` as :class:`bytes`)."""
190
+ MODULUS_BITS = 0x00000121
191
+ """
192
+ RSA private key modulus length. Use this for private key generation
193
+ (:class:`int`).
194
+ """
195
+ PUBLIC_EXPONENT = 0x00000122
196
+ """
197
+ RSA public exponent (e) (`biginteger` as :class:`bytes`).
198
+
199
+ Default is b'\1\0\1' (65537).
200
+ """
201
+ PRIVATE_EXPONENT = 0x00000123
202
+ """RSA private exponent (d) (`biginteger` as :class:`bytes`)."""
203
+ PRIME_1 = 0x00000124
204
+ """
205
+ RSA private key prime #1 (p). May not be stored.
206
+ (`biginteger` as :class:`bytes`).
207
+ """
208
+ PRIME_2 = 0x00000125
209
+ """
210
+ RSA private key prime #2 (q). May not be stored.
211
+ (`biginteger` as :class:`bytes`).
212
+ """
213
+ EXPONENT_1 = 0x00000126
214
+ """
215
+ RSA private key exponent #1 (d mod p-1). May not be stored.
216
+ (`biginteger` as :class:`bytes`).
217
+ """
218
+ EXPONENT_2 = 0x00000127
219
+ """
220
+ RSA private key exponent #2 (d mod q-1). May not be stored.
221
+ (`biginteger` as :class:`bytes`).
222
+ """
223
+ COEFFICIENT = 0x00000128
224
+ """
225
+ RSA private key CRT coefficient (q^-1 mod p). May not be stored.
226
+ (`biginteger` as :class:`bytes`).
227
+ """
228
+ PRIME = 0x00000130
229
+ """
230
+ Prime number 'q' (used for DH).
231
+ (`biginteger` as :class:`bytes`).
232
+ """
233
+ SUBPRIME = 0x00000131
234
+ """
235
+ Subprime number 'q' (used for DH).
236
+ (`biginteger` as :class:`bytes`).
237
+ """
238
+ BASE = 0x00000132
239
+ """
240
+ Base number 'g' (used for DH).
241
+ (`biginteger` as :class:`bytes`).
242
+ """
243
+
244
+ PRIME_BITS = 0x00000133
245
+ SUBPRIME_BITS = 0x00000134
246
+
247
+ VALUE_BITS = 0x00000160
248
+ VALUE_LEN = 0x00000161
249
+ """
250
+ `VALUE` length in bytes. Use this for secret key generation
251
+ (:class:`int`).
252
+ """
253
+ EXTRACTABLE = 0x00000162
254
+ """Key can be extracted wrapped."""
255
+ LOCAL = 0x00000163
256
+ """True if generated on the token, False if imported."""
257
+ NEVER_EXTRACTABLE = 0x00000164
258
+ """`EXTRACTABLE` has always been False."""
259
+ ALWAYS_SENSITIVE = 0x00000165
260
+ """`SENSITIVE` has always been True."""
261
+ KEY_GEN_MECHANISM = 0x00000166
262
+ """Key generation mechanism (:class:`pkcs11.mechanisms.Mechanism`)."""
263
+
264
+ MODIFIABLE = 0x00000170
265
+ """Object can be modified (:class:`bool`)."""
266
+ COPYABLE = 0x00000171
267
+ """Object can be copied (:class:`bool`)."""
268
+ DESTROYABLE = 0x00000172
269
+ """Object can be destroyed (:class:`bool`)."""
270
+
271
+ EC_PARAMS = 0x00000180
272
+ """
273
+ DER-encoded ANSI X9.62 Elliptic-Curve domain parameters (:class:`bytes`).
274
+
275
+ These can packed using :mod:`pkcs11.util.ec.encode_named_curve_parameters`:
276
+
277
+ ::
278
+
279
+ from pkcs11.util.ec import encode_named_curve_parameters
280
+
281
+ ecParams = encode_named_curve_parameters('secp256r1')
282
+
283
+ Or output by OpenSSL:
284
+
285
+ ::
286
+
287
+ openssl ecparam -outform der -name <curve name> | base64
288
+
289
+ """
290
+
291
+ EC_POINT = 0x00000181
292
+ """
293
+ DER-encoded ANSI X9.62 Public key for :attr:`KeyType.EC` (:class:`bytes`).
294
+ """
295
+
296
+ SECONDARY_AUTH = 0x00000200
297
+ AUTH_PIN_FLAGS = 0x00000201
298
+
299
+ ALWAYS_AUTHENTICATE = 0x00000202
300
+ """
301
+ User has to provide pin with each use (sign or decrypt) (:class:`bool`).
302
+ """
303
+
304
+ WRAP_WITH_TRUSTED = 0x00000210
305
+ """Key can only be wrapped with a `TRUSTED` key."""
306
+ WRAP_TEMPLATE = _ARRAY_ATTRIBUTE | 0x00000211
307
+ UNWRAP_TEMPLATE = _ARRAY_ATTRIBUTE | 0x00000212
308
+ DERIVE_TEMPLATE = _ARRAY_ATTRIBUTE | 0x00000213
309
+
310
+ OTP_FORMAT = 0x00000220
311
+ OTP_LENGTH = 0x00000221
312
+ OTP_TIME_INTERVAL = 0x00000222
313
+ OTP_USER_FRIENDLY_MODE = 0x00000223
314
+ OTP_CHALLENGE_REQUIREMENT = 0x00000224
315
+ OTP_TIME_REQUIREMENT = 0x00000225
316
+ OTP_COUNTER_REQUIREMENT = 0x00000226
317
+ OTP_PIN_REQUIREMENT = 0x00000227
318
+ OTP_COUNTER = 0x0000022E
319
+ OTP_TIME = 0x0000022F
320
+ OTP_USER_IDENTIFIER = 0x0000022A
321
+ OTP_SERVICE_IDENTIFIER = 0x0000022B
322
+ OTP_SERVICE_LOGO = 0x0000022C
323
+ OTP_SERVICE_LOGO_TYPE = 0x0000022D
324
+
325
+ GOSTR3410_PARAMS = 0x00000250
326
+ GOSTR3411_PARAMS = 0x00000251
327
+ GOST28147_PARAMS = 0x00000252
328
+
329
+ HW_FEATURE_TYPE = 0x00000300
330
+ RESET_ON_INIT = 0x00000301
331
+ HAS_RESET = 0x00000302
332
+
333
+ PIXEL_X = 0x00000400
334
+ PIXEL_Y = 0x00000401
335
+ RESOLUTION = 0x00000402
336
+ CHAR_ROWS = 0x00000403
337
+ CHAR_COLUMNS = 0x00000404
338
+ COLOR = 0x00000405
339
+ BITS_PER_PIXEL = 0x00000406
340
+ CHAR_SETS = 0x00000480
341
+ ENCODING_METHODS = 0x00000481
342
+ MIME_TYPES = 0x00000482
343
+ MECHANISM_TYPE = 0x00000500
344
+ REQUIRED_CMS_ATTRIBUTES = 0x00000501
345
+ DEFAULT_CMS_ATTRIBUTES = 0x00000502
346
+ SUPPORTED_CMS_ATTRIBUTES = 0x00000503
347
+ ALLOWED_MECHANISMS = _ARRAY_ATTRIBUTE | 0x00000600
348
+
349
+ PARAMETER_SET = 0x0000061D
350
+ SEED = 0x00000637
351
+
352
+ ENCAPSULATE_TEMPLATE = 0x0000062A
353
+ DECAPSULATE_TEMPLATE = 0x0000062B
354
+ ENCAPSULATE = 0x00000633
355
+ DECAPSULATE = 0x00000634
356
+
357
+ _VENDOR_DEFINED = 0x80000000
358
+
359
+ def __repr__(self) -> str:
360
+ return f"<Attribute.{self.name}>"
361
+
362
+
363
+ class CertificateType(IntEnum):
364
+ """
365
+ Certificate type of a :class:`pkcs11.Certificate`.
366
+ """
367
+
368
+ X_509 = 0x00000000
369
+ X_509_ATTR_CERT = 0x00000001
370
+ WTLS = 0x00000002
371
+ _VENDOR_DEFINED = 0x80000000
372
+
373
+
374
+ @unique
375
+ class MechanismFlag(IntFlag):
376
+ """
377
+ Describes the capabilities of a :class:`pkcs11.mechanisms.Mechanism`
378
+ or :class:`pkcs11.Object`.
379
+
380
+ Some objects and mechanisms are symmetric (i.e. can be used for encryption
381
+ and decryption), some are asymmetric (e.g. public key cryptography).
382
+ """
383
+
384
+ HW = 0x00000001
385
+ """Mechanism is performed in hardware."""
386
+
387
+ ENCRYPT = 0x00000100
388
+ """Can be used for encryption."""
389
+ DECRYPT = 0x00000200
390
+ """Can be used for decryption."""
391
+ DIGEST = 0x00000400
392
+ """Can make a message digest (hash)."""
393
+ SIGN = 0x00000800
394
+ """Can calculate digital signature."""
395
+ SIGN_RECOVER = 0x00001000
396
+ VERIFY = 0x00002000
397
+ """Can verify digital signature."""
398
+ VERIFY_RECOVER = 0x00004000
399
+ GENERATE = 0x00008000
400
+ """Can generate key/object."""
401
+ GENERATE_KEY_PAIR = 0x00010000
402
+ """Can generate key pair."""
403
+ WRAP = 0x00020000
404
+ """Can wrap a key for export."""
405
+ UNWRAP = 0x00040000
406
+ """Can unwrap a key for import."""
407
+ DERIVE = 0x00080000
408
+ """Can derive a key from another key."""
409
+
410
+ EC_F_P = 0x00100000
411
+ EC_F_2M = 0x00200000
412
+ EC_ECPARAMETERS = 0x00400000
413
+ EC_NAMEDCURVE = 0x00800000
414
+ EC_UNCOMPRESS = 0x01000000
415
+ EC_COMPRESS = 0x02000000
416
+
417
+ ENCAPSULATE = 0x10000000
418
+ """Can perform ML-KEM key encapsulation."""
419
+ DECAPSULATE = 0x20000000
420
+ """Can perform ML-KEM key decapsulation."""
421
+
422
+ EXTENSION = 0x80000000
423
+
424
+
425
+ @unique
426
+ class SlotFlag(IntFlag):
427
+ """:class:`pkcs11.Slot` flags."""
428
+
429
+ TOKEN_PRESENT = 0x00000001
430
+ """
431
+ A token is present in the slot
432
+ (N.B. some hardware known not to set this for soft-tokens.)
433
+ """
434
+ REMOVABLE_DEVICE = 0x00000002
435
+ """Removable devices."""
436
+ HW_SLOT = 0x00000004
437
+ """Hardware slot."""
438
+
439
+
440
+ @unique
441
+ class TokenFlag(IntFlag):
442
+ """:class:`pkcs11.Token` flags."""
443
+
444
+ RNG = 0x00000001
445
+ """Has random number generator."""
446
+ WRITE_PROTECTED = 0x00000002
447
+ """Token is write protected."""
448
+ LOGIN_REQUIRED = 0x00000004
449
+ """User must login."""
450
+ USER_PIN_INITIALIZED = 0x00000008
451
+ """Normal user's pin is set."""
452
+
453
+ RESTORE_KEY_NOT_NEEDED = 0x00000020
454
+ """
455
+ If it is set, that means that *every* time the state of cryptographic
456
+ operations of a session is successfully saved, all keys needed to continue
457
+ those operations are stored in the state.
458
+ """
459
+
460
+ CLOCK_ON_TOKEN = 0x00000040
461
+ """
462
+ If it is set, that means that the token has some sort of clock. The time
463
+ on that clock is returned in the token info structure.
464
+ """
465
+
466
+ PROTECTED_AUTHENTICATION_PATH = 0x00000100
467
+ """
468
+ If it is set, that means that there is some way for the user to login
469
+ without sending a PIN through the Cryptoki library itself.
470
+ """
471
+
472
+ DUAL_CRYPTO_OPERATIONS = 0x00000200
473
+ """
474
+ If it is true, that means that a single session with the token can perform
475
+ dual simultaneous cryptographic operations (digest and encrypt; decrypt and
476
+ digest; sign and encrypt; and decrypt and sign).
477
+ """
478
+
479
+ TOKEN_INITIALIZED = 0x00000400
480
+ """
481
+ If it is true, the token has been initialized using C_InitializeToken or an
482
+ equivalent mechanism outside the scope of PKCS #11. Calling
483
+ C_InitializeToken when this flag is set will cause the token to be
484
+ reinitialized.
485
+ """
486
+
487
+ USER_PIN_COUNT_LOW = 0x00010000
488
+ """
489
+ If it is true, an incorrect user login PIN has been entered at least once
490
+ since the last successful authentication.
491
+ """
492
+
493
+ USER_PIN_FINAL_TRY = 0x00020000
494
+ """
495
+ If it is true, supplying an incorrect user PIN will it to become locked.
496
+ """
497
+
498
+ USER_PIN_LOCKED = 0x00040000
499
+ """
500
+ If it is true, the user PIN has been locked. User login to the token is not
501
+ possible.
502
+ """
503
+
504
+ USER_PIN_TO_BE_CHANGED = 0x00080000
505
+ """
506
+ If it is true, the user PIN value is the default value set by token
507
+ initialization or manufacturing, or the PIN has been expired by the card.
508
+ """
509
+
510
+ SO_PIN_COUNT_LOW = 0x00100000
511
+ """
512
+ If it is true, an incorrect SO (security officer) login PIN has been
513
+ entered at least once since the last successful authentication.
514
+ """
515
+
516
+ SO_PIN_FINAL_TRY = 0x00200000
517
+ """
518
+ If it is true, supplying an incorrect SO (security officer) PIN will it to
519
+ become locked.
520
+ """
521
+
522
+ SO_PIN_LOCKED = 0x00400000
523
+ """
524
+ If it is true, the SO (security officer) PIN has been locked. SO login to
525
+ the token is not possible.
526
+ """
527
+
528
+ SO_PIN_TO_BE_CHANGED = 0x00800000
529
+ """
530
+ If it is true, the SO PIN value is the default value set by token
531
+ initialization or manufacturing, or the PIN has been expired by the card.
532
+ """
533
+
534
+ ERROR_STATE = 0x01000000
535
+
536
+
537
+ @unique
538
+ class CancelStrategy(IntEnum):
539
+ """
540
+ Strategy to cancel cryptographic operations
541
+ """
542
+
543
+ DEFAULT = 0
544
+ """
545
+ Default strategy: attempt to cancel by finalising the operation using dummy data,
546
+ regardless of whether the operation is successful or not.
547
+ This approach should work universally, but is semantically difficult to identify
548
+ as a cancellation.
549
+ """
550
+
551
+ CANCEL_WITH_INIT = 1
552
+ """
553
+ Attempt to cancel by calling the ``C_XYZInit`` function of the running operation
554
+ with a ``NULL`` mechanism.
555
+
556
+ This usage is defined in PKCS#11 3.0 but not universally implemented.
557
+ """
558
+
559
+ # TODO support cancelling with C_SessionCancel on PKCS#11 3.0 and up
pkcs11/defaults.py ADDED
@@ -0,0 +1,121 @@
1
+ """
2
+ Default mappings for various key types and mechanisms.
3
+
4
+ None of this is provided for in PKCS#11 and its correctness should not be
5
+ assumed.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from typing import Final
11
+
12
+ from pkcs11.constants import MechanismFlag
13
+ from pkcs11.mechanisms import MGF, KeyType, Mechanism
14
+
15
+ DEFAULT_GENERATE_MECHANISMS: Final[dict[KeyType, Mechanism]] = {
16
+ KeyType.AES: Mechanism.AES_KEY_GEN,
17
+ KeyType.DES2: Mechanism.DES2_KEY_GEN,
18
+ KeyType.DES3: Mechanism.DES3_KEY_GEN,
19
+ KeyType.DH: Mechanism.DH_PKCS_KEY_PAIR_GEN,
20
+ KeyType.DSA: Mechanism.DSA_KEY_PAIR_GEN,
21
+ KeyType.EC: Mechanism.EC_KEY_PAIR_GEN,
22
+ KeyType.RSA: Mechanism.RSA_PKCS_KEY_PAIR_GEN,
23
+ KeyType.X9_42_DH: Mechanism.X9_42_DH_KEY_PAIR_GEN,
24
+ KeyType.EC_EDWARDS: Mechanism.EC_EDWARDS_KEY_PAIR_GEN,
25
+ KeyType.ML_KEM: Mechanism.ML_KEM_KEY_PAIR_GEN,
26
+ KeyType.ML_DSA: Mechanism.ML_DSA_KEY_PAIR_GEN,
27
+ KeyType.GENERIC_SECRET: Mechanism.GENERIC_SECRET_KEY_GEN,
28
+ }
29
+ """
30
+ Default mechanisms for generating keys.
31
+ """
32
+
33
+ _ENCRYPTION: Final[MechanismFlag] = MechanismFlag.ENCRYPT | MechanismFlag.DECRYPT
34
+ _SIGNING: Final[MechanismFlag] = MechanismFlag.SIGN | MechanismFlag.VERIFY
35
+ _WRAPPING: Final[MechanismFlag] = MechanismFlag.WRAP | MechanismFlag.UNWRAP
36
+ _ENCAPSULATING: Final[MechanismFlag] = MechanismFlag.ENCAPSULATE | MechanismFlag.DECAPSULATE
37
+
38
+ DEFAULT_KEY_CAPABILITIES: Final[dict[KeyType, MechanismFlag | int]] = {
39
+ KeyType.AES: _ENCRYPTION | _SIGNING | _WRAPPING,
40
+ KeyType.DES2: _ENCRYPTION | _SIGNING | _WRAPPING,
41
+ KeyType.DES3: _ENCRYPTION | _SIGNING | _WRAPPING,
42
+ KeyType.DH: MechanismFlag.DERIVE,
43
+ KeyType.DSA: _SIGNING,
44
+ KeyType.EC: _SIGNING | MechanismFlag.DERIVE,
45
+ KeyType.RSA: _ENCRYPTION | _SIGNING | _WRAPPING,
46
+ KeyType.GENERIC_SECRET: 0,
47
+ KeyType.EC_EDWARDS: _SIGNING,
48
+ KeyType.ML_KEM: _ENCAPSULATING,
49
+ KeyType.ML_DSA: _SIGNING,
50
+ }
51
+ """
52
+ Default capabilities for generating keys.
53
+ """
54
+
55
+ DEFAULT_ENCRYPT_MECHANISMS: Final[dict[KeyType, Mechanism]] = {
56
+ KeyType.AES: Mechanism.AES_CBC_PAD,
57
+ KeyType.DES2: Mechanism.DES3_CBC_PAD,
58
+ KeyType.DES3: Mechanism.DES3_CBC_PAD,
59
+ KeyType.RSA: Mechanism.RSA_PKCS_OAEP,
60
+ }
61
+ """
62
+ Default mechanisms for encrypt/decrypt.
63
+ """
64
+
65
+ DEFAULT_SIGN_MECHANISMS: Final[dict[KeyType, Mechanism]] = {
66
+ KeyType.AES: Mechanism.AES_MAC,
67
+ KeyType.DES2: Mechanism.DES3_MAC,
68
+ KeyType.DES3: Mechanism.DES3_MAC,
69
+ KeyType.DSA: Mechanism.DSA_SHA512,
70
+ KeyType.EC: Mechanism.ECDSA_SHA512,
71
+ KeyType.RSA: Mechanism.SHA512_RSA_PKCS,
72
+ KeyType.EC_EDWARDS: Mechanism.EDDSA,
73
+ KeyType.ML_DSA: Mechanism.ML_DSA,
74
+ }
75
+ """
76
+ Default mechanisms for sign/verify.
77
+ """
78
+
79
+ DEFAULT_WRAP_MECHANISMS: Final[dict[KeyType, Mechanism]] = {
80
+ KeyType.AES: Mechanism.AES_KEY_WRAP,
81
+ KeyType.DES2: Mechanism.DES3_ECB,
82
+ KeyType.DES3: Mechanism.DES3_ECB,
83
+ KeyType.RSA: Mechanism.RSA_PKCS_OAEP,
84
+ }
85
+ """
86
+ Default mechanism for wrap/unwrap.
87
+ """
88
+
89
+ DEFAULT_ENCAPSULATE_MECHANISMS: Final[dict[KeyType, Mechanism]] = {
90
+ KeyType.ML_KEM: Mechanism.ML_KEM,
91
+ }
92
+ """Default mechanisms for ML-KEM encapsulate/decapsulate."""
93
+
94
+ DEFAULT_DERIVE_MECHANISMS: Final[dict[KeyType, Mechanism]] = {
95
+ KeyType.DH: Mechanism.DH_PKCS_DERIVE,
96
+ KeyType.EC: Mechanism.ECDH1_DERIVE,
97
+ KeyType.X9_42_DH: Mechanism.X9_42_DH_DERIVE,
98
+ }
99
+ """
100
+ Default mechanisms for key derivation
101
+ """
102
+
103
+ DEFAULT_PARAM_GENERATE_MECHANISMS: Final[dict[KeyType, Mechanism]] = {
104
+ KeyType.DH: Mechanism.DH_PKCS_PARAMETER_GEN,
105
+ KeyType.DSA: Mechanism.DSA_PARAMETER_GEN,
106
+ KeyType.X9_42_DH: Mechanism.X9_42_DH_PARAMETER_GEN,
107
+ }
108
+ """
109
+ Default mechanisms for domain parameter generation
110
+ """
111
+
112
+
113
+ DEFAULT_MECHANISM_PARAMS: Final[
114
+ dict[Mechanism, tuple[Mechanism, MGF, None] | tuple[Mechanism, MGF, int]]
115
+ ] = {
116
+ Mechanism.RSA_PKCS_OAEP: (Mechanism.SHA_1, MGF.SHA1, None),
117
+ Mechanism.RSA_PKCS_PSS: (Mechanism.SHA_1, MGF.SHA1, 20),
118
+ }
119
+ """
120
+ Default mechanism parameters
121
+ """