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