xref: /rk3399_rockchip-uboot/include/android_avb/avb_atx_ops.h (revision ab608f806ee1d7fa63a18cc035e8ea62b67634e5)
13ccd4bb0SJason Zhu /*
23ccd4bb0SJason Zhu  * Copyright (C) 2016 The Android Open Source Project
33ccd4bb0SJason Zhu  *
43ccd4bb0SJason Zhu  * Permission is hereby granted, free of charge, to any person
53ccd4bb0SJason Zhu  * obtaining a copy of this software and associated documentation
63ccd4bb0SJason Zhu  * files (the "Software"), to deal in the Software without
73ccd4bb0SJason Zhu  * restriction, including without limitation the rights to use, copy,
83ccd4bb0SJason Zhu  * modify, merge, publish, distribute, sublicense, and/or sell copies
93ccd4bb0SJason Zhu  * of the Software, and to permit persons to whom the Software is
103ccd4bb0SJason Zhu  * furnished to do so, subject to the following conditions:
113ccd4bb0SJason Zhu  *
123ccd4bb0SJason Zhu  * The above copyright notice and this permission notice shall be
133ccd4bb0SJason Zhu  * included in all copies or substantial portions of the Software.
143ccd4bb0SJason Zhu  *
153ccd4bb0SJason Zhu  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
163ccd4bb0SJason Zhu  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
173ccd4bb0SJason Zhu  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
183ccd4bb0SJason Zhu  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
193ccd4bb0SJason Zhu  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
203ccd4bb0SJason Zhu  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
213ccd4bb0SJason Zhu  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
223ccd4bb0SJason Zhu  * SOFTWARE.
233ccd4bb0SJason Zhu  */
243ccd4bb0SJason Zhu 
253ccd4bb0SJason Zhu /*
263ccd4bb0SJason Zhu #if !defined(AVB_INSIDE_LIBAVB_ATX_H) && !defined(AVB_COMPILATION)
273ccd4bb0SJason Zhu #error \
283ccd4bb0SJason Zhu     "Never include this file directly, include libavb_atx/libavb_atx.h instead."
293ccd4bb0SJason Zhu #endif
303ccd4bb0SJason Zhu */
313ccd4bb0SJason Zhu 
323ccd4bb0SJason Zhu #ifndef AVB_ATX_OPS_H_
333ccd4bb0SJason Zhu #define AVB_ATX_OPS_H_
343ccd4bb0SJason Zhu 
353ccd4bb0SJason Zhu #include <android_avb/libavb.h>
363ccd4bb0SJason Zhu 
373ccd4bb0SJason Zhu #include <android_avb/avb_atx_types.h>
383ccd4bb0SJason Zhu 
393ccd4bb0SJason Zhu #ifdef __cplusplus
403ccd4bb0SJason Zhu extern "C" {
413ccd4bb0SJason Zhu #endif
423ccd4bb0SJason Zhu 
433ccd4bb0SJason Zhu struct AvbAtxOps;
443ccd4bb0SJason Zhu typedef struct AvbAtxOps AvbAtxOps;
453ccd4bb0SJason Zhu 
463ccd4bb0SJason Zhu /* An extension to AvbOps required by avb_atx_validate_vbmeta_public_key(). */
473ccd4bb0SJason Zhu struct AvbAtxOps {
483ccd4bb0SJason Zhu   /* Operations from libavb. */
493ccd4bb0SJason Zhu   AvbOps* ops;
503ccd4bb0SJason Zhu 
513ccd4bb0SJason Zhu   /* Reads permanent |attributes| data. There are no restrictions on where this
523ccd4bb0SJason Zhu    * data is stored. On success, returns AVB_IO_RESULT_OK and populates
533ccd4bb0SJason Zhu    * |attributes|.
543ccd4bb0SJason Zhu    */
553ccd4bb0SJason Zhu   AvbIOResult (*read_permanent_attributes)(
563ccd4bb0SJason Zhu       AvbAtxOps* atx_ops, AvbAtxPermanentAttributes* attributes);
573ccd4bb0SJason Zhu 
583ccd4bb0SJason Zhu   /* Reads a |hash| of permanent attributes. This hash MUST be retrieved from a
593ccd4bb0SJason Zhu    * permanently read-only location (e.g. fuses) when a device is LOCKED. On
603ccd4bb0SJason Zhu    * success, returned AVB_IO_RESULT_OK and populates |hash|.
613ccd4bb0SJason Zhu    */
623ccd4bb0SJason Zhu   AvbIOResult (*read_permanent_attributes_hash)(
633ccd4bb0SJason Zhu       AvbAtxOps* atx_ops, uint8_t hash[AVB_SHA256_DIGEST_SIZE]);
6437a7bc39SJason Zhu 
6537a7bc39SJason Zhu   /* Provides the key version of a key used during verification. This may be
6637a7bc39SJason Zhu    * useful for managing the minimum key version.
6737a7bc39SJason Zhu    */
6837a7bc39SJason Zhu   void (*set_key_version)(AvbAtxOps* atx_ops,
6937a7bc39SJason Zhu                           size_t rollback_index_location,
7037a7bc39SJason Zhu                           uint64_t key_version);
71*ab608f80SJason Zhu 
72*ab608f80SJason Zhu   /* Generates |num_bytes| random bytes and stores them in |output|,
73*ab608f80SJason Zhu    * which must point to a buffer large enough to store the bytes.
74*ab608f80SJason Zhu    *
75*ab608f80SJason Zhu    * Returns AVB_IO_RESULT_OK on success, otherwise an error code.
76*ab608f80SJason Zhu    */
77*ab608f80SJason Zhu   AvbIOResult (*get_random)(AvbAtxOps* atx_ops,
78*ab608f80SJason Zhu                             size_t num_bytes,
79*ab608f80SJason Zhu                             uint8_t* output);
803ccd4bb0SJason Zhu };
813ccd4bb0SJason Zhu 
823ccd4bb0SJason Zhu #ifdef __cplusplus
833ccd4bb0SJason Zhu }
843ccd4bb0SJason Zhu #endif
853ccd4bb0SJason Zhu 
863ccd4bb0SJason Zhu #endif /* AVB_ATX_OPS_H_ */
87