• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 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_OPS_TRAIT_COSE_H_
16 #define DICE_OPS_TRAIT_COSE_H_
17 
18 #include <dice/config.h>
19 #include <dice/dice.h>
20 #include <stddef.h>
21 #include <stdint.h>
22 
23 // These functions may optionally be implemented by a COSE based integration.
24 // They aren't directly depended on by the main DICE functions but provide
25 // extra utilities that can be used as part of the integration.
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 // Encodes a public key into |buffer| as a COSE_Key structure, setting
32 // |encoded_size| to the number of bytes used.
33 DiceResult DiceCoseEncodePublicKey(
34     void* context, const uint8_t public_key[DICE_PUBLIC_KEY_SIZE],
35     size_t buffer_size, uint8_t* buffer, size_t* encoded_size);
36 
37 // Signs the payload and additional authenticated data, formatting the result
38 // into a COSE_Sign1 structure. There are no unprotected attributes included in
39 // the result.
40 //
41 // |buffer| is used to hold the intermediate To-Be-Signed (TBS) structure and
42 // then the final result. |encoded_size| is set to the size of the final result
43 // in |buffer|.
44 DiceResult DiceCoseSignAndEncodeSign1(
45     void* context, const uint8_t* payload, size_t payload_size,
46     const uint8_t* aad, size_t aad_size,
47     const uint8_t private_key[DICE_PRIVATE_KEY_SIZE], size_t buffer_size,
48     uint8_t* buffer, size_t* encoded_size);
49 
50 #ifdef __cplusplus
51 }  // extern "C"
52 #endif
53 
54 #endif  // DICE_OPS_TRAIT_COSE_H_
55