xref: /aosp_15_r20/external/avb/libavb_cert/avb_cert_ops.h (revision d289c2ba6de359471b23d594623b906876bc48a0)
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_CERT_H) && !defined(AVB_COMPILATION)
26*d289c2baSAndroid Build Coastguard Worker #error \
27*d289c2baSAndroid Build Coastguard Worker     "Never include this file directly, include libavb_cert/libavb_cert.h instead."
28*d289c2baSAndroid Build Coastguard Worker #endif
29*d289c2baSAndroid Build Coastguard Worker 
30*d289c2baSAndroid Build Coastguard Worker #ifndef AVB_CERT_OPS_H_
31*d289c2baSAndroid Build Coastguard Worker #define AVB_CERT_OPS_H_
32*d289c2baSAndroid Build Coastguard Worker 
33*d289c2baSAndroid Build Coastguard Worker #include <libavb/libavb.h>
34*d289c2baSAndroid Build Coastguard Worker 
35*d289c2baSAndroid Build Coastguard Worker #include "avb_cert_types.h"
36*d289c2baSAndroid Build Coastguard Worker 
37*d289c2baSAndroid Build Coastguard Worker #ifdef __cplusplus
38*d289c2baSAndroid Build Coastguard Worker extern "C" {
39*d289c2baSAndroid Build Coastguard Worker #endif
40*d289c2baSAndroid Build Coastguard Worker 
41*d289c2baSAndroid Build Coastguard Worker struct AvbCertOps;
42*d289c2baSAndroid Build Coastguard Worker typedef struct AvbCertOps AvbCertOps;
43*d289c2baSAndroid Build Coastguard Worker 
44*d289c2baSAndroid Build Coastguard Worker /* An extension to AvbOps required by avb_cert_validate_vbmeta_public_key(). */
45*d289c2baSAndroid Build Coastguard Worker struct AvbCertOps {
46*d289c2baSAndroid Build Coastguard Worker   /* Operations from libavb. */
47*d289c2baSAndroid Build Coastguard Worker   AvbOps* ops;
48*d289c2baSAndroid Build Coastguard Worker 
49*d289c2baSAndroid Build Coastguard Worker   /* Reads permanent |attributes| data. There are no restrictions on where this
50*d289c2baSAndroid Build Coastguard Worker    * data is stored. On success, returns AVB_IO_RESULT_OK and populates
51*d289c2baSAndroid Build Coastguard Worker    * |attributes|.
52*d289c2baSAndroid Build Coastguard Worker    */
53*d289c2baSAndroid Build Coastguard Worker   AvbIOResult (*read_permanent_attributes)(
54*d289c2baSAndroid Build Coastguard Worker       AvbCertOps* cert_ops, AvbCertPermanentAttributes* attributes);
55*d289c2baSAndroid Build Coastguard Worker 
56*d289c2baSAndroid Build Coastguard Worker   /* Reads a |hash| of permanent attributes. This hash MUST be retrieved from a
57*d289c2baSAndroid Build Coastguard Worker    * permanently read-only location (e.g. fuses) when a device is LOCKED. On
58*d289c2baSAndroid Build Coastguard Worker    * success, returned AVB_IO_RESULT_OK and populates |hash|.
59*d289c2baSAndroid Build Coastguard Worker    */
60*d289c2baSAndroid Build Coastguard Worker   AvbIOResult (*read_permanent_attributes_hash)(
61*d289c2baSAndroid Build Coastguard Worker       AvbCertOps* cert_ops, uint8_t hash[AVB_SHA256_DIGEST_SIZE]);
62*d289c2baSAndroid Build Coastguard Worker 
63*d289c2baSAndroid Build Coastguard Worker   /* Provides the key version of a key used during verification. This may be
64*d289c2baSAndroid Build Coastguard Worker    * useful for managing the minimum key version.
65*d289c2baSAndroid Build Coastguard Worker    */
66*d289c2baSAndroid Build Coastguard Worker   void (*set_key_version)(AvbCertOps* cert_ops,
67*d289c2baSAndroid Build Coastguard Worker                           size_t rollback_index_location,
68*d289c2baSAndroid Build Coastguard Worker                           uint64_t key_version);
69*d289c2baSAndroid Build Coastguard Worker 
70*d289c2baSAndroid Build Coastguard Worker   /* Generates |num_bytes| random bytes and stores them in |output|,
71*d289c2baSAndroid Build Coastguard Worker    * which must point to a buffer large enough to store the bytes.
72*d289c2baSAndroid Build Coastguard Worker    *
73*d289c2baSAndroid Build Coastguard Worker    * Returns AVB_IO_RESULT_OK on success, otherwise an error code.
74*d289c2baSAndroid Build Coastguard Worker    */
75*d289c2baSAndroid Build Coastguard Worker   AvbIOResult (*get_random)(AvbCertOps* cert_ops,
76*d289c2baSAndroid Build Coastguard Worker                             size_t num_bytes,
77*d289c2baSAndroid Build Coastguard Worker                             uint8_t* output);
78*d289c2baSAndroid Build Coastguard Worker };
79*d289c2baSAndroid Build Coastguard Worker 
80*d289c2baSAndroid Build Coastguard Worker #ifdef __cplusplus
81*d289c2baSAndroid Build Coastguard Worker }
82*d289c2baSAndroid Build Coastguard Worker #endif
83*d289c2baSAndroid Build Coastguard Worker 
84*d289c2baSAndroid Build Coastguard Worker #endif /* AVB_CERT_OPS_H_ */
85