{{ message }}
Repository navigation
Expand file tree
/
Copy pathcryptkrn.h
More file actions
1700 lines (1453 loc) · 75.3 KB
/
Copy pathcryptkrn.h
File metadata and controls
1700 lines (1453 loc) · 75.3 KB
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
/****************************************************************************
* *
* cryptlib Kernel Interface Header File *
* Copyright Peter Gutmann 1992-2024 *
* *
****************************************************************************/
#ifndef _CRYPTKRN_DEFINED
#define _CRYPTKRN_DEFINED
/* Macros to handle code correctness checking of critical sections of the
code such as the kernel and CSPRNG (sed quis custodiet ipsos custodes?),
extending the design-by-contract macros in misc/int_api.h */
/* Value of a variable at the start of block scope, used for postcondition
predicates. The pointer is declared as BYTE * rather than the more
general void * in order to allow range comparisons, and a BYTE * rather
than char * because of compilers that complain about comparisons between
signed and unsigned pointer types. Note that these declarations must be
the last in any set of variable declarations since some of the higher-
overhead checks are only applied in the debug build and the release build
expands them to nothing, leaving only the terminating semicolon on the
line, which must follow all other declarations */
#ifndef CONFIG_CONSERVE_MEMORY_EXTRA
#define ORIGINAL_VALUE( x ) orig_##x
#define ORIGINAL_INT( x ) const int orig_##x = ( int ) x
#define ORIGINAL_PTR( x ) const BYTE *orig_##x = ( const BYTE * ) x
#else
#define ORIGINAL_VALUE( x )
#define ORIGINAL_INT( x )
#define ORIGINAL_PTR( x )
#endif /* !CONFIG_CONSERVE_MEMORY_EXTRA */
/* Sometimes we can't use the preprocessor tricks above because the value
being saved isn't a primitive type or the variable value isn't available
at the start of the block, in which case we have to use the somewhat less
transparent macros below.
In a small number of cases the values declared by these macros are only
used in debug builds, leading to unused-variable warnings in release
builds. This is infrequent enough that there's not much point in adding
even further special-casing for them */
#ifndef CONFIG_CONSERVE_MEMORY_EXTRA
#define ORIGINAL_INT_VAR( x, y ) const int orig_##x = ( y )
#define DECLARE_ORIGINAL_INT( x ) int orig_##x
#define STORE_ORIGINAL_INT( x, y ) orig_##x = ( y )
#else
#define ORIGINAL_INT_VAR( x, y )
#define DECLARE_ORIGINAL_INT( x )
#define STORE_ORIGINAL_INT( x, y )
#endif /* !CONFIG_CONSERVE_MEMORY_EXTRA */
/* Some checks have a relatively high overhead (for example for_all and
there_exists on arrays) so we only perform them in the debug build */
#if !( defined( NDEBUG ) || defined( CONFIG_CONSERVE_MEMORY_EXTRA ) )
/* Universal qualifiers: for_all, there_exists. Because of the typical use
of 'i' as loop variables we'll get compiler warnings about duplicate
variable declarations, unfortunately we can't fix this with something
like '_local_##iter' because the loop test condition is a free-form
expression and there's no easy way to create a localised form of all
references to the loop variable inside the expression */
#define FORALL( iter, start, end, condition ) \
{ \
int iter; \
\
for( iter = ( start ); iter < ( end ); iter++ ) \
assert( condition ); \
}
#define EXISTS( iter, start, end, condition ) \
{ \
int iter; \
\
for( iter = ( start ); iter < ( end ); iter++ ) \
{ \
if( condition ) \
break; \
} \
assert( iter < ( end ) ); \
}
#else
/* Non-debug version, no-op out the various checks */
#define FORALL( a, b, c, d )
#define EXISTS( a, b, c, d )
#endif /* !( NDEBUG || CONFIG_CONSERVE_MEMORY_EXTRA ) */
/****************************************************************************
* *
* Object Message Types *
* *
****************************************************************************/
/* The object types */
typedef enum {
OBJECT_TYPE_NONE, /* No object type */
OBJECT_TYPE_CONTEXT, /* Context */
OBJECT_TYPE_KEYSET, /* Keyset */
OBJECT_TYPE_ENVELOPE, /* Envelope */
OBJECT_TYPE_CERTIFICATE, /* Certificate */
OBJECT_TYPE_DEVICE, /* Crypto device */
OBJECT_TYPE_SESSION, /* Secure session */
OBJECT_TYPE_USER, /* User object */
OBJECT_TYPE_LAST /* Last possible object type */
} OBJECT_TYPE;
/* Object subtypes. The subtype names aren't needed by the kernel (it just
treats the values as an anonymous bitfield during an ACL check) but they
are used in the ACL definitions and by the code that calls
krnlCreateObject(), so they need to be defined here.
Because there are so many object subtypes we have to split them across
two 32-bit bitfields in order to permit a simple bitwise AND check, if we
ordered them by the more obvious major and minor type (that is, object
type and subtype) this wouldn't be necessary but it would increase the
size of the compiled ACL table (from 2 * 32 bits to NO_OBJECT_TYPES *
32 bits) and would make automated consistency checking difficult since
it's no longer possible to spot a case where a subtype bit for object A
has inadvertently been set for object B.
To resolve this, we divide the subtype bit field into smaller bit fields
(classes) with the high two bits designating which class the subtype is
in (actually we use the bits one below the high bit since this may be
interpreted as a sign bit by some preprocessors even if it's declared as
a xxxxUL, so in the following discussion we're talking about logical
rather than physical high bits). Class A is always 001xxx..., class B is
always 010xxx..., class C is always 100xxx.... This isn't pretty, but
it's the least ugly way to do it that still allows the ACL table to be
built using the preprocessor. Note that this also means that the
highest subtype that we can have is 28, which results in a value of
1 << ( 28 - 1 ). Anything higher than that would shift the bit into
the class bits.
Note that the device and keyset values must be in the same class, since
they're interchangeable for many message types and this simplifies some
of the MKACL() macros that only need to initialise one class type.
The different between SUBTYPE_KEYSET_FILE, SUBTYPE_KEYSET_FILE_PARTIAL,
and SUBTYPE_KEYSET_FILE_READONLY is that SUBTYPE_KEYSET_FILE stores a
full index of key ID types and allows storage of any data type,
SUBTYPE_KEYSET_FILE_PARTIAL only handles one or two key IDs and a
restricted set of data types so that only a single private key and
associated public key and certificate can be stored, and
SUBTYPE_KEYSET_FILE_READONLY is even more restricted and can't be
updated in any sensible manner.
The difference between SUBTYPE_KEYSET_DBMS and SUBTYPE_KEYSET_DBMS_STORE
is similar, the former is a simple certificate-and-CRL store while the
latter stores assorted CA management data items and supports extended
operations */
#define SUBTYPE_CLASS_MASK 0x70000000L
#define SUBTYPE_CLASS_A 0x10000000L
#define SUBTYPE_CLASS_B 0x20000000L
#define SUBTYPE_CLASS_C 0x40000000L
#define MK_SUBTYPE_A( value ) ( SUBTYPE_CLASS_A | ( 1L << ( ( value ) - 1 ) ) )
#define MK_SUBTYPE_B( value ) ( SUBTYPE_CLASS_B | ( 1L << ( ( value ) - 1 ) ) )
#define MK_SUBTYPE_C( value ) ( SUBTYPE_CLASS_C | ( 1L << ( ( value ) - 1 ) ) )
#define SUBTYPE_NONE 0x00000000L
#define SUBTYPE_CTX_CONV MK_SUBTYPE_A( 1 )
#define SUBTYPE_CTX_PKC MK_SUBTYPE_A( 2 )
#define SUBTYPE_CTX_HASH MK_SUBTYPE_A( 3 )
#define SUBTYPE_CTX_MAC MK_SUBTYPE_A( 4 )
#define SUBTYPE_CTX_GENERIC MK_SUBTYPE_A( 5 )
#define SUBTYPE_CERT_CERT MK_SUBTYPE_A( 6 )
#define SUBTYPE_CERT_CERTREQ MK_SUBTYPE_A( 7 )
#define SUBTYPE_CERT_REQ_CERT MK_SUBTYPE_A( 8 )
#define SUBTYPE_CERT_REQ_REV MK_SUBTYPE_A( 9 )
#define SUBTYPE_CERT_CERTCHAIN MK_SUBTYPE_A( 10 )
#define SUBTYPE_CERT_ATTRCERT MK_SUBTYPE_A( 11 )
#define SUBTYPE_CERT_CRL MK_SUBTYPE_A( 12 )
#define SUBTYPE_CERT_CMSATTR MK_SUBTYPE_A( 13 )
#define SUBTYPE_CERT_RTCS_REQ MK_SUBTYPE_A( 14 )
#define SUBTYPE_CERT_RTCS_RESP MK_SUBTYPE_A( 15 )
#define SUBTYPE_CERT_OCSP_REQ MK_SUBTYPE_A( 16 )
#define SUBTYPE_CERT_OCSP_RESP MK_SUBTYPE_A( 17 )
#define SUBTYPE_CERT_PKIUSER MK_SUBTYPE_A( 18 )
#define SUBTYPE_ENV_ENV MK_SUBTYPE_B( 1 )
#define SUBTYPE_ENV_ENV_PGP MK_SUBTYPE_B( 2 )
#define SUBTYPE_ENV_DEENV MK_SUBTYPE_B( 3 )
#define SUBTYPE_KEYSET_FILE MK_SUBTYPE_B( 4 )
#define SUBTYPE_KEYSET_FILE_PARTIAL MK_SUBTYPE_B( 5 )
#define SUBTYPE_KEYSET_FILE_READONLY MK_SUBTYPE_B( 6 )
#define SUBTYPE_KEYSET_DBMS MK_SUBTYPE_B( 7 )
#define SUBTYPE_KEYSET_DBMS_STORE MK_SUBTYPE_B( 8 )
#define SUBTYPE_KEYSET_HTTP MK_SUBTYPE_B( 9 )
#define SUBTYPE_KEYSET_LDAP MK_SUBTYPE_B( 10 )
#define SUBTYPE_DEV_SYSTEM MK_SUBTYPE_B( 11 )
#define SUBTYPE_DEV_PKCS11 MK_SUBTYPE_B( 12 )
#define SUBTYPE_DEV_CRYPTOAPI MK_SUBTYPE_B( 13 )
#define SUBTYPE_DEV_TPM MK_SUBTYPE_B( 14 )
#define SUBTYPE_DEV_HARDWARE MK_SUBTYPE_B( 15 )
#define SUBTYPE_SESSION_SSH MK_SUBTYPE_C( 1 )
#define SUBTYPE_SESSION_SSH_SVR MK_SUBTYPE_C( 2 )
#define SUBTYPE_SESSION_TLS MK_SUBTYPE_C( 3 )
#define SUBTYPE_SESSION_TLS_SVR MK_SUBTYPE_C( 4 )
#define SUBTYPE_SESSION_RTCS MK_SUBTYPE_C( 5 )
#define SUBTYPE_SESSION_RTCS_SVR MK_SUBTYPE_C( 6 )
#define SUBTYPE_SESSION_SCVP MK_SUBTYPE_C( 7 )
#define SUBTYPE_SESSION_SCVP_SVR MK_SUBTYPE_C( 8 )
#define SUBTYPE_SESSION_OCSP MK_SUBTYPE_C( 9 )
#define SUBTYPE_SESSION_OCSP_SVR MK_SUBTYPE_C( 10 )
#define SUBTYPE_SESSION_TSP MK_SUBTYPE_C( 11 )
#define SUBTYPE_SESSION_TSP_SVR MK_SUBTYPE_C( 12 )
#define SUBTYPE_SESSION_CMP MK_SUBTYPE_C( 13 )
#define SUBTYPE_SESSION_CMP_SVR MK_SUBTYPE_C( 14 )
#define SUBTYPE_SESSION_SCEP MK_SUBTYPE_C( 15 )
#define SUBTYPE_SESSION_SCEP_SVR MK_SUBTYPE_C( 16 )
#define SUBTYPE_SESSION_CERT_SVR MK_SUBTYPE_C( 17 )
#define SUBTYPE_USER_SO MK_SUBTYPE_C( 18 )
#define SUBTYPE_USER_NORMAL MK_SUBTYPE_C( 19 )
#define SUBTYPE_USER_CA MK_SUBTYPE_C( 20 )
#define SUBTYPE_LAST SUBTYPE_USER_CA
/* The data type used to store subtype values */
typedef int OBJECT_SUBTYPE;
/* Message flags. Normally messages can only be sent to external objects,
however we can also explicitly send them to internal objects which means
that we use the internal rather than external access ACL. This can only
be done from inside cryptlib, for example when an object sends a message
to a subordinate object */
#define MESSAGE_FLAG_INTERNAL 0x100
#define MKINTERNAL( message ) ( ( message ) | MESSAGE_FLAG_INTERNAL )
/* A mask to extract the basic message type */
#define MESSAGE_MASK 0xFF
/* The message types that can be sent to an object via krnlSendMessage()
(although one or two are generated internally by the kernel in response
to other messages, for example MESSAGE_CHANGENOTIFY). By default messages
can only be sent to externally visible objects, there are also internal
versions that can be sent to all objects. The object messages have the
following arguments:
Type DataPtr Value
--------------------------- ------- -----
MESSAGE_DESTROY NULL 0
MESSAGE_INC/DECREFCOUNT NULL 0
MESSAGE_GETDEPENDENT &objectHandle objectType
MESSAGE_SETDEPENDENT &objectHandle setDepType
MESSAGE_CLEARDEPENDENT NULL 0
MESSAGE_CLONE NULL cloneContext
MESSAGE_GET/SETATTRIBUTE &value attributeType
MESSAGE_DELETEATTRIBUTE NULL attributeType
MESSAGE_COMPARE &value compareType
MESSAGE_CHECK NULL requestedUse
MESSAGE_SELFTEST NULL 0
MESSAGE_CHANGENOTIFY NULL 0
MESSAGE_CTX_ENCRYPT/DECRYPT/SIGN/-
SIGCHECK/SIGN_MSG/
SIGCHECK_MSG/HASH &value valueLength
MESSAGE_CTX_GENKEY NULL 0
MESSAGE_CTX_GENIV NULL 0
MESSAGE_CRT_SIGN, NULL sigKey
MESSAGE_CRT_SIGCHECK, NULL verifyObject
MESSAGE_CRT_EXPORT, &value formatType
MESSAGE_DEV_QUERYCAPABILITY &queryInfo algorithm
MESSAGE_DEV_CATALOGQUERY &catalogInfo queryType
MESSAGE_DEV_EXPORT/IMPORT/SIGN/-
SIGCHECK/DERIVE/KDF &mechanismInfo mechanismType
MESSAGE_DEV_CREATEOBJECT &createInfo objectType
MESSAGE_DEV_CREATEOBJECT_INDIRECT &createInfo objectType
MESSAGE_ENV_PUSH/POPDATA &value 0
MESSAGE_KEY_GET/SET/DELETEKEY &keymgmtInfo itemType
MESSAGE_KEY_GETFIRST/NEXTCERT &keymgmtInfo itemType
MESSAGE_KEY_CERTMGMT &certMgmtInfo action
MESSAGE_USER_USERMGMT &value action
MESSAGE_USER_TRUSTMGMT &value action */
typedef enum {
MESSAGE_NONE, /* No message type */
/* Control messages to externally visible objects (the internal versions
are defined further down). These messages are handled directly by
the kernel and don't affect the object itself except for
MESSAGE_DESTROY which is generated by the kernel in response to the
final MESSAGE_DECREFCOUNT sent to an object. These are forwarded out
to the object to get it to clean up its state before the kernel
destroys it */
MESSAGE_DESTROY, /* Destroy the object */
MESSAGE_INCREFCOUNT, /* Increment object ref.count */
MESSAGE_DECREFCOUNT, /* Decrement object ref.count */
MESSAGE_GETDEPENDENT, /* Get dependent object */
MESSAGE_SETDEPENDENT, /* Set dependent object (e.g.ctx->dev) */
MESSAGE_CLEARDEPENDENT, /* Clear dependent object (e.g.ctx->cert) */
MESSAGE_CLONE, /* Clone the object */
/* Attribute messages. The reason for the numeric vs.non-numeric
attribute messages is that for improved error checking the data types
that these work with are explicitly specified by the user based on
which function they call to get/set them rather than being implicitly
specified by the attribute ID. Because of the explicit typing, the
handlers have to be able to check to make sure that the actual type
matches what the user specified, so we need one message type for
numeric attributes and one for string attributes */
MESSAGE_GETATTRIBUTE, /* Get numeric object attribute */
MESSAGE_GETATTRIBUTE_S, /* Get string object attribute */
MESSAGE_SETATTRIBUTE, /* Set numeric object attribute */
MESSAGE_SETATTRIBUTE_S, /* Set string object attribute */
MESSAGE_DELETEATTRIBUTE, /* Delete object attribute */
/* General messages. The check message is used for informational
purposes only so that problems (e.g. an attempt to use a public key
where a private key is required) can be reported to the user
immediately as a function parameter error rather than appearing much
later as an object use permission error when the kernel blocks the
access. Final access checking is always still done at the kernel
level to avoid the confused deputy problem */
MESSAGE_COMPARE, /* Compare objs. or obj.properties */
MESSAGE_CHECK, /* Check object info */
MESSAGE_SELFTEST, /* Perform a self-test */
/* Messages sent from the kernel to object message handlers. These never
originate from outside the kernel but are generated in response to
other messages to notify an object of a change in its state */
MESSAGE_CHANGENOTIFY, /* Notification of obj.status chge.*/
/* Object-type-specific messages. The reason why there's a SIGN_MSG
alongside the SIGN is to deal with special-snowflake algorithms
designed to not allow signing a hash value, or at least that in
theory allow it but that were cargo-culted in a form that doesn't
allow it */
MESSAGE_CTX_ENCRYPT, /* Context: Action = encrypt */
MESSAGE_CTX_DECRYPT, /* Context: Action = decrypt */
MESSAGE_CTX_SIGN, /* Context: Action = sign */
MESSAGE_CTX_SIGCHECK, /* Context: Action = sigcheck */
MESSAGE_CTX_SIGN_MSG, /* Context: Action = sign message */
MESSAGE_CTX_SIGCHECK_MSG, /* Context: Action = sigcheck message */
MESSAGE_CTX_HASH, /* Context: Action = hash */
MESSAGE_CTX_GENKEY, /* Context: Generate a key */
MESSAGE_CTX_GENIV, /* Context: Generate an IV */
MESSAGE_CRT_SIGN, /* Cert: Action = sign cert */
MESSAGE_CRT_SIGCHECK, /* Cert: Action = check/verify cert */
MESSAGE_CRT_EXPORT, /* Cert: Export encoded cert data */
MESSAGE_DEV_QUERYCAPABILITY,/* Device: Query capability */
MESSAGE_DEV_CATALOGQUERY, /* Device: Catalog query */
MESSAGE_DEV_EXPORT, /* Device: Action = export key */
MESSAGE_DEV_IMPORT, /* Device: Action = import key */
MESSAGE_DEV_SIGN, /* Device: Action = sign */
MESSAGE_DEV_SIGCHECK, /* Device: Action = sig.check */
MESSAGE_DEV_DERIVE, /* Device: Action = derive key */
MESSAGE_DEV_KDF, /* Device: Action = KDF */
MESSAGE_DEV_CREATEOBJECT, /* Device: Create object */
MESSAGE_DEV_CREATEOBJECT_INDIRECT, /* Device: Create obj.from data */
MESSAGE_ENV_PUSHDATA, /* Envelope: Push data */
MESSAGE_ENV_POPDATA, /* Envelope: Pop data */
MESSAGE_KEY_GETKEY, /* Keyset: Instantiate ctx/cert */
MESSAGE_KEY_SETKEY, /* Keyset: Add ctx/cert */
MESSAGE_KEY_DELETEKEY, /* Keyset: Delete key/cert */
MESSAGE_KEY_GETFIRSTCERT, /* Keyset: Get first cert in sequence */
MESSAGE_KEY_GETNEXTCERT, /* Keyset: Get next cert in sequence */
MESSAGE_KEY_CERTMGMT, /* Keyset: Cert management */
MESSAGE_USER_USERMGMT, /* User: User management */
MESSAGE_USER_TRUSTMGMT, /* User: Trust management */
MESSAGE_LAST, /* Last valid message type */
/* Internal-object versions of the above messages */
IMESSAGE_DESTROY = MKINTERNAL( MESSAGE_DESTROY ),
IMESSAGE_INCREFCOUNT = MKINTERNAL( MESSAGE_INCREFCOUNT ),
IMESSAGE_DECREFCOUNT = MKINTERNAL( MESSAGE_DECREFCOUNT ),
IMESSAGE_GETDEPENDENT = MKINTERNAL( MESSAGE_GETDEPENDENT ),
IMESSAGE_SETDEPENDENT = MKINTERNAL( MESSAGE_SETDEPENDENT ),
IMESSAGE_CLEARDEPENDENT = MKINTERNAL( MESSAGE_CLEARDEPENDENT ),
IMESSAGE_CLONE = MKINTERNAL( MESSAGE_CLONE ),
IMESSAGE_GETATTRIBUTE = MKINTERNAL( MESSAGE_GETATTRIBUTE ),
IMESSAGE_GETATTRIBUTE_S = MKINTERNAL( MESSAGE_GETATTRIBUTE_S ),
IMESSAGE_SETATTRIBUTE = MKINTERNAL( MESSAGE_SETATTRIBUTE ),
IMESSAGE_SETATTRIBUTE_S = MKINTERNAL( MESSAGE_SETATTRIBUTE_S ),
IMESSAGE_DELETEATTRIBUTE = MKINTERNAL( MESSAGE_DELETEATTRIBUTE ),
IMESSAGE_COMPARE = MKINTERNAL( MESSAGE_COMPARE ),
IMESSAGE_CHECK = MKINTERNAL( MESSAGE_CHECK ),
IMESSAGE_SELFTEST = MKINTERNAL( MESSAGE_SELFTEST ),
IMESSAGE_CHANGENOTIFY = MKINTERNAL( MESSAGE_CHANGENOTIFY ),
IMESSAGE_CTX_ENCRYPT = MKINTERNAL( MESSAGE_CTX_ENCRYPT ),
IMESSAGE_CTX_DECRYPT = MKINTERNAL( MESSAGE_CTX_DECRYPT ),
IMESSAGE_CTX_SIGN = MKINTERNAL( MESSAGE_CTX_SIGN ),
IMESSAGE_CTX_SIGCHECK = MKINTERNAL( MESSAGE_CTX_SIGCHECK ),
IMESSAGE_CTX_SIGN_MSG = MKINTERNAL( MESSAGE_CTX_SIGN_MSG ),
IMESSAGE_CTX_SIGCHECK_MSG = MKINTERNAL( MESSAGE_CTX_SIGCHECK_MSG ),
IMESSAGE_CTX_HASH = MKINTERNAL( MESSAGE_CTX_HASH ),
IMESSAGE_CTX_GENKEY = MKINTERNAL( MESSAGE_CTX_GENKEY ),
IMESSAGE_CTX_GENIV = MKINTERNAL( MESSAGE_CTX_GENIV ),
IMESSAGE_CRT_SIGN = MKINTERNAL( MESSAGE_CRT_SIGN ),
IMESSAGE_CRT_SIGCHECK = MKINTERNAL( MESSAGE_CRT_SIGCHECK ),
IMESSAGE_CRT_EXPORT = MKINTERNAL( MESSAGE_CRT_EXPORT ),
IMESSAGE_DEV_QUERYCAPABILITY = MKINTERNAL( MESSAGE_DEV_QUERYCAPABILITY ),
IMESSAGE_DEV_CATALOGQUERY = MKINTERNAL( MESSAGE_DEV_CATALOGQUERY ),
IMESSAGE_DEV_EXPORT = MKINTERNAL( MESSAGE_DEV_EXPORT ),
IMESSAGE_DEV_IMPORT = MKINTERNAL( MESSAGE_DEV_IMPORT ),
IMESSAGE_DEV_SIGN = MKINTERNAL( MESSAGE_DEV_SIGN ),
IMESSAGE_DEV_SIGCHECK = MKINTERNAL( MESSAGE_DEV_SIGCHECK ),
IMESSAGE_DEV_DERIVE = MKINTERNAL( MESSAGE_DEV_DERIVE ),
IMESSAGE_DEV_KDF = MKINTERNAL( MESSAGE_DEV_KDF ),
IMESSAGE_DEV_CREATEOBJECT = MKINTERNAL( MESSAGE_DEV_CREATEOBJECT ),
IMESSAGE_DEV_CREATEOBJECT_INDIRECT = MKINTERNAL( MESSAGE_DEV_CREATEOBJECT_INDIRECT ),
IMESSAGE_ENV_PUSHDATA = MKINTERNAL( MESSAGE_ENV_PUSHDATA ),
IMESSAGE_ENV_POPDATA = MKINTERNAL( MESSAGE_ENV_POPDATA ),
IMESSAGE_KEY_GETKEY = MKINTERNAL( MESSAGE_KEY_GETKEY ),
IMESSAGE_KEY_SETKEY = MKINTERNAL( MESSAGE_KEY_SETKEY ),
IMESSAGE_KEY_DELETEKEY = MKINTERNAL( MESSAGE_KEY_DELETEKEY ),
IMESSAGE_KEY_GETFIRSTCERT = MKINTERNAL( MESSAGE_KEY_GETFIRSTCERT ),
IMESSAGE_KEY_GETNEXTCERT = MKINTERNAL( MESSAGE_KEY_GETNEXTCERT ),
IMESSAGE_KEY_CERTMGMT = MKINTERNAL( MESSAGE_KEY_CERTMGMT ),
IMESSAGE_USER_USERMGMT = MKINTERNAL( MESSAGE_USER_USERMGMT ),
IMESSAGE_USER_TRUSTMGMT = MKINTERNAL( MESSAGE_USER_TRUSTMGMT ),
IMESSAGE_LAST = MKINTERNAL( MESSAGE_LAST )
} MESSAGE_TYPE;
/* The properties that MESSAGE_COMPARE can compare */
typedef enum {
MESSAGE_COMPARE_NONE, /* No comparison type */
MESSAGE_COMPARE_HASH, /* Compare hash/MAC value */
MESSAGE_COMPARE_ICV, /* Compare ICV value */
MESSAGE_COMPARE_KEYID, /* Compare key IDs */
MESSAGE_COMPARE_KEYID_PGP, /* Compare PGP key IDs */
MESSAGE_COMPARE_KEYID_OPENPGP, /* Compare OpenPGP key IDs */
MESSAGE_COMPARE_SUBJECT, /* Compare subject */
MESSAGE_COMPARE_ISSUERANDSERIALNUMBER, /* Compare iAndS */
MESSAGE_COMPARE_SUBJECTKEYIDENTIFIER, /* Compare subjectKeyIdentifier */
MESSAGE_COMPARE_FINGERPRINT_SHA1,/* Compare cert.fingerprint */
MESSAGE_COMPARE_FINGERPRINT_SHA2,/* Compare fingerprint, SHA2 */
MESSAGE_COMPARE_FINGERPRINT_SHAng,/* Compare fingerprint, SHAng */
MESSAGE_COMPARE_CERTOBJ, /* Compare cert objects */
MESSAGE_COMPARE_EKU, /* Compare extendedKeyUsage */
MESSAGE_COMPARE_LAST /* Last possible compare type */
} MESSAGE_COMPARE_TYPE;
/* The checks that MESSAGE_CHECK performs. There are a number of variations
of the checking we can perform, either the object is initialised in a
state to perform the required action (meaning that it has to be in the
high state), the object is ready to be initialised for the required
action, for example an encryption context about to have a key loaded for
encryption (meaning that it has to be in the low state), or the check is
on a passive container object that constrains another object (for example
a certificate being attached to a context) for which the state isn't
important in this instance. Usually we check to make sure that the
certificate is in the high state, but when a certificate is being
created/imported it may not be in the high state yet at the time the
check is being carried out */
typedef enum {
/* Standard checks, for which the object must be initialised in a state
to perform this operation */
MESSAGE_CHECK_NONE, /* No check type */
MESSAGE_CHECK_PKC, /* Public or private key context */
MESSAGE_CHECK_PKC_PRIVATE, /* Private key context */
MESSAGE_CHECK_PKC_ENCRYPT, /* Public encryption context */
MESSAGE_CHECK_PKC_DECRYPT, /* Private decryption context */
MESSAGE_CHECK_PKC_SIGCHECK, /* Public signature check context */
MESSAGE_CHECK_PKC_SIGN, /* Private signature context */
MESSAGE_CHECK_PKC_KA_EXPORT, /* Key agreement - export context */
MESSAGE_CHECK_PKC_KA_IMPORT, /* Key agreement - import context */
MESSAGE_CHECK_CRYPT, /* Conventional encryption context */
MESSAGE_CHECK_HASH, /* Hash context */
MESSAGE_CHECK_MAC, /* MAC context */
/* Checks that an object is ready to be initialised to perform this
operation */
MESSAGE_CHECK_CRYPT_READY, /* Ready for conv.encr. init */
MESSAGE_CHECK_MAC_READY, /* Ready for MAC init */
MESSAGE_CHECK_KEYGEN_READY, /* Ready for key generation */
/* Checks on purely passive container objects that constrain action
objects */
MESSAGE_CHECK_PKC_ENCRYPT_AVAIL,/* Encryption available */
MESSAGE_CHECK_PKC_DECRYPT_AVAIL,/* Decryption available */
MESSAGE_CHECK_PKC_SIGCHECK_AVAIL, /* Signature check available */
MESSAGE_CHECK_PKC_SIGN_AVAIL, /* Signature available */
MESSAGE_CHECK_PKC_KA_EXPORT_AVAIL, /* Key agreement - export available */
MESSAGE_CHECK_PKC_KA_IMPORT_AVAIL, /* Key agreement - import available */
/* The use of certificates introduces an oddball special case in which a
signing key is allowed to sign any conceivable bit pattern except for
one that looks like a certificate, and vice versa. This means that
while a CA key can be used for signing, it can't be used to sign c
anything other than a certificate, so a check for a general signing
capability via MESSAGE_CHECK_PKC_SIGN/MESSAGE_CHECK_PKC_SIGCHECK
should fail.
This leads to a problematic situation in which a check for the
signing capability of a context would indicate that it's unusable if
it's associated with a CA certificate rather than a general signing
certificate. Because of this we have to provide special-case checks
that checks for data-that-looks-like-a-certificate signing rather
than the default data-that-isnt-a-certificate signing capability.
The following checks mirror the standard checks, but apply to
certificate-only signing */
MESSAGE_CHECK_PKC_SIGCHECK_CA, /* Certificate sig.check */
MESSAGE_CHECK_PKC_SIGN_CA, /* Certificate signing */
MESSAGE_CHECK_PKC_SIGCHECK_CA_AVAIL,/* Certificate sig.check available */
MESSAGE_CHECK_PKC_SIGN_CA_AVAIL,/* Certificate signing available */
/* Miscellaneous checks for meta-capabilities not directly connected
with object actions. The certificate check is used to verify that a
certificate is generally valid (for example not expired) without
having to performing a full signature verification up to a trusted
root. This is used to verify certificates passed in as parameters,
for example server certificates, to ensure that the client doesn't
get invalid data back when it tries to connect to the server */
MESSAGE_CHECK_CERT, /* Generic certificate */
MESSAGE_CHECK_LAST /* Last possible check type */
} MESSAGE_CHECK_TYPE;
/* The notifications that a MESSAGE_CHANGENOTIFY can deliver */
typedef enum {
MESSAGE_CHANGENOTIFY_NONE, /* No notification type */
MESSAGE_CHANGENOTIFY_STATE, /* Object should save/rest.int.state */
MESSAGE_CHANGENOTIFY_OBJHANDLE, /* Object cloned, handle changed */
MESSAGE_CHANGENOTIFY_OWNERHANDLE, /* Object cloned, owner handle changed */
MESSAGE_CHANGENOTIFY_LAST /* Last possible notification type */
} MESSAGE_CHANGENOTIFY_TYPE;
/* The operations that a MESSAGE_USER_USERMGMT can perform */
typedef enum {
MESSAGE_USERMGMT_NONE, /* No operation type */
MESSAGE_USERMGMT_ZEROISE, /* Zeroise users */
MESSAGE_USERMGMT_LAST /* Last possible operation type */
} MESSAGE_USERMGMT_TYPE;
/* The operations that a MESSAGE_USER_TRUSTMGMT can perform */
typedef enum {
MESSAGE_TRUSTMGMT_NONE, /* No operation type */
MESSAGE_TRUSTMGMT_ADD, /* Add trusted certificate */
MESSAGE_TRUSTMGMT_DELETE, /* Delete trusted certificate */
MESSAGE_TRUSTMGMT_CHECK, /* Check trust status of certificate */
MESSAGE_TRUSTMGMT_GETISSUER, /* Get trusted issuer certificate */
MESSAGE_TRUSTMGMT_LAST /* Last possible operation type */
} MESSAGE_TRUSTMGMT_TYPE;
/* Options for the MESSAGE_SETDEPENDENT message */
typedef enum {
SETDEP_OPTION_NONE, /* No option type */
SETDEP_OPTION_NOINCREF, /* Don't inc.dep.objs reference count */
SETDEP_OPTION_INCREF, /* Increment dep.objs reference count */
SETDEP_OPTION_LAST /* Last possible option type */
} MESSAGE_SETDEPENDENT_TYPE;
/* When getting/setting string data that consists of (value, length) pairs,
we pass a pointer to a value-and-length structure rather than a pointer
to the data itself */
typedef struct {
BUFFER_OPT_FIXED( length ) \
void *data; /* Data */
int length; /* Length */
} MESSAGE_DATA;
#define setMessageData( msgDataPtr, dataPtr, dataLength ) \
{ \
( msgDataPtr )->data = ( dataPtr ); \
( msgDataPtr )->length = ( dataLength ); \
}
/* When passing constant data to krnlSendMessage() we get compiler warnings
because the function is prototyped as taking a 'void *', and the same for
krnlAcquireObject(), which takes a 'void **'. The following symbolic
values for use in casts correct the parameter mismatch */
typedef void *MESSAGE_CAST;
typedef void **MESSAGE_PTR_CAST;
/* Some messages communicate standard data values that are used again and
again, so we predefine values for these that can be used globally */
#define MESSAGE_VALUE_TRUE ( ( MESSAGE_CAST ) &messageValueTrue )
#define MESSAGE_VALUE_FALSE ( ( MESSAGE_CAST ) &messageValueFalse )
#define MESSAGE_VALUE_OK ( ( MESSAGE_CAST ) &messageValueCryptOK )
#define MESSAGE_VALUE_ERROR ( ( MESSAGE_CAST ) &messageValueCryptError )
#define MESSAGE_VALUE_UNUSED ( ( MESSAGE_CAST ) &messageValueCryptUnused )
#define MESSAGE_VALUE_DEFAULT ( ( MESSAGE_CAST ) &messageValueCryptUseDefault )
#define MESSAGE_VALUE_CURSORFIRST ( ( MESSAGE_CAST ) &messageValueCursorFirst )
#define MESSAGE_VALUE_CURSORNEXT ( ( MESSAGE_CAST ) &messageValueCursorNext )
#define MESSAGE_VALUE_CURSORPREVIOUS ( ( MESSAGE_CAST ) &messageValueCursorPrevious )
#define MESSAGE_VALUE_CURSORLAST ( ( MESSAGE_CAST ) &messageValueCursorLast )
extern const int messageValueTrue, messageValueFalse;
extern const int messageValueCryptOK, messageValueCryptError;
extern const int messageValueCryptUnused, messageValueCryptUseDefault;
extern const int messageValueCursorFirst, messageValueCursorNext;
extern const int messageValueCursorPrevious, messageValueCursorLast;
/* Check for membership within an attribute class */
#define isAttribute( attribute ) \
( ( attribute ) > CRYPT_ATTRIBUTE_NONE && \
( attribute ) < CRYPT_ATTRIBUTE_LAST )
#define isInternalAttribute( attribute ) \
( ( attribute ) > CRYPT_IATTRIBUTE_FIRST && \
( attribute ) < CRYPT_IATTRIBUTE_LAST )
/* Check whether a message is in a given message class, used in object
message handlers. Note that isActionMessage() excludes
MESSAGE_CTX_GENKEY which is a special-case action message (vs. encrypt,
decrypt, sign, etc), so it's included in the ACTION_PERM bitmap further
down but not routed to the same handler as the other actions */
#define isAttributeMessage( message ) \
( ( message ) >= MESSAGE_GETATTRIBUTE && \
( message ) <= MESSAGE_DELETEATTRIBUTE )
#define isActionMessage( message ) \
( ( message ) >= MESSAGE_CTX_ENCRYPT && \
( message ) <= MESSAGE_CTX_HASH )
#define isMechanismActionMessage( message ) \
( ( message ) >= MESSAGE_DEV_EXPORT && \
( message ) <= MESSAGE_DEV_KDF )
/* The following handles correspond to built-in fixed object types that are
available throughout the architecture. Currently there are two objects,
an internal system object that encapsulates the built-in RNG and the
built-in mechanism types as well as acting as the parent object for all
new objects created, and a default user object which is used when there
are no explicit user objects being employed.
By default, all crypto is handled via the built-in implementation which
means that crypto-related messages are processed via the system object.
However it's also possible to replace the built-in crypto with external
crypto, for example to implement nonstandard or non-public algorithms.
In this case there are two additional objects, one for low-level crypto
and one for higher-level crypto mechanisms. The standard configuration
has these as the same object:
STD: { system = crypto = mech, user }
The two possible alternatives are:
HW1: { system = mech, user, crypto }
HW2: { system, user, crypto = mech }
The HW1 option replaces the crypto with an external implementation, the
HW2 option replaces both the crypto and higher-level mechanisms with
external implementations */
#define SYSTEM_OBJECT_HANDLE 0 /* Internal system object */
#if defined( CONFIG_CRYPTO_HW1 )
/* Crypto handled via separate crypto object */
#define DEFAULTUSER_OBJECT_HANDLE 1 /* Default user object */
#define CRYPTO_OBJECT_HANDLE 2
#define MECHANISM_OBJECT_HANDLE SYSTEM_OBJECT_HANDLE
#define NO_SYSTEM_OBJECTS 3 /* Total number of system objects */
#elif defined( CONFIG_CRYPTO_HW2 )
/* Crypto and mechanisms handled via separate crypto object */
#define DEFAULTUSER_OBJECT_HANDLE 1 /* Default user object */
#define CRYPTO_OBJECT_HANDLE 2
#define MECHANISM_OBJECT_HANDLE CRYPTO_OBJECT_HANDLE
#define NO_SYSTEM_OBJECTS 3 /* Total number of system objects */
#else
/* Crypto handled via the built-in implementation */
#define DEFAULTUSER_OBJECT_HANDLE 1 /* Default user object */
#define CRYPTO_OBJECT_HANDLE SYSTEM_OBJECT_HANDLE
#define MECHANISM_OBJECT_HANDLE SYSTEM_OBJECT_HANDLE
#define NO_SYSTEM_OBJECTS 2 /* Total number of system objects */
#endif /* CONFIG_CRYPTO_HW1 || CONFIG_CRYPTO_HW2 */
/* The maximum number of objects. By default we use a fixed limit set to an
appropriate large-enough value because the only time anyone that would
really be creating thousands of objects is if they're leaking them and
setting a fixed limit means this is detected without the code having to
run for days or weeks leaking handles, however we allow a dynamically-
configurable limit set via CONFIG_NUM_OBJECTS if someone really needs to
use vast numbers of objects */
#if defined( CONFIG_CONSERVE_MEMORY )
#define MAX_NO_OBJECTS 64
#elif defined( CONFIG_NUM_OBJECTS )
#if CONFIG_NUM_OBJECTS != 64 && CONFIG_NUM_OBJECTS != 128 && \
CONFIG_NUM_OBJECTS != 256 && CONFIG_NUM_OBJECTS != 512 && \
CONFIG_NUM_OBJECTS != 1024 && CONFIG_NUM_OBJECTS != 2048 && \
CONFIG_NUM_OBJECTS != 4096 && CONFIG_NUM_OBJECTS != 8192 && \
CONFIG_NUM_OBJECTS != 16384
#error CONFIG_NUM_OBJECTS must be 64, 128, 256, 512, 1K, 2K, 4K, 8K, or 16K
#endif /* CONFIG_NUM_OBJECTS settings */
#define MAX_NO_OBJECTS CONFIG_NUM_OBJECTS
#else
#define MAX_NO_OBJECTS 256
#endif /* Low-memory environments */
/****************************************************************************
* *
* Action Message Types *
* *
****************************************************************************/
/* Action messages come in two types, direct action messages and mechanism-
action messages. Action messages apply directly to action objects (for
example transform a block of data) while mechanism-action messages apply
to device objects and involve extra formatting above and beyond the
direct action (for example perform PKCS #1 padding and then transform a
block of data).
Each object that processes direct action messages can can have a range of
permission settings that control how action messages sent to it are
handled. The most common case is that the action isn't available for
this object, ACTION_PERM_NOTAVAIL. This is an all-zero permission, so
the default is deny-all unless the action is explicitly permitted. The
other permissions are ACTION_PERM_NONE, which means that the action is in
theory available but has been turned off, ACTION_PERM_NONE_EXTERNAL,
which means that the action is only valid if the message is coming from
inside cryptlib, and ACTION_PERM_ALL, which means that the action is
available for anyone. In order to set all permissions to a certain value
(e.g. NONE_EXTERNAL), we define overall values xxx_ALL that (in
combination with the kernel-enforced ratchet) can be used to set all
settings to (at most) the given value.
The order of the action bits is:
hash sign encr
| | |
xx xx xx xx xx xx
| | |
kgen sigch decr
x. .x|x. .x|x. .x Hex digits
Common settings are 0xCFF (new PKC, all operations), 0x0F (key-loaded
conv., all operations), and 0xAA (key-loaded PKC, internal-only
operations).
The kernel enforces a ratchet for these setting that only allows them to
be set to a more restrictive value than their existing one. If a setting
starts out as not available on object creation, it can never be enabled.
If a setting starts as 'none-external', it can only be set to a straight
'none', but never to 'all' */
#define ACTION_PERM_NOTAVAIL 0x00
#define ACTION_PERM_NONE 0x01
#define ACTION_PERM_NONE_EXTERNAL 0x02
#define ACTION_PERM_ALL 0x03
#define ACTION_PERM_NONE_ALL 0x000
#define ACTION_PERM_NONE_EXTERNAL_ALL 0xAAA
#define ACTION_PERM_ALL_MAX 0xFFF
#define ACTION_PERM_BASE MESSAGE_CTX_ENCRYPT /* First action message */
#define ACTION_PERM_BITS 2 /* Number of bits for each perm.*/
#define ACTION_PERM_COUNT 6 /* Number of permissions */
#define ACTION_PERM_MASK 0x03 /* Mask for permission bits */
#define ACTION_MAP_INVALID ( -1 )
#define ACTION_MAP( action ) \
( ( ( action ) < MESSAGE_CTX_ENCRYPT || \
( action ) > MESSAGE_CTX_GENKEY ) ? ACTION_MAP_INVALID : \
( action ) < MESSAGE_CTX_SIGN_MSG ? \
( action ) - ACTION_PERM_BASE : \
( action ) - ( ACTION_PERM_BASE + 2 ) )
/* A complex macro to map an action like MESSAGE_CTX_SIGN to a value
that can be used to create a permission bitmap by acting as a
shift amount for the base permission. If the value is out of
range (programming error) it's turned into an invalid value that's
checked for by the macros that use it and turned into
ACTION_PERM_NOTAVAIL.
Failing that, if it's before one of the two alternative signature-
type actions then it's mapped to the value, if it's at or above
one of the two alternative signature-type actions then it's
remapped down below the two extra actions and from there to the
value.
This rather complex expression relies on the fact that in almost
all cases where it's used the preprocessor can evaluate the
result at compile time from constant values, so the final
expression is a single integer constant which then feeds into the
macros that follow */
#define MK_ACTION_PERM( action, perm ) \
( ( ACTION_MAP( action ) == ACTION_MAP_INVALID ) ? \
ACTION_PERM_NOTAVAIL : \
( ( perm ) << ( ACTION_MAP( action ) * ACTION_PERM_BITS ) ) )
/* Turn an action + desired permission into a permission bitmap */
#define EXTRACT_ACTION_PERM( perm, action ) \
( ( ACTION_MAP( action ) == ACTION_MAP_INVALID ) ? \
ACTION_PERM_NOTAVAIL : \
( ( ( perm ) >> ( ACTION_MAP( action ) * ACTION_PERM_BITS ) ) & \
ACTION_PERM_MASK ) )
/* Extract a permission from an action and permission bitmap. This
one is only used in one location,
kernel/msg_acl.c:checkActionPermitted() to return an error
status */
#define MK_ACTION_PERM_NONE_EXTERNAL( action ) \
( ( action ) & ACTION_PERM_NONE_EXTERNAL_ALL )
/* Mask actions so no external access is permitted */
#define ACTION_PERM_LAST \
( 1 << ( ( ( ACTION_PERM_COUNT ) * ACTION_PERM_BITS ) ) )
/* Used for range checks */
/* Symbolic defines to allow the action flags to be range-checked alongside
all of the other flag types */
#define ACTION_PERM_FLAG_NONE 0x000
#define ACTION_PERM_FLAG_MAX 0xFFF
/* The mechanism types. The distinction between the PKCS #1 and raw PKCS #1
mechanisms is somewhat artificial in that they do the same thing, however
it's easier for the kernel to perform security checks on parameters if
the two are distinct */
typedef enum {
MECHANISM_NONE, /* No mechanism type */
/* En/decryption mechanisms, parameter MECHANISM_WRAP_INFO */
MECHANISM_ENC_PKCS1, /* PKCS #1 en/decrypt */
MECHANISM_ENC_PKCS1_PGP, /* PKCS #1 using PGP formatting */
MECHANISM_ENC_PKCS1_RAW, /* PKCS #1 returning uninterpreted data */
MECHANISM_ENC_OAEP, /* OAEP en/decrypt */
MECHANISM_ENC_CMS, /* CMS key wrap */
/* Signature mechanisms, parameter MECHANISM_SIGN_INFO */
MECHANISM_SIG_PKCS1, /* PKCS #1 sign */
MECHANISM_SIG_PSS, /* PSS sign */
MECHANISM_SIG_TLS, /* TLS sign with dual hashes */
/* Key derivation mechanisms, parameter MECHANISM_DERIVE_INFO */
MECHANISM_DERIVE_PBKDF2, /* PBKDF2 / PKCS #5v2 derive */
MECHANISM_DERIVE_HKDF, /* HKDF derive */
MECHANISM_DERIVE_PKCS12, /* PKCS #12 derive */
MECHANISM_DERIVE_TLS, /* TLS 1.0-1.1 derive */
MECHANISM_DERIVE_TLS12, /* TLS 1.2 derive */
MECHANISM_DERIVE_CMP, /* CMP/Entrust derive */
MECHANISM_DERIVE_PGP, /* OpenPGP S2K derive */
MECHANISM_DERIVE_HOTP, /* HOTP/TOTP derive */
/* Key wrap mechanisms, parameter MECHANISM_WRAP_INFO */
MECHANISM_PRIVATEKEYWRAP, /* Private key wrap */
MECHANISM_PRIVATEKEYWRAP_EXT, /* Priv.key wrap with crypto binding */
MECHANISM_PRIVATEKEYWRAP_PKCS8, /* PKCS #8 private key wrap */
MECHANISM_PRIVATEKEYWRAP_PGP2, /* PGP 2.x private key wrap */
MECHANISM_PRIVATEKEYWRAP_OPENPGP_OLD,/* Legacy OpenPGP private key wrap */
MECHANISM_PRIVATEKEYWRAP_OPENPGP,/* OpenPGP private key wrap */
/* Self-test mechanisms for the above families, taking the same
parameters as the mechanism family type */
MECHANISM_SELFTEST_ENC, /* Test encryption mechanisms */
MECHANISM_SELFTEST_SIG, /* Test signature mechanisms */
MECHANISM_SELFTEST_DERIVE, /* Test derivation mechanisms */
MECHANISM_SELFTEST_KDF, /* Test KDF mechanisms */
MECHANISM_LAST /* Last possible mechanism type */
} MECHANISM_TYPE;
/* A structure to hold information needed by the key export/import mechanism.
The key can be passed as raw key data or as a context if tied to hardware
that doesn't allow keying material outside the hardware's security
perimeter:
PKCS #1, wrappedData = wrapped key
PKCS #1 PGP keyData = -
keyContext = context containing key
wrapContext = wrap/unwrap PKC context
auxContext = CRYPT_UNUSED
auxInfo = CRYPT_UNUSED
PKCS #1 raw wrappedData = wrapped raw data
keyData = raw data
keyContext = CRYPT_UNUSED
wrapContext = wrap/unwrap PKC context
auxContext = CRYPT_UNUSED
auxInfo = CRYPT_UNUSED
OAEP wrappedData = wrapped key
keyData = -
keyContext = context containing key
wrapContext = wrap/unwrap PKC context
auxContext = CRYPT_UNUSED
auxInfo = MGF1 hash algorithm
[ auxInfoExt = MGF1 hash parameter - currently always SHA-256 ]
CMS wrappedData = wrapped key
keyData = -
keyContext = context containing key
wrapContext = wrap/unwrap conventional context
auxContext = CRYPT_UNUSED
auxInfo = CRYPT_UNUSED
Private wrappedData = padded encrypted private key components
key wrap keyData = -
keyContext = context containing private key
wrapContext = wrap/unwrap conventional context
auxContext = CRYPT_UNUSED
auxInfo = CRYPT_UNUSED */
typedef struct { //-V802
BUFFER_OPT_FIXED( wrappedDataLength ) \
void *wrappedData; /* Wrapped key */
int wrappedDataLength;
BUFFER_OPT_FIXED( keyDataLength ) \
void *keyData; /* Raw key */
int keyDataLength;
VALUE_HANDLE_OPT CRYPT_HANDLE keyContext;/* Context containing raw key */
VALUE_HANDLE CRYPT_HANDLE wrapContext; /* Wrap/unwrap context */
VALUE_HANDLE_OPT CRYPT_HANDLE auxContext;/* Auxiliary context */
int auxInfo; /* Auxiliary info */
} MECHANISM_WRAP_INFO;
/* A structure to hold information needed by the sign/sig check mechanism:
PKCS #1 signature = signature
PSS hashContext = hash to sign
signContext = signing key
SSL signature = signature
hashContext, hashContext2 = dual hashes to sign
signContext = signing key */
typedef struct {
BUFFER_OPT_FIXED( signatureLength ) \
void *signature; /* Signature */
int signatureLength;
VALUE_HANDLE CRYPT_CONTEXT hashContext; /* Hash context */
VALUE_HANDLE CRYPT_CONTEXT hashContext2;/* Secondary hash context */
VALUE_HANDLE CRYPT_HANDLE signContext; /* Signing/sig check context */
} MECHANISM_SIGN_INFO;
/* A structure to hold information needed by the sign/sig check message
mechanism */
#if 0 /* Not needed at present */
typedef struct {
BUFFER_OPT_FIXED( signatureLength ) \
void *signature; /* Signature */
int signatureLength;
BUFFER_FIXED( messageLength ) \
void *message; /* Message to sign/sig check */
int messageLength;
VALUE_HANDLE CRYPT_HANDLE signContext; /* Signing/sig check context */
} MECHANISM_SIGN_MSG_INFO;
#endif /* 0 */
/* A structure to hold information needed by the key derivation mechanism.
This differs from the KDF mechanism that follows in that the "Derive"
form is used with an iteration count for password-based key derivation
while the "KDF" form is used without an iteration count for straight key
derivation from a master secret. An exception to this is the TLS
derivation, which uses the resulting data in so many ways that it's not
possible to perform a generic context -> context transformation but
requires a generalisation in which the raw output data is available:
PKCS #5, dataOut = key data
CMP, PGP dataIn = password
hashAlgo = hash algorithm
salt = salt
iterations = iteration count
SSL/TLS/ dataOut = key data/master secret
TLS 1.2 dataIn = master secret/premaster secret
hashAlgo = CRYPT_USE_DEFAULT
salt = client || server random/server || client random
iterations = 1
HOTP dataOut = OTP value
dataIn = seed
hashAlgo = CRYPT_ALGO_SHA1
salt = counter (HOTP)/timestamp (TOTP)
iterations = 1 */
typedef struct {
BUFFER_OPT_FIXED( dataOutLength ) \
You can’t perform that action at this time.
