xref: /aosp_15_r20/external/open-dice/include/dice/config/boringssl_multialg/dice/config.h (revision 60b67249c2e226f42f35cc6cfe66c6048e0bae6b)
1 // Copyright 2024 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 
15 #ifndef DICE_CONFIG_BORINGSSL_MULTIALG_DICE_CONFIG_H_
16 #define DICE_CONFIG_BORINGSSL_MULTIALG_DICE_CONFIG_H_
17 
18 #include <stddef.h>
19 #include <stdint.h>
20 
21 #include "dice/types.h"
22 
23 // Upper bound of sizes for all the supported algorithms.
24 #define DICE_PUBLIC_KEY_BUFFER_SIZE 96
25 #define DICE_PRIVATE_KEY_BUFFER_SIZE 64
26 #define DICE_SIGNATURE_BUFFER_SIZE 96
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 typedef enum {
33   kDiceKeyAlgorithmEd25519,
34   kDiceKeyAlgorithmP256,
35   kDiceKeyAlgorithmP384,
36 } DiceKeyAlgorithm;
37 
38 // Provides the algorithm configuration and must be passed as the context
39 // parameter to every function in the library.
40 typedef struct DiceContext_ {
41   DiceKeyAlgorithm authority_algorithm;
42   DiceKeyAlgorithm subject_algorithm;
43 } DiceContext;
44 
DiceGetKeyAlgorithm(void * context,DicePrincipal principal,DiceKeyAlgorithm * alg)45 static inline DiceResult DiceGetKeyAlgorithm(void* context,
46                                              DicePrincipal principal,
47                                              DiceKeyAlgorithm* alg) {
48   DiceContext* c = (DiceContext*)context;
49   if (context == NULL) {
50     return kDiceResultInvalidInput;
51   }
52   switch (principal) {
53     case kDicePrincipalAuthority:
54       *alg = c->authority_algorithm;
55       break;
56     case kDicePrincipalSubject:
57       *alg = c->subject_algorithm;
58       break;
59   }
60   return kDiceResultOk;
61 }
62 
63 #ifdef __cplusplus
64 }  // extern "C"
65 #endif
66 
67 #endif  // DICE_CONFIG_BORINGSSL_MULTIALG_DICE_DICE_CONFIG_H_
68