1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <dice/dice.h> 18 #include <openssl/curve25519.h> 19 20 /* 21 The implementation of validation functions is shared by Rust and C++ 22 applications, and so two different interfaces are provided -- one that 23 uses primitive C types to interface with bindgen, and one that uses 24 C++ standard library types. 25 26 For Rust, `validate_bcc` and `validate_bcc_handover` are exposed. 27 For C++, `validate_bcc_impl` and `validate_bcc_handover_impl` are 28 exposed in addition to the aforementioned interfaces. 29 */ 30 31 #ifdef __cplusplus 32 #include <array> 33 #include <vector> 34 35 using PubKey = std::array<uint8_t, ED25519_PUBLIC_KEY_LEN>; 36 using CDI = std::array<uint8_t, DICE_CDI_SIZE>; 37 38 bool validate_bcc_impl(const uint8_t* bcc, 39 size_t bcc_size, 40 std::vector<PubKey>* keys); 41 42 bool validate_bcc_handover_impl(const uint8_t* bcc_handover, 43 size_t bcc_handover_size, 44 CDI* next_cdi_attest, 45 CDI* next_cdi_seal); 46 #endif 47 48 #ifdef __cplusplus 49 extern "C" { 50 #endif 51 52 bool validate_bcc(const uint8_t* bcc, 53 size_t bcc_size, 54 uint8_t dk_pub_key[ED25519_PUBLIC_KEY_LEN], 55 uint8_t km_pub_key[ED25519_PUBLIC_KEY_LEN]); 56 57 bool validate_bcc_handover(const uint8_t* bcc_handover, 58 size_t bcc_handover_size, 59 uint8_t next_cdi_attest[DICE_CDI_SIZE], 60 uint8_t next_cdi_seal[DICE_CDI_SIZE]); 61 62 #ifdef __cplusplus 63 } 64 #endif