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