xref: /OK3568_Linux_fs/u-boot/include/android_avb/avb_atx_ops.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (C) 2016 The Android Open Source Project
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Permission is hereby granted, free of charge, to any person
5*4882a593Smuzhiyun  * obtaining a copy of this software and associated documentation
6*4882a593Smuzhiyun  * files (the "Software"), to deal in the Software without
7*4882a593Smuzhiyun  * restriction, including without limitation the rights to use, copy,
8*4882a593Smuzhiyun  * modify, merge, publish, distribute, sublicense, and/or sell copies
9*4882a593Smuzhiyun  * of the Software, and to permit persons to whom the Software is
10*4882a593Smuzhiyun  * furnished to do so, subject to the following conditions:
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  * The above copyright notice and this permission notice shall be
13*4882a593Smuzhiyun  * included in all copies or substantial portions of the Software.
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16*4882a593Smuzhiyun  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17*4882a593Smuzhiyun  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18*4882a593Smuzhiyun  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19*4882a593Smuzhiyun  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20*4882a593Smuzhiyun  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21*4882a593Smuzhiyun  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22*4882a593Smuzhiyun  * SOFTWARE.
23*4882a593Smuzhiyun  */
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun /*
26*4882a593Smuzhiyun #if !defined(AVB_INSIDE_LIBAVB_ATX_H) && !defined(AVB_COMPILATION)
27*4882a593Smuzhiyun #error \
28*4882a593Smuzhiyun     "Never include this file directly, include libavb_atx/libavb_atx.h instead."
29*4882a593Smuzhiyun #endif
30*4882a593Smuzhiyun */
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun #ifndef AVB_ATX_OPS_H_
33*4882a593Smuzhiyun #define AVB_ATX_OPS_H_
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun #include <android_avb/libavb.h>
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun #include <android_avb/avb_atx_types.h>
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun #ifdef __cplusplus
40*4882a593Smuzhiyun extern "C" {
41*4882a593Smuzhiyun #endif
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun struct AvbAtxOps;
44*4882a593Smuzhiyun typedef struct AvbAtxOps AvbAtxOps;
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun /* An extension to AvbOps required by avb_atx_validate_vbmeta_public_key(). */
47*4882a593Smuzhiyun struct AvbAtxOps {
48*4882a593Smuzhiyun   /* Operations from libavb. */
49*4882a593Smuzhiyun   AvbOps* ops;
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun   /* Reads permanent |attributes| data. There are no restrictions on where this
52*4882a593Smuzhiyun    * data is stored. On success, returns AVB_IO_RESULT_OK and populates
53*4882a593Smuzhiyun    * |attributes|.
54*4882a593Smuzhiyun    */
55*4882a593Smuzhiyun   AvbIOResult (*read_permanent_attributes)(
56*4882a593Smuzhiyun       AvbAtxOps* atx_ops, AvbAtxPermanentAttributes* attributes);
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun   /* Reads a |hash| of permanent attributes. This hash MUST be retrieved from a
59*4882a593Smuzhiyun    * permanently read-only location (e.g. fuses) when a device is LOCKED. On
60*4882a593Smuzhiyun    * success, returned AVB_IO_RESULT_OK and populates |hash|.
61*4882a593Smuzhiyun    */
62*4882a593Smuzhiyun   AvbIOResult (*read_permanent_attributes_hash)(
63*4882a593Smuzhiyun       AvbAtxOps* atx_ops, uint8_t hash[AVB_SHA256_DIGEST_SIZE]);
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun   /* Provides the key version of a key used during verification. This may be
66*4882a593Smuzhiyun    * useful for managing the minimum key version.
67*4882a593Smuzhiyun    */
68*4882a593Smuzhiyun   void (*set_key_version)(AvbAtxOps* atx_ops,
69*4882a593Smuzhiyun                           size_t rollback_index_location,
70*4882a593Smuzhiyun                           uint64_t key_version);
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun   /* Generates |num_bytes| random bytes and stores them in |output|,
73*4882a593Smuzhiyun    * which must point to a buffer large enough to store the bytes.
74*4882a593Smuzhiyun    *
75*4882a593Smuzhiyun    * Returns AVB_IO_RESULT_OK on success, otherwise an error code.
76*4882a593Smuzhiyun    */
77*4882a593Smuzhiyun   AvbIOResult (*get_random)(AvbAtxOps* atx_ops,
78*4882a593Smuzhiyun                             size_t num_bytes,
79*4882a593Smuzhiyun                             uint8_t* output);
80*4882a593Smuzhiyun };
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun #ifdef __cplusplus
83*4882a593Smuzhiyun }
84*4882a593Smuzhiyun #endif
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun #endif /* AVB_ATX_OPS_H_ */
87