forked from OpenKMIP/libkmip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkmip.c
14662 lines (11981 loc) · 407 KB
/
kmip.c
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
/* Copyright (c) 2018 The Johns Hopkins University/Applied Physics Laboratory
* All Rights Reserved.
*
* This file is dual licensed under the terms of the Apache 2.0 License and
* the BSD 3-Clause License. See the LICENSE file in the root of this
* repository for more information.
*/
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "kmip.h"
#include "kmip_memset.h"
/*
Miscellaneous Utilities
*/
size_t
kmip_strnlen_s(const char *str, size_t strsz)
{
if(str == NULL)
{
return(0);
}
size_t length = 0;
for(const char *i = str; *i != 0; i++)
{
length++;
if(length >= strsz)
{
return(strsz);
}
}
return(length);
}
LinkedListItem *
kmip_linked_list_pop(LinkedList *list)
{
if(list == NULL)
{
return(NULL);
}
LinkedListItem *popped = list->head;
if(popped != NULL)
{
list->head = popped->next;
popped->next = NULL;
popped->prev = NULL;
if(list->head != NULL)
{
list->head->prev = NULL;
}
if(popped == list->tail)
{
list->tail = NULL;
}
if(list->size > 0)
{
list->size -= 1;
}
}
else
{
if(list->size != 0)
{
list->size = 0;
}
}
return(popped);
}
void
kmip_linked_list_push(LinkedList *list, LinkedListItem *item)
{
if(list != NULL && item != NULL)
{
LinkedListItem *head = list->head;
list->head = item;
item->next = head;
item->prev = NULL;
list->size += 1;
if(head != NULL)
{
head->prev = item;
}
if(list->tail == NULL)
{
list->tail = list->head;
}
}
}
void
kmip_linked_list_enqueue(LinkedList *list, LinkedListItem *item)
{
if(list != NULL && item != NULL)
{
LinkedListItem *tail = list->tail;
list->tail = item;
item->next = NULL;
item->prev = tail;
list->size += 1;
if(tail != NULL)
{
tail->next = item;
}
if(list->head == NULL)
{
list->head = list->tail;
}
}
}
/*
Memory Handlers
*/
void *
kmip_calloc(void *state, size_t num, size_t size)
{
(void)state;
return(calloc(num, size));
}
void *
kmip_realloc(void *state, void *ptr, size_t size)
{
(void)state;
return(realloc(ptr, size));
}
void
kmip_free(void *state, void *ptr)
{
(void)state;
free(ptr);
return;
}
/* TODO (ph) Consider replacing this with memcpy_s, ala memset_s. */
void *
kmip_memcpy(void *state, void *destination, const void *source, size_t size)
{
(void)state;
return(memcpy(destination, source, size));
}
/*
Enumeration Utilities
*/
static const char *kmip_attribute_names[26] = {
"Attestation Type",
"BatchErrorContinuation Option",
"BlockCipher Mode",
"Credential Type",
"Cryptographic Algorithm",
"Cryptographic Usage Mask",
"DigitalSignature Algorithm",
"Encoding Option",
"Hashing Algorithm",
"Key Compression Type",
"Key Format Type",
"Key Role Type",
"Key Wrap Type",
"Mask Generator",
"Name Type",
"Object Type",
"Operation",
"Padding Method",
"Protection Storage Mask",
"Result Reason",
"Result Status",
"State",
"Tag", /*?*/
"Type", /*?*/
"Wrapping Method",
"Unknown" /* Catch all for unsupported enumerations */
};
int
kmip_get_enum_string_index(enum tag t)
{
switch(t)
{
case KMIP_TAG_ATTESTATION_TYPE:
return(0);
break;
case KMIP_TAG_BATCH_ERROR_CONTINUATION_OPTION:
return(1);
break;
case KMIP_TAG_BLOCK_CIPHER_MODE:
return(2);
break;
case KMIP_TAG_CREDENTIAL_TYPE:
return(3);
break;
case KMIP_TAG_CRYPTOGRAPHIC_ALGORITHM:
return(4);
break;
case KMIP_TAG_CRYPTOGRAPHIC_USAGE_MASK:
return(5);
break;
case KMIP_TAG_DIGITAL_SIGNATURE_ALGORITHM:
return(6);
break;
case KMIP_TAG_ENCODING_OPTION:
return(7);
break;
case KMIP_TAG_HASHING_ALGORITHM:
return(8);
break;
case KMIP_TAG_KEY_COMPRESSION_TYPE:
return(9);
break;
case KMIP_TAG_KEY_FORMAT_TYPE:
return(10);
break;
case KMIP_TAG_KEY_ROLE_TYPE:
return(11);
break;
case KMIP_TAG_KEY_WRAP_TYPE:
return(12);
break;
case KMIP_TAG_MASK_GENERATOR:
return(13);
break;
case KMIP_TAG_NAME_TYPE:
return(14);
break;
case KMIP_TAG_OBJECT_TYPE:
return(15);
break;
case KMIP_TAG_OPERATION:
return(16);
break;
case KMIP_TAG_PADDING_METHOD:
return(17);
break;
case KMIP_TAG_PROTECTION_STORAGE_MASK:
return(18);
break;
case KMIP_TAG_RESULT_REASON:
return(19);
break;
case KMIP_TAG_RESULT_STATUS:
return(20);
break;
case KMIP_TAG_STATE:
return(21);
break;
case KMIP_TAG_TAG:
return(22);
break;
case KMIP_TAG_TYPE:
return(23);
break;
case KMIP_TAG_WRAPPING_METHOD:
return(24);
break;
default:
return(25);
break;
};
}
int
kmip_check_enum_value(enum kmip_version version, enum tag t, int value)
{
switch(t)
{
case KMIP_TAG_ATTESTATION_TYPE:
switch(value)
{
case KMIP_ATTEST_TPM_QUOTE:
case KMIP_ATTEST_TCG_INTEGRITY_REPORT:
case KMIP_ATTEST_SAML_ASSERTION:
if(version >= KMIP_1_2)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
default:
return(KMIP_ENUM_MISMATCH);
break;
};
break;
case KMIP_TAG_BATCH_ERROR_CONTINUATION_OPTION:
switch(value)
{
case KMIP_BATCH_CONTINUE:
case KMIP_BATCH_STOP:
case KMIP_BATCH_UNDO:
return(KMIP_OK);
break;
default:
return(KMIP_ENUM_MISMATCH);
break;
};
break;
case KMIP_TAG_BLOCK_CIPHER_MODE:
switch(value)
{
case KMIP_BLOCK_CBC:
case KMIP_BLOCK_ECB:
case KMIP_BLOCK_PCBC:
case KMIP_BLOCK_CFB:
case KMIP_BLOCK_OFB:
case KMIP_BLOCK_CTR:
case KMIP_BLOCK_CMAC:
case KMIP_BLOCK_CCM:
case KMIP_BLOCK_GCM:
case KMIP_BLOCK_CBC_MAC:
case KMIP_BLOCK_XTS:
case KMIP_BLOCK_AES_KEY_WRAP_PADDING:
case KMIP_BLOCK_NIST_KEY_WRAP:
case KMIP_BLOCK_X9102_AESKW:
case KMIP_BLOCK_X9102_TDKW:
case KMIP_BLOCK_X9102_AKW1:
case KMIP_BLOCK_X9102_AKW2:
return(KMIP_OK);
break;
case KMIP_BLOCK_AEAD:
if(version >= KMIP_1_4)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
default:
return(KMIP_ENUM_MISMATCH);
break;
};
break;
case KMIP_TAG_CREDENTIAL_TYPE:
switch(value)
{
case KMIP_CRED_USERNAME_AND_PASSWORD:
return(KMIP_OK);
break;
case KMIP_CRED_DEVICE:
if(version >= KMIP_1_1)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
case KMIP_CRED_ATTESTATION:
if(version >= KMIP_1_2)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
/* KMIP 2.0 */
case KMIP_CRED_ONE_TIME_PASSWORD:
case KMIP_CRED_HASHED_PASSWORD:
case KMIP_CRED_TICKET:
if(version >= KMIP_2_0)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
default:
return(KMIP_ENUM_MISMATCH);
break;
};
break;
case KMIP_TAG_CRYPTOGRAPHIC_ALGORITHM:
switch(value)
{
case KMIP_CRYPTOALG_DES:
case KMIP_CRYPTOALG_TRIPLE_DES:
case KMIP_CRYPTOALG_AES:
case KMIP_CRYPTOALG_RSA:
case KMIP_CRYPTOALG_DSA:
case KMIP_CRYPTOALG_ECDSA:
case KMIP_CRYPTOALG_HMAC_SHA1:
case KMIP_CRYPTOALG_HMAC_SHA224:
case KMIP_CRYPTOALG_HMAC_SHA256:
case KMIP_CRYPTOALG_HMAC_SHA384:
case KMIP_CRYPTOALG_HMAC_SHA512:
case KMIP_CRYPTOALG_HMAC_MD5:
case KMIP_CRYPTOALG_DH:
case KMIP_CRYPTOALG_ECDH:
case KMIP_CRYPTOALG_ECMQV:
case KMIP_CRYPTOALG_BLOWFISH:
case KMIP_CRYPTOALG_CAMELLIA:
case KMIP_CRYPTOALG_CAST5:
case KMIP_CRYPTOALG_IDEA:
case KMIP_CRYPTOALG_MARS:
case KMIP_CRYPTOALG_RC2:
case KMIP_CRYPTOALG_RC4:
case KMIP_CRYPTOALG_RC5:
case KMIP_CRYPTOALG_SKIPJACK:
case KMIP_CRYPTOALG_TWOFISH:
return(KMIP_OK);
break;
case KMIP_CRYPTOALG_EC:
if(version >= KMIP_1_2)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
case KMIP_CRYPTOALG_ONE_TIME_PAD:
if(version >= KMIP_1_3)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
case KMIP_CRYPTOALG_CHACHA20:
case KMIP_CRYPTOALG_POLY1305:
case KMIP_CRYPTOALG_CHACHA20_POLY1305:
case KMIP_CRYPTOALG_SHA3_224:
case KMIP_CRYPTOALG_SHA3_256:
case KMIP_CRYPTOALG_SHA3_384:
case KMIP_CRYPTOALG_SHA3_512:
case KMIP_CRYPTOALG_HMAC_SHA3_224:
case KMIP_CRYPTOALG_HMAC_SHA3_256:
case KMIP_CRYPTOALG_HMAC_SHA3_384:
case KMIP_CRYPTOALG_HMAC_SHA3_512:
case KMIP_CRYPTOALG_SHAKE_128:
case KMIP_CRYPTOALG_SHAKE_256:
if(version >= KMIP_1_4)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
/* KMIP 2.0 */
case KMIP_CRYPTOALG_ARIA:
case KMIP_CRYPTOALG_SEED:
case KMIP_CRYPTOALG_SM2:
case KMIP_CRYPTOALG_SM3:
case KMIP_CRYPTOALG_SM4:
case KMIP_CRYPTOALG_GOST_R_34_10_2012:
case KMIP_CRYPTOALG_GOST_R_34_11_2012:
case KMIP_CRYPTOALG_GOST_R_34_13_2015:
case KMIP_CRYPTOALG_GOST_28147_89:
case KMIP_CRYPTOALG_XMSS:
case KMIP_CRYPTOALG_SPHINCS_256:
case KMIP_CRYPTOALG_MCELIECE:
case KMIP_CRYPTOALG_MCELIECE_6960119:
case KMIP_CRYPTOALG_MCELIECE_8192128:
case KMIP_CRYPTOALG_ED25519:
case KMIP_CRYPTOALG_ED448:
if(version >= KMIP_2_0)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
default:
return(KMIP_ENUM_MISMATCH);
break;
};
break;
case KMIP_TAG_CRYPTOGRAPHIC_USAGE_MASK:
switch(value)
{
case KMIP_CRYPTOMASK_SIGN:
case KMIP_CRYPTOMASK_VERIFY:
case KMIP_CRYPTOMASK_ENCRYPT:
case KMIP_CRYPTOMASK_DECRYPT:
case KMIP_CRYPTOMASK_WRAP_KEY:
case KMIP_CRYPTOMASK_UNWRAP_KEY:
case KMIP_CRYPTOMASK_EXPORT:
case KMIP_CRYPTOMASK_MAC_GENERATE:
case KMIP_CRYPTOMASK_MAC_VERIFY:
case KMIP_CRYPTOMASK_DERIVE_KEY:
case KMIP_CRYPTOMASK_CONTENT_COMMITMENT:
case KMIP_CRYPTOMASK_KEY_AGREEMENT:
case KMIP_CRYPTOMASK_CERTIFICATE_SIGN:
case KMIP_CRYPTOMASK_CRL_SIGN:
case KMIP_CRYPTOMASK_GENERATE_CRYPTOGRAM:
case KMIP_CRYPTOMASK_VALIDATE_CRYPTOGRAM:
case KMIP_CRYPTOMASK_TRANSLATE_ENCRYPT:
case KMIP_CRYPTOMASK_TRANSLATE_DECRYPT:
case KMIP_CRYPTOMASK_TRANSLATE_WRAP:
case KMIP_CRYPTOMASK_TRANSLATE_UNWRAP:
return(KMIP_OK);
break;
/* KMIP 2.0 */
case KMIP_CRYPTOMASK_AUTHENTICATE:
case KMIP_CRYPTOMASK_UNRESTRICTED:
case KMIP_CRYPTOMASK_FPE_ENCRYPT:
case KMIP_CRYPTOMASK_FPE_DECRYPT:
if(version >= KMIP_2_0)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
default:
return(KMIP_ENUM_MISMATCH);
break;
};
break;
case KMIP_TAG_DIGITAL_SIGNATURE_ALGORITHM:
switch(value)
{
case KMIP_DIGITAL_MD2_WITH_RSA:
case KMIP_DIGITAL_MD5_WITH_RSA:
case KMIP_DIGITAL_SHA1_WITH_RSA:
case KMIP_DIGITAL_SHA224_WITH_RSA:
case KMIP_DIGITAL_SHA256_WITH_RSA:
case KMIP_DIGITAL_SHA384_WITH_RSA:
case KMIP_DIGITAL_SHA512_WITH_RSA:
case KMIP_DIGITAL_RSASSA_PSS:
case KMIP_DIGITAL_DSA_WITH_SHA1:
case KMIP_DIGITAL_DSA_WITH_SHA224:
case KMIP_DIGITAL_DSA_WITH_SHA256:
case KMIP_DIGITAL_ECDSA_WITH_SHA1:
case KMIP_DIGITAL_ECDSA_WITH_SHA224:
case KMIP_DIGITAL_ECDSA_WITH_SHA256:
case KMIP_DIGITAL_ECDSA_WITH_SHA384:
case KMIP_DIGITAL_ECDSA_WITH_SHA512:
if(version >= KMIP_1_1)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
case KMIP_DIGITAL_SHA3_256_WITH_RSA:
case KMIP_DIGITAL_SHA3_384_WITH_RSA:
case KMIP_DIGITAL_SHA3_512_WITH_RSA:
if(version >= KMIP_1_4)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
default:
return(KMIP_ENUM_MISMATCH);
break;
};
break;
case KMIP_TAG_ENCODING_OPTION:
switch(value)
{
case KMIP_ENCODE_NO_ENCODING:
case KMIP_ENCODE_TTLV_ENCODING:
if(version >= KMIP_1_1)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
default:
return(KMIP_ENUM_MISMATCH);
break;
};
break;
case KMIP_TAG_HASHING_ALGORITHM:
switch(value)
{
case KMIP_HASH_MD2:
case KMIP_HASH_MD4:
case KMIP_HASH_MD5:
case KMIP_HASH_SHA1:
case KMIP_HASH_SHA224:
case KMIP_HASH_SHA256:
case KMIP_HASH_SHA384:
case KMIP_HASH_SHA512:
case KMIP_HASH_RIPEMD160:
case KMIP_HASH_TIGER:
case KMIP_HASH_WHIRLPOOL:
return(KMIP_OK);
break;
case KMIP_HASH_SHA512_224:
case KMIP_HASH_SHA512_256:
if(version >= KMIP_1_2)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
case KMIP_HASH_SHA3_224:
case KMIP_HASH_SHA3_256:
case KMIP_HASH_SHA3_384:
case KMIP_HASH_SHA3_512:
if(version >= KMIP_1_4)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
default:
return(KMIP_ENUM_MISMATCH);
break;
};
break;
case KMIP_TAG_KEY_COMPRESSION_TYPE:
switch(value)
{
case KMIP_KEYCOMP_EC_PUB_UNCOMPRESSED:
case KMIP_KEYCOMP_EC_PUB_X962_COMPRESSED_PRIME:
case KMIP_KEYCOMP_EC_PUB_X962_COMPRESSED_CHAR2:
case KMIP_KEYCOMP_EC_PUB_X962_HYBRID:
return(KMIP_OK);
break;
default:
return(KMIP_ENUM_MISMATCH);
break;
};
break;
case KMIP_TAG_KEY_FORMAT_TYPE:
switch(value)
{
case KMIP_KEYFORMAT_RAW:
case KMIP_KEYFORMAT_OPAQUE:
case KMIP_KEYFORMAT_PKCS1:
case KMIP_KEYFORMAT_PKCS8:
case KMIP_KEYFORMAT_X509:
case KMIP_KEYFORMAT_EC_PRIVATE_KEY:
case KMIP_KEYFORMAT_TRANS_SYMMETRIC_KEY:
case KMIP_KEYFORMAT_TRANS_DSA_PRIVATE_KEY:
case KMIP_KEYFORMAT_TRANS_DSA_PUBLIC_KEY:
case KMIP_KEYFORMAT_TRANS_RSA_PRIVATE_KEY:
case KMIP_KEYFORMAT_TRANS_RSA_PUBLIC_KEY:
case KMIP_KEYFORMAT_TRANS_DH_PRIVATE_KEY:
case KMIP_KEYFORMAT_TRANS_DH_PUBLIC_KEY:
return(KMIP_OK);
break;
/* The following set is deprecated as of KMIP 1.3 */
case KMIP_KEYFORMAT_TRANS_ECDSA_PRIVATE_KEY:
case KMIP_KEYFORMAT_TRANS_ECDSA_PUBLIC_KEY:
case KMIP_KEYFORMAT_TRANS_ECDH_PRIVATE_KEY:
case KMIP_KEYFORMAT_TRANS_ECDH_PUBLIC_KEY:
case KMIP_KEYFORMAT_TRANS_ECMQV_PRIVATE_KEY:
case KMIP_KEYFORMAT_TRANS_ECMQV_PUBLIC_KEY:
/* TODO (ph) What should happen if version >= 1.3? */
return(KMIP_OK);
break;
case KMIP_KEYFORMAT_TRANS_EC_PRIVATE_KEY:
case KMIP_KEYFORMAT_TRANS_EC_PUBLIC_KEY:
if(version >= KMIP_1_3)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
case KMIP_KEYFORMAT_PKCS12:
if(version >= KMIP_1_4)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
/* KMIP 2.0 */
case KMIP_KEYFORMAT_PKCS10:
if(version >= KMIP_2_0)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
default:
return(KMIP_ENUM_MISMATCH);
break;
};
break;
case KMIP_TAG_KEY_ROLE_TYPE:
switch(value)
{
/* KMIP 1.0 */
case KMIP_ROLE_BDK:
case KMIP_ROLE_CVK:
case KMIP_ROLE_DEK:
case KMIP_ROLE_MKAC:
case KMIP_ROLE_MKSMC:
case KMIP_ROLE_MKSMI:
case KMIP_ROLE_MKDAC:
case KMIP_ROLE_MKDN:
case KMIP_ROLE_MKCP:
case KMIP_ROLE_MKOTH:
case KMIP_ROLE_KEK:
case KMIP_ROLE_MAC16609:
case KMIP_ROLE_MAC97971:
case KMIP_ROLE_MAC97972:
case KMIP_ROLE_MAC97973:
case KMIP_ROLE_MAC97974:
case KMIP_ROLE_MAC97975:
case KMIP_ROLE_ZPK:
case KMIP_ROLE_PVKIBM:
case KMIP_ROLE_PVKPVV:
case KMIP_ROLE_PVKOTH:
return(KMIP_OK);
break;
/* KMIP 1.4 */
case KMIP_ROLE_DUKPT:
case KMIP_ROLE_IV:
case KMIP_ROLE_TRKBK:
if(version >= KMIP_1_4)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
default:
return(KMIP_ENUM_MISMATCH);
break;
};
break;
case KMIP_TAG_KEY_WRAP_TYPE:
switch(value)
{
/* KMIP 1.4 */
case KMIP_WRAPTYPE_NOT_WRAPPED:
case KMIP_WRAPTYPE_AS_REGISTERED:
if(version >= KMIP_1_4)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
default:
return(KMIP_ENUM_MISMATCH);
break;
};
break;
case KMIP_TAG_MASK_GENERATOR:
switch(value)
{
/* KMIP 1.4 */
case KMIP_MASKGEN_MGF1:
if(version >= KMIP_1_4)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
default:
return(KMIP_ENUM_MISMATCH);
break;
};
break;
case KMIP_TAG_NAME_TYPE:
switch(value)
{
/* KMIP 1.0 */
case KMIP_NAME_UNINTERPRETED_TEXT_STRING:
case KMIP_NAME_URI:
return(KMIP_OK);
break;
default:
return(KMIP_ENUM_MISMATCH);
break;
};
break;
case KMIP_TAG_OBJECT_TYPE:
switch(value)
{
/* KMIP 1.0 */
case KMIP_OBJTYPE_CERTIFICATE:
case KMIP_OBJTYPE_SYMMETRIC_KEY:
case KMIP_OBJTYPE_PUBLIC_KEY:
case KMIP_OBJTYPE_PRIVATE_KEY:
case KMIP_OBJTYPE_SPLIT_KEY:
case KMIP_OBJTYPE_SECRET_DATA:
case KMIP_OBJTYPE_OPAQUE_OBJECT:
return(KMIP_OK);
break;
/* The following set is deprecated as of KMIP 1.3 */
case KMIP_OBJTYPE_TEMPLATE:
/* TODO (ph) What should happen if version >= 1.3? */
return(KMIP_OK);
break;
/* KMIP 1.2 */
case KMIP_OBJTYPE_PGP_KEY:
if(version >= KMIP_1_2)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
/* KMIP 2.0 */
case KMIP_OBJTYPE_CERTIFICATE_REQUEST:
if(version >= KMIP_2_0)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
default:
return(KMIP_ENUM_MISMATCH);
break;
};
break;
case KMIP_TAG_OPERATION:
switch(value)
{
/* KMIP 1.0 */
case KMIP_OP_CREATE:
case KMIP_OP_GET:
case KMIP_OP_DESTROY:
case KMIP_OP_QUERY:
return(KMIP_OK);
break;
default:
return(KMIP_ENUM_MISMATCH);
break;
};
break;
case KMIP_TAG_PADDING_METHOD:
switch(value)
{
/* KMIP 1.0 */
case KMIP_PAD_NONE:
case KMIP_PAD_OAEP:
case KMIP_PAD_PKCS5:
case KMIP_PAD_SSL3:
case KMIP_PAD_ZEROS:
case KMIP_PAD_ANSI_X923:
case KMIP_PAD_ISO_10126:
case KMIP_PAD_PKCS1v15:
case KMIP_PAD_X931:
case KMIP_PAD_PSS:
return(KMIP_OK);
break;
default:
return(KMIP_ENUM_MISMATCH);
break;
};
break;
case KMIP_TAG_PROTECTION_STORAGE_MASK:
{
switch(value)
{
/* KMIP 2.0 */
case KMIP_PROTECT_SOFTWARE:
case KMIP_PROTECT_HARDWARE:
case KMIP_PROTECT_ON_PROCESSOR:
case KMIP_PROTECT_ON_SYSTEM:
case KMIP_PROTECT_OFF_SYSTEM:
case KMIP_PROTECT_HYPERVISOR:
case KMIP_PROTECT_OPERATING_SYSTEM:
case KMIP_PROTECT_CONTAINER:
case KMIP_PROTECT_ON_PREMISES:
case KMIP_PROTECT_OFF_PREMISES:
case KMIP_PROTECT_SELF_MANAGED:
case KMIP_PROTECT_OUTSOURCED:
case KMIP_PROTECT_VALIDATED:
case KMIP_PROTECT_SAME_JURISDICTION:
if(version >= KMIP_2_0)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
default:
return(KMIP_ENUM_MISMATCH);
break;
};
};
break;
case KMIP_TAG_RESULT_REASON:
switch(value)
{
/* KMIP 1.0 */
case KMIP_REASON_GENERAL_FAILURE:
case KMIP_REASON_ITEM_NOT_FOUND:
case KMIP_REASON_RESPONSE_TOO_LARGE:
case KMIP_REASON_AUTHENTICATION_NOT_SUCCESSFUL:
case KMIP_REASON_INVALID_MESSAGE:
case KMIP_REASON_OPERATION_NOT_SUPPORTED:
case KMIP_REASON_MISSING_DATA:
case KMIP_REASON_INVALID_FIELD:
case KMIP_REASON_FEATURE_NOT_SUPPORTED:
case KMIP_REASON_OPERATION_CANCELED_BY_REQUESTER:
case KMIP_REASON_CRYPTOGRAPHIC_FAILURE:
case KMIP_REASON_ILLEGAL_OPERATION:
case KMIP_REASON_PERMISSION_DENIED:
case KMIP_REASON_OBJECT_ARCHIVED:
case KMIP_REASON_INDEX_OUT_OF_BOUNDS:
case KMIP_REASON_APPLICATION_NAMESPACE_NOT_SUPPORTED:
case KMIP_REASON_KEY_FORMAT_TYPE_NOT_SUPPORTED:
case KMIP_REASON_KEY_COMPRESSION_TYPE_NOT_SUPPORTED:
return(KMIP_OK);
break;
/* KMIP 1.1 */
case KMIP_REASON_ENCODING_OPTION_FAILURE:
if(version >= KMIP_1_1)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
/* KMIP 1.2 */
case KMIP_REASON_KEY_VALUE_NOT_PRESENT:
case KMIP_REASON_ATTESTATION_REQUIRED:
case KMIP_REASON_ATTESTATION_FAILED:
if(version >= KMIP_1_2)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
/* KMIP 1.4 */
case KMIP_REASON_SENSITIVE:
case KMIP_REASON_NOT_EXTRACTABLE:
case KMIP_REASON_OBJECT_ALREADY_EXISTS:
if(version >= KMIP_1_4)
return(KMIP_OK);
else
return(KMIP_INVALID_FOR_VERSION);
break;
/* KMIP 2.0 */
case KMIP_REASON_INVALID_TICKET:
case KMIP_REASON_USAGE_LIMIT_EXCEEDED:
case KMIP_REASON_NUMERIC_RANGE:
case KMIP_REASON_INVALID_DATA_TYPE:
case KMIP_REASON_READ_ONLY_ATTRIBUTE:
case KMIP_REASON_MULTI_VALUED_ATTRIBUTE:
case KMIP_REASON_UNSUPPORTED_ATTRIBUTE:
case KMIP_REASON_ATTRIBUTE_INSTANCE_NOT_FOUND:
case KMIP_REASON_ATTRIBUTE_NOT_FOUND:
case KMIP_REASON_ATTRIBUTE_READ_ONLY: