1*d289c2baSAndroid Build Coastguard Worker /* 2*d289c2baSAndroid Build Coastguard Worker * Copyright (C) 2016 The Android Open Source Project 3*d289c2baSAndroid Build Coastguard Worker * 4*d289c2baSAndroid Build Coastguard Worker * Permission is hereby granted, free of charge, to any person 5*d289c2baSAndroid Build Coastguard Worker * obtaining a copy of this software and associated documentation 6*d289c2baSAndroid Build Coastguard Worker * files (the "Software"), to deal in the Software without 7*d289c2baSAndroid Build Coastguard Worker * restriction, including without limitation the rights to use, copy, 8*d289c2baSAndroid Build Coastguard Worker * modify, merge, publish, distribute, sublicense, and/or sell copies 9*d289c2baSAndroid Build Coastguard Worker * of the Software, and to permit persons to whom the Software is 10*d289c2baSAndroid Build Coastguard Worker * furnished to do so, subject to the following conditions: 11*d289c2baSAndroid Build Coastguard Worker * 12*d289c2baSAndroid Build Coastguard Worker * The above copyright notice and this permission notice shall be 13*d289c2baSAndroid Build Coastguard Worker * included in all copies or substantial portions of the Software. 14*d289c2baSAndroid Build Coastguard Worker * 15*d289c2baSAndroid Build Coastguard Worker * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16*d289c2baSAndroid Build Coastguard Worker * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17*d289c2baSAndroid Build Coastguard Worker * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18*d289c2baSAndroid Build Coastguard Worker * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19*d289c2baSAndroid Build Coastguard Worker * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20*d289c2baSAndroid Build Coastguard Worker * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21*d289c2baSAndroid Build Coastguard Worker * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22*d289c2baSAndroid Build Coastguard Worker * SOFTWARE. 23*d289c2baSAndroid Build Coastguard Worker */ 24*d289c2baSAndroid Build Coastguard Worker 25*d289c2baSAndroid Build Coastguard Worker #if !defined(AVB_INSIDE_LIBAVB_H) && !defined(AVB_COMPILATION) 26*d289c2baSAndroid Build Coastguard Worker #error "Never include this file directly, include libavb.h instead." 27*d289c2baSAndroid Build Coastguard Worker #endif 28*d289c2baSAndroid Build Coastguard Worker 29*d289c2baSAndroid Build Coastguard Worker #ifndef AVB_VBMETA_IMAGE_H_ 30*d289c2baSAndroid Build Coastguard Worker #define AVB_VBMETA_IMAGE_H_ 31*d289c2baSAndroid Build Coastguard Worker 32*d289c2baSAndroid Build Coastguard Worker #include "avb_sysdeps.h" 33*d289c2baSAndroid Build Coastguard Worker 34*d289c2baSAndroid Build Coastguard Worker #ifdef __cplusplus 35*d289c2baSAndroid Build Coastguard Worker extern "C" { 36*d289c2baSAndroid Build Coastguard Worker #endif 37*d289c2baSAndroid Build Coastguard Worker 38*d289c2baSAndroid Build Coastguard Worker #include "avb_crypto.h" 39*d289c2baSAndroid Build Coastguard Worker #include "avb_descriptor.h" 40*d289c2baSAndroid Build Coastguard Worker 41*d289c2baSAndroid Build Coastguard Worker /* Size of the vbmeta image header. */ 42*d289c2baSAndroid Build Coastguard Worker #define AVB_VBMETA_IMAGE_HEADER_SIZE 256 43*d289c2baSAndroid Build Coastguard Worker 44*d289c2baSAndroid Build Coastguard Worker /* Magic for the vbmeta image header. */ 45*d289c2baSAndroid Build Coastguard Worker #define AVB_MAGIC "AVB0" 46*d289c2baSAndroid Build Coastguard Worker #define AVB_MAGIC_LEN 4 47*d289c2baSAndroid Build Coastguard Worker 48*d289c2baSAndroid Build Coastguard Worker /* Maximum size of the release string including the terminating NUL byte. */ 49*d289c2baSAndroid Build Coastguard Worker #define AVB_RELEASE_STRING_SIZE 48 50*d289c2baSAndroid Build Coastguard Worker 51*d289c2baSAndroid Build Coastguard Worker /* Flags for the vbmeta image. 52*d289c2baSAndroid Build Coastguard Worker * 53*d289c2baSAndroid Build Coastguard Worker * AVB_VBMETA_IMAGE_FLAGS_HASHTREE_DISABLED: If this flag is set, 54*d289c2baSAndroid Build Coastguard Worker * hashtree image verification will be disabled. 55*d289c2baSAndroid Build Coastguard Worker * 56*d289c2baSAndroid Build Coastguard Worker * AVB_VBMETA_IMAGE_FLAGS_VERIFICATION_DISABLED: If this flag is set, 57*d289c2baSAndroid Build Coastguard Worker * verification will be disabled and descriptors will not be parsed. 58*d289c2baSAndroid Build Coastguard Worker */ 59*d289c2baSAndroid Build Coastguard Worker typedef enum { 60*d289c2baSAndroid Build Coastguard Worker AVB_VBMETA_IMAGE_FLAGS_HASHTREE_DISABLED = (1 << 0), 61*d289c2baSAndroid Build Coastguard Worker AVB_VBMETA_IMAGE_FLAGS_VERIFICATION_DISABLED = (1 << 1) 62*d289c2baSAndroid Build Coastguard Worker } AvbVBMetaImageFlags; 63*d289c2baSAndroid Build Coastguard Worker 64*d289c2baSAndroid Build Coastguard Worker /* Binary format for header of the vbmeta image. 65*d289c2baSAndroid Build Coastguard Worker * 66*d289c2baSAndroid Build Coastguard Worker * The vbmeta image consists of three blocks: 67*d289c2baSAndroid Build Coastguard Worker * 68*d289c2baSAndroid Build Coastguard Worker * +-----------------------------------------+ 69*d289c2baSAndroid Build Coastguard Worker * | Header data - fixed size | 70*d289c2baSAndroid Build Coastguard Worker * +-----------------------------------------+ 71*d289c2baSAndroid Build Coastguard Worker * | Authentication data - variable size | 72*d289c2baSAndroid Build Coastguard Worker * +-----------------------------------------+ 73*d289c2baSAndroid Build Coastguard Worker * | Auxiliary data - variable size | 74*d289c2baSAndroid Build Coastguard Worker * +-----------------------------------------+ 75*d289c2baSAndroid Build Coastguard Worker * 76*d289c2baSAndroid Build Coastguard Worker * The "Header data" block is described by this struct and is always 77*d289c2baSAndroid Build Coastguard Worker * |AVB_VBMETA_IMAGE_HEADER_SIZE| bytes long. 78*d289c2baSAndroid Build Coastguard Worker * 79*d289c2baSAndroid Build Coastguard Worker * The "Authentication data" block is |authentication_data_block_size| 80*d289c2baSAndroid Build Coastguard Worker * bytes long and contains the hash and signature used to authenticate 81*d289c2baSAndroid Build Coastguard Worker * the vbmeta image. The type of the hash and signature is defined by 82*d289c2baSAndroid Build Coastguard Worker * the |algorithm_type| field. 83*d289c2baSAndroid Build Coastguard Worker * 84*d289c2baSAndroid Build Coastguard Worker * The "Auxiliary data" is |auxiliary_data_block_size| bytes long and 85*d289c2baSAndroid Build Coastguard Worker * contains the auxiliary data including the public key used to make 86*d289c2baSAndroid Build Coastguard Worker * the signature and descriptors. 87*d289c2baSAndroid Build Coastguard Worker * 88*d289c2baSAndroid Build Coastguard Worker * The public key is at offset |public_key_offset| with size 89*d289c2baSAndroid Build Coastguard Worker * |public_key_size| in this block. The size of the public key data is 90*d289c2baSAndroid Build Coastguard Worker * defined by the |algorithm_type| field. The format of the public key 91*d289c2baSAndroid Build Coastguard Worker * data is described in the |AvbRSAPublicKeyHeader| struct. 92*d289c2baSAndroid Build Coastguard Worker * 93*d289c2baSAndroid Build Coastguard Worker * The descriptors starts at |descriptors_offset| from the beginning 94*d289c2baSAndroid Build Coastguard Worker * of the "Auxiliary Data" block and take up |descriptors_size| 95*d289c2baSAndroid Build Coastguard Worker * bytes. Each descriptor is stored as a |AvbDescriptor| with tag and 96*d289c2baSAndroid Build Coastguard Worker * number of bytes following. The number of descriptors can be 97*d289c2baSAndroid Build Coastguard Worker * determined by walking this data until |descriptors_size| is 98*d289c2baSAndroid Build Coastguard Worker * exhausted. 99*d289c2baSAndroid Build Coastguard Worker * 100*d289c2baSAndroid Build Coastguard Worker * The size of each of the "Authentication data" and "Auxiliary data" 101*d289c2baSAndroid Build Coastguard Worker * blocks must be divisible by 64. This is to ensure proper alignment. 102*d289c2baSAndroid Build Coastguard Worker * 103*d289c2baSAndroid Build Coastguard Worker * Descriptors are free-form blocks stored in a part of the vbmeta 104*d289c2baSAndroid Build Coastguard Worker * image subject to the same integrity checks as the rest of the 105*d289c2baSAndroid Build Coastguard Worker * image. See the documentation for |AvbDescriptor| for well-known 106*d289c2baSAndroid Build Coastguard Worker * descriptors. See avb_descriptor_foreach() for a convenience 107*d289c2baSAndroid Build Coastguard Worker * function to iterate over descriptors. 108*d289c2baSAndroid Build Coastguard Worker * 109*d289c2baSAndroid Build Coastguard Worker * This struct is versioned, see the |required_libavb_version_major| 110*d289c2baSAndroid Build Coastguard Worker * and |required_libavb_version_minor| fields. This represents the 111*d289c2baSAndroid Build Coastguard Worker * minimum version of libavb required to verify the header and depends 112*d289c2baSAndroid Build Coastguard Worker * on the features (e.g. algorithms, descriptors) used. Note that this 113*d289c2baSAndroid Build Coastguard Worker * may be 1.0 even if generated by an avbtool from 1.4 but where no 114*d289c2baSAndroid Build Coastguard Worker * features introduced after 1.0 has been used. See the "Versioning 115*d289c2baSAndroid Build Coastguard Worker * and compatibility" section in the README.md file for more details. 116*d289c2baSAndroid Build Coastguard Worker * 117*d289c2baSAndroid Build Coastguard Worker * All fields are stored in network byte order when serialized. To 118*d289c2baSAndroid Build Coastguard Worker * generate a copy with fields swapped to native byte order, use the 119*d289c2baSAndroid Build Coastguard Worker * function avb_vbmeta_image_header_to_host_byte_order(). 120*d289c2baSAndroid Build Coastguard Worker * 121*d289c2baSAndroid Build Coastguard Worker * Before reading and/or using any of this data, you MUST verify it 122*d289c2baSAndroid Build Coastguard Worker * using avb_vbmeta_image_verify() and reject it unless it's signed by 123*d289c2baSAndroid Build Coastguard Worker * a known good public key. 124*d289c2baSAndroid Build Coastguard Worker */ 125*d289c2baSAndroid Build Coastguard Worker typedef struct AvbVBMetaImageHeader { 126*d289c2baSAndroid Build Coastguard Worker /* 0: Four bytes equal to "AVB0" (AVB_MAGIC). */ 127*d289c2baSAndroid Build Coastguard Worker uint8_t magic[AVB_MAGIC_LEN]; 128*d289c2baSAndroid Build Coastguard Worker 129*d289c2baSAndroid Build Coastguard Worker /* 4: The major version of libavb required for this header. */ 130*d289c2baSAndroid Build Coastguard Worker uint32_t required_libavb_version_major; 131*d289c2baSAndroid Build Coastguard Worker /* 8: The minor version of libavb required for this header. */ 132*d289c2baSAndroid Build Coastguard Worker uint32_t required_libavb_version_minor; 133*d289c2baSAndroid Build Coastguard Worker 134*d289c2baSAndroid Build Coastguard Worker /* 12: The size of the signature block. */ 135*d289c2baSAndroid Build Coastguard Worker uint64_t authentication_data_block_size; 136*d289c2baSAndroid Build Coastguard Worker /* 20: The size of the auxiliary data block. */ 137*d289c2baSAndroid Build Coastguard Worker uint64_t auxiliary_data_block_size; 138*d289c2baSAndroid Build Coastguard Worker 139*d289c2baSAndroid Build Coastguard Worker /* 28: The verification algorithm used, see |AvbAlgorithmType| enum. */ 140*d289c2baSAndroid Build Coastguard Worker uint32_t algorithm_type; 141*d289c2baSAndroid Build Coastguard Worker 142*d289c2baSAndroid Build Coastguard Worker /* 32: Offset into the "Authentication data" block of hash data. */ 143*d289c2baSAndroid Build Coastguard Worker uint64_t hash_offset; 144*d289c2baSAndroid Build Coastguard Worker /* 40: Length of the hash data. */ 145*d289c2baSAndroid Build Coastguard Worker uint64_t hash_size; 146*d289c2baSAndroid Build Coastguard Worker 147*d289c2baSAndroid Build Coastguard Worker /* 48: Offset into the "Authentication data" block of signature data. */ 148*d289c2baSAndroid Build Coastguard Worker uint64_t signature_offset; 149*d289c2baSAndroid Build Coastguard Worker /* 56: Length of the signature data. */ 150*d289c2baSAndroid Build Coastguard Worker uint64_t signature_size; 151*d289c2baSAndroid Build Coastguard Worker 152*d289c2baSAndroid Build Coastguard Worker /* 64: Offset into the "Auxiliary data" block of public key data. */ 153*d289c2baSAndroid Build Coastguard Worker uint64_t public_key_offset; 154*d289c2baSAndroid Build Coastguard Worker /* 72: Length of the public key data. */ 155*d289c2baSAndroid Build Coastguard Worker uint64_t public_key_size; 156*d289c2baSAndroid Build Coastguard Worker 157*d289c2baSAndroid Build Coastguard Worker /* 80: Offset into the "Auxiliary data" block of public key metadata. */ 158*d289c2baSAndroid Build Coastguard Worker uint64_t public_key_metadata_offset; 159*d289c2baSAndroid Build Coastguard Worker /* 88: Length of the public key metadata. Must be set to zero if there 160*d289c2baSAndroid Build Coastguard Worker * is no public key metadata. 161*d289c2baSAndroid Build Coastguard Worker */ 162*d289c2baSAndroid Build Coastguard Worker uint64_t public_key_metadata_size; 163*d289c2baSAndroid Build Coastguard Worker 164*d289c2baSAndroid Build Coastguard Worker /* 96: Offset into the "Auxiliary data" block of descriptor data. */ 165*d289c2baSAndroid Build Coastguard Worker uint64_t descriptors_offset; 166*d289c2baSAndroid Build Coastguard Worker /* 104: Length of descriptor data. */ 167*d289c2baSAndroid Build Coastguard Worker uint64_t descriptors_size; 168*d289c2baSAndroid Build Coastguard Worker 169*d289c2baSAndroid Build Coastguard Worker /* 112: The rollback index which can be used to prevent rollback to 170*d289c2baSAndroid Build Coastguard Worker * older versions. 171*d289c2baSAndroid Build Coastguard Worker */ 172*d289c2baSAndroid Build Coastguard Worker uint64_t rollback_index; 173*d289c2baSAndroid Build Coastguard Worker 174*d289c2baSAndroid Build Coastguard Worker /* 120: Flags from the AvbVBMetaImageFlags enumeration. This must be 175*d289c2baSAndroid Build Coastguard Worker * set to zero if the vbmeta image is not a top-level image. 176*d289c2baSAndroid Build Coastguard Worker */ 177*d289c2baSAndroid Build Coastguard Worker uint32_t flags; 178*d289c2baSAndroid Build Coastguard Worker 179*d289c2baSAndroid Build Coastguard Worker /* 124: The location of the rollback index defined in this header. 180*d289c2baSAndroid Build Coastguard Worker * Only valid for the main vbmeta. For chained partitions, the rollback 181*d289c2baSAndroid Build Coastguard Worker * index location must be specified in the AvbChainPartitionDescriptor 182*d289c2baSAndroid Build Coastguard Worker * and this value must be set to 0. 183*d289c2baSAndroid Build Coastguard Worker */ 184*d289c2baSAndroid Build Coastguard Worker uint32_t rollback_index_location; 185*d289c2baSAndroid Build Coastguard Worker 186*d289c2baSAndroid Build Coastguard Worker /* 128: The release string from avbtool, e.g. "avbtool 1.0.0" or 187*d289c2baSAndroid Build Coastguard Worker * "avbtool 1.0.0 xyz_board Git-234abde89". Is guaranteed to be NUL 188*d289c2baSAndroid Build Coastguard Worker * terminated. Applications must not make assumptions about how this 189*d289c2baSAndroid Build Coastguard Worker * string is formatted. 190*d289c2baSAndroid Build Coastguard Worker */ 191*d289c2baSAndroid Build Coastguard Worker uint8_t release_string[AVB_RELEASE_STRING_SIZE]; 192*d289c2baSAndroid Build Coastguard Worker 193*d289c2baSAndroid Build Coastguard Worker /* 176: Padding to ensure struct is size AVB_VBMETA_IMAGE_HEADER_SIZE 194*d289c2baSAndroid Build Coastguard Worker * bytes. This must be set to zeroes. 195*d289c2baSAndroid Build Coastguard Worker */ 196*d289c2baSAndroid Build Coastguard Worker uint8_t reserved[80]; 197*d289c2baSAndroid Build Coastguard Worker } AVB_ATTR_PACKED AvbVBMetaImageHeader; 198*d289c2baSAndroid Build Coastguard Worker 199*d289c2baSAndroid Build Coastguard Worker /* Copies |src| to |dest|, byte-swapping fields in the process. 200*d289c2baSAndroid Build Coastguard Worker * 201*d289c2baSAndroid Build Coastguard Worker * Make sure you've verified |src| using avb_vbmeta_image_verify() 202*d289c2baSAndroid Build Coastguard Worker * before accessing the data and/or using this function. 203*d289c2baSAndroid Build Coastguard Worker */ 204*d289c2baSAndroid Build Coastguard Worker void avb_vbmeta_image_header_to_host_byte_order(const AvbVBMetaImageHeader* src, 205*d289c2baSAndroid Build Coastguard Worker AvbVBMetaImageHeader* dest); 206*d289c2baSAndroid Build Coastguard Worker 207*d289c2baSAndroid Build Coastguard Worker /* Return codes used in avb_vbmeta_image_verify(). 208*d289c2baSAndroid Build Coastguard Worker * 209*d289c2baSAndroid Build Coastguard Worker * AVB_VBMETA_VERIFY_RESULT_OK is returned if the vbmeta image header 210*d289c2baSAndroid Build Coastguard Worker * is valid, the hash is correct and the signature is correct. Keep in 211*d289c2baSAndroid Build Coastguard Worker * mind that you still need to check that you know the public key used 212*d289c2baSAndroid Build Coastguard Worker * to sign the image, see avb_vbmeta_image_verify() for details. 213*d289c2baSAndroid Build Coastguard Worker * 214*d289c2baSAndroid Build Coastguard Worker * AVB_VBMETA_VERIFY_RESULT_OK_NOT_SIGNED is returned if the vbmeta 215*d289c2baSAndroid Build Coastguard Worker * image header is valid but there is no signature or hash. 216*d289c2baSAndroid Build Coastguard Worker * 217*d289c2baSAndroid Build Coastguard Worker * AVB_VBMETA_VERIFY_RESULT_INVALID_VBMETA_HEADER is returned if the 218*d289c2baSAndroid Build Coastguard Worker * header of the vbmeta image is invalid, for example, invalid magic 219*d289c2baSAndroid Build Coastguard Worker * or inconsistent data. 220*d289c2baSAndroid Build Coastguard Worker * 221*d289c2baSAndroid Build Coastguard Worker * AVB_VBMETA_VERIFY_RESULT_UNSUPPORTED_VERSION is returned if a) the 222*d289c2baSAndroid Build Coastguard Worker * vbmeta image requires a minimum version of libavb which exceeds the 223*d289c2baSAndroid Build Coastguard Worker * version of libavb used; or b) the vbmeta image major version 224*d289c2baSAndroid Build Coastguard Worker * differs from the major version of libavb in use. 225*d289c2baSAndroid Build Coastguard Worker * 226*d289c2baSAndroid Build Coastguard Worker * AVB_VBMETA_VERIFY_RESULT_HASH_MISMATCH is returned if the hash 227*d289c2baSAndroid Build Coastguard Worker * stored in the "Authentication data" block does not match the 228*d289c2baSAndroid Build Coastguard Worker * calculated hash. 229*d289c2baSAndroid Build Coastguard Worker * 230*d289c2baSAndroid Build Coastguard Worker * AVB_VBMETA_VERIFY_RESULT_SIGNATURE_MISMATCH is returned if the 231*d289c2baSAndroid Build Coastguard Worker * signature stored in the "Authentication data" block is invalid or 232*d289c2baSAndroid Build Coastguard Worker * doesn't match the public key stored in the vbmeta image. 233*d289c2baSAndroid Build Coastguard Worker */ 234*d289c2baSAndroid Build Coastguard Worker typedef enum { 235*d289c2baSAndroid Build Coastguard Worker AVB_VBMETA_VERIFY_RESULT_OK, 236*d289c2baSAndroid Build Coastguard Worker AVB_VBMETA_VERIFY_RESULT_OK_NOT_SIGNED, 237*d289c2baSAndroid Build Coastguard Worker AVB_VBMETA_VERIFY_RESULT_INVALID_VBMETA_HEADER, 238*d289c2baSAndroid Build Coastguard Worker AVB_VBMETA_VERIFY_RESULT_UNSUPPORTED_VERSION, 239*d289c2baSAndroid Build Coastguard Worker AVB_VBMETA_VERIFY_RESULT_HASH_MISMATCH, 240*d289c2baSAndroid Build Coastguard Worker AVB_VBMETA_VERIFY_RESULT_SIGNATURE_MISMATCH, 241*d289c2baSAndroid Build Coastguard Worker } AvbVBMetaVerifyResult; 242*d289c2baSAndroid Build Coastguard Worker 243*d289c2baSAndroid Build Coastguard Worker /* Get a textual representation of |result|. */ 244*d289c2baSAndroid Build Coastguard Worker const char* avb_vbmeta_verify_result_to_string(AvbVBMetaVerifyResult result); 245*d289c2baSAndroid Build Coastguard Worker 246*d289c2baSAndroid Build Coastguard Worker /* Checks that vbmeta image at |data| of size |length| is a valid 247*d289c2baSAndroid Build Coastguard Worker * vbmeta image. The complete contents of the vbmeta image must be 248*d289c2baSAndroid Build Coastguard Worker * passed in. It's fine if |length| is bigger than the actual image, 249*d289c2baSAndroid Build Coastguard Worker * typically callers of this function will load the entire contents of 250*d289c2baSAndroid Build Coastguard Worker * the 'vbmeta_a' or 'vbmeta_b' partition and pass in its length (for 251*d289c2baSAndroid Build Coastguard Worker * example, 1 MiB). 252*d289c2baSAndroid Build Coastguard Worker * 253*d289c2baSAndroid Build Coastguard Worker * See the |AvbVBMetaImageHeader| struct for information about the 254*d289c2baSAndroid Build Coastguard Worker * three blocks (header, authentication, auxiliary) that make up a 255*d289c2baSAndroid Build Coastguard Worker * vbmeta image. 256*d289c2baSAndroid Build Coastguard Worker * 257*d289c2baSAndroid Build Coastguard Worker * If the function returns |AVB_VBMETA_VERIFY_RESULT_OK| and 258*d289c2baSAndroid Build Coastguard Worker * |out_public_key_data| is non-NULL, it will be set to point inside 259*d289c2baSAndroid Build Coastguard Worker * |data| for where the serialized public key data is stored and 260*d289c2baSAndroid Build Coastguard Worker * |out_public_key_length|, if non-NULL, will be set to the length of 261*d289c2baSAndroid Build Coastguard Worker * the public key data. If there is no public key in the metadata then 262*d289c2baSAndroid Build Coastguard Worker * |out_public_key_data| is set to NULL. 263*d289c2baSAndroid Build Coastguard Worker * 264*d289c2baSAndroid Build Coastguard Worker * See the |AvbVBMetaVerifyResult| enum for possible return values. 265*d289c2baSAndroid Build Coastguard Worker * 266*d289c2baSAndroid Build Coastguard Worker * VERY IMPORTANT: 267*d289c2baSAndroid Build Coastguard Worker * 268*d289c2baSAndroid Build Coastguard Worker * 1. Even if |AVB_VBMETA_VERIFY_RESULT_OK| is returned, you still 269*d289c2baSAndroid Build Coastguard Worker * need to check that the public key embedded in the image 270*d289c2baSAndroid Build Coastguard Worker * matches a known key! You can use 'avbtool extract_public_key' 271*d289c2baSAndroid Build Coastguard Worker * to extract the key (at build time, then store it along your 272*d289c2baSAndroid Build Coastguard Worker * code) and compare it to what is returned in 273*d289c2baSAndroid Build Coastguard Worker * |out_public_key_data|. 274*d289c2baSAndroid Build Coastguard Worker * 275*d289c2baSAndroid Build Coastguard Worker * 2. You need to check the |rollback_index| field against a stored 276*d289c2baSAndroid Build Coastguard Worker * value in NVRAM and reject the vbmeta image if the value in 277*d289c2baSAndroid Build Coastguard Worker * NVRAM is bigger than |rollback_index|. You must also update 278*d289c2baSAndroid Build Coastguard Worker * the value stored in NVRAM to the smallest value of 279*d289c2baSAndroid Build Coastguard Worker * |rollback_index| field from boot images in all bootable and 280*d289c2baSAndroid Build Coastguard Worker * authentic slots marked as GOOD. 281*d289c2baSAndroid Build Coastguard Worker * 282*d289c2baSAndroid Build Coastguard Worker * This is a low-level function to only verify the vbmeta data - you 283*d289c2baSAndroid Build Coastguard Worker * are likely looking for avb_slot_verify() instead for verifying 284*d289c2baSAndroid Build Coastguard Worker * integrity data for a whole set of partitions. 285*d289c2baSAndroid Build Coastguard Worker */ 286*d289c2baSAndroid Build Coastguard Worker AvbVBMetaVerifyResult avb_vbmeta_image_verify( 287*d289c2baSAndroid Build Coastguard Worker const uint8_t* data, 288*d289c2baSAndroid Build Coastguard Worker size_t length, 289*d289c2baSAndroid Build Coastguard Worker const uint8_t** out_public_key_data, 290*d289c2baSAndroid Build Coastguard Worker size_t* out_public_key_length) AVB_ATTR_WARN_UNUSED_RESULT; 291*d289c2baSAndroid Build Coastguard Worker 292*d289c2baSAndroid Build Coastguard Worker #ifdef __cplusplus 293*d289c2baSAndroid Build Coastguard Worker } 294*d289c2baSAndroid Build Coastguard Worker #endif 295*d289c2baSAndroid Build Coastguard Worker 296*d289c2baSAndroid Build Coastguard Worker #endif /* AVB_VBMETA_IMAGE_H_ */ 297