summaryrefslogtreecommitdiff
path: root/MdePkg/Include/Protocol/Kms.h
blob: 1a1375578a8144d47d167de5da5c40deb6a77529 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
/** @file
  The Key Management Service (KMS) protocol as defined in the UEFI 2.3.1 specification is to
  provides services to generate, store, retrieve, and manage cryptographic keys.
  The intention is to specify a simple generic protocol that could be used for many implementations.

  A driver implementing the protocol may need to provide basic key service that consists of a
  key store and cryptographic key generation capability. It may connect to an external key
  server over the network, or to a Hardware Security Module (HSM) attached to the system it
  runs on, or anything else that is capable of providing the key management service.

  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
  This program and the accompanying materials are licensed and made available under
  the terms and conditions of the BSD License that accompanies this distribution.
  The full text of the license may be found at
  http://opensource.org/licenses/bsd-license.php.

  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

**/

#ifndef __KMS_H__
#define __KMS_H__

#define EFI_KMS_PROTOCOL_GUID \
  { \
    0xEC3A978D, 0x7C4E, 0x48FA, {0x9A, 0xBE, 0x6A, 0xD9, 0x1C, 0xC8, 0xF8, 0x11 } \
  }

typedef struct _EFI_KMS_PROTOCOL EFI_KMS_PROTOCOL;

//
// Where appropriate, EFI_KMS_DATA_TYPE values may be combined using a bitwise 'OR'
// operation to indicate support for multiple data types.
//
#define EFI_KMS_DATA_TYPE_NONE      0
#define EFI_KMS_DATA_TYPE_BINARY    1
#define EFI_KMS_DATA_TYPE_ASCII     2
#define EFI_KMS_DATA_TYPE_UNICODE   4
#define EFI_KMS_DATA_TYPE_UTF8      8


//
// The key formats recognized by the KMS protocol are defined by an EFI_GUID which specifies
// a (key-algorithm, key-size) pair. The names of these GUIDs are in the format
// EFI_KMS_KEY_(key-algorithm)_(key-size)_GUID, where the key-size is expressed in bits.
// The key formats recognized fall into three categories, generic (no algorithm), hash algorithms,
// and encrypted algorithms.
//

///
/// The following GUIDs define formats that contain generic key data of a specific size in bits,
/// but which is not associated with any specific key algorithm(s).
///@{
#define EFI_KMS_FORMAT_GENERIC_128_GUID \
  { \
    0xec8a3d69, 0x6ddf, 0x4108, {0x94, 0x76, 0x73, 0x37, 0xfc, 0x52, 0x21, 0x36 } \
  }
#define EFI_KMS_FORMAT_GENERIC_160_GUID \
  { \
    0xa3b3e6f8, 0xefca, 0x4bc1, {0x88, 0xfb, 0xcb, 0x87, 0x33, 0x9b, 0x25, 0x79 } \
  }
#define EFI_KMS_FORMAT_GENERIC_256_GUID \
  { \
    0x70f64793, 0xc323, 0x4261, {0xac, 0x2c, 0xd8, 0x76, 0xf2, 0x7c, 0x53, 0x45 } \
  }
#define EFI_KMS_FORMAT_GENERIC_512_GUID \
  { \
    0x978fe043, 0xd7af, 0x422e, {0x8a, 0x92, 0x2b, 0x48, 0xe4, 0x63, 0xbd, 0xe6 } \
  }
#define EFI_KMS_FORMAT_GENERIC_1024_GUID \
  { \
    0x43be0b44, 0x874b, 0x4ead, {0xb0, 0x9c, 0x24, 0x1a, 0x4f, 0xbd, 0x7e, 0xb3 } \
  }
#define EFI_KMS_FORMAT_GENERIC_2048_GUID \
  { \
    0x40093f23, 0x630c, 0x4626, {0x9c, 0x48, 0x40, 0x37, 0x3b, 0x19, 0xcb, 0xbe } \
  }
#define EFI_KMS_FORMAT_GENERIC_3072_GUID \
  { \
    0xb9237513, 0x6c44, 0x4411, {0xa9, 0x90, 0x21, 0xe5, 0x56, 0xe0, 0x5a, 0xde } \
  }
///@}

///
/// These GUIDS define key data formats that contain data generated by basic hash algorithms
/// with no cryptographic properties.
///@{
#define EFI_KMS_FORMAT_MD2_128_GUID \
  { \
    0x78be11c4, 0xee44, 0x4a22, {0x9f, 0x05, 0x03, 0x85, 0x2e, 0xc5, 0xc9, 0x78 } \
  }
#define EFI_KMS_FORMAT_MDC2_128_GUID \
  { \
    0xf7ad60f8, 0xefa8, 0x44a3, {0x91, 0x13, 0x23, 0x1f, 0x39, 0x9e, 0xb4, 0xc7 } \
  }
#define EFI_KMS_FORMAT_MD4_128_GUID \
  { \
    0xd1c17aa1, 0xcac5, 0x400f, {0xbe, 0x17, 0xe2, 0xa2, 0xae, 0x06, 0x67, 0x7c } \
  }
#define EFI_KMS_FORMAT_MDC4_128_GUID \
  { \
    0x3fa4f847, 0xd8eb, 0x4df4, {0xbd, 0x49, 0x10, 0x3a, 0x0a, 0x84, 0x7b, 0xbc } \
  }
#define EFI_KMS_FORMAT_MD5_128_GUID \
  { \
    0xdcbc3662, 0x9cda, 0x4b52, {0xa0, 0x4c, 0x82, 0xeb, 0x1d, 0x23, 0x48, 0xc7 } \
  }
#define EFI_KMS_FORMAT_MD5SHA_128_GUID \
  { \
    0x1c178237, 0x6897, 0x459e, {0x9d, 0x36, 0x67, 0xce, 0x8e, 0xf9, 0x4f, 0x76 } \
  }
#define EFI_KMS_FORMAT_SHA1_160_GUID \
  { \
    0x453c5e5a, 0x482d, 0x43f0, {0x87, 0xc9, 0x59, 0x41, 0xf3, 0xa3, 0x8a, 0xc2 } \
  }
#define EFI_KMS_FORMAT_SHA256_256_GUID \
  { \
    0x6bb4f5cd, 0x8022, 0x448d, {0xbc, 0x6d, 0x77, 0x1b, 0xae, 0x93, 0x5f, 0xc6 } \
  }
#define EFI_KMS_FORMAT_SHA512_512_GUID \
  { \
    0x2f240e12, 0xe14d, 0x475c, {0x83, 0xb0, 0xef, 0xff, 0x22, 0xd7, 0x7b, 0xe7 } \
  }
///@}

///
/// These GUIDs define key data formats that contain data generated by cryptographic key algorithms.
/// There may or may not be a separate data hashing algorithm associated with the key algorithm.
///@{
#define EFI_KMS_FORMAT_AESXTS_128_GUID \
  { \
    0x4776e33f, 0xdb47, 0x479a, {0xa2, 0x5f, 0xa1, 0xcd, 0x0a, 0xfa, 0xb3, 0x8b } \
  }
#define EFI_KMS_FORMAT_AESXTS_256_GUID \
  { \
    0xdc7e8613, 0xc4bb, 0x4db0, {0x84, 0x62, 0x13, 0x51, 0x13, 0x57, 0xab, 0xe2 } \
  }
#define EFI_KMS_FORMAT_AESCBC_128_GUID \
  { \
    0xa0e8ee6a, 0x0e92, 0x44d4, {0x86, 0x1b, 0x0e, 0xaa, 0x4a, 0xca, 0x44, 0xa2 } \
  }
#define EFI_KMS_FORMAT_AESCBC_256_GUID \
  { \
    0xd7e69789, 0x1f68, 0x45e8, {0x96, 0xef, 0x3b, 0x64, 0x07, 0xa5, 0xb2, 0xdc } \
  }
#define EFI_KMS_FORMAT_RSASHA1_1024_GUID \
  { \
    0x56417bed, 0x6bbe, 0x4882, {0x86, 0xa0, 0x3a, 0xe8, 0xbb, 0x17, 0xf8, 0xf9 } \
  }
#define EFI_KMS_FORMAT_RSASHA1_2048_GUID \
  { \
    0xf66447d4, 0x75a6, 0x463e, {0xa8, 0x19, 0x07, 0x7f, 0x2d, 0xda, 0x05, 0xe9 } \
  }
#define EFI_KMS_FORMAT_RSASHA256_2048_GUID \
  { \
    0xa477af13, 0x877d, 0x4060, {0xba, 0xa1, 0x25, 0xd1, 0xbe, 0xa0, 0x8a, 0xd3 } \
  }
#define EFI_KMS_FORMAT_RSASHA256_3072_GUID \
  { \
    0x4e1356c2,  0xeed, 0x463f, {0x81, 0x47, 0x99, 0x33, 0xab, 0xdb, 0xc7, 0xd5 } \
  }
///@}

#define EFI_KMS_ATTRIBUTE_TYPE_NONE             0x00
#define EFI_KMS_ATTRIBUTE_TYPE_INTEGER          0x01
#define EFI_KMS_ATTRIBUTE_TYPE_LONG_INTEGER     0x02
#define EFI_KMS_ATTRIBUTE_TYPE_BIG_INTEGER      0x03
#define EFI_KMS_ATTRIBUTE_TYPE_ENUMERATION      0x04
#define EFI_KMS_ATTRIBUTE_TYPE_BOOLEAN          0x05
#define EFI_KMS_ATTRIBUTE_TYPE_BYTE_STRING      0x06
#define EFI_KMS_ATTRIBUTE_TYPE_TEXT_STRING      0x07
#define EFI_KMS_ATTRIBUTE_TYPE_DATE_TIME        0x08
#define EFI_KMS_ATTRIBUTE_TYPE_INTERVAL         0x09
#define EFI_KMS_ATTRIBUTE_TYPE_STRUCTURE        0x0A
#define EFI_KMS_ATTRIBUTE_TYPE_DYNAMIC          0x0B

typedef struct {
  ///
  /// The size in bytes for the client identifier.
  ///
  UINT16        ClientIdSize;
  ///
  /// Pointer to a valid client identifier.
  ///
  VOID          *ClientId;
  ///
  /// The client name string type used by this client. The string type set here must be one of
  /// the string types reported in the ClientNameStringTypes field of the KMS protocol. If the
  /// KMS does not support client names, this field should be set to EFI_KMS_DATA_TYPE_NONE.
  ///
  UINT8         ClientNameType;
  ///
  /// The size in characters for the client name. This field will be ignored if
  /// ClientNameStringType is set to EFI_KMS_DATA_TYPE_NONE. Otherwise, it must contain
  /// number of characters contained in the ClientName field.
  ///
  UINT8         ClientNameCount;
  ///
  /// Pointer to a client name. This field will be ignored if ClientNameStringType is set to
  /// EFI_KMS_DATA_TYPE_NONE. Otherwise, it must point to a valid string of the specified type.
  ///
  VOID          *ClientName;
} EFI_KMS_CLIENT_INFO;

typedef struct {
  ///
  /// The size of the KeyIdentifier field in bytes. This field is limited to the range 0 to 255.
  ///
  UINT8         KeyIdentifierSize;
  ///
  /// Pointer to an array of KeyIdentifierType elements.
  ///
  VOID          *KeyIdentifier;
  ///
  /// An EFI_GUID which specifies the algorithm and key value size for this key.
  ///
  EFI_GUID      KeyFormat;
  ///
  /// Pointer to a key value for a key specified by the KeyFormat field. A NULL value for this
  /// field indicates that no key is available.
  ///
  VOID          *KeyValue;
  ///
  /// Specifies the results of KMS operations performed with this descriptor. This field is used
  /// to indicate the status of individual operations when a KMS function is called with multiple
  /// EFI_KMS_KEY_DESCRIPTOR structures.
  /// KeyStatus codes returned for the individual key requests are:
  ///   EFI_SUCCESS             Successfully processed this key.
  ///   EFI_WARN_STALE_DATA     Successfully processed this key, however, the key's parameters
  ///                           exceed internal policies/limits and should be replaced.
  ///   EFI_COMPROMISED_DATA    Successfully processed this key, but the key may have been
  ///                           compromised and must be replaced.
  ///   EFI_UNSUPPORTED         Key format is not supported by the service.
  ///   EFI_OUT_OF_RESOURCES    Could not allocate resources for the key processing.
  ///   EFI_TIMEOUT             Timed out waiting for device or key server.
  ///   EFI_DEVICE_ERROR        Device or key server error.
  ///   EFI_INVALID_PARAMETER   KeyFormat is invalid.
  ///   EFI_NOT_FOUND           The key does not exist on the KMS.
  ///
  EFI_STATUS    KeyStatus;
} EFI_KMS_KEY_DESCRIPTOR;

typedef struct {
  ///
  /// Part of a tag-type-length triplet that identifies the KeyAttributeData formatting. The
  /// definition of the value is outside the scope of this standard and may be defined by the KMS.
  ///
  UINT16        Tag;
  ///
  /// Part of a tag-type-length triplet that identifies the KeyAttributeData formatting. The
  /// definition of the value is outside the scope of this standard and may be defined by the KMS.
  ///
  UINT16        Type;
  ///
  /// Length in bytes of the KeyAttributeData.
  ///
  UINT32        Length;
  ///
  /// An array of bytes to hold the attribute data associated with the KeyAttributeIdentifier.
  ///
  UINT8         KeyAttributeData[1];
} EFI_KMS_DYNAMIC_FIELD;

typedef struct {
  ///
  /// The number of members in the EFI_KMS_DYNAMIC_ATTRIBUTE structure.
  ///
  UINT32                    FieldCount;
  ///
  /// An array of EFI_KMS_DYNAMIC_FIELD structures.
  ///
  EFI_KMS_DYNAMIC_FIELD     Field[1];
} EFI_KMS_DYNAMIC_ATTRIBUTE;

typedef struct {
  ///
  /// The data type used for the KeyAttributeIdentifier field. Values for this field are defined
  /// by the EFI_KMS_DATA_TYPE constants, except that EFI_KMS_DATA_TYPE_BINARY is not
  /// valid for this field.
  ///
  UINT8         KeyAttributeIdentifierType;
  ///
  /// The length of the KeyAttributeIdentifier field in units defined by KeyAttributeIdentifierType
  /// field. This field is limited to the range 0 to 255.
  ///
  UINT8         KeyAttributeIdentifierCount;
  ///
  /// Pointer to an array of KeyAttributeIdentifierType elements. For string types, there must
  /// not be a null-termination element at the end of the array.
  ///
  VOID          *KeyAttributeIdentifier;
  ///
  /// The instance number of this attribute. If there is only one instance, the value is set to
  /// one. If this value is set to 0xFFFF (all binary 1's) then this field should be ignored if an
  /// output or treated as a wild card matching any value if it is an input. If the attribute is
  /// stored with this field, it will match any attribute request regardless of the setting of the
  /// field in the request. If set to 0xFFFF in the request, it will match any attribute with the
  /// same KeyAttributeIdentifier.
  ///
  UINT16        KeyAttributeInstance;
  ///
  /// The data type of the KeyAttributeValue (e.g. struct, bool, etc.). See the list of
  /// KeyAttributeType definitions.
  ///
  UINT16        KeyAttributeType;
  ///
  /// The size in bytes of the KeyAttribute field. A value of zero for this field indicates that no
  /// key attribute value is available.
  ///
  UINT16        KeyAttributeValueSize;
  ///
  /// Pointer to a key attribute value for the attribute specified by the KeyAttributeIdentifier
  /// field. If the KeyAttributeValueSize field is zero, then this field must be NULL.
  ///
  VOID          *KeyAttributeValue;
  ///
  /// KeyAttributeStatusSpecifies the results of KMS operations performed with this attribute.
  /// This field is used to indicate the status of individual operations when a KMS function is
  /// called with multiple EFI_KMS_KEY_ATTRIBUTE structures.
  /// KeyAttributeStatus codes returned for the individual key attribute requests are:
  ///   EFI_SUCCESS             Successfully processed this request.
  ///   EFI_WARN_STALE_DATA     Successfully processed this request, however, the key's
  ///                           parameters exceed internal policies/limits and should be replaced.
  ///   EFI_COMPROMISED_DATA    Successfully processed this request, but the key may have been
  ///                           compromised and must be replaced.
  ///   EFI_UNSUPPORTED         Key attribute format is not supported by the service.
  ///   EFI_OUT_OF_RESOURCES    Could not allocate resources for the request processing.
  ///   EFI_TIMEOUT             Timed out waiting for device or key server.
  ///   EFI_DEVICE_ERROR        Device or key server error.
  ///   EFI_INVALID_PARAMETER   A field in the EFI_KMS_KEY_ATTRIBUTE structure is invalid.
  ///   EFI_NOT_FOUND           The key attribute does not exist on the KMS.
  ///
  EFI_STATUS    KeyAttributeStatus;
} EFI_KMS_KEY_ATTRIBUTE;

/**
  Get the current status of the key management service.

  @param[in]      This              Pointer to the EFI_KMS_PROTOCOL instance.

  @retval EFI_SUCCESS               The KMS is ready for use.
  @retval EFI_NOT_READY             No connection to the KMS is available.
  @retval EFI_NO_MAPPING            No valid connection configuration exists for the KMS.
  @retval EFI_NO_RESPONSE           No response was received from the KMS.
  @retval EFI_DEVICE_ERROR          An error occurred when attempting to access the KMS.
  @retval EFI_INVALID_PARAMETER     This is NULL.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_KMS_GET_SERVICE_STATUS) (
  IN EFI_KMS_PROTOCOL           *This
  );

/**
  Register client information with the supported KMS.

  @param[in]      This              Pointer to the EFI_KMS_PROTOCOL instance.
  @param[in]      Client            Pointer to a valid EFI_KMS_CLIENT_INFO structure.
  @param[in, out] ClientDataSize    Pointer to the size, in bytes, of an arbitrary block of 
                                    data specified by the ClientData parameter. This
                                    parameter may be NULL, in which case the ClientData
                                    parameter will be ignored and no data will be
                                    transferred to or from the KMS. If the parameter is
                                    not NULL, then ClientData must be a valid pointer.
                                    If the value pointed to is 0, no data will be transferred
                                    to the KMS, but data may be returned by the KMS.
                                    For all non-zero values *ClientData will be transferred
                                    to the KMS, which may also return data to the caller.
                                    In all cases, the value upon return to the caller will
                                    be the size of the data block returned to the caller,
                                    which will be zero if no data is returned from the KMS.
  @param[in, out] ClientData        Pointer to a pointer to an arbitrary block of data of
                                    *ClientDataSize that is to be passed directly to the
                                    KMS if it supports the use of client data. This 
                                    parameter may be NULL if and only if the 
                                    ClientDataSize parameter is also NULL. Upon return to
                                    the caller, *ClientData points to a block of data of 
                                    *ClientDataSize that was returned from the KMS. 
                                    If the returned value for *ClientDataSize is zero,
                                    then the returned value for *ClientData must be NULL
                                    and should be ignored by the caller. The KMS protocol
                                    consumer is responsible for freeing all valid buffers
                                    used for client data regardless of whether they are
                                    allocated by the caller for input to the function or by
                                    the implementation for output back to the caller.

  @retval EFI_SUCCESS               The client information has been accepted by the KMS.
  @retval EFI_NOT_READY             No connection to the KMS is available.
  @retval EFI_NO_RESPONSE           There was no response from the device or the key server.
  @retval EFI_ACCESS_DENIED         Access was denied by the device or the key server.
  @retval EFI_DEVICE_ERROR          An error occurred when attempting to access the KMS.
  @retval EFI_OUT_OF_RESOURCES      Required resources were not available to perform the function.
  @retval EFI_INVALID_PARAMETER     This is NULL.
  @retval EFI_UNSUPPORTED           The KMS does not support the use of client identifiers.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_KMS_REGISTER_CLIENT) (
  IN EFI_KMS_PROTOCOL           *This,
  IN EFI_KMS_CLIENT_INFO        *Client,
  IN OUT UINTN                  *ClientDataSize OPTIONAL,
  IN OUT VOID                   **ClientData OPTIONAL
  ); 

/**
  Request that the KMS generate one or more new keys and associate them with key identifiers.
  The key value(s) is returned to the caller.

  @param[in]      This               Pointer to the EFI_KMS_PROTOCOL instance.
  @param[in]      Client             Pointer to a valid EFI_KMS_CLIENT_INFO structure.
  @param[in, out] KeyDescriptorCount Pointer to a count of the number of key descriptors to be
                                     processed by this operation. On return, this number
                                     will be updated with the number of key descriptors
                                     successfully processed.
  @param[in, out] KeyDescriptors     Pointer to an array of EFI_KMS_KEY_DESCRIPTOR
                                     structures which describe the keys to be generated.
                                     On input, the KeyIdentifierSize and the KeyIdentifier
                                     may specify an identifier to be used for the key,
                                     but this is not required. The KeyFormat field must
                                     specify a key format GUID reported as supported by
                                     the KeyFormats field of the EFI_KMS_PROTOCOL.
                                     The value for this field in the first key descriptor will
                                     be considered the default value for subsequent key
                                     descriptors requested in this operation if those key
                                     descriptors have a NULL GUID in the key format field.
                                     On output, the KeyIdentifierSize and KeyIdentifier fields
                                     will specify an identifier for the key which will be either
                                     the original identifier if one was provided, or an identifier
                                     generated either by the KMS or the KMS protocol
                                     implementation. The KeyFormat field will be updated
                                     with the GUID used to generate the key if it was a
                                     NULL GUID, and the KeyValue field will contain a pointer
                                     to memory containing the key value for the generated
                                     key. Memory for both the KeyIdentifier and the KeyValue
                                     fields will be allocated with the BOOT_SERVICES_DATA
                                     type and must be freed by the caller when it is no longer
                                     needed. Also, the KeyStatus field must reflect the result
                                     of the request relative to that key.
  @param[in, out] ClientDataSize     Pointer to the size, in bytes, of an arbitrary block of 
                                     data specified by the ClientData parameter. This
                                     parameter may be NULL, in which case the ClientData
                                     parameter will be ignored and no data will be
                                     transferred to or from the KMS. If the parameter is
                                     not NULL, then ClientData must be a valid pointer.
                                     If the value pointed to is 0, no data will be transferred
                                     to the KMS, but data may be returned by the KMS.
                                     For all non-zero values *ClientData will be transferred
                                     to the KMS, which may also return data to the caller.
                                     In all cases, the value upon return to the caller will
                                     be the size of the data block returned to the caller,
                                     which will be zero if no data is returned from the KMS.
  @param[in, out] ClientData         Pointer to a pointer to an arbitrary block of data of
                                     *ClientDataSize that is to be passed directly to the
                                     KMS if it supports the use of client data. This 
                                     parameter may be NULL if and only if the 
                                     ClientDataSize parameter is also NULL. Upon return to
                                     the caller, *ClientData points to a block of data of 
                                     *ClientDataSize that was returned from the KMS. 
                                     If the returned value for *ClientDataSize is zero,
                                     then the returned value for *ClientData must be NULL
                                     and should be ignored by the caller. The KMS protocol
                                     consumer is responsible for freeing all valid buffers
                                     used for client data regardless of whether they are
                                     allocated by the caller for input to the function or by
                                     the implementation for output back to the caller.

  @retval EFI_SUCCESS                Successfully generated and retrieved all requested keys.
  @retval EFI_UNSUPPORTED            This function is not supported by the KMS. --OR--
                                     One (or more) of the key requests submitted is not supported by
                                     the KMS. Check individual key request(s) to see which ones
                                     may have been processed.
  @retval EFI_OUT_OF_RESOURCES       Required resources were not available to perform the function.
  @retval EFI_TIMEOUT                Timed out waiting for device or key server. Check individual key
                                     request(s) to see which ones may have been processed.
  @retval EFI_ACCESS_DENIED          Access was denied by the device or the key server; OR a
                                     ClientId is required by the server and either no id was
                                     provided or an invalid id was provided.
  @retval EFI_DEVICE_ERROR           An error occurred when attempting to access the KMS. Check
                                     individual key request(s) to see which ones may have been
                                     processed.
  @retval EFI_INVALID_PARAMETER      This is NULL, ClientId is required but it is NULL,
                                     KeyDescriptorCount is NULL, or Keys is NULL.
  @retval EFI_NOT_FOUND              One or more EFI_KMS_KEY_DESCRIPTOR structures
                                     could not be processed properly. KeyDescriptorCount
                                     contains the number of structures which were successfully
                                     processed. Individual structures will reflect the status of the
                                     processing for that structure.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_KMS_CREATE_KEY) (
  IN EFI_KMS_PROTOCOL           *This,
  IN EFI_KMS_CLIENT_INFO        *Client,
  IN OUT UINT16                 *KeyDescriptorCount,
  IN OUT EFI_KMS_KEY_DESCRIPTOR *KeyDescriptors,
  IN OUT UINTN                  *ClientDataSize OPTIONAL,
  IN OUT VOID                   **ClientData OPTIONAL
  );

/**
  Retrieve an existing key.

  @param[in]      This               Pointer to the EFI_KMS_PROTOCOL instance.
  @param[in]      Client             Pointer to a valid EFI_KMS_CLIENT_INFO structure.
  @param[in, out] KeyDescriptorCount Pointer to a count of the number of key descriptors to be
                                     processed by this operation. On return, this number
                                     will be updated with the number of key descriptors
                                     successfully processed.
  @param[in, out] KeyDescriptors     Pointer to an array of EFI_KMS_KEY_DESCRIPTOR
                                     structures which describe the keys to be retrieved
                                     from the KMS.
                                     On input, the KeyIdentifierSize and the KeyIdentifier
                                     must specify an identifier to be used to retrieve a
                                     specific key. All other fields in the descriptor should
                                     be NULL.
                                     On output, the KeyIdentifierSize and KeyIdentifier fields
                                     will be unchanged, while the KeyFormat and KeyValue
                                     fields will be updated values associated with this key
                                     identifier. Memory for the KeyValue field will be 
                                     allocated with the BOOT_SERVICES_DATA type and
                                     must be freed by the caller when it is no longer needed.
                                     Also, the KeyStatus field will reflect the result of the
                                     request relative to the individual key descriptor.
  @param[in, out] ClientDataSize     Pointer to the size, in bytes, of an arbitrary block of 
                                     data specified by the ClientData parameter. This
                                     parameter may be NULL, in which case the ClientData
                                     parameter will be ignored and no data will be
                                     transferred to or from the KMS. If the parameter is
                                     not NULL, then ClientData must be a valid pointer.
                                     If the value pointed to is 0, no data will be transferred
                                     to the KMS, but data may be returned by the KMS.
                                     For all non-zero values *ClientData will be transferred
                                     to the KMS, which may also return data to the caller.
                                     In all cases, the value upon return to the caller will
                                     be the size of the data block returned to the caller,
                                     which will be zero if no data is returned from the KMS.
  @param[in, out] ClientData         Pointer to a pointer to an arbitrary block of data of
                                     *ClientDataSize that is to be passed directly to the
                                     KMS if it supports the use of client data. This 
                                     parameter may be NULL if and only if the 
                                     ClientDataSize parameter is also NULL. Upon return to
                                     the caller, *ClientData points to a block of data of 
                                     *ClientDataSize that was returned from the KMS. 
                                     If the returned value for *ClientDataSize is zero,
                                     then the returned value for *ClientData must be NULL
                                     and should be ignored by the caller. The KMS protocol
                                     consumer is responsible for freeing all valid buffers
                                     used for client data regardless of whether they are
                                     allocated by the caller for input to the function or by
                                     the implementation for output back to the caller.

  @retval EFI_SUCCESS                Successfully retrieved all requested keys.
  @retval EFI_OUT_OF_RESOURCES       Could not allocate resources for the method processing.
  @retval EFI_TIMEOUT                Timed out waiting for device or key server. Check individual key
                                     request(s) to see which ones may have been processed.
  @retval EFI_BUFFER_TOO_SMALL       If multiple keys are associated with a single identifier, and the
                                     KeyValue buffer does not contain enough structures
                                     (KeyDescriptorCount) to contain all the key data, then
                                     the available structures will be filled and
                                     KeyDescriptorCount will be updated to indicate the
                                     number of keys which could not be processed.
  @retval EFI_ACCESS_DENIED          Access was denied by the device or the key server; OR a
                                     ClientId is required by the server and either none or an
                                     invalid id was provided.
  @retval EFI_DEVICE_ERROR           Device or key server error. Check individual key request(s) to
                                     see which ones may have been processed.
  @retval EFI_INVALID_PARAMETER      This is NULL, ClientId is required but it is NULL,
                                     KeyDescriptorCount is NULL, or Keys is NULL.
  @retval EFI_NOT_FOUND              One or more EFI_KMS_KEY_DESCRIPTOR structures
                                     could not be processed properly. KeyDescriptorCount
                                     contains the number of structures which were successfully
                                     processed. Individual structures will reflect the status of the
                                     processing for that structure.
  @retval EFI_UNSUPPORTED            The implementation/KMS does not support this function.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_KMS_GET_KEY) (
  IN EFI_KMS_PROTOCOL           *This,
  IN EFI_KMS_CLIENT_INFO        *Client,
  IN OUT UINT16                 *KeyDescriptorCount,
  IN OUT EFI_KMS_KEY_DESCRIPTOR *KeyDescriptors,
  IN OUT UINTN                  *ClientDataSize OPTIONAL,
  IN OUT VOID                   **ClientData OPTIONAL
  );

/**
  Add a new key.

  @param[in]      This               Pointer to the EFI_KMS_PROTOCOL instance.
  @param[in]      Client             Pointer to a valid EFI_KMS_CLIENT_INFO structure.
  @param[in, out] KeyDescriptorCount Pointer to a count of the number of key descriptors to be
                                     processed by this operation. On normal return, this
                                     number will be updated with the number of key
                                     descriptors successfully processed.
  @param[in, out] KeyDescriptors     Pointer to an array of EFI_KMS_KEY_DESCRIPTOR
                                     structures which describe the keys to be added.
                                     On input, the KeyId field for first key must contain
                                     valid identifier data to be used for adding a key to
                                     the KMS. The values for these fields in this key
                                     definition will be considered default values for
                                     subsequent keys requested in this operation. A value
                                     of 0 in any subsequent KeyId field will be replaced
                                     with the current default value. The KeyFormat and
                                     KeyValue fields for each key to be added must contain
                                     consistent values to be associated with the given KeyId.
                                     On return, the KeyStatus field will reflect the result
                                     of the operation for each key request.
  @param[in, out] ClientDataSize     Pointer to the size, in bytes, of an arbitrary block of 
                                     data specified by the ClientData parameter. This
                                     parameter may be NULL, in which case the ClientData
                                     parameter will be ignored and no data will be
                                     transferred to or from the KMS. If the parameter is
                                     not NULL, then ClientData must be a valid pointer.
                                     If the value pointed to is 0, no data will be transferred
                                     to the KMS, but data may be returned by the KMS.
                                     For all non-zero values *ClientData will be transferred
                                     to the KMS, which may also return data to the caller.
                                     In all cases, the value upon return to the caller will
                                     be the size of the data block returned to the caller,
                                     which will be zero if no data is returned from the KMS.
  @param[in, out] ClientData         Pointer to a pointer to an arbitrary block of data of
                                     *ClientDataSize that is to be passed directly to the
                                     KMS if it supports the use of client data. This 
                                     parameter may be NULL if and only if the 
                                     ClientDataSize parameter is also NULL. Upon return to
                                     the caller, *ClientData points to a block of data of 
                                     *ClientDataSize that was returned from the KMS. 
                                     If the returned value for *ClientDataSize is zero,
                                     then the returned value for *ClientData must be NULL
                                     and should be ignored by the caller. The KMS protocol
                                     consumer is responsible for freeing all valid buffers
                                     used for client data regardless of whether they are
                                     allocated by the caller for input to the function or by
                                     the implementation for output back to the caller.

  @retval EFI_SUCCESS                Successfully added all requested keys.
  @retval EFI_OUT_OF_RESOURCES       Could not allocate required resources.
  @retval EFI_TIMEOUT                Timed out waiting for device or key server. Check individual key
                                     request(s) to see which ones may have been processed.
  @retval EFI_BUFFER_TOO_SMALL       If multiple keys are associated with a single identifier, and the
                                     KeyValue buffer does not contain enough structures
                                     (KeyDescriptorCount) to contain all the key data, then
                                     the available structures will be filled and
                                     KeyDescriptorCount will be updated to indicate the
                                     number of keys which could not be processed
  @retval EFI_ACCESS_DENIED          Access was denied by the device or the key server; OR a
                                     ClientId is required by the server and either none or an
                                     invalid id was provided.
  @retval EFI_DEVICE_ERROR           Device or key server error. Check individual key request(s) to
                                     see which ones may have been processed.
  @retval EFI_INVALID_PARAMETER      This is NULL, ClientId is required but it is NULL,
                                     KeyDescriptorCount is NULL, or Keys is NULL.
  @retval EFI_NOT_FOUND              One or more EFI_KMS_KEY_DESCRIPTOR structures
                                     could not be processed properly. KeyDescriptorCount
                                     contains the number of structures which were successfully
                                     processed. Individual structures will reflect the status of the
                                     processing for that structure.
  @retval EFI_UNSUPPORTED            The implementation/KMS does not support this function.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_KMS_ADD_KEY) (
  IN EFI_KMS_PROTOCOL           *This,
  IN EFI_KMS_CLIENT_INFO        *Client,
  IN OUT UINT16                 *KeyDescriptorCount,
  IN OUT EFI_KMS_KEY_DESCRIPTOR *KeyDescriptors,
  IN OUT UINTN                  *ClientDataSize OPTIONAL,
  IN OUT VOID                   **ClientData OPTIONAL
  );

/**
  Delete an existing key from the KMS database.

  @param[in]      This               Pointer to the EFI_KMS_PROTOCOL instance.
  @param[in]      Client             Pointer to a valid EFI_KMS_CLIENT_INFO structure.
  @param[in, out] KeyDescriptorCount Pointer to a count of the number of key descriptors to be
                                     processed by this operation. On normal return, this
                                     number will be updated with the number of key
                                     descriptors successfully processed.
  @param[in, out] KeyDescriptors     Pointer to an array of EFI_KMS_KEY_DESCRIPTOR
                                     structures which describe the keys to be deleted.
                                     On input, the KeyId field for first key must contain
                                     valid identifier data to be used for adding a key to
                                     the KMS. The values for these fields in this key
                                     definition will be considered default values for
                                     subsequent keys requested in this operation. A value
                                     of 0 in any subsequent KeyId field will be replaced
                                     with the current default value. The KeyFormat and
                                     KeyValue fields are ignored, but should be 0.
                                     On return, the KeyStatus field will reflect the result
                                     of the operation for each key request.
  @param[in, out] ClientDataSize     Pointer to the size, in bytes, of an arbitrary block of 
                                     data specified by the ClientData parameter. This
                                     parameter may be NULL, in which case the ClientData
                                     parameter will be ignored and no data will be
                                     transferred to or from the KMS. If the parameter is
                                     not NULL, then ClientData must be a valid pointer.
                                     If the value pointed to is 0, no data will be transferred
                                     to the KMS, but data may be returned by the KMS.
                                     For all non-zero values *ClientData will be transferred
                                     to the KMS, which may also return data to the caller.
                                     In all cases, the value upon return to the caller will
                                     be the size of the data block returned to the caller,
                                     which will be zero if no data is returned from the KMS.
  @param[in, out] ClientData         Pointer to a pointer to an arbitrary block of data of
                                     *ClientDataSize that is to be passed directly to the
                                     KMS if it supports the use of client data. This 
                                     parameter may be NULL if and only if the 
                                     ClientDataSize parameter is also NULL. Upon return to
                                     the caller, *ClientData points to a block of data of 
                                     *ClientDataSize that was returned from the KMS. 
                                     If the returned value for *ClientDataSize is zero,
                                     then the returned value for *ClientData must be NULL
                                     and should be ignored by the caller. The KMS protocol
                                     consumer is responsible for freeing all valid buffers
                                     used for client data regardless of whether they are
                                     allocated by the caller for input to the function or by
                                     the implementation for output back to the caller.

  @retval EFI_SUCCESS                Successfully deleted all requested keys.
  @retval EFI_OUT_OF_RESOURCES       Could not allocate required resources.
  @retval EFI_TIMEOUT                Timed out waiting for device or key server. Check individual key
                                     request(s) to see which ones may have been processed.
  @retval EFI_ACCESS_DENIED          Access was denied by the device or the key server; OR a
                                     ClientId is required by the server and either none or an
                                     invalid id was provided.
  @retval EFI_DEVICE_ERROR           Device or key server error. Check individual key request(s) to
                                     see which ones may have been processed.
  @retval EFI_INVALID_PARAMETER      This is NULL, ClientId is required but it is NULL,
                                     KeyDescriptorCount is NULL, or Keys is NULL.
  @retval EFI_NOT_FOUND              One or more EFI_KMS_KEY_DESCRIPTOR structures
                                     could not be processed properly. KeyDescriptorCount
                                     contains the number of structures which were successfully
                                     processed. Individual structures will reflect the status of the
                                     processing for that structure.
  @retval EFI_UNSUPPORTED            The implementation/KMS does not support this function.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_KMS_DELETE_KEY) (
  IN EFI_KMS_PROTOCOL           *This,
  IN EFI_KMS_CLIENT_INFO        *Client,
  IN OUT UINT16                 *KeyDescriptorCount,
  IN OUT EFI_KMS_KEY_DESCRIPTOR *KeyDescriptors,
  IN OUT UINTN                  *ClientDataSize OPTIONAL,
  IN OUT VOID                   **ClientData OPTIONAL
  );

/**
  Get one or more attributes associated with a specified key identifier.
  If none are found, the returned attributes count contains a value of zero.

  @param[in]      This               Pointer to the EFI_KMS_PROTOCOL instance.
  @param[in]      Client             Pointer to a valid EFI_KMS_CLIENT_INFO structure.
  @param[in]      KeyIdentifierSize  Pointer to the size in bytes of the KeyIdentifier variable.
  @param[in]      KeyIdentifier      Pointer to the key identifier associated with this key.
  @param[in, out] KeyAttributesCount Pointer to the number of EFI_KMS_KEY_ATTRIBUTE
                                     structures associated with the Key identifier. If none
                                     are found, the count value is zero on return.
                                     On input this value reflects the number of KeyAttributes
                                     that may be returned.
                                     On output, the value reflects the number of completed
                                     KeyAttributes structures found.
  @param[in, out] KeyAttributes      Pointer to an array of EFI_KMS_KEY_ATTRIBUTE
                                     structures associated with the Key Identifier.
                                     On input, the fields in the structure should be NULL.
                                     On output, the attribute fields will have updated values
                                     for attributes associated with this key identifier.
  @param[in, out] ClientDataSize     Pointer to the size, in bytes, of an arbitrary block of 
                                     data specified by the ClientData parameter. This
                                     parameter may be NULL, in which case the ClientData
                                     parameter will be ignored and no data will be
                                     transferred to or from the KMS. If the parameter is
                                     not NULL, then ClientData must be a valid pointer.
                                     If the value pointed to is 0, no data will be transferred
                                     to the KMS, but data may be returned by the KMS.
                                     For all non-zero values *ClientData will be transferred
                                     to the KMS, which may also return data to the caller.
                                     In all cases, the value upon return to the caller will
                                     be the size of the data block returned to the caller,
                                     which will be zero if no data is returned from the KMS.
  @param[in, out] ClientData         Pointer to a pointer to an arbitrary block of data of
                                     *ClientDataSize that is to be passed directly to the
                                     KMS if it supports the use of client data. This 
                                     parameter may be NULL if and only if the 
                                     ClientDataSize parameter is also NULL. Upon return to
                                     the caller, *ClientData points to a block of data of 
                                     *ClientDataSize that was returned from the KMS. 
                                     If the returned value for *ClientDataSize is zero,
                                     then the returned value for *ClientData must be NULL
                                     and should be ignored by the caller. The KMS protocol
                                     consumer is responsible for freeing all valid buffers
                                     used for client data regardless of whether they are
                                     allocated by the caller for input to the function or by
                                     the implementation for output back to the caller.

  @retval EFI_SUCCESS                Successfully retrieved all key attributes.
  @retval EFI_OUT_OF_RESOURCES       Could not allocate resources for the method processing.
  @retval EFI_TIMEOUT                Timed out waiting for device or key server. Check individual key
                                     attribute request(s) to see which ones may have been
                                     processed.
  @retval EFI_BUFFER_TOO_SMALL       If multiple key attributes are associated with a single identifier,
                                     and the KeyAttributes buffer does not contain enough
                                     structures (KeyAttributesCount) to contain all the key
                                     attributes data, then the available structures will be filled and
                                     KeyAttributesCount will be updated to indicate the
                                     number of key attributes which could not be processed.
  @retval EFI_ACCESS_DENIED          Access was denied by the device or the key server; OR a
                                     ClientId is required by the server and either none or an
                                     invalid id was provided.
  @retval EFI_DEVICE_ERROR           Device or key server error. Check individual key attribute
                                     request(s) (i.e. key attribute status for each) to see which ones
                                     may have been processed.
  @retval EFI_INVALID_PARAMETER      This is NULL, ClientId is required but it is NULL,
                                     KeyIdentifierSize is NULL , or KeyIdentifier
                                     is NULL, or KeyAttributes is NULL, or
                                     KeyAttributesSize is NULL.
  @retval EFI_NOT_FOUND              The KeyIdentifier could not be found.
                                     KeyAttributesCount contains zero. Individual
                                     structures will reflect the status of the processing for that
                                     structure.
  @retval EFI_UNSUPPORTED            The implementation/KMS does not support this function.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_KMS_GET_KEY_ATTRIBUTES) (
  IN EFI_KMS_PROTOCOL           *This,
  IN EFI_KMS_CLIENT_INFO        *Client,
  IN UINT8                      *KeyIdentifierSize,
  IN CONST VOID                 *KeyIdentifier,
  IN OUT UINT16                 *KeyAttributesCount,
  IN OUT EFI_KMS_KEY_ATTRIBUTE  *KeyAttributes,
  IN OUT UINTN                  *ClientDataSize OPTIONAL,
  IN OUT VOID                   **ClientData OPTIONAL
  );

/**
  Add one or more attributes to a key specified by a key identifier.

  @param[in]      This               Pointer to the EFI_KMS_PROTOCOL instance.
  @param[in]      Client             Pointer to a valid EFI_KMS_CLIENT_INFO structure.
  @param[in]      KeyIdentifierSize  Pointer to the size in bytes of the KeyIdentifier variable.
  @param[in]      KeyIdentifier      Pointer to the key identifier associated with this key.
  @param[in, out] KeyAttributesCount Pointer to the number of EFI_KMS_KEY_ATTRIBUTE
                                     structures to associate with the Key. On normal returns,
                                     this number will be updated with the number of key
                                     attributes successfully processed.
  @param[in, out] KeyAttributes      Pointer to an array of EFI_KMS_KEY_ATTRIBUTE
                                     structures providing the attribute information to
                                     associate with the key.
                                     On input, the values for the fields in the structure
                                     are completely filled in.
                                     On return the KeyAttributeStatus field will reflect the
                                     result of the operation for each key attribute request.
  @param[in, out] ClientDataSize     Pointer to the size, in bytes, of an arbitrary block of 
                                     data specified by the ClientData parameter. This
                                     parameter may be NULL, in which case the ClientData
                                     parameter will be ignored and no data will be
                                     transferred to or from the KMS. If the parameter is
                                     not NULL, then ClientData must be a valid pointer.
                                     If the value pointed to is 0, no data will be transferred
                                     to the KMS, but data may be returned by the KMS.
                                     For all non-zero values *ClientData will be transferred
                                     to the KMS, which may also return data to the caller.
                                     In all cases, the value upon return to the caller will
                                     be the size of the data block returned to the caller,
                                     which will be zero if no data is returned from the KMS.
  @param[in, out] ClientData         Pointer to a pointer to an arbitrary block of data of
                                     *ClientDataSize that is to be passed directly to the
                                     KMS if it supports the use of client data. This 
                                     parameter may be NULL if and only if the 
                                     ClientDataSize parameter is also NULL. Upon return to
                                     the caller, *ClientData points to a block of data of 
                                     *ClientDataSize that was returned from the KMS. 
                                     If the returned value for *ClientDataSize is zero,
                                     then the returned value for *ClientData must be NULL
                                     and should be ignored by the caller. The KMS protocol
                                     consumer is responsible for freeing all valid buffers
                                     used for client data regardless of whether they are
                                     allocated by the caller for input to the function or by
                                     the implementation for output back to the caller.

  @retval EFI_SUCCESS                Successfully added all requested key attributes.
  @retval EFI_OUT_OF_RESOURCES       Could not allocate required resources.
  @retval EFI_TIMEOUT                Timed out waiting for device or key server. Check individual key
                                     attribute request(s) to see which ones may have been
                                     processed.
  @retval EFI_BUFFER_TOO_SMALL       If multiple keys attributes are associated with a single key
                                     identifier, and the attributes buffer does not contain
                                     enough structures (KeyAttributesCount) to contain all
                                     the data, then the available structures will be filled and
                                     KeyAttributesCount will be updated to indicate the
                                     number of key attributes which could not be processed. The
                                     status of each key attribute is also updated indicating success or
                                     failure for that attribute in case there are other errors for those
                                     attributes that could be processed.
  @retval EFI_ACCESS_DENIED          Access was denied by the device or the key server; OR a
                                     ClientId is required by the server and either none or an
                                     invalid id was provided.
  @retval EFI_DEVICE_ERROR           Device or key server error. Check individual key attribute
                                     request(s) (i.e. key attribute status for each) to see which ones
                                     may have been processed.
  @retval EFI_INVALID_PARAMETER      This is NULL, ClientId is required but it is NULL,
                                     KeyAttributesCount is NULL, or KeyAttributes
                                     is NULL, or KeyIdentifierSize is NULL, or
                                     KeyIdentifer is NULL.
  @retval EFI_NOT_FOUND              The KeyIdentifier could not be found. On return the
                                     KeyAttributesCount contains the number of attributes
                                     processed. Individual structures will reflect the status of the
                                     processing for that structure.
  @retval EFI_UNSUPPORTED            The implementation/KMS does not support this function.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_KMS_ADD_KEY_ATTRIBUTES) (
  IN EFI_KMS_PROTOCOL           *This,
  IN EFI_KMS_CLIENT_INFO        *Client,
  IN UINT8                      *KeyIdentifierSize,
  IN CONST VOID                 *KeyIdentifier,
  IN OUT UINT16                 *KeyAttributesCount,
  IN OUT EFI_KMS_KEY_ATTRIBUTE  *KeyAttributes,
  IN OUT UINTN                  *ClientDataSize OPTIONAL,
  IN OUT VOID                   **ClientData OPTIONAL
  );

/**
  Delete attributes to a key specified by a key identifier.

  @param[in]      This               Pointer to the EFI_KMS_PROTOCOL instance.
  @param[in]      Client             Pointer to a valid EFI_KMS_CLIENT_INFO structure.
  @param[in]      KeyIdentifierSize  Pointer to the size in bytes of the KeyIdentifier variable.
  @param[in]      KeyIdentifier      Pointer to the key identifier associated with this key.
  @param[in, out] KeyAttributesCount Pointer to the number of EFI_KMS_KEY_ATTRIBUTE
                                     structures to associate with the Key.
                                     On input, the count value is one or more.
                                     On normal returns, this number will be updated with
                                     the number of key attributes successfully processed.
  @param[in, out] KeyAttributes      Pointer to an array of EFI_KMS_KEY_ATTRIBUTE
                                     structures providing the attribute information to
                                     associate with the key.
                                     On input, the values for the fields in the structure
                                     are completely filled in.
                                     On return the KeyAttributeStatus field will reflect the
                                     result of the operation for each key attribute request.
  @param[in, out] ClientDataSize     Pointer to the size, in bytes, of an arbitrary block of 
                                     data specified by the ClientData parameter. This
                                     parameter may be NULL, in which case the ClientData
                                     parameter will be ignored and no data will be
                                     transferred to or from the KMS. If the parameter is
                                     not NULL, then ClientData must be a valid pointer.
                                     If the value pointed to is 0, no data will be transferred
                                     to the KMS, but data may be returned by the KMS.
                                     For all non-zero values *ClientData will be transferred
                                     to the KMS, which may also return data to the caller.
                                     In all cases, the value upon return to the caller will
                                     be the size of the data block returned to the caller,
                                     which will be zero if no data is returned from the KMS.
  @param[in, out] ClientData         Pointer to a pointer to an arbitrary block of data of
                                     *ClientDataSize that is to be passed directly to the
                                     KMS if it supports the use of client data. This 
                                     parameter may be NULL if and only if the 
                                     ClientDataSize parameter is also NULL. Upon return to
                                     the caller, *ClientData points to a block of data of 
                                     *ClientDataSize that was returned from the KMS. 
                                     If the returned value for *ClientDataSize is zero,
                                     then the returned value for *ClientData must be NULL
                                     and should be ignored by the caller. The KMS protocol
                                     consumer is responsible for freeing all valid buffers
                                     used for client data regardless of whether they are
                                     allocated by the caller for input to the function or by
                                     the implementation for output back to the caller.

  @retval EFI_SUCCESS                Successfully deleted all requested key attributes.
  @retval EFI_OUT_OF_RESOURCES       Could not allocate required resources.
  @retval EFI_TIMEOUT                Timed out waiting for device or key server. Check individual key
                                     attribute request(s) to see which ones may have been
                                     processed.
  @retval EFI_ACCESS_DENIED          Access was denied by the device or the key server; OR a
                                     ClientId is required by the server and either none or an
                                     invalid id was provided.
  @retval EFI_DEVICE_ERROR           Device or key server error. Check individual key attribute
                                     request(s) (i.e. key attribute status for each) to see which ones
                                     may have been processed.
  @retval EFI_INVALID_PARAMETER      This is NULL, ClientId is required but it is NULL,
                                     KeyAttributesCount is NULL, or
                                     KeyAttributes is NULL, or KeyIdentifierSize
                                     is NULL, or KeyIdentifer is NULL.
  @retval EFI_NOT_FOUND              The KeyIdentifier could not be found or the attribute
                                     could not be found. On return the KeyAttributesCount
                                     contains the number of attributes processed. Individual
                                     structures will reflect the status of the processing for that
                                     structure.
  @retval EFI_UNSUPPORTED            The implementation/KMS does not support this function.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_KMS_DELETE_KEY_ATTRIBUTES) (
  IN EFI_KMS_PROTOCOL           *This,
  IN EFI_KMS_CLIENT_INFO        *Client,
  IN UINT8                      *KeyIdentifierSize,
  IN CONST VOID                 *KeyIdentifier,
  IN OUT UINT16                 *KeyAttributesCount,
  IN OUT EFI_KMS_KEY_ATTRIBUTE  *KeyAttributes,
  IN OUT UINTN                  *ClientDataSize OPTIONAL,
  IN OUT VOID                   **ClientData OPTIONAL
  );

/**
  Retrieve one or more key that has matched all of the specified key attributes.

  @param[in]      This               Pointer to the EFI_KMS_PROTOCOL instance.
  @param[in]      Client             Pointer to a valid EFI_KMS_CLIENT_INFO structure.
  @param[in, out] KeyAttributesCount Pointer to a count of the number of key attribute structures
                                     that must be matched for each returned key descriptor.
                                     On input the count value is one or more.
                                     On normal returns, this number will be updated with
                                     the number of key attributes successfully processed.
  @param[in, out] KeyAttributes      Pointer to an array of EFI_KMS_KEY_ATTRIBUTE
                                     structure to search for.
                                     On input, the values for the fields in the structure are
                                     completely filled in.
                                     On return the KeyAttributeStatus field will reflect the
                                     result of the operation for each key attribute request.
  @param[in, out] KeyDescriptorCount Pointer to a count of the number of key descriptors matched
                                     by this operation.
                                     On entry, this number will be zero.
                                     On return, this number will be updated to the number
                                     of key descriptors successfully found.
  @param[in, out] KeyDescriptors     Pointer to an array of EFI_KMS_KEY_DESCRIPTOR
                                     structures which describe the keys from the KMS
                                     having the KeyAttribute(s) specified.
                                     On input, this pointer will be NULL.
                                     On output, the array will contain an
                                     EFI_KMS_KEY_DESCRIPTOR structure for each key
                                     meeting the search criteria. Memory for the array
                                     and all KeyValue fields will be allocated with the
                                     EfiBootServicesData type and must be freed by the
                                     caller when it is no longer needed. Also, the KeyStatus
                                     field of each descriptor will reflect the result of the
                                     request relative to that key descriptor.
  @param[in, out] ClientDataSize     Pointer to the size, in bytes, of an arbitrary block of 
                                     data specified by the ClientData parameter. This
                                     parameter may be NULL, in which case the ClientData
                                     parameter will be ignored and no data will be
                                     transferred to or from the KMS. If the parameter is
                                     not NULL, then ClientData must be a valid pointer.
                                     If the value pointed to is 0, no data will be transferred
                                     to the KMS, but data may be returned by the KMS.
                                     For all non-zero values *ClientData will be transferred
                                     to the KMS, which may also return data to the caller.
                                     In all cases, the value upon return to the caller will
                                     be the size of the data block returned to the caller,
                                     which will be zero if no data is returned from the KMS.
  @param[in, out] ClientData         Pointer to a pointer to an arbitrary block of data of
                                     *ClientDataSize that is to be passed directly to the
                                     KMS if it supports the use of client data. This 
                                     parameter may be NULL if and only if the 
                                     ClientDataSize parameter is also NULL. Upon return to
                                     the caller, *ClientData points to a block of data of 
                                     *ClientDataSize that was returned from the KMS. 
                                     If the returned value for *ClientDataSize is zero,
                                     then the returned value for *ClientData must be NULL
                                     and should be ignored by the caller. The KMS protocol
                                     consumer is responsible for freeing all valid buffers
                                     used for client data regardless of whether they are
                                     allocated by the caller for input to the function or by
                                     the implementation for output back to the caller.

  @retval EFI_SUCCESS                Successfully retrieved all requested keys.
  @retval EFI_OUT_OF_RESOURCES       Could not allocate required resources.
  @retval EFI_TIMEOUT                Timed out waiting for device or key server. Check individual key
                                     attribute request(s) to see which ones may have been
                                     processed.
  @retval EFI_BUFFER_TOO_SMALL       If multiple keys are associated with the attribute(s), and the
                                     KeyValue buffer does not contain enough structures
                                     (KeyDescriptorCount) to contain all the key data, then
                                     the available structures will be filled and
                                     KeyDescriptorCount will be updated to indicate the
                                     number of keys which could not be processed.
  @retval EFI_ACCESS_DENIED          Access was denied by the device or the key server; OR a
                                     ClientId is required by the server and either none or an
                                     invalid id was provided.
  @retval EFI_DEVICE_ERROR           Device or key server error. Check individual key attribute
                                     request(s) (i.e. key attribute status for each) to see which ones
                                     may have been processed.
  @retval EFI_INVALID_PARAMETER      This is NULL, ClientId is required but it is NULL,
                                     KeyDescriptorCount is NULL, or
                                     KeyDescriptors is NULL or KeyAttributes is
                                     NULL, or KeyAttributesCount is NULL.
  @retval EFI_NOT_FOUND              One or more EFI_KMS_KEY_ATTRIBUTE structures could
                                     not be processed properly. KeyAttributeCount contains
                                     the number of structures which were successfully processed.
                                     Individual structures will reflect the status of the processing for
                                     that structure.
  @retval EFI_UNSUPPORTED            The implementation/KMS does not support this function.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_KMS_GET_KEY_BY_ATTRIBUTES) (
  IN EFI_KMS_PROTOCOL           *This,
  IN EFI_KMS_CLIENT_INFO        *Client,
  IN OUT UINTN                  *KeyAttributeCount,
  IN OUT EFI_KMS_KEY_ATTRIBUTE  *KeyAttributes,
  IN OUT UINTN                  *KeyDescriptorCount,
  IN OUT EFI_KMS_KEY_DESCRIPTOR *KeyDescriptors,
  IN OUT UINTN                  *ClientDataSize OPTIONAL,
  IN OUT VOID                   **ClientData OPTIONAL
  );

///
/// The Key Management Service (KMS) protocol provides services to generate, store, retrieve,
/// and manage cryptographic keys.
///
struct _EFI_KMS_PROTOCOL {
  ///
  /// Get the current status of the key management service. If the implementation has not yet
  /// connected to the KMS, then a call to this function will initiate a connection. This is the
  /// only function that is valid for use prior to the service being marked available.
  ///
  EFI_KMS_GET_SERVICE_STATUS        GetServiceStatus;
  ///
  /// Register a specific client with the KMS.
  ///
  EFI_KMS_REGISTER_CLIENT           RegisterClient;
  ///
  /// Request the generation of a new key and retrieve it.
  ///
  EFI_KMS_CREATE_KEY                CreateKey;
  ///
  /// Retrieve an existing key.
  ///
  EFI_KMS_GET_KEY                   GetKey;
  ///
  /// Add a local key to KMS database. If there is an existing key with this key identifier in the
  /// KMS database, it will be replaced with the new key.
  ///
  EFI_KMS_ADD_KEY                   AddKey;
  ///
  /// Delete an existing key from the KMS database.
  ///
  EFI_KMS_DELETE_KEY                DeleteKey;
  ///
  /// Get attributes for an existing key in the KMS database.
  ///
  EFI_KMS_GET_KEY_ATTRIBUTES        GetKeyAttributes;
  ///
  /// Add attributes to an existing key in the KMS database.
  ///
  EFI_KMS_ADD_KEY_ATTRIBUTES        AddKeyAttributes;
  ///
  /// Delete attributes for an existing key in the KMS database.
  ///
  EFI_KMS_DELETE_KEY_ATTRIBUTES     DeleteKeyAttributes;
  ///
  /// Get existing key(s) with the specified attributes.
  ///
  EFI_KMS_GET_KEY_BY_ATTRIBUTES     GetKeyByAttributes;
  ///
  /// The version of this EFI_KMS_PROTOCOL structure. This must be set to 0x00020040 for
  /// the initial version of this protocol.
  ///
  UINT32                            ProtocolVersion;
  ///
  /// Optional GUID used to identify a specific KMS. This GUID may be supplied by the provider,
  /// by the implementation, or may be null. If is null, then the ServiceName must not be null.
  ///
  EFI_GUID                          ServiceId;
  ///
  /// Optional pointer to a unicode string which may be used to identify the KMS or provide
  /// other information about the supplier.
  ///
  CHAR16                            *ServiceName;
  ///
  /// Optional 32-bit value which may be used to indicate the version of the KMS provided by
  /// the supplier.
  ///
  UINT32                            ServiceVersion;
  ///
  /// TRUE if and only if the service is active and available for use. To avoid unnecessary
  /// delays in POST, this protocol may be installed without connecting to the service. In this
  /// case, the first call to the GetServiceStatus () function will cause the implementation to
  /// connect to the supported service and mark it as available. The capabilities of this service
  /// as defined in the reminder of this protocol are not guaranteed to be valid until the service
  /// has been marked available.
  ///
  BOOLEAN                           ServiceAvailable;
  ///
  /// TURE if and only if the service supports client identifiers. Client identifiers may be used
  /// for auditing, access control or any other purpose specific to the implementation.
  ///
  BOOLEAN                           ClientIdSupported;
  ///
  /// TURE if and only if the service requires a client identifier in order to process key requests.
  /// FALSE otherwise.
  ///
  BOOLEAN                           ClientIdRequired;
  ///
  /// The maximum size in bytes for the client identifier.
  ///
  UINT16                            ClientIdMaxSize;
  ///
  /// The client name string type(s) supported by the KMS service. If client names are not
  /// supported, this field will be set the EFI_KMS_DATA_TYPE_NONE. Otherwise, it will be set
  /// to the inclusive 'OR' of all client name formats supported. Client names may be used for
  /// auditing, access control or any other purpose specific to the implementation.
  ///
  UINT8                             ClientNameStringTypes;
  ///
  /// TURE if only if the KMS requires a client name to be supplied to the service.
  /// FALSE otherwise.
  ///
  BOOLEAN                           ClientNameRequired;
  ///
  /// The maximum number of characters allowed for the client name.
  ///
  UINT16                            ClientNameMaxCount;
  ///
  /// TURE if and only if the service supports arbitrary client data requests. The use of client
  /// data requires the caller to have specific knowledge of the individual KMS service and
  /// should be used only if absolutely necessary.
  /// FALSE otherwise.
  ///
  BOOLEAN                           ClientDataSupported;
  ///
  /// The maximum size in bytes for the client data. If the maximum data size is not specified
  /// by the KMS or it is not known, then this field must be filled with all ones.
  ///
  UINTN                             ClientDataMaxSize;
  ///
  /// TURE if variable length key identifiers are supported.
  /// FALSE if a fixed length key identifier is supported.
  ///
  BOOLEAN                           KeyIdVariableLenSupported;
  ///
  /// If KeyIdVariableLenSupported is TRUE, this is the maximum supported key identifier length
  /// in bytes. Otherwise this is the fixed length of key identifier supported. Key ids shorter
  /// than the fixed length will be padded on the right with blanks.
  ///
  UINTN                             KeyIdMaxSize;
  ///
  /// The number of key format/size GUIDs returned in the KeyFormats field.
  ///
  UINTN                             KeyFormatsCount;
  ///
  /// A pointer to an array of EFI_GUID values which specify key formats/sizes supported by
  /// this KMS. Each format/size pair will be specified by a separate EFI_GUID. At least one
  /// key format/size must be supported. All formats/sizes with the same hashing algorithm
  /// must be contiguous in the array, and for each hashing algorithm, the key sizes must be in
  /// ascending order. See "Related Definitions" for GUIDs which identify supported key formats/sizes.
  /// This list of GUIDs supported by the KMS is not required to be exhaustive, and the KMS
  /// may provide support for additional key formats/sizes. Users may request key information
  /// using an arbitrary GUID, but any GUID not recognized by the implementation or not
  /// supported by the KMS will return an error code of EFI_UNSUPPORTED
  ///
  EFI_GUID                          *KeyFormats;
  ///
  /// TRUE if key attributes are supported.
  /// FALSE if key attributes are not supported.
  ///
  BOOLEAN                           KeyAttributesSupported;
  ///
  /// The key attribute identifier string type(s) supported by the KMS service. If key attributes
  /// are not supported, this field will be set to EFI_KMS_DATA_TYPE_NONE. Otherwise, it will
  /// be set to the inclusive 'OR' of all key attribute identifier string types supported.
  /// EFI_KMS_DATA_TYPE_BINARY is not valid for this field.
  ///
  UINT8                             KeyAttributeIdStringTypes;
  UINT16                            KeyAttributeIdMaxCount;
  ///
  /// The number of predefined KeyAttributes structures returned in the KeyAttributes
  /// parameter. If the KMS does not support predefined key attributes, or if it does not
  /// provide a method to obtain predefined key attributes data, then this field must be zero.
  ///
  UINTN                             KeyAttributesCount;
  ///
  /// A pointer to an array of KeyAttributes structures which contains the predefined
  /// attributes supported by this KMS. Each structure must contain a valid key attribute
  /// identifier and should provide any other information as appropriate for the attribute,
  /// including a default value if one exists. This variable must be set to NULL if the
  /// KeyAttributesCount variable is zero. It must point to a valid buffer if the
  /// KeyAttributesCount variable is non-zero.
  /// This list of predefined attributes is not required to be exhaustive, and the KMS may
  /// provide additional predefined attributes not enumerated in this list. The implementation
  /// does not distinguish between predefined and used defined attributes, and therefore,
  /// predefined attributes not enumerated will still be processed to the KMS.
  ///
  EFI_KMS_KEY_ATTRIBUTE             *KeyAttributes;
};

extern EFI_GUID gEfiKmsFormatGeneric128Guid;
extern EFI_GUID gEfiKmsFormatGeneric160Guid;
extern EFI_GUID gEfiKmsFormatGeneric256Guid;
extern EFI_GUID gEfiKmsFormatGeneric512Guid;
extern EFI_GUID gEfiKmsFormatGeneric1024Guid;
extern EFI_GUID gEfiKmsFormatGeneric2048Guid;
extern EFI_GUID gEfiKmsFormatGeneric3072Guid;
extern EFI_GUID gEfiKmsFormatMd2128Guid;
extern EFI_GUID gEfiKmsFormatMdc2128Guid;
extern EFI_GUID gEfiKmsFormatMd4128Guid;
extern EFI_GUID gEfiKmsFormatMdc4128Guid;
extern EFI_GUID gEfiKmsFormatMd5128Guid;
extern EFI_GUID gEfiKmsFormatMd5sha128Guid;
extern EFI_GUID gEfiKmsFormatSha1160Guid;
extern EFI_GUID gEfiKmsFormatSha256256Guid;
extern EFI_GUID gEfiKmsFormatSha512512Guid;
extern EFI_GUID gEfiKmsFormatAesxts128Guid;
extern EFI_GUID gEfiKmsFormatAesxts256Guid;
extern EFI_GUID gEfiKmsFormatAescbc128Guid;
extern EFI_GUID gEfiKmsFormatAescbc256Guid;
extern EFI_GUID gEfiKmsFormatRsasha11024Guid;
extern EFI_GUID gEfiKmsFormatRsasha12048Guid;
extern EFI_GUID gEfiKmsFormatRsasha2562048Guid;
extern EFI_GUID gEfiKmsFormatRsasha2563072Guid;
extern EFI_GUID gEfiKmsProtocolGuid;

#endif