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/mechanisms.py ADDED
@@ -0,0 +1,862 @@
1
+ from __future__ import annotations
2
+
3
+ from enum import IntEnum
4
+
5
+ from pkcs11.exceptions import ArgumentsBad
6
+
7
+
8
+ class KeyType(IntEnum):
9
+ """
10
+ Key types known by PKCS#11.
11
+
12
+ Making use of a given key type requires the appropriate
13
+ :class:`Mechanism` to be available.
14
+
15
+ Key types beginning with an underscore are historic and are best avoided.
16
+ """
17
+
18
+ RSA = 0x00000000
19
+ """
20
+ See the `RSA section
21
+ <http://docs.oasis-open.org/pkcs11/pkcs11-curr/v2.40/errata01/os/pkcs11-curr-v2.40-errata01-os-complete.html#_Toc441850404>`_
22
+ of the PKCS #11 specification for valid :class:`Mechanism` and
23
+ :class:`pkcs11.constants.Attribute` types.
24
+ """
25
+ DSA = 0x00000001
26
+ """
27
+ See the `DSA section
28
+ <http://docs.oasis-open.org/pkcs11/pkcs11-curr/v2.40/errata01/os/pkcs11-curr-v2.40-errata01-os-complete.html#_Toc441850428>`_
29
+ of the PKCS #11 specification for valid :class:`Mechanism` and
30
+ :class:`pkcs11.constants.Attribute` types.
31
+ """
32
+ DH = 0x00000002
33
+ """
34
+ PKCS #3 Diffie-Hellman key. See the `Diffie-Hellman section
35
+ <http://docs.oasis-open.org/pkcs11/pkcs11-curr/v2.40/errata01/os/pkcs11-curr-v2.40-errata01-os-complete.html#_Toc441850461>`_
36
+ of the PKCS #11 specification for valid :class:`Mechanism` and
37
+ :class:`pkcs11.constants.Attribute` types.
38
+ """
39
+ EC = 0x00000003
40
+ """
41
+ See the `Elliptic Curve section
42
+ <http://docs.oasis-open.org/pkcs11/pkcs11-curr/v2.40/csd01/pkcs11-curr-v2.40-csd01.html#_Toc372721391>`_
43
+ of the PKCS #11 specification for valid :class:`Mechanism` and
44
+ :class:`pkcs11.constants.Attribute` types.
45
+ """
46
+ X9_42_DH = 0x00000004
47
+ """
48
+ X9.42 Diffie-Hellman key.
49
+ """
50
+ _KEA = 0x00000005
51
+ GENERIC_SECRET = 0x00000010
52
+ _RC2 = 0x00000011
53
+ _RC4 = 0x00000012
54
+ _DES = 0x00000013
55
+ DES2 = 0x00000014
56
+ """
57
+ .. warning:: Considered insecure. Use AES where possible.
58
+ """
59
+ DES3 = 0x00000015
60
+ """
61
+ .. warning:: Considered insecure. Use AES where possible.
62
+ """
63
+ _CAST = 0x00000016
64
+ _CAST3 = 0x00000017
65
+ _CAST5 = 0x00000018
66
+ _CAST128 = 0x00000018
67
+ _RC5 = 0x00000019
68
+ _IDEA = 0x0000001A
69
+ _SKIPJACK = 0x0000001B
70
+ _BATON = 0x0000001C
71
+ _JUNIPER = 0x0000001D
72
+ _CDMF = 0x0000001E
73
+ AES = 0x0000001F
74
+ """
75
+ See the `AES section
76
+ <http://docs.oasis-open.org/pkcs11/pkcs11-curr/v2.40/errata01/os/pkcs11-curr-v2.40-errata01-os-complete.html#_Toc441850484>`_
77
+ of PKCS#11 for valid :class:`Mechanism` and
78
+ :class:`pkcs11.constants.Attribute` types.
79
+ """
80
+ BLOWFISH = 0x00000020
81
+ TWOFISH = 0x00000021
82
+ SECURID = 0x00000022
83
+ HOTP = 0x00000023
84
+ ACTI = 0x00000024
85
+ CAMELLIA = 0x00000025
86
+ ARIA = 0x00000026
87
+ _MD5_HMAC = 0x00000027
88
+ SHA_1_HMAC = 0x00000028
89
+ """
90
+ .. warning:: SHA-1 is no longer considered secure.
91
+ """
92
+ _RIPEMD128_HMAC = 0x00000029
93
+ _RIPEMD160_HMAC = 0x0000002A
94
+ SHA256_HMAC = 0x0000002B
95
+ SHA384_HMAC = 0x0000002C
96
+ SHA512_HMAC = 0x0000002D
97
+ SHA224_HMAC = 0x0000002E
98
+ SHA3_224_HMAC = 0x00000036
99
+ SHA3_256_HMAC = 0x00000037
100
+ SHA3_384_HMAC = 0x00000038
101
+ SHA3_512_HMAC = 0x00000039
102
+ SEED = 0x0000002F
103
+ GOSTR3410 = 0x00000030
104
+ GOSTR3411 = 0x00000031
105
+ GOST28147 = 0x00000032
106
+
107
+ # from version 3.0
108
+ EC_EDWARDS = 0x00000040
109
+ # from version 3.2
110
+ ML_KEM = 0x00000049
111
+ ML_DSA = 0x0000004A
112
+
113
+ _VENDOR_DEFINED = 0x80000000
114
+
115
+ def __repr__(self) -> str:
116
+ return f"<KeyType.{self.name}>"
117
+
118
+
119
+ class Mechanism(IntEnum):
120
+ """
121
+ Cryptographic mechanisms known by PKCS#11.
122
+
123
+ The list of supported cryptographic mechanisms for a :class:`pkcs11.Slot`
124
+ can be retrieved with :meth:`pkcs11.Slot.get_mechanisms()`.
125
+
126
+ Mechanisms beginning with an underscore are historic and best avoided.
127
+ Descriptions of the `current
128
+ <http://docs.oasis-open.org/pkcs11/pkcs11-curr/v2.40/pkcs11-curr-v2.40.html>`_
129
+ and `historical
130
+ <http://docs.oasis-open.org/pkcs11/pkcs11-hist/v2.40/pkcs11-hist-v2.40.html>`_
131
+ mechanisms, including their valid :class:`pkcs11.constants.Attribute`
132
+ types and `mechanism_param` can be found in the PKCS#11 specification.
133
+
134
+ Additionally, while still in the `current` spec, a number of mechanisms
135
+ including cryptographic hash functions and certain block modes are no
136
+ longer considered secure, and should not be used for new applications, e.g.
137
+ MD2, MD5, SHA1, ECB.
138
+ """
139
+
140
+ RSA_PKCS_KEY_PAIR_GEN = 0x00000000
141
+ """
142
+ RSA PKCS #1 v1.5 key generation.
143
+
144
+ .. note:: Default for generating :attr:`KeyType.RSA` keys.
145
+ """
146
+ RSA_PKCS = 0x00000001
147
+ """
148
+ RSA PKCS #1 v1.5 general purpose mechanism.
149
+
150
+ .. warning:: Consider using the more robust PKCS#1 OAEP.
151
+ """
152
+ RSA_PKCS_TPM_1_1 = 0x00004001
153
+ """
154
+ .. warning:: Consider using the more robust PKCS#1 OAEP.
155
+ """
156
+ RSA_PKCS_OAEP = 0x00000009
157
+ """
158
+ RSA PKCS #1 OAEP (v2.0+)
159
+
160
+ .. note:: Default for encrypting/decrypting with :attr:`KeyType.RSA` keys.
161
+
162
+ Optionally takes a `mechanism_param` which is a tuple of:
163
+
164
+ * message digest algorithm used to calculate the digest of the
165
+ encoding parameter (:class:`Mechanism`), default is
166
+ :attr:`Mechanism.SHA_1`;
167
+ * mask generation function to use on the encoded block
168
+ (:class:`MGF`), default is :attr:`MGF.SHA1`;
169
+ * data used as the input for the encoding parameter source
170
+ (:class:`bytes`), default is None.
171
+ """
172
+ RSA_PKCS_OAEP_TPM_1_1 = 0x00004002
173
+ RSA_X_509 = 0x00000003
174
+ """
175
+ X.509 (raw) RSA.
176
+
177
+ No padding, supply your own.
178
+ """
179
+ RSA_9796 = 0x00000002
180
+ """
181
+ ISO/IEC 9796 RSA.
182
+
183
+ .. warning:: DS1 and DS3 are considered broken. The PKCS #11 spec doesn't
184
+ specify which scheme is used. Use `PSS` instead.
185
+ """
186
+
187
+ MD2_RSA_PKCS = 0x00000004
188
+ """
189
+ .. warning:: Not considered secure.
190
+ """
191
+ MD5_RSA_PKCS = 0x00000005
192
+ """
193
+ .. warning:: Not considered secure.
194
+ """
195
+ SHA1_RSA_PKCS = 0x00000006
196
+ """
197
+ .. warning:: SHA-1 is no longer considered secure.
198
+ """
199
+ SHA224_RSA_PKCS = 0x00000046
200
+ SHA256_RSA_PKCS = 0x00000040
201
+ SHA384_RSA_PKCS = 0x00000041
202
+ SHA512_RSA_PKCS = 0x00000042
203
+ """
204
+ .. note:: Default for signing/verification with :attr:`KeyType.RSA` keys.
205
+ """
206
+ SHA3_224_RSA_PKCS = 0x00000066
207
+ SHA3_256_RSA_PKCS = 0x00000060
208
+ SHA3_384_RSA_PKCS = 0x00000061
209
+ SHA3_512_RSA_PKCS = 0x00000062
210
+
211
+ RSA_PKCS_PSS = 0x0000000D
212
+ """
213
+ RSA PSS without hashing.
214
+
215
+ PSS schemes optionally take a tuple of:
216
+
217
+ * message digest algorithm used to calculate the digest of the
218
+ encoding parameter (:class:`Mechanism`), default is
219
+ :attr:`Mechanism.SHA_1`;
220
+ * mask generation function to use on the encoded block
221
+ (:class:`MGF`), default is :attr:`MGF.SHA1`; and
222
+ * salt length, default is 20
223
+ """
224
+ SHA1_RSA_PKCS_PSS = 0x0000000E
225
+ """
226
+ .. warning:: SHA-1 is no longer considered secure.
227
+ """
228
+ SHA224_RSA_PKCS_PSS = 0x00000047
229
+ SHA256_RSA_PKCS_PSS = 0x00000043
230
+ SHA384_RSA_PKCS_PSS = 0x00000044
231
+ SHA512_RSA_PKCS_PSS = 0x00000045
232
+ SHA3_256_RSA_PKCS_PSS = 0x00000063
233
+ SHA3_384_RSA_PKCS_PSS = 0x00000064
234
+ SHA3_512_RSA_PKCS_PSS = 0x00000065
235
+ SHA3_224_RSA_PKCS_PSS = 0x00000067
236
+
237
+ RSA_X9_31_KEY_PAIR_GEN = 0x0000000A
238
+ RSA_X9_31 = 0x0000000B
239
+ SHA1_RSA_X9_31 = 0x0000000C
240
+ """
241
+ .. warning:: SHA-1 is no longer considered secure.
242
+ """
243
+
244
+ _RIPEMD128_RSA_PKCS = 0x00000007
245
+ _RIPEMD160_RSA_PKCS = 0x00000008
246
+
247
+ DSA_KEY_PAIR_GEN = 0x00000010
248
+ """
249
+ .. note:: Default mechanism for generating :attr:`KeyType.DSA` keypairs
250
+
251
+ Requires :class:`pkcs11.DomainParameters`.
252
+ """
253
+ DSA = 0x00000011
254
+ """
255
+ DSA without hashing.
256
+ """
257
+ DSA_SHA1 = 0x00000012
258
+ """
259
+ .. warning:: SHA-1 is no longer considered secure.
260
+ """
261
+ DSA_SHA224 = 0x00000013
262
+ DSA_SHA256 = 0x00000014
263
+ DSA_SHA384 = 0x00000015
264
+ DSA_SHA512 = 0x00000016
265
+ """
266
+ DSA with SHA512 hashing.
267
+
268
+ .. note:: Default for signing/verification with :attr:`KeyType.DSA` keys.
269
+ """
270
+
271
+ DH_PKCS_KEY_PAIR_GEN = 0x00000020
272
+ """
273
+ .. note:: Default mechanism for generating :attr:`KeyType.DH` key pairs.
274
+
275
+ This is the mechanism defined in PKCS #3.
276
+
277
+ Requires :class:`pkcs11.DomainParameters` of
278
+ :attr:`pkcs11.constants.Attribute.BASE` and
279
+ :attr:`pkcs11.constants.Attribute.PRIME`.
280
+ """
281
+ DH_PKCS_DERIVE = 0x00000021
282
+ """
283
+ .. note:: Default mechanism for deriving shared keys from
284
+ :attr:`KeyType.DH` private keys.
285
+
286
+ This is the mechanism defined in PKCS #3.
287
+
288
+ Takes the other participant's public key
289
+ :attr:`pkcs11.constants.Attribute.VALUE` as the `mechanism_param`.
290
+ """
291
+
292
+ X9_42_DH_KEY_PAIR_GEN = 0x00000030
293
+ X9_42_DH_DERIVE = 0x00000031
294
+ X9_42_DH_HYBRID_DERIVE = 0x00000032
295
+ X9_42_MQV_DERIVE = 0x00000033
296
+
297
+ _RC2_KEY_GEN = 0x00000100
298
+ _RC2_ECB = 0x00000101
299
+ _RC2_CBC = 0x00000102
300
+ _RC2_MAC = 0x00000103
301
+
302
+ _RC2_MAC_GENERAL = 0x00000104
303
+ _RC2_CBC_PAD = 0x00000105
304
+
305
+ _RC4_KEY_GEN = 0x00000110
306
+ _RC4 = 0x00000111
307
+ _DES_KEY_GEN = 0x00000120
308
+ _DES_ECB = 0x00000121
309
+ _DES_CBC = 0x00000122
310
+ _DES_MAC = 0x00000123
311
+
312
+ _DES_MAC_GENERAL = 0x00000124
313
+ _DES_CBC_PAD = 0x00000125
314
+
315
+ DES2_KEY_GEN = 0x00000130
316
+ """
317
+ .. note:: Default for generating DES2 keys.
318
+
319
+ .. warning:: Considered insecure. Use AES where possible.
320
+ """
321
+ DES3_KEY_GEN = 0x00000131
322
+ """
323
+ .. note:: Default for generating DES3 keys.
324
+
325
+ .. warning:: Considered insecure. Use AES where possible.
326
+ """
327
+ DES3_ECB = 0x00000132
328
+ """
329
+ .. note:: Default for key wrapping with DES2/3.
330
+
331
+ .. warning:: Identical blocks will encipher to the same result.
332
+ Considered insecure. Use AES where possible.
333
+ """
334
+ DES3_CBC = 0x00000133
335
+ DES3_MAC = 0x00000134
336
+ """
337
+ .. note:: This is the default for signing/verification with
338
+ :class:`KeyType.DES2` and :class:`KeyType.DES3`.
339
+
340
+ .. warning:: Considered insecure. Use AES where possible.
341
+ """
342
+
343
+ DES3_MAC_GENERAL = 0x00000135
344
+ DES3_CBC_PAD = 0x00000136
345
+ """
346
+ .. note:: Default for encryption/decryption with DES2/3.
347
+
348
+ .. warning:: Considered insecure. Use AES where possible.
349
+ """
350
+ DES3_CMAC_GENERAL = 0x00000137
351
+ DES3_CMAC = 0x00000138
352
+
353
+ _CDMF_KEY_GEN = 0x00000140
354
+ _CDMF_ECB = 0x00000141
355
+ _CDMF_CBC = 0x00000142
356
+ _CDMF_MAC = 0x00000143
357
+ _CDMF_MAC_GENERAL = 0x00000144
358
+ _CDMF_CBC_PAD = 0x00000145
359
+
360
+ _DES_OFB64 = 0x00000150
361
+ _DES_OFB8 = 0x00000151
362
+ _DES_CFB64 = 0x00000152
363
+ _DES_CFB8 = 0x00000153
364
+
365
+ _MD2 = 0x00000200
366
+ _MD2_HMAC = 0x00000201
367
+ _MD2_HMAC_GENERAL = 0x00000202
368
+
369
+ _MD5 = 0x00000210
370
+ _MD5_HMAC = 0x00000211
371
+ _MD5_HMAC_GENERAL = 0x00000212
372
+
373
+ SHA_1 = 0x00000220
374
+ """
375
+ .. warning:: SHA-1 is no longer considered secure.
376
+ """
377
+ SHA_1_HMAC = 0x00000221
378
+ """
379
+ .. warning:: SHA-1 is no longer considered secure.
380
+ """
381
+ SHA_1_HMAC_GENERAL = 0x00000222
382
+ """
383
+ .. warning:: SHA-1 is no longer considered secure.
384
+ """
385
+
386
+ _RIPEMD128 = 0x00000230
387
+ _RIPEMD128_HMAC = 0x00000231
388
+ _RIPEMD128_HMAC_GENERAL = 0x00000232
389
+ _RIPEMD160 = 0x00000240
390
+ _RIPEMD160_HMAC = 0x00000241
391
+ _RIPEMD160_HMAC_GENERAL = 0x00000242
392
+
393
+ SHA256 = 0x00000250
394
+ SHA256_HMAC = 0x00000251
395
+ SHA256_HMAC_GENERAL = 0x00000252
396
+
397
+ SHA224 = 0x00000255
398
+ SHA224_HMAC = 0x00000256
399
+ SHA224_HMAC_GENERAL = 0x00000257
400
+
401
+ SHA384 = 0x00000260
402
+ SHA384_HMAC = 0x00000261
403
+ SHA384_HMAC_GENERAL = 0x00000262
404
+
405
+ SHA512 = 0x00000270
406
+ SHA512_HMAC = 0x00000271
407
+ SHA512_HMAC_GENERAL = 0x00000272
408
+
409
+ SECURID_KEY_GEN = 0x00000280
410
+ SECURID = 0x00000282
411
+ HOTP_KEY_GEN = 0x00000290
412
+ HOTP = 0x00000291
413
+ ACTI = 0x000002A0
414
+ ACTI_KEY_GEN = 0x000002A1
415
+
416
+ _CAST_KEY_GEN = 0x00000300
417
+ _CAST_ECB = 0x00000301
418
+ _CAST_CBC = 0x00000302
419
+ _CAST_MAC = 0x00000303
420
+ _CAST_MAC_GENERAL = 0x00000304
421
+ _CAST_CBC_PAD = 0x00000305
422
+ _CAST3_KEY_GEN = 0x00000310
423
+ _CAST3_ECB = 0x00000311
424
+ _CAST3_CBC = 0x00000312
425
+ _CAST3_MAC = 0x00000313
426
+ _CAST3_MAC_GENERAL = 0x00000314
427
+ _CAST3_CBC_PAD = 0x00000315
428
+
429
+ _CAST5_KEY_GEN = 0x00000320
430
+ _CAST128_KEY_GEN = 0x00000320
431
+ _CAST5_ECB = 0x00000321
432
+ _CAST128_ECB = 0x00000321
433
+ _CAST5_CBC = 0x00000322
434
+ _CAST128_CBC = 0x00000322
435
+ _CAST5_MAC = 0x00000323
436
+ _CAST128_MAC = 0x00000323
437
+ _CAST5_MAC_GENERAL = 0x00000324
438
+ _CAST128_MAC_GENERAL = 0x00000324
439
+ _CAST5_CBC_PAD = 0x00000325
440
+ _CAST128_CBC_PAD = 0x00000325
441
+
442
+ _RC5_KEY_GEN = 0x00000330
443
+ _RC5_ECB = 0x00000331
444
+ _RC5_CBC = 0x00000332
445
+ _RC5_MAC = 0x00000333
446
+ _RC5_MAC_GENERAL = 0x00000334
447
+ _RC5_CBC_PAD = 0x00000335
448
+
449
+ _IDEA_KEY_GEN = 0x00000340
450
+ _IDEA_ECB = 0x00000341
451
+ _IDEA_CBC = 0x00000342
452
+ _IDEA_MAC = 0x00000343
453
+ _IDEA_MAC_GENERAL = 0x00000344
454
+ _IDEA_CBC_PAD = 0x00000345
455
+
456
+ GENERIC_SECRET_KEY_GEN = 0x00000350
457
+ CONCATENATE_BASE_AND_KEY = 0x00000360
458
+ CONCATENATE_BASE_AND_DATA = 0x00000362
459
+ CONCATENATE_DATA_AND_BASE = 0x00000363
460
+ XOR_BASE_AND_DATA = 0x00000364
461
+ EXTRACT_KEY_FROM_KEY = 0x00000365
462
+
463
+ SSL3_PRE_MASTER_KEY_GEN = 0x00000370
464
+ SSL3_MASTER_KEY_DERIVE = 0x00000371
465
+ SSL3_KEY_AND_MAC_DERIVE = 0x00000372
466
+ SSL3_MASTER_KEY_DERIVE_DH = 0x00000373
467
+ SSL3_MD5_MAC = 0x00000380
468
+ SSL3_SHA1_MAC = 0x00000381
469
+
470
+ TLS_PRE_MASTER_KEY_GEN = 0x00000374
471
+ TLS_MASTER_KEY_DERIVE = 0x00000375
472
+ TLS_KEY_AND_MAC_DERIVE = 0x00000376
473
+ TLS_MASTER_KEY_DERIVE_DH = 0x00000377
474
+ TLS_PRF = 0x00000378
475
+
476
+ _MD5_KEY_DERIVATION = 0x00000390
477
+ _MD2_KEY_DERIVATION = 0x00000391
478
+ SHA1_KEY_DERIVATION = 0x00000392
479
+
480
+ SHA256_KEY_DERIVATION = 0x00000393
481
+ SHA384_KEY_DERIVATION = 0x00000394
482
+ SHA512_KEY_DERIVATION = 0x00000395
483
+ SHA224_KEY_DERIVATION = 0x00000396
484
+
485
+ SHA3_256_KEY_DERIVATION = 0x00000397
486
+ SHA3_224_KEY_DERIVATION = 0x00000398
487
+ SHA3_384_KEY_DERIVATION = 0x00000399
488
+ SHA3_512_KEY_DERIVATION = 0x0000039A
489
+ SHAKE_128_KEY_DERIVATION = 0x0000039B
490
+ SHAKE_256_KEY_DERIVATION = 0x0000039C
491
+
492
+ _PBE_MD2_DES_CBC = 0x000003A0
493
+ _PBE_MD5_DES_CBC = 0x000003A1
494
+ _PBE_MD5_CAST_CBC = 0x000003A2
495
+ _PBE_MD5_CAST3_CBC = 0x000003A3
496
+ _PBE_MD5_CAST5_CBC = 0x000003A4
497
+ _PBE_MD5_CAST128_CBC = 0x000003A4
498
+ _PBE_SHA1_CAST5_CBC = 0x000003A5
499
+ _PBE_SHA1_CAST128_CBC = 0x000003A5
500
+ _PBE_SHA1_RC4_128 = 0x000003A6
501
+ _PBE_SHA1_RC4_40 = 0x000003A7
502
+ _PBE_SHA1_DES3_EDE_CBC = 0x000003A8
503
+ _PBE_SHA1_DES2_EDE_CBC = 0x000003A9
504
+ _PBE_SHA1_RC2_128_CBC = 0x000003AA
505
+ _PBE_SHA1_RC2_40_CBC = 0x000003AB
506
+
507
+ PKCS5_PBKD2 = 0x000003B0
508
+
509
+ _PBA_SHA1_WITH_SHA1_HMAC = 0x000003C0
510
+
511
+ WTLS_PRE_MASTER_KEY_GEN = 0x000003D0
512
+ WTLS_MASTER_KEY_DERIVE = 0x000003D1
513
+ WTLS_MASTER_KEY_DERIVE_DH_ECC = 0x000003D2
514
+ WTLS_PRF = 0x000003D3
515
+ WTLS_SERVER_KEY_AND_MAC_DERIVE = 0x000003D4
516
+ WTLS_CLIENT_KEY_AND_MAC_DERIVE = 0x000003D5
517
+
518
+ _KEY_WRAP_LYNKS = 0x00000400
519
+ _KEY_WRAP_SET_OAEP = 0x00000401
520
+
521
+ CMS_SIG = 0x00000500
522
+
523
+ KIP_DERIVE = 0x00000510
524
+ KIP_WRAP = 0x00000511
525
+ KIP_MAC = 0x00000512
526
+
527
+ _CAMELLIA_KEY_GEN = 0x00000550
528
+ _CAMELLIA_ECB = 0x00000551
529
+ _CAMELLIA_CBC = 0x00000552
530
+ _CAMELLIA_MAC = 0x00000553
531
+ _CAMELLIA_MAC_GENERAL = 0x00000554
532
+ _CAMELLIA_CBC_PAD = 0x00000555
533
+ _CAMELLIA_ECB_ENCRYPT_DATA = 0x00000556
534
+ _CAMELLIA_CBC_ENCRYPT_DATA = 0x00000557
535
+ _CAMELLIA_CTR = 0x00000558
536
+
537
+ _ARIA_KEY_GEN = 0x00000560
538
+ _ARIA_ECB = 0x00000561
539
+ _ARIA_CBC = 0x00000562
540
+ _ARIA_MAC = 0x00000563
541
+ _ARIA_MAC_GENERAL = 0x00000564
542
+ _ARIA_CBC_PAD = 0x00000565
543
+ _ARIA_ECB_ENCRYPT_DATA = 0x00000566
544
+ _ARIA_CBC_ENCRYPT_DATA = 0x00000567
545
+
546
+ SEED_KEY_GEN = 0x00000650
547
+ SEED_ECB = 0x00000651
548
+ """
549
+ .. warning:: Identical blocks will encipher to the same result.
550
+ """
551
+ SEED_CBC = 0x00000652
552
+ SEED_MAC = 0x00000653
553
+ SEED_MAC_GENERAL = 0x00000654
554
+ SEED_CBC_PAD = 0x00000655
555
+ SEED_ECB_ENCRYPT_DATA = 0x00000656
556
+ SEED_CBC_ENCRYPT_DATA = 0x00000657
557
+
558
+ _SKIPJACK_KEY_GEN = 0x00001000
559
+ _SKIPJACK_ECB64 = 0x00001001
560
+ _SKIPJACK_CBC64 = 0x00001002
561
+ _SKIPJACK_OFB64 = 0x00001003
562
+ _SKIPJACK_CFB64 = 0x00001004
563
+ _SKIPJACK_CFB32 = 0x00001005
564
+ _SKIPJACK_CFB16 = 0x00001006
565
+ _SKIPJACK_CFB8 = 0x00001007
566
+ _SKIPJACK_WRAP = 0x00001008
567
+ _SKIPJACK_PRIVATE_WRAP = 0x00001009
568
+ _SKIPJACK_RELAYX = 0x0000100A
569
+
570
+ _KEA_KEY_PAIR_GEN = 0x00001010
571
+ _KEA_KEY_DERIVE = 0x00001011
572
+
573
+ _FORTEZZA_TIMESTAMP = 0x00001020
574
+
575
+ _BATON_KEY_GEN = 0x00001030
576
+ _BATON_ECB128 = 0x00001031
577
+ _BATON_ECB96 = 0x00001032
578
+ _BATON_CBC128 = 0x00001033
579
+ _BATON_COUNTER = 0x00001034
580
+ _BATON_SHUFFLE = 0x00001035
581
+ _BATON_WRAP = 0x00001036
582
+
583
+ EC_KEY_PAIR_GEN = 0x00001040
584
+ """
585
+ .. note:: Default mechanism for generating :attr:`KeyType.EC` key pairs
586
+
587
+ Requires :class:`pkcs11.DomainParameters` of
588
+ :attr:`pkcs11.constants.Attribute.EC_PARAMS`.
589
+ """
590
+
591
+ ECDSA = 0x00001041
592
+ """ECDSA with no hashing. Input truncated to 1024-bits."""
593
+ ECDSA_SHA1 = 0x00001042
594
+ """
595
+ .. warning:: SHA-1 is no longer considered secure.
596
+ """
597
+ ECDSA_SHA224 = 0x00001043
598
+ ECDSA_SHA256 = 0x00001044
599
+ ECDSA_SHA384 = 0x00001045
600
+ ECDSA_SHA512 = 0x00001046
601
+ """
602
+ ECDSA with SHA512 hashing.
603
+
604
+ .. note:: Default for signing/verification with :attr:`KeyType.EC` keys.
605
+ """
606
+
607
+ ECDH1_DERIVE = 0x00001050
608
+ """
609
+ .. note:: Default mechanism for deriving shared keys from
610
+ :attr:`KeyType.EC` private keys.
611
+
612
+ Takes a tuple of:
613
+
614
+ * key derivation function (:class:`pkcs11.mechanisms.KDF`);
615
+ * shared value (:class:`bytes`); and
616
+ * other participant's :attr:`pkcs11.constants.Attribute.EC_POINT`
617
+ (:class:`bytes`)
618
+
619
+ as the `mechanism_param`.
620
+ """
621
+ ECDH1_COFACTOR_DERIVE = 0x00001051
622
+ ECMQV_DERIVE = 0x00001052
623
+
624
+ _JUNIPER_KEY_GEN = 0x00001060
625
+ _JUNIPER_ECB128 = 0x00001061
626
+ _JUNIPER_CBC128 = 0x00001062
627
+ _JUNIPER_COUNTER = 0x00001063
628
+ _JUNIPER_SHUFFLE = 0x00001064
629
+ _JUNIPER_WRAP = 0x00001065
630
+ _FASTHASH = 0x00001070
631
+
632
+ AES_KEY_GEN = 0x00001080
633
+ """
634
+ .. note:: Default for generating :attr:`KeyType.AES` keys.
635
+ """
636
+ AES_ECB = 0x00001081
637
+ """
638
+ .. note:: Default wrapping mechanism for :attr:`KeyType.AES` keys.
639
+
640
+ .. warning:: Identical blocks will encipher to the same result.
641
+ """
642
+ AES_CBC = 0x00001082
643
+ AES_CBC_PAD = 0x00001085
644
+ """
645
+ CBC with PKCS#7 padding to pad files to a whole number of blocks.
646
+
647
+ .. note:: Default for encrypting/decrypting with :attr:`KeyType.AES` keys.
648
+
649
+ Requires a 128-bit initialisation vector passed as `mechanism_param`.
650
+ """
651
+ AES_CTR = 0x00001086
652
+ AES_CTS = 0x00001089
653
+ AES_MAC = 0x00001083
654
+ """
655
+ .. note:: This is the default for signing/verification with
656
+ :class:`KeyType.AES`.
657
+ """
658
+ AES_MAC_GENERAL = 0x00001084
659
+ AES_CMAC = 0x0000108A
660
+ AES_CMAC_GENERAL = 0x0000108B
661
+
662
+ BLOWFISH_KEY_GEN = 0x00001090
663
+ BLOWFISH_CBC = 0x00001091
664
+ BLOWFISH_CBC_PAD = 0x00001094
665
+
666
+ TWOFISH_KEY_GEN = 0x00001092
667
+ TWOFISH_CBC = 0x00001093
668
+ TWOFISH_CBC_PAD = 0x00001095
669
+
670
+ AES_GCM = 0x00001087
671
+ AES_CCM = 0x00001088
672
+ _AES_KEY_WRAP = 0x00001090
673
+ """This is the old value for AES_KEY_WRAP. Changed in the 2016 spec."""
674
+ _AES_KEY_WRAP_PAD = 0x00001091
675
+ """This is the old value for AES_KEY_WRAP_PAD. Changed in the 2016 spec."""
676
+
677
+ AES_XCBC_MAC = 0x0000108C
678
+ AES_XCBC_MAC_96 = 0x0000108D
679
+ AES_GMAC = 0x0000108E
680
+
681
+ AES_OFB = 0x00002104
682
+ AES_CFB64 = 0x00002105
683
+ AES_CFB8 = 0x00002106
684
+ AES_CFB128 = 0x00002107
685
+
686
+ AES_CFB1 = 0x00002108
687
+ AES_KEY_WRAP = 0x00002109
688
+ AES_KEY_WRAP_PAD = 0x0000210A
689
+ AES_KEY_WRAP_KWP = 0x0000210B
690
+ """Bug: SoftHSMv2 mechanism AES_KEY_WRAP_PAD is actually AES_KEY_WRAP_KWP"""
691
+ AES_KEY_WRAP_PKCS7 = 0x0000210C
692
+ """PKCS #11 v3.1: AES_KEY_WRAP_PAD is deprecated due to confusion in implementation"""
693
+
694
+ DES_ECB_ENCRYPT_DATA = 0x00001100
695
+ DES_CBC_ENCRYPT_DATA = 0x00001101
696
+ DES3_ECB_ENCRYPT_DATA = 0x00001102
697
+ DES3_CBC_ENCRYPT_DATA = 0x00001103
698
+ AES_ECB_ENCRYPT_DATA = 0x00001104
699
+ AES_CBC_ENCRYPT_DATA = 0x00001105
700
+
701
+ GOSTR3410_KEY_PAIR_GEN = 0x00001200
702
+ GOSTR3410 = 0x00001201
703
+ GOSTR3410_WITH_GOSTR3411 = 0x00001202
704
+ GOSTR3410_KEY_WRAP = 0x00001203
705
+ GOSTR3410_DERIVE = 0x00001204
706
+ GOSTR3411 = 0x00001210
707
+ GOSTR3411_HMAC = 0x00001211
708
+ GOST28147_KEY_GEN = 0x00001220
709
+ GOST28147_ECB = 0x00001221
710
+ """
711
+ .. warning:: Identical blocks will encipher to the same result.
712
+ """
713
+ GOST28147 = 0x00001222
714
+ GOST28147_MAC = 0x00001223
715
+ GOST28147_KEY_WRAP = 0x00001224
716
+
717
+ DSA_PARAMETER_GEN = 0x00002000
718
+ """
719
+ .. note:: Default mechanism for generating :attr:`KeyType.DSA` domain
720
+ parameters.
721
+ """
722
+ DH_PKCS_PARAMETER_GEN = 0x00002001
723
+ """
724
+ .. note:: Default mechanism for generating :attr:`KeyType.DH` domain
725
+ parameters.
726
+
727
+ This is the mechanism defined in PKCS #3.
728
+ """
729
+
730
+ X9_42_DH_PARAMETER_GEN = 0x00002002
731
+ """
732
+ .. note:: Default mechanism for generating :attr:`KeyType.X9_42_DH` domain
733
+ parameters (X9.42 DH).
734
+ """
735
+
736
+ # from version 3.0
737
+ EDDSA = 0x00001057
738
+ EC_EDWARDS_KEY_PAIR_GEN = 0x00001055
739
+
740
+ # ML-KEM (v3.2)
741
+ ML_KEM_KEY_PAIR_GEN = 0x0000000F
742
+ ML_KEM = 0x00000017
743
+
744
+ # ML-DSA (v3.2)
745
+ ML_DSA_KEY_PAIR_GEN = 0x0000001C
746
+ ML_DSA = 0x0000001D
747
+
748
+ SHA3_256 = 0x000002B0
749
+ SHA3_256_HMAC = 0x000002B1
750
+ SHA3_256_HMAC_GENERAL = 0x000002B2
751
+ SHA3_256_KEY_GEN = 0x000002B3
752
+ SHA3_224 = 0x000002B5
753
+ SHA3_224_HMAC = 0x000002B6
754
+ SHA3_224_HMAC_GENERAL = 0x000002B7
755
+ SHA3_224_KEY_GEN = 0x000002B8
756
+ SHA3_384 = 0x000002C0
757
+ SHA3_384_HMAC = 0x000002C1
758
+ SHA3_384_HMAC_GENERAL = 0x000002C2
759
+ SHA3_384_KEY_GEN = 0x000002C3
760
+ SHA3_512 = 0x000002D0
761
+ SHA3_512_HMAC = 0x000002D1
762
+ SHA3_512_HMAC_GENERAL = 0x000002D2
763
+ SHA3_512_KEY_GEN = 0x000002D3
764
+
765
+ _VENDOR_DEFINED = 0x80000000
766
+
767
+ def __repr__(self) -> str:
768
+ return f"<Mechanism.{self.name}>"
769
+
770
+
771
+ class KDF(IntEnum):
772
+ """
773
+ Key Derivation Functions.
774
+ """
775
+
776
+ NULL = 0x00000001
777
+ SHA1 = 0x00000002
778
+
779
+ SHA1_ASN1 = 0x00000003
780
+ SHA1_CONCATENATE = 0x00000004
781
+ SHA224 = 0x00000005
782
+ SHA256 = 0x00000006
783
+ SHA384 = 0x00000007
784
+ SHA512 = 0x00000008
785
+ CPDIVERSIFY = 0x00000009
786
+ SHA3_224_KDF = 0x0000000A
787
+ SHA3_256_KDF = 0x0000000B
788
+ SHA3_384_KDF = 0x0000000C
789
+ SHA3_512_KDF = 0x0000000D
790
+
791
+ def __repr__(self) -> str:
792
+ return f"<KDF.{self.name}>"
793
+
794
+
795
+ class MGF(IntEnum):
796
+ """
797
+ RSA PKCS #1 Mask Generation Functions.
798
+ """
799
+
800
+ SHA1 = 0x00000001
801
+ SHA256 = 0x00000002
802
+ SHA384 = 0x00000003
803
+ SHA512 = 0x00000004
804
+ SHA224 = 0x00000005
805
+ SHA3_224 = 0x00000006
806
+ SHA3_256 = 0x00000007
807
+ SHA3_384 = 0x00000008
808
+ SHA3_512 = 0x00000009
809
+
810
+ def __repr__(self) -> str:
811
+ return f"<MGF.{self.name}>"
812
+
813
+
814
+ class MLKEMParameterSet(IntEnum):
815
+ """ML-KEM parameter sets as defined in FIPS 203."""
816
+
817
+ ML_KEM_512 = 0x00000001
818
+ ML_KEM_768 = 0x00000002
819
+ ML_KEM_1024 = 0x00000003
820
+
821
+ def __repr__(self) -> str:
822
+ return f"<MLKEMParameterSet.{self.name}>"
823
+
824
+
825
+ class MLDSAParameterSet(IntEnum):
826
+ """ML-DSA parameter sets as defined in FIPS 204."""
827
+
828
+ ML_DSA_44 = 0x00000001
829
+ ML_DSA_65 = 0x00000002
830
+ ML_DSA_87 = 0x00000003
831
+
832
+ def __repr__(self) -> str:
833
+ return f"<MLDSAParameterSet.{self.name}>"
834
+
835
+
836
+ class GCMParams:
837
+ """Parameters for AES-GCM mode."""
838
+
839
+ nonce: bytes
840
+ aad: bytes | None
841
+ tag_bits: int
842
+
843
+ def __init__(self, nonce: bytes, aad: bytes | None = None, tag_bits: int = 128) -> None:
844
+ if len(nonce) > 12:
845
+ raise ArgumentsBad("IV must be less than 12 bytes")
846
+ self.nonce = nonce
847
+ self.aad = aad
848
+ self.tag_bits = tag_bits
849
+
850
+
851
+ class CTRParams:
852
+ """Parameters for AES-CTR mode."""
853
+
854
+ nonce: bytes
855
+
856
+ def __init__(self, nonce: bytes) -> None:
857
+ if len(nonce) >= 16:
858
+ raise ArgumentsBad(
859
+ f"{nonce.hex()} is too long to serve as a CTR nonce, must be 15 bytes or less "
860
+ f"to leave room for the block counter."
861
+ )
862
+ self.nonce = nonce