-
Notifications
You must be signed in to change notification settings - Fork 242
/
Copy pathpkcs11_ta.h
1331 lines (1250 loc) · 43 KB
/
pkcs11_ta.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* Copyright (c) 2018-2020, Linaro Limited
*/
#ifndef PKCS11_TA_H
#define PKCS11_TA_H
#include <stdbool.h>
#include <stdint.h>
#define PKCS11_TA_UUID { 0xfd02c9da, 0x306c, 0x48c7, \
{ 0xa4, 0x9c, 0xbb, 0xd8, 0x27, 0xae, 0x86, 0xee } }
/* PKCS11 trusted application version information */
#define PKCS11_TA_VERSION_MAJOR 0
#define PKCS11_TA_VERSION_MINOR 1
#define PKCS11_TA_VERSION_PATCH 0
/* Attribute specific values */
#define PKCS11_CK_UNAVAILABLE_INFORMATION UINT32_C(0xFFFFFFFF)
#define PKCS11_UNDEFINED_ID UINT32_C(0xFFFFFFFF)
#define PKCS11_FALSE false
#define PKCS11_TRUE true
/*
* Note on PKCS#11 TA commands ABI
*
* For evolution of the TA API and to not mess with the GPD TEE 4 parameters
* constraint, all the PKCS11 TA invocation commands use a subset of available
* the GPD TEE invocation parameter types.
*
* Param#0 is used for the so-called control arguments of the invoked command
* and for providing a PKCS#11 compliant status code for the request command.
* Param#0 is an in/out memory reference (aka memref[0]). The input buffer
* stores serialized arguments for the command. The output buffer store the
* 32bit TA return code for the command. As a consequence, param#0 shall
* always be an input/output memory reference of at least 32bit, more if
* the command expects more input arguments.
*
* When the TA returns with TEE_SUCCESS result, client shall always get the
* 32bit value stored in param#0 output buffer and use the value as TA
* return code for the invoked command.
*
* Param#1 can be used for input data arguments of the invoked command.
* It is unused or is an input memory reference, aka memref[1].
* Evolution of the API may use memref[1] for output data as well.
*
* Param#2 is mostly used for output data arguments of the invoked command
* and for output handles generated from invoked commands.
* Few commands uses it for a secondary input data buffer argument.
* It is unused or is an input/output/in-out memory reference, aka memref[2].
*
* Param#3 is currently unused and reserved for evolution of the API.
*/
enum pkcs11_ta_cmd {
/*
* PKCS11_CMD_PING Ack TA presence and return version info
*
* [in] memref[0] = 32bit, unused, must be 0
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [out] memref[2] = [
* 32bit version major value,
* 32bit version minor value
* 32bit version patch value
* ]
*/
PKCS11_CMD_PING = 0,
/*
* PKCS11_CMD_SLOT_LIST - Get the table of the valid slot IDs
*
* [in] memref[0] = 32bit, unused, must be 0
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [out] memref[2] = 32bit array slot_ids[slot counts]
*
* The TA instance may represent several PKCS#11 slots and
* associated tokens. This commadn reports the IDs of embedded tokens.
* This command relates the PKCS#11 API function C_GetSlotList().
*/
PKCS11_CMD_SLOT_LIST = 1,
/*
* PKCS11_CMD_SLOT_INFO - Get cryptoki structured slot information
*
* [in] memref[0] = 32bit slot ID
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [out] memref[2] = (struct pkcs11_slot_info)info
*
* The TA instance may represent several PKCS#11 slots/tokens.
* This command relates the PKCS#11 API function C_GetSlotInfo().
*/
PKCS11_CMD_SLOT_INFO = 2,
/*
* PKCS11_CMD_TOKEN_INFO - Get cryptoki structured token information
*
* [in] memref[0] = 32bit slot ID
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [out] memref[2] = (struct pkcs11_token_info)info
*
* The TA instance may represent several PKCS#11 slots/tokens.
* This command relates the PKCS#11 API function C_GetTokenInfo().
*/
PKCS11_CMD_TOKEN_INFO = 3,
/*
* PKCS11_CMD_MECHANISM_IDS - Get list of the supported mechanisms
*
* [in] memref[0] = 32bit slot ID
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [out] memref[2] = 32bit array mechanism IDs
*
* This command relates to the PKCS#11 API function
* C_GetMechanismList().
*/
PKCS11_CMD_MECHANISM_IDS = 4,
/*
* PKCS11_CMD_MECHANISM_INFO - Get information on a specific mechanism
*
* [in] memref[0] = [
* 32bit slot ID,
* 32bit mechanism ID (PKCS11_CKM_*)
* ]
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [out] memref[2] = (struct pkcs11_mechanism_info)info
*
* This command relates to the PKCS#11 API function
* C_GetMechanismInfo().
*/
PKCS11_CMD_MECHANISM_INFO = 5,
/*
* PKCS11_CMD_OPEN_SESSION - Open a session
*
* [in] memref[0] = [
* 32bit slot ID,
* 32bit session flags,
* ]
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [out] memref[2] = 32bit session handle
*
* This command relates to the PKCS#11 API function C_OpenSession().
*/
PKCS11_CMD_OPEN_SESSION = 6,
/*
* PKCS11_CMD_CLOSE_SESSION - Close an opened session
*
* [in] memref[0] = 32bit session handle
* [out] memref[0] = 32bit return code, enum pkcs11_rc
*
* This command relates to the PKCS#11 API function C_CloseSession().
*/
PKCS11_CMD_CLOSE_SESSION = 7,
/*
* PKCS11_CMD_CLOSE_ALL_SESSIONS - Close all client sessions on token
*
* [in] memref[0] = 32bit slot ID
* [out] memref[0] = 32bit return code, enum pkcs11_rc
*
* This command relates to the PKCS#11 API function
* C_CloseAllSessions().
*/
PKCS11_CMD_CLOSE_ALL_SESSIONS = 8,
/*
* PKCS11_CMD_SESSION_INFO - Get Cryptoki information on a session
*
* [in] memref[0] = 32bit session handle
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [out] memref[2] = (struct pkcs11_session_info)info
*
* This command relates to the PKCS#11 API function C_GetSessionInfo().
*/
PKCS11_CMD_SESSION_INFO = 9,
/*
* PKCS11_CMD_INIT_TOKEN - Initialize PKCS#11 token
*
* [in] memref[0] = [
* 32bit slot ID,
* 32bit PIN length,
* byte array label[32]
* byte array PIN[PIN length],
* ]
* [out] memref[0] = 32bit return code, enum pkcs11_rc
*
* This command relates to the PKCS#11 API function C_InitToken().
*/
PKCS11_CMD_INIT_TOKEN = 10,
/*
* PKCS11_CMD_INIT_PIN - Initialize user PIN
*
* [in] memref[0] = [
* 32bit session handle,
* 32bit PIN byte size,
* byte array: PIN data
* ]
* [out] memref[0] = 32bit return code, enum pkcs11_rc
*
* This command relates to the PKCS#11 API function C_InitPIN().
*/
PKCS11_CMD_INIT_PIN = 11,
/*
* PKCS11_CMD_SET_PIN - Change user PIN
*
* [in] memref[0] = [
* 32bit session handle,
* 32bit old PIN byte size,
* 32bit new PIN byte size,
* byte array: PIN data,
* byte array: new PIN data,
* ]
* [out] memref[0] = 32bit return code, enum pkcs11_rc
*
* This command relates to the PKCS#11 API function C_SetPIN().
*/
PKCS11_CMD_SET_PIN = 12,
/*
* PKCS11_CMD_LOGIN - Initialize user PIN
*
* [in] memref[0] = [
* 32bit session handle,
* 32bit user identifier, enum pkcs11_user_type
* 32bit PIN byte size,
* byte array: PIN data
* ]
* [out] memref[0] = 32bit return code, enum pkcs11_rc
*
* This command relates to the PKCS#11 API function C_Login().
*/
PKCS11_CMD_LOGIN = 13,
/*
* PKCS11_CMD_LOGOUT - Log out from token
*
* [in] memref[0] = [
* 32bit session handle,
* ]
* [out] memref[0] = 32bit return code, enum pkcs11_rc
*
* This command relates to the PKCS#11 API function C_Logout().
*/
PKCS11_CMD_LOGOUT = 14,
/*
* PKCS11_CMD_CREATE_OBJECT - Create a raw client assembled object in
* the session or token
*
*
* [in] memref[0] = [
* 32bit session handle,
* (struct pkcs11_object_head)attribs + attributes data
* ]
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [out] memref[2] = 32bit object handle
*
* This command relates to the PKCS#11 API function C_CreateObject().
*/
PKCS11_CMD_CREATE_OBJECT = 15,
/*
* PKCS11_CMD_DESTROY_OBJECT - Destroy an object
*
* [in] memref[0] = [
* 32bit session handle,
* 32bit object handle
* ]
* [out] memref[0] = 32bit return code, enum pkcs11_rc
*
* This command relates to the PKCS#11 API function C_DestroyObject().
*/
PKCS11_CMD_DESTROY_OBJECT = 16,
/*
* PKCS11_CMD_ENCRYPT_INIT - Initialize encryption processing
* PKCS11_CMD_DECRYPT_INIT - Initialize decryption processing
*
* [in] memref[0] = [
* 32bit session handle,
* 32bit object handle of the key,
* (struct pkcs11_attribute_head)mechanism + mecha params
* ]
* [out] memref[0] = 32bit return code, enum pkcs11_rc
*
* These commands relate to the PKCS#11 API functions
* C_EncryptInit() and C_DecryptInit().
*/
PKCS11_CMD_ENCRYPT_INIT = 17,
PKCS11_CMD_DECRYPT_INIT = 18,
/*
* PKCS11_CMD_ENCRYPT_UPDATE - Update encryption processing
* PKCS11_CMD_DECRYPT_UPDATE - Update decryption processing
*
* [in] memref[0] = 32bit session handle
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [in] memref[1] = input data to be processed
* [out] memref[2] = output processed data
*
* These commands relate to the PKCS#11 API functions
* C_EncryptUpdate() and C_DecryptUpdate().
*/
PKCS11_CMD_ENCRYPT_UPDATE = 19,
PKCS11_CMD_DECRYPT_UPDATE = 20,
/*
* PKCS11_CMD_ENCRYPT_FINAL - Finalize encryption processing
* PKCS11_CMD_DECRYPT_FINAL - Finalize decryption processing
*
* [in] memref[0] = 32bit session handle
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [out] memref[2] = output processed data
*
* These commands relate to the PKCS#11 API functions
* C_EncryptFinal() and C_DecryptFinal().
*/
PKCS11_CMD_ENCRYPT_FINAL = 21,
PKCS11_CMD_DECRYPT_FINAL = 22,
/*
* PKCS11_CMD_ENCRYPT_ONESHOT - Update and finalize encryption
* processing
* PKCS11_CMD_DECRYPT_ONESHOT - Update and finalize decryption
* processing
*
* [in] memref[0] = 32bit session handle
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [in] memref[1] = input data to be processed
* [out] memref[2] = output processed data
*
* These commands relate to the PKCS#11 API functions C_Encrypt and
* C_Decrypt.
*/
PKCS11_CMD_ENCRYPT_ONESHOT = 23,
PKCS11_CMD_DECRYPT_ONESHOT = 24,
/*
* PKCS11_CMD_SIGN_INIT - Initialize a signature computation
* processing
* PKCS11_CMD_VERIFY_INIT - Initialize a signature verification
* processing
*
* [in] memref[0] = [
* 32bit session handle,
* 32bit key handle,
* (struct pkcs11_attribute_head)mechanism +
* mechanism params,
* ]
* [out] memref[0] = 32bit return code, enum pkcs11_rc
*
* These commands relate to the PKCS#11 API functions C_SignInit() and
* C_VerifyInit().
*/
PKCS11_CMD_SIGN_INIT = 25,
PKCS11_CMD_VERIFY_INIT = 26,
/*
* PKCS11_CMD_SIGN_UPDATE - Update a signature computation processing
* PKCS11_CMD_VERIFY_UPDATE - Update a signature verification processing
*
* [in] memref[0] = 32bit session handle
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [in] memref[1] = input data to be processed
*
* These commands relate to the PKCS#11 API functions C_SignUpdate() and
* C_VerifyUpdate().
*/
PKCS11_CMD_SIGN_UPDATE = 27,
PKCS11_CMD_VERIFY_UPDATE = 28,
/*
* PKCS11_CMD_SIGN_FINAL - Finalize a signature computation processing
*
* [in] memref[0] = 32bit session handle
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [out] memref[2] = output signature
*
* This command relates to the PKCS#11 API functions C_SignFinal().
*/
PKCS11_CMD_SIGN_FINAL = 29,
/*
* PKCS11_CMD_VERIFY_FINAL - Finalize a signature verification
* processing
*
* [in] memref[0] = 32bit session handle
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [in] memref[2] = input signature to be processed
*
* This command relates to the PKCS#11 API functions C_VerifyFinal().
*/
PKCS11_CMD_VERIFY_FINAL = 30,
/*
* PKCS11_CMD_SIGN_ONESHOT - Compute a signature
*
* [in] memref[0] = 32bit session handle
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [in] memref[1] = input data to be processed
* [out] memref[2] = byte array: generated signature
*
* This command relates to the PKCS#11 API function C_Sign().
*/
PKCS11_CMD_SIGN_ONESHOT = 31,
/*
* PKCS11_CMD_VERIFY_ONESHOT - Compute and compare a signature
*
* [in] memref[0] = 32bit session handle
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [in] memref[1] = input data to be processed
* [in] memref[2] = input signature to be processed
*
* This command relates to the PKCS#11 API function C_Verify().
*/
PKCS11_CMD_VERIFY_ONESHOT = 32,
/*
* PKCS11_CMD_GENERATE_KEY - Generate a symmetric key or domain
* parameters
*
* [in] memref[0] = [
* 32bit session handle,
* (struct pkcs11_attribute_head)mechanism + mecha params,
* (struct pkcs11_object_head)attribs + attributes data
* ]
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [out] memref[2] = 32bit object handle
*
* This command relates to the PKCS#11 API function C_GenerateKey().
*/
PKCS11_CMD_GENERATE_KEY = 33,
/*
* PKCS11_CMD_FIND_OBJECTS_INIT - Initialize an object search
*
* [in] memref[0] = [
* 32bit session handle,
* (struct pkcs11_object_head)attribs + attributes data
* ]
* [out] memref[0] = 32bit return code, enum pkcs11_rc
*
* This command relates to the PKCS#11 API function C_FindOjectsInit().
*/
PKCS11_CMD_FIND_OBJECTS_INIT = 34,
/*
* PKCS11_CMD_FIND_OBJECTS - Get handles of matching objects
*
* [in] memref[0] = 32bit session handle
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [out] memref[2] = 32bit array object_handle_array[N]
*
* This command relates to the PKCS#11 API function C_FindOjects().
* The size of object_handle_array depends on the size of the output
* buffer provided by the client.
*/
PKCS11_CMD_FIND_OBJECTS = 35,
/*
* PKCS11_CMD_FIND_OBJECTS_FINAL - Finalize current objects search
*
* [in] memref[0] = 32bit session handle
* [out] memref[0] = 32bit return code, enum pkcs11_rc
*
* This command relates to the PKCS#11 API function C_FindOjectsFinal().
*/
PKCS11_CMD_FIND_OBJECTS_FINAL = 36,
/*
* PKCS11_CMD_GET_OBJECT_SIZE - Get byte size used by object in the TEE
*
* [in] memref[0] = [
* 32bit session handle,
* 32bit object handle
* ]
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [out] memref[2] = 32bit object_byte_size
*
* This command relates to the PKCS#11 API function C_GetObjectSize().
*/
PKCS11_CMD_GET_OBJECT_SIZE = 37,
/*
* PKCS11_CMD_GET_ATTRIBUTE_VALUE - Get the value of object attribute(s)
*
* [in] memref[0] = [
* 32bit session handle,
* 32bit object handle,
* (struct pkcs11_object_head)attribs + attributes data
* ]
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [out] memref[2] = (struct pkcs11_object_head)attribs + attributes
* data
*
* This command relates to the PKCS#11 API function C_GetAttributeValue.
* Caller provides an attribute template as 3rd argument in memref[0]
* (referred here as attribs + attributes data). Upon successful
* completion, the TA returns the provided template filled with expected
* data through output argument memref[2] (referred here again as
* attribs + attributes data).
*/
PKCS11_CMD_GET_ATTRIBUTE_VALUE = 38,
/*
* PKCS11_CMD_SET_ATTRIBUTE_VALUE - Set the value of object attribute(s)
*
* [in] memref[0] = [
* 32bit session handle,
* 32bit object handle,
* (struct pkcs11_object_head)attribs + attributes data
* ]
* [out] memref[0] = 32bit return code, enum pkcs11_rc
*
* This command relates to the PKCS#11 API function C_SetAttributeValue.
* Caller provides an attribute template as 3rd argument in memref[0]
* (referred here as attribs + attributes data).
*/
PKCS11_CMD_SET_ATTRIBUTE_VALUE = 39,
/*
* PKCS11_CMD_COPY_OBJECT - Copies an object, creating a new object for
* the copy.
*
* [in] memref[0] = [
* 32bit session handle,
* 32bit object handle,
* (struct pkcs11_object_head)attribs + attributes data
* ]
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [out] memref[2] = 32bit object handle
*
* This command relates to the PKCS#11 API function C_CopyObject().
* Caller provides an attribute template as 3rd argument in memref[0]
* (referred here as attribs + attributes data).
*/
PKCS11_CMD_COPY_OBJECT = 40,
/*
* PKCS11_CMD_SEED_RANDOM - Seed random data generator
*
* [in] memref[0] = 32bit session handle
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [in] memref[1] = byte array: seed material to feed into the RNG
*
* This command relates to the PKCS#11 API function C_SeedRandom().
*/
PKCS11_CMD_SEED_RANDOM = 41,
/*
* PKCS11_CMD_GENERATE_RANDOM - Generate random data
*
* [in] memref[0] = 32bit session handle
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [out] memref[2] = byte array: generated random
*
* This command relates to the PKCS#11 API function C_GenerateRandom().
*/
PKCS11_CMD_GENERATE_RANDOM = 42,
/*
* PKCS11_CMD_DERIVE_KEY - Derive a key from a parent key.
*
* [in] memref[0] = [
* 32bit session handle,
* 32bit parent key handle,
* (struct pkcs11_attribute_head)mechanism + mecha params,
* (struct pkcs11_object_head)attribs + attributes data
* ]
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [out] memref[2] = 32bit object handle
*
* This command relates to the PKCS#11 API function C_DeriveKey().
*/
PKCS11_CMD_DERIVE_KEY = 43,
/*
* PKCS11_CMD_RELEASE_ACTIVE_PROCESSING - Release active processing
*
* [in] memref[0] = [
* 32bit session handle,
* 32bit enum pkcs11_ta_cmd
* ]
* [out] memref[0] = 32bit return code, enum pkcs11_rc
*
* This command is used to release active processing in case of
* Cryptoki API invocation error is detected in user space processing.
* Function derived from pkcs11_ta_cmd is used to verify that active
* processing matches.
*/
PKCS11_CMD_RELEASE_ACTIVE_PROCESSING = 44,
/*
* PKCS11_CMD_DIGEST_INIT - Initialize a digest computation processing
*
* [in] memref[0] = [
* 32bit session handle,
* (struct pkcs11_attribute_head)mechanism + mecha params
* ]
* [out] memref[0] = 32bit return code, enum pkcs11_rc
*
* This command relates to the PKCS#11 API function C_DigestInit().
*/
PKCS11_CMD_DIGEST_INIT = 45,
/*
* PKCS11_CMD_DIGEST_KEY - Update digest with a key
*
* [in] memref[0] = [
* 32bit session handle,
* 32bit key handle
* ]
* [out] memref[0] = 32bit return code, enum pkcs11_rc
*
* This command relates to the PKCS#11 API function C_DigestKey().
*/
PKCS11_CMD_DIGEST_KEY = 46,
/*
* PKCS11_CMD_DIGEST_UPDATE - Update digest with data
*
* [in] memref[0] = 32bit session handle
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [in] memref[1] = input data to be processed
*
* This command relates to the PKCS#11 API function C_DigestUpdate().
*/
PKCS11_CMD_DIGEST_UPDATE = 47,
/*
* PKCS11_CMD_DIGEST_FINAL - Finalize a digest computation processing
*
* [in] memref[0] = 32bit session handle
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [out] memref[2] = output digest
*
* This command relates to the PKCS#11 API function C_DigestFinal().
*/
PKCS11_CMD_DIGEST_FINAL = 48,
/*
* PKCS11_CMD_DIGEST_ONESHOT - Compute a digest
*
* [in] memref[0] = 32bit session handle
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [in] memref[1] = input data to be processed
* [out] memref[2] = byte array: generated digest
*
* This command relates to the PKCS#11 API function C_Digest().
*/
PKCS11_CMD_DIGEST_ONESHOT = 49,
/*
* PKCS11_CMD_GENERATE_KEY_PAIR - Generate an asymmetric key pair
*
* [in] memref[0] = [
* 32bit session handle,
* (struct pkcs11_attribute_head)mechanism + mecha params,
* (struct pkcs11_object_head)public key attribs +
* attributes data,
* (struct pkcs11_object_head)private key attribs +
* attributes data
* ]
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [out] memref[2] = [
* 32bit public key object handle,
* 32bit private key object handle
* ]
*
* This command relates to the PKCS#11 API function
* C_GenerateKeyPair().
*/
PKCS11_CMD_GENERATE_KEY_PAIR = 50,
/*
* PKCS11_CMD_WRAP_KEY - Wraps a private or secret key.
*
* [in] memref[0] = [
* 32bit session handle,
* 32bit wrapping key handle,
* 32bit key handle,
* (struct pkcs11_attribute_head)mechanism + mecha params
* ]
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [out] memref[2] = wrapped key
*
* This command relates to the PKCS#11 API function C_WrapKey().
*/
PKCS11_CMD_WRAP_KEY = 51,
/*
* PKCS11_CMD_UNWRAP_KEY - Unwraps a wrapped key, creating a new
* private or secret key object.
*
* [in] memref[0] = [
* 32bit session handle,
* 32bit unwrapping key handle,
* (struct pkcs11_attribute_head)mechanism + mecha params,
* (struct pkcs11_object_head)attribs + attributes data
* ]
* [out] memref[0] = 32bit return code, enum pkcs11_rc
* [in] memref[1] = wrapped key
* [out] memref[2] = 32bit object handle
*
* This command relates to the PKCS#11 API function C_UnwrapKey().
*/
PKCS11_CMD_UNWRAP_KEY = 52,
};
/*
* Command return codes
* PKCS11_<x> relates CryptoKi client API CKR_<x>
*/
enum pkcs11_rc {
PKCS11_CKR_OK = 0,
PKCS11_CKR_CANCEL = 0x0001,
PKCS11_CKR_SLOT_ID_INVALID = 0x0003,
PKCS11_CKR_GENERAL_ERROR = 0x0005,
PKCS11_CKR_FUNCTION_FAILED = 0x0006,
PKCS11_CKR_ARGUMENTS_BAD = 0x0007,
PKCS11_CKR_ATTRIBUTE_READ_ONLY = 0x0010,
PKCS11_CKR_ATTRIBUTE_SENSITIVE = 0x0011,
PKCS11_CKR_ATTRIBUTE_TYPE_INVALID = 0x0012,
PKCS11_CKR_ATTRIBUTE_VALUE_INVALID = 0x0013,
PKCS11_CKR_ACTION_PROHIBITED = 0x001b,
PKCS11_CKR_DATA_INVALID = 0x0020,
PKCS11_CKR_DATA_LEN_RANGE = 0x0021,
PKCS11_CKR_DEVICE_ERROR = 0x0030,
PKCS11_CKR_DEVICE_MEMORY = 0x0031,
PKCS11_CKR_DEVICE_REMOVED = 0x0032,
PKCS11_CKR_ENCRYPTED_DATA_INVALID = 0x0040,
PKCS11_CKR_ENCRYPTED_DATA_LEN_RANGE = 0x0041,
PKCS11_CKR_KEY_HANDLE_INVALID = 0x0060,
PKCS11_CKR_KEY_SIZE_RANGE = 0x0062,
PKCS11_CKR_KEY_TYPE_INCONSISTENT = 0x0063,
PKCS11_CKR_KEY_INDIGESTIBLE = 0x0067,
PKCS11_CKR_KEY_FUNCTION_NOT_PERMITTED = 0x0068,
PKCS11_CKR_KEY_NOT_WRAPPABLE = 0x0069,
PKCS11_CKR_KEY_UNEXTRACTABLE = 0x006a,
PKCS11_CKR_MECHANISM_INVALID = 0x0070,
PKCS11_CKR_MECHANISM_PARAM_INVALID = 0x0071,
PKCS11_CKR_OBJECT_HANDLE_INVALID = 0x0082,
PKCS11_CKR_OPERATION_ACTIVE = 0x0090,
PKCS11_CKR_OPERATION_NOT_INITIALIZED = 0x0091,
PKCS11_CKR_PIN_INCORRECT = 0x00a0,
PKCS11_CKR_PIN_INVALID = 0x00a1,
PKCS11_CKR_PIN_LEN_RANGE = 0x00a2,
PKCS11_CKR_PIN_EXPIRED = 0x00a3,
PKCS11_CKR_PIN_LOCKED = 0x00a4,
PKCS11_CKR_SESSION_CLOSED = 0x00b0,
PKCS11_CKR_SESSION_COUNT = 0x00b1,
PKCS11_CKR_SESSION_HANDLE_INVALID = 0x00b3,
PKCS11_CKR_SESSION_PARALLEL_NOT_SUPPORTED = 0x00b4,
PKCS11_CKR_SESSION_READ_ONLY = 0x00b5,
PKCS11_CKR_SESSION_EXISTS = 0x00b6,
PKCS11_CKR_SESSION_READ_ONLY_EXISTS = 0x00b7,
PKCS11_CKR_SESSION_READ_WRITE_SO_EXISTS = 0x00b8,
PKCS11_CKR_SIGNATURE_INVALID = 0x00c0,
PKCS11_CKR_SIGNATURE_LEN_RANGE = 0x00c1,
PKCS11_CKR_TEMPLATE_INCOMPLETE = 0x00d0,
PKCS11_CKR_TEMPLATE_INCONSISTENT = 0x00d1,
PKCS11_CKR_TOKEN_NOT_PRESENT = 0x00e0,
PKCS11_CKR_TOKEN_NOT_RECOGNIZED = 0x00e1,
PKCS11_CKR_TOKEN_WRITE_PROTECTED = 0x00e2,
PKCS11_CKR_UNWRAPPING_KEY_HANDLE_INVALID = 0x00f0,
PKCS11_CKR_UNWRAPPING_KEY_SIZE_RANGE = 0x00f1,
PKCS11_CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT = 0x00f2,
PKCS11_CKR_USER_ALREADY_LOGGED_IN = 0x0100,
PKCS11_CKR_USER_NOT_LOGGED_IN = 0x0101,
PKCS11_CKR_USER_PIN_NOT_INITIALIZED = 0x0102,
PKCS11_CKR_USER_TYPE_INVALID = 0x0103,
PKCS11_CKR_USER_ANOTHER_ALREADY_LOGGED_IN = 0x0104,
PKCS11_CKR_USER_TOO_MANY_TYPES = 0x0105,
PKCS11_CKR_WRAPPED_KEY_INVALID = 0x0110,
PKCS11_CKR_WRAPPED_KEY_LEN_RANGE = 0x0112,
PKCS11_CKR_WRAPPING_KEY_HANDLE_INVALID = 0x0113,
PKCS11_CKR_WRAPPING_KEY_SIZE_RANGE = 0x0114,
PKCS11_CKR_WRAPPING_KEY_TYPE_INCONSISTENT = 0x0115,
PKCS11_CKR_RANDOM_SEED_NOT_SUPPORTED = 0x0120,
PKCS11_CKR_RANDOM_NO_RNG = 0x0121,
PKCS11_CKR_DOMAIN_PARAMS_INVALID = 0x0130,
PKCS11_CKR_CURVE_NOT_SUPPORTED = 0x0140,
PKCS11_CKR_BUFFER_TOO_SMALL = 0x0150,
PKCS11_CKR_SAVED_STATE_INVALID = 0x0160,
PKCS11_CKR_INFORMATION_SENSITIVE = 0x0170,
PKCS11_CKR_STATE_UNSAVEABLE = 0x0180,
PKCS11_CKR_PIN_TOO_WEAK = 0x01b8,
PKCS11_CKR_PUBLIC_KEY_INVALID = 0x01b9,
PKCS11_CKR_FUNCTION_REJECTED = 0x0200,
/* Vendor specific IDs not returned to client */
PKCS11_RV_NOT_FOUND = 0x80000000,
PKCS11_RV_NOT_IMPLEMENTED = 0x80000001,
};
/*
* Arguments for PKCS11_CMD_SLOT_INFO
*/
#define PKCS11_SLOT_DESC_SIZE 64
#define PKCS11_SLOT_MANUFACTURER_SIZE 32
#define PKCS11_SLOT_VERSION_SIZE 2
struct pkcs11_slot_info {
uint8_t slot_description[PKCS11_SLOT_DESC_SIZE];
uint8_t manufacturer_id[PKCS11_SLOT_MANUFACTURER_SIZE];
uint32_t flags;
uint8_t hardware_version[PKCS11_SLOT_VERSION_SIZE];
uint8_t firmware_version[PKCS11_SLOT_VERSION_SIZE];
};
/*
* Values for pkcs11_slot_info::flags.
* PKCS11_CKFS_<x> reflects CryptoKi client API slot flags CKF_<x>.
*/
#define PKCS11_CKFS_TOKEN_PRESENT (1U << 0)
#define PKCS11_CKFS_REMOVABLE_DEVICE (1U << 1)
#define PKCS11_CKFS_HW_SLOT (1U << 2)
/*
* Arguments for PKCS11_CMD_TOKEN_INFO
*/
#define PKCS11_TOKEN_LABEL_SIZE 32
#define PKCS11_TOKEN_MANUFACTURER_SIZE 32
#define PKCS11_TOKEN_MODEL_SIZE 16
#define PKCS11_TOKEN_SERIALNUM_SIZE 16
struct pkcs11_token_info {
uint8_t label[PKCS11_TOKEN_LABEL_SIZE];
uint8_t manufacturer_id[PKCS11_TOKEN_MANUFACTURER_SIZE];
uint8_t model[PKCS11_TOKEN_MODEL_SIZE];
uint8_t serial_number[PKCS11_TOKEN_SERIALNUM_SIZE];
uint32_t flags;
uint32_t max_session_count;
uint32_t session_count;
uint32_t max_rw_session_count;
uint32_t rw_session_count;
uint32_t max_pin_len;
uint32_t min_pin_len;
uint32_t total_public_memory;
uint32_t free_public_memory;
uint32_t total_private_memory;
uint32_t free_private_memory;
uint8_t hardware_version[2];
uint8_t firmware_version[2];
uint8_t utc_time[16];
};
/*
* Values for pkcs11_token_info::flags.
* PKCS11_CKFT_<x> reflects CryptoKi client API token flags CKF_<x>.
*/
#define PKCS11_CKFT_RNG (1U << 0)
#define PKCS11_CKFT_WRITE_PROTECTED (1U << 1)
#define PKCS11_CKFT_LOGIN_REQUIRED (1U << 2)
#define PKCS11_CKFT_USER_PIN_INITIALIZED (1U << 3)
#define PKCS11_CKFT_RESTORE_KEY_NOT_NEEDED (1U << 5)
#define PKCS11_CKFT_CLOCK_ON_TOKEN (1U << 6)
#define PKCS11_CKFT_PROTECTED_AUTHENTICATION_PATH (1U << 8)
#define PKCS11_CKFT_DUAL_CRYPTO_OPERATIONS (1U << 9)
#define PKCS11_CKFT_TOKEN_INITIALIZED (1U << 10)
#define PKCS11_CKFT_SECONDARY_AUTHENTICATION (1U << 11)
#define PKCS11_CKFT_USER_PIN_COUNT_LOW (1U << 16)
#define PKCS11_CKFT_USER_PIN_FINAL_TRY (1U << 17)
#define PKCS11_CKFT_USER_PIN_LOCKED (1U << 18)
#define PKCS11_CKFT_USER_PIN_TO_BE_CHANGED (1U << 19)
#define PKCS11_CKFT_SO_PIN_COUNT_LOW (1U << 20)
#define PKCS11_CKFT_SO_PIN_FINAL_TRY (1U << 21)
#define PKCS11_CKFT_SO_PIN_LOCKED (1U << 22)
#define PKCS11_CKFT_SO_PIN_TO_BE_CHANGED (1U << 23)
#define PKCS11_CKFT_ERROR_STATE (1U << 24)
/* Values for user identity */
enum pkcs11_user_type {
PKCS11_CKU_SO = 0x000,
PKCS11_CKU_USER = 0x001,
PKCS11_CKU_CONTEXT_SPECIFIC = 0x002,
};
/*
* TEE Identity based authentication for tokens
*
* When configuration CFG_PKCS11_TA_AUTH_TEE_IDENTITY is enabled TEE Identity
* based authentication scheme is enabled.
*
* Feature enablement per token basis is controlled by token flag:
* pkcs11_token_info->flags & PKCS11_CKFT_PROTECTED_AUTHENTICATION_PATH
*
* When calling C_InitToken() mode is determined based on SO PIN value.
* - If the PIN is empty (or NULL_PTR) then active client TEE Identity will be
* used as SO TEE Identity
* - If the PIN is given then normal PIN behavior is used
*
* Once TEE Identity based authentication is activated following operational
* changes happen:
* - PIN failure counters are disabled to prevent token authentication lockups
* - Switching to different authentication mode needs C_InitToken()
* - When C_Login() or so is performed actual PIN value is ignored and active
* client TEE Identity will be used
*
* Different types of TEE Identity authentication methods can be configured:
* - Configured with C_InitToken(), C_InitPIN() or by C_SetPIN()
* - PIN value follows below PIN syntax
*
* TEE Identity based authenticate PIN syntax:
* - PIN value: NULL_PTR or empty
* - Use active client TEE Identity
* - PIN value: public
* - TEE public login
* - PIN value: user:<client UUID string>
* - TEE user login with client UUID matching user credentials
* - PIN value: group:<client UUID string>
* - TEE group login with client UUID matching group credentials
*/
/* Keywords for protected authenticated path PIN parser */
#define PKCS11_AUTH_TEE_IDENTITY_PUBLIC "public"
#define PKCS11_AUTH_TEE_IDENTITY_USER "user:"
#define PKCS11_AUTH_TEE_IDENTITY_GROUP "group:"
/*
* Values for 32bit session flags argument to PKCS11_CMD_OPEN_SESSION
* and pkcs11_session_info::flags.
* PKCS11_CKFSS_<x> reflects CryptoKi client API session flags CKF_<x>.
*/
#define PKCS11_CKFSS_RW_SESSION (1U << 1)
#define PKCS11_CKFSS_SERIAL_SESSION (1U << 2)
/*
* Arguments for PKCS11_CMD_SESSION_INFO
*/
struct pkcs11_session_info {
uint32_t slot_id;
uint32_t state;
uint32_t flags;
uint32_t device_error;
};
/* Valid values for pkcs11_session_info::state */
enum pkcs11_session_state {
PKCS11_CKS_RO_PUBLIC_SESSION = 0,
PKCS11_CKS_RO_USER_FUNCTIONS = 1,
PKCS11_CKS_RW_PUBLIC_SESSION = 2,
PKCS11_CKS_RW_USER_FUNCTIONS = 3,
PKCS11_CKS_RW_SO_FUNCTIONS = 4,
};
/*
* Arguments for PKCS11_CMD_MECHANISM_INFO
*/
struct pkcs11_mechanism_info {
uint32_t min_key_size;
uint32_t max_key_size;
uint32_t flags;
};
/*
* Values for pkcs11_mechanism_info::flags.
* PKCS11_CKFM_<x> reflects CryptoKi client API mechanism flags CKF_<x>.
*/
#define PKCS11_CKFM_HW (1U << 0)
#define PKCS11_CKFM_ENCRYPT (1U << 8)
#define PKCS11_CKFM_DECRYPT (1U << 9)
#define PKCS11_CKFM_DIGEST (1U << 10)
#define PKCS11_CKFM_SIGN (1U << 11)
#define PKCS11_CKFM_SIGN_RECOVER (1U << 12)
#define PKCS11_CKFM_VERIFY (1U << 13)
#define PKCS11_CKFM_VERIFY_RECOVER (1U << 14)
#define PKCS11_CKFM_GENERATE (1U << 15)
#define PKCS11_CKFM_GENERATE_KEY_PAIR (1U << 16)
#define PKCS11_CKFM_WRAP (1U << 17)
#define PKCS11_CKFM_UNWRAP (1U << 18)
#define PKCS11_CKFM_DERIVE (1U << 19)
#define PKCS11_CKFM_EC_F_P (1U << 20)
#define PKCS11_CKFM_EC_F_2M (1U << 21)
#define PKCS11_CKFM_EC_ECPARAMETERS (1U << 22)
#define PKCS11_CKFM_EC_NAMEDCURVE (1U << 23)
#define PKCS11_CKFM_EC_UNCOMPRESS (1U << 24)
#define PKCS11_CKFM_EC_COMPRESS (1U << 25)
/*
* pkcs11_object_head - Header of object whose data are serialized in memory
*
* An object is made of several attributes. Attributes are stored one next to
* the other with byte alignment as a serialized byte array. The byte array
* of serialized attributes is prepended with the size of the attrs[] array
* in bytes and the number of attributes in the array, yielding the struct
* pkcs11_object_head.
*
* @attrs_size - byte size of whole byte array attrs[]
* @attrs_count - number of attribute items stored in attrs[]
* @attrs - then starts the attributes data