121e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen/*
221e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * Copyright (C) 2016 The Android Open Source Project
321e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen *
4c612e2e353444f6ad714e43702c2afd057516254David Zeuthen * Permission is hereby granted, free of charge, to any person
5c612e2e353444f6ad714e43702c2afd057516254David Zeuthen * obtaining a copy of this software and associated documentation
6c612e2e353444f6ad714e43702c2afd057516254David Zeuthen * files (the "Software"), to deal in the Software without
7c612e2e353444f6ad714e43702c2afd057516254David Zeuthen * restriction, including without limitation the rights to use, copy,
8c612e2e353444f6ad714e43702c2afd057516254David Zeuthen * modify, merge, publish, distribute, sublicense, and/or sell copies
9c612e2e353444f6ad714e43702c2afd057516254David Zeuthen * of the Software, and to permit persons to whom the Software is
10c612e2e353444f6ad714e43702c2afd057516254David Zeuthen * furnished to do so, subject to the following conditions:
1121e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen *
12c612e2e353444f6ad714e43702c2afd057516254David Zeuthen * The above copyright notice and this permission notice shall be
13c612e2e353444f6ad714e43702c2afd057516254David Zeuthen * included in all copies or substantial portions of the Software.
1421e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen *
15c612e2e353444f6ad714e43702c2afd057516254David Zeuthen * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16c612e2e353444f6ad714e43702c2afd057516254David Zeuthen * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17c612e2e353444f6ad714e43702c2afd057516254David Zeuthen * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18c612e2e353444f6ad714e43702c2afd057516254David Zeuthen * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19c612e2e353444f6ad714e43702c2afd057516254David Zeuthen * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20c612e2e353444f6ad714e43702c2afd057516254David Zeuthen * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21c612e2e353444f6ad714e43702c2afd057516254David Zeuthen * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22c612e2e353444f6ad714e43702c2afd057516254David Zeuthen * SOFTWARE.
2321e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen */
2421e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen
2521e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen#if !defined(AVB_INSIDE_LIBAVB_H) && !defined(AVB_COMPILATION)
2621e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen#error "Never include this file directly, include libavb.h instead."
2721e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen#endif
2821e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen
2921e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen#ifndef AVB_SLOT_VERIFY_H_
3021e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen#define AVB_SLOT_VERIFY_H_
3121e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen
3221e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen#include "avb_ops.h"
3321e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen#include "avb_vbmeta_image.h"
3421e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen
3521e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen#ifdef __cplusplus
3621e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthenextern "C" {
3721e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen#endif
3821e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen
3921e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen/* Return codes used in avb_slot_verify(), see that function for
4021e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * documentation for each field.
418b6973be7468f5c0db42ff8fcd91f8e97a345a27David Zeuthen *
428b6973be7468f5c0db42ff8fcd91f8e97a345a27David Zeuthen * Use avb_slot_verify_result_to_string() to get a textual
438b6973be7468f5c0db42ff8fcd91f8e97a345a27David Zeuthen * representation usable for error/debug output.
4421e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen */
4521e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthentypedef enum {
4621e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen  AVB_SLOT_VERIFY_RESULT_OK,
4721e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen  AVB_SLOT_VERIFY_RESULT_ERROR_OOM,
4821e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen  AVB_SLOT_VERIFY_RESULT_ERROR_IO,
4921e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen  AVB_SLOT_VERIFY_RESULT_ERROR_VERIFICATION,
5021e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen  AVB_SLOT_VERIFY_RESULT_ERROR_ROLLBACK_INDEX,
5121e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen  AVB_SLOT_VERIFY_RESULT_ERROR_PUBLIC_KEY_REJECTED,
52e3cadcacd798effe83b1593dba1ee0e3d84cf6e4David Zeuthen  AVB_SLOT_VERIFY_RESULT_ERROR_INVALID_METADATA,
53e3cadcacd798effe83b1593dba1ee0e3d84cf6e4David Zeuthen  AVB_SLOT_VERIFY_RESULT_ERROR_UNSUPPORTED_VERSION
5421e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen} AvbSlotVerifyResult;
5521e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen
568b6973be7468f5c0db42ff8fcd91f8e97a345a27David Zeuthen/* Get a textual representation of |result|. */
578b6973be7468f5c0db42ff8fcd91f8e97a345a27David Zeuthenconst char* avb_slot_verify_result_to_string(AvbSlotVerifyResult result);
588b6973be7468f5c0db42ff8fcd91f8e97a345a27David Zeuthen
59baf59e232e48d0111e4b38f74c60c89e6f8f0b14David Zeuthen/* Maximum number of rollback index locations supported. */
6040ee1da883c634ce94bb69e97a52598f8fbc151dDavid Zeuthen#define AVB_MAX_NUMBER_OF_ROLLBACK_INDEX_LOCATIONS 32
6121e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen
62a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen/* AvbPartitionData contains data loaded from partitions when using
63a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen * avb_slot_verify(). The |partition_name| field contains the name of
648681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen * the partition (without A/B suffix), |data| points to the loaded
658681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen * data which is |data_size| bytes long.
66a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen *
67a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen * Note that this is strictly less than the partition size - it's only
68a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen * the image stored there, not the entire partition nor any of the
69a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen * metadata.
70a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen */
71a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthentypedef struct {
72a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen  char* partition_name;
73a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen  uint8_t* data;
74a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen  size_t data_size;
75a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen} AvbPartitionData;
76a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen
778681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen/* AvbVBMetaData contains a vbmeta struct loaded from a partition when
788681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen * using avb_slot_verify(). The |partition_name| field contains the
798681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen * name of the partition (without A/B suffix), |vbmeta_data| points to
808681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen * the loaded data which is |vbmeta_size| bytes long.
818681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen *
828681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen * The |verify_result| field contains the result of
838681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen * avb_vbmeta_image_verify() on the data. This is guaranteed to be
848681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen * AVB_VBMETA_VERIFY_RESULT_OK for all vbmeta images if
858681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen * avb_slot_verify() returns AVB_SLOT_VERIFY_RESULT_OK.
868681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen *
878681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen * You can use avb_descriptor_get_all(), avb_descriptor_foreach(), and
888681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen * avb_vbmeta_image_header_to_host_byte_order() with this data.
898681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen */
908681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthentypedef struct {
918681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen  char* partition_name;
928681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen  uint8_t* vbmeta_data;
938681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen  size_t vbmeta_size;
948681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen  AvbVBMetaVerifyResult verify_result;
958681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen} AvbVBMetaData;
968681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen
9721e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen/* AvbSlotVerifyData contains data needed to boot a particular slot
9821e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * and is returned by avb_slot_verify() if partitions in a slot are
9921e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * successfully verified.
10021e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen *
101a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen * All data pointed to by this struct - including data in each item in
102a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen * the |partitions| array - will be freed when the
10321e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * avb_slot_verify_data_free() function is called.
10421e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen *
1058b6973be7468f5c0db42ff8fcd91f8e97a345a27David Zeuthen * The |ab_suffix| field is the copy of the of |ab_suffix| field
1068b6973be7468f5c0db42ff8fcd91f8e97a345a27David Zeuthen * passed to avb_slot_verify(). It is the A/B suffix of the slot.
1078b6973be7468f5c0db42ff8fcd91f8e97a345a27David Zeuthen *
1088681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen * The VBMeta images that were checked are available in the
1098681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen * |vbmeta_images| field. The field |num_vbmeta_images| contains the
1108681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen * number of elements in this array. The first element -
111a5fd3a4b5617b75ce5666e1bfd38be578e865e1fDavid Zeuthen * vbmeta_images[0] - is guaranteed to be from the partition with the
112a5fd3a4b5617b75ce5666e1bfd38be578e865e1fDavid Zeuthen * top-level vbmeta struct. This is usually the "vbmeta" partition in
113a5fd3a4b5617b75ce5666e1bfd38be578e865e1fDavid Zeuthen * the requested slot but if there is no "vbmeta" partition it can
114a5fd3a4b5617b75ce5666e1bfd38be578e865e1fDavid Zeuthen * also be the "boot" partition.
1158681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen *
116a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen * The partitions loaded and verified from from the slot are
117a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen * accessible in the |loaded_partitions| array. The field
118a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen * |num_loaded_partitions| contains the number of elements in this
119a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen * array. The order of partitions in this array may not necessarily be
120a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen * the same order as in the passed-in |requested_partitions| array.
12121e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen *
122baf59e232e48d0111e4b38f74c60c89e6f8f0b14David Zeuthen * Rollback indexes for the verified slot are stored in the
123baf59e232e48d0111e4b38f74c60c89e6f8f0b14David Zeuthen * |rollback_indexes| field. Note that avb_slot_verify() will NEVER
124baf59e232e48d0111e4b38f74c60c89e6f8f0b14David Zeuthen * modify stored_rollback_index[n] locations e.g. it will never use
125baf59e232e48d0111e4b38f74c60c89e6f8f0b14David Zeuthen * the write_rollback_index() AvbOps operation. Instead it is the job
126baf59e232e48d0111e4b38f74c60c89e6f8f0b14David Zeuthen * of the caller of avb_slot_verify() to do this based on e.g. A/B
127baf59e232e48d0111e4b38f74c60c89e6f8f0b14David Zeuthen * policy and other factors. See libavb_ab/avb_ab_flow.c for an
128baf59e232e48d0111e4b38f74c60c89e6f8f0b14David Zeuthen * example of how to do this.
12921e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen *
13021e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * The |cmdline| field is a NUL-terminated string in UTF-8 resulting
13121e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * from concatenating all |AvbKernelCmdlineDescriptor| and then
13221e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * performing proper substitution of the variables
13357ac06e6e4fae29eb616613eb2e2623d79230290David Zeuthen * $(ANDROID_SYSTEM_PARTUUID), $(ANDROID_BOOT_PARTUUID), and
13457ac06e6e4fae29eb616613eb2e2623d79230290David Zeuthen * $(ANDROID_VBMETA_PARTUUID) using the
13521e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * get_unique_guid_for_partition() operation in |AvbOps|.
13621e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen *
13721e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * Additionally, the |cmdline| field will have the following kernel
13821e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * command-line options set:
13921e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen *
1408681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen *   androidboot.vbmeta.device_state: set to "locked" or "unlocked"
14121e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen *   depending on the result of the result of AvbOps's
14221e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen *   read_is_unlocked() function.
14321e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen *
14421e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen *   androidboot.vbmeta.{hash_alg, size, digest}: Will be set to
1458681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen *   the digest of all images in |vbmeta_images|.
146a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen *
14757ac06e6e4fae29eb616613eb2e2623d79230290David Zeuthen *   androidboot.vbmeta.device: This is set to the value
14857ac06e6e4fae29eb616613eb2e2623d79230290David Zeuthen *   PARTUUID=$(ANDROID_VBMETA_PARTUUID) before substitution so it
14957ac06e6e4fae29eb616613eb2e2623d79230290David Zeuthen *   will end up pointing to the vbmeta partition for the verified
150a5fd3a4b5617b75ce5666e1bfd38be578e865e1fDavid Zeuthen *   slot. If there is no vbmeta partition it will point to the boot
151a5fd3a4b5617b75ce5666e1bfd38be578e865e1fDavid Zeuthen *   partition of the verified slot.
15257ac06e6e4fae29eb616613eb2e2623d79230290David Zeuthen *
153e3cadcacd798effe83b1593dba1ee0e3d84cf6e4David Zeuthen *   androidboot.vbmeta.avb_version: This is set to the decimal value
154e3cadcacd798effe83b1593dba1ee0e3d84cf6e4David Zeuthen *   of AVB_VERSION_MAJOR followed by a dot followed by the decimal
155e3cadcacd798effe83b1593dba1ee0e3d84cf6e4David Zeuthen *   value of AVB_VERSION_MINOR, for example "1.0" or "1.4". This
156e3cadcacd798effe83b1593dba1ee0e3d84cf6e4David Zeuthen *   version number represents the vbmeta file format version
157e3cadcacd798effe83b1593dba1ee0e3d84cf6e4David Zeuthen *   supported by libavb copy used in the boot loader. This is not
158e3cadcacd798effe83b1593dba1ee0e3d84cf6e4David Zeuthen *   necessarily the same version number of the on-disk metadata for
159e3cadcacd798effe83b1593dba1ee0e3d84cf6e4David Zeuthen *   the slot that was verified.
160bc41cead048a90f63e3dd4335097c5588ec09345David Zeuthen *
16119c38437eb77101ac30b29135cca58fbc684eaceDavid Zeuthen * Note that androidboot.slot_suffix is not set in |cmdline| - you
162bc41cead048a90f63e3dd4335097c5588ec09345David Zeuthen * will have to pass this command-line option yourself.
16319c38437eb77101ac30b29135cca58fbc684eaceDavid Zeuthen *
164a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen * This struct may grow in the future without it being considered an
165a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen * ABI break.
16621e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen */
16721e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthentypedef struct {
1688b6973be7468f5c0db42ff8fcd91f8e97a345a27David Zeuthen  char* ab_suffix;
1698681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen  AvbVBMetaData* vbmeta_images;
1708681a33e249cb68c5159ebccb50b55c56867fcdfDavid Zeuthen  size_t num_vbmeta_images;
171a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen  AvbPartitionData* loaded_partitions;
172a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen  size_t num_loaded_partitions;
17321e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen  char* cmdline;
17440ee1da883c634ce94bb69e97a52598f8fbc151dDavid Zeuthen  uint64_t rollback_indexes[AVB_MAX_NUMBER_OF_ROLLBACK_INDEX_LOCATIONS];
17521e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen} AvbSlotVerifyData;
17621e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen
17721e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen/* Frees a |AvbSlotVerifyData| including all data it points to. */
17821e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthenvoid avb_slot_verify_data_free(AvbSlotVerifyData* data);
17921e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen
180a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen/* Performs a full verification of the slot identified by |ab_suffix|
181a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen * and load the contents of the partitions whose name is in the
182a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen * NULL-terminated string array |requested_partitions| (each partition
183a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen * must use hash verification). If not using A/B, pass an empty string
184a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen * (e.g. "", not NULL) for |ab_suffix|.
185a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen *
186a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen * Typically the |requested_partitions| array only contains a single
187a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen * item for the boot partition, 'boot'.
18821e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen *
189a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen * Verification includes loading data from the 'vbmeta', all hash
190a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen * partitions, and possibly other partitions (with |ab_suffix|
191a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen * appended), inspecting rollback indexes, and checking if the public
192a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen * key used to sign the data is acceptable. The functions in |ops|
193a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen * will be used to do this.
19421e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen *
19521e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * If |out_data| is not NULL, it will be set to a newly allocated
19621e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * |AvbSlotVerifyData| struct containing all the data needed to
19721e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * actually boot the slot. This data structure should be freed with
1980155e6b158bdc5b3a442f16a5dc124d5dee9c71cDavid Zeuthen * avb_slot_verify_data_free() when you are done with it. See below
1990155e6b158bdc5b3a442f16a5dc124d5dee9c71cDavid Zeuthen * for when this is returned.
2000155e6b158bdc5b3a442f16a5dc124d5dee9c71cDavid Zeuthen *
2010155e6b158bdc5b3a442f16a5dc124d5dee9c71cDavid Zeuthen * If |allow_verification_error| is false this function will bail out
2020155e6b158bdc5b3a442f16a5dc124d5dee9c71cDavid Zeuthen * as soon as an error is encountered and |out_data| is set only if
2030155e6b158bdc5b3a442f16a5dc124d5dee9c71cDavid Zeuthen * AVB_SLOT_VERIFY_RESULT_OK is returned.
2040155e6b158bdc5b3a442f16a5dc124d5dee9c71cDavid Zeuthen *
2050155e6b158bdc5b3a442f16a5dc124d5dee9c71cDavid Zeuthen * Otherwise if |allow_verification_error| is true the function will
2060155e6b158bdc5b3a442f16a5dc124d5dee9c71cDavid Zeuthen * continue verification efforts and |out_data| is also set if
2070155e6b158bdc5b3a442f16a5dc124d5dee9c71cDavid Zeuthen * AVB_SLOT_VERIFY_RESULT_ERROR_PUBLIC_KEY_REJECTED,
2080155e6b158bdc5b3a442f16a5dc124d5dee9c71cDavid Zeuthen * AVB_SLOT_VERIFY_RESULT_ERROR_VERIFICATION, or
2090155e6b158bdc5b3a442f16a5dc124d5dee9c71cDavid Zeuthen * AVB_SLOT_VERIFY_RESULT_ERROR_ROLLBACK_INDEX is returned. It is
2100155e6b158bdc5b3a442f16a5dc124d5dee9c71cDavid Zeuthen * undefined which error is returned if more than one distinct error
2110155e6b158bdc5b3a442f16a5dc124d5dee9c71cDavid Zeuthen * is encountered. It is guaranteed that AVB_SLOT_VERIFY_RESULT_OK is
2120155e6b158bdc5b3a442f16a5dc124d5dee9c71cDavid Zeuthen * returned if, and only if, there are no errors. This mode is needed
2130155e6b158bdc5b3a442f16a5dc124d5dee9c71cDavid Zeuthen * to boot valid but unverified slots when the device is unlocked.
2140155e6b158bdc5b3a442f16a5dc124d5dee9c71cDavid Zeuthen *
2150155e6b158bdc5b3a442f16a5dc124d5dee9c71cDavid Zeuthen * Also note that |out_data| is never set if
2160155e6b158bdc5b3a442f16a5dc124d5dee9c71cDavid Zeuthen * AVB_SLOT_VERIFY_RESULT_ERROR_OOM, AVB_SLOT_VERIFY_RESULT_ERROR_IO,
2170155e6b158bdc5b3a442f16a5dc124d5dee9c71cDavid Zeuthen * or AVB_SLOT_VERIFY_RESULT_ERROR_INVALID_METADATA is returned.
21821e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen *
21921e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * AVB_SLOT_VERIFY_RESULT_OK is returned if everything is verified
22021e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * correctly and all public keys are accepted.
22121e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen *
22221e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * AVB_SLOT_VERIFY_RESULT_ERROR_PUBLIC_KEY_REJECTED is returned if
22321e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * everything is verified correctly out but one or more public keys
22421e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * are not accepted. This includes the case where integrity data is
22521e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * not signed.
22621e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen *
22721e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * AVB_SLOT_VERIFY_RESULT_ERROR_OOM is returned if unable to
22821e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * allocate memory.
22921e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen *
23021e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * AVB_SLOT_VERIFY_RESULT_ERROR_IO is returned if an I/O error
23121e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * occurred while trying to load data or get a rollback index.
23221e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen *
23321e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * AVB_SLOT_VERIFY_RESULT_ERROR_VERIFICATION is returned if the data
23421e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * did not verify, e.g. the digest didn't match or signature checks
23521e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * failed.
23621e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen *
23721e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * AVB_SLOT_VERIFY_RESULT_ERROR_ROLLBACK_INDEX is returned if a
23821e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * rollback index was less than its stored value.
23921e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen *
24021e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * AVB_SLOT_VERIFY_RESULT_ERROR_INVALID_METADATA is returned if some
24121e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen * of the metadata is invalid or inconsistent.
242e3cadcacd798effe83b1593dba1ee0e3d84cf6e4David Zeuthen *
243e3cadcacd798effe83b1593dba1ee0e3d84cf6e4David Zeuthen * AVB_SLOT_VERIFY_RESULT_ERROR_UNSUPPORTED_VERSION is returned if
244e3cadcacd798effe83b1593dba1ee0e3d84cf6e4David Zeuthen * some of the metadata requires a newer version of libavb than what
245e3cadcacd798effe83b1593dba1ee0e3d84cf6e4David Zeuthen * is in use.
24621e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen */
247a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David ZeuthenAvbSlotVerifyResult avb_slot_verify(AvbOps* ops,
248a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen                                    const char* const* requested_partitions,
249a8bb9a0e8635e3562367ebfe89b1870b4e2cc8e2David Zeuthen                                    const char* ab_suffix,
2500155e6b158bdc5b3a442f16a5dc124d5dee9c71cDavid Zeuthen                                    bool allow_verification_error,
25121e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen                                    AvbSlotVerifyData** out_data);
25221e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen
25321e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen#ifdef __cplusplus
25421e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen}
25521e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen#endif
25621e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen
25721e95266704e572ced1c633bbc4aea9f42afa0a5David Zeuthen#endif /* AVB_SLOT_VERIFY_H_ */
258