Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
u-boot-imx
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
arm-boot
u-boot-imx
Commits
71dc860a
Commit
71dc860a
authored
Apr 27, 2017
by
fang hui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MA-9530-2 [iot] Revet avb in uboot
Revert "libavb: upgrade avb" This reverts commit
94734eec
. Change-Id: I6eae3fa9579fb43fa6956c450011b230875d0a96
parent
4dc1d71d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
37 changed files
with
270 additions
and
948 deletions
+270
-948
f_fastboot.c
drivers/usb/gadget/f_fastboot.c
+16
-26
fsl_avb.h
include/fsl_avb.h
+0
-2
fsl_avbkey.c
lib/avb/fsl/fsl_avbkey.c
+4
-6
fsl_avbkey.h
lib/avb/fsl/fsl_avbkey.h
+1
-1
avb_chain_partition_descriptor.c
lib/avb/libavb/avb_chain_partition_descriptor.c
+3
-3
avb_chain_partition_descriptor.h
lib/avb/libavb/avb_chain_partition_descriptor.h
+2
-2
avb_crc32.c
lib/avb/libavb/avb_crc32.c
+3
-4
avb_crypto.c
lib/avb/libavb/avb_crypto.c
+0
-0
avb_crypto.h
lib/avb/libavb/avb_crypto.h
+0
-28
avb_descriptor.c
lib/avb/libavb/avb_descriptor.c
+5
-6
avb_descriptor.h
lib/avb/libavb/avb_descriptor.h
+4
-6
avb_footer.c
lib/avb/libavb/avb_footer.c
+1
-1
avb_footer.h
lib/avb/libavb/avb_footer.h
+3
-3
avb_kernel_cmdline_descriptor.c
lib/avb/libavb/avb_kernel_cmdline_descriptor.c
+0
-1
avb_kernel_cmdline_descriptor.h
lib/avb/libavb/avb_kernel_cmdline_descriptor.h
+0
-19
avb_ops.h
lib/avb/libavb/avb_ops.h
+16
-53
avb_property_descriptor.c
lib/avb/libavb/avb_property_descriptor.c
+14
-32
avb_property_descriptor.h
lib/avb/libavb/avb_property_descriptor.h
+6
-12
avb_rsa.c
lib/avb/libavb/avb_rsa.c
+16
-44
avb_rsa.h
lib/avb/libavb/avb_rsa.h
+12
-7
avb_sha.h
lib/avb/libavb/avb_sha.h
+5
-1
avb_sha256.c
lib/avb/libavb/avb_sha256.c
+4
-10
avb_sha512.c
lib/avb/libavb/avb_sha512.c
+8
-16
avb_slot_verify.c
lib/avb/libavb/avb_slot_verify.c
+0
-0
avb_slot_verify.h
lib/avb/libavb/avb_slot_verify.h
+20
-82
avb_sysdeps.h
lib/avb/libavb/avb_sysdeps.h
+9
-13
avb_sysdeps_posix.c
lib/avb/libavb/avb_sysdeps_posix.c
+0
-78
avb_util.c
lib/avb/libavb/avb_util.c
+10
-94
avb_util.h
lib/avb/libavb/avb_util.h
+34
-79
avb_vbmeta_image.c
lib/avb/libavb/avb_vbmeta_image.c
+0
-0
avb_vbmeta_image.h
lib/avb/libavb/avb_vbmeta_image.h
+25
-75
avb_version.c
lib/avb/libavb/avb_version.c
+0
-34
avb_version.h
lib/avb/libavb/avb_version.h
+0
-63
libavb.h
lib/avb/libavb/libavb.h
+0
-1
avb_ab_flow.c
lib/avb/libavb_ab/avb_ab_flow.c
+38
-107
avb_ab_flow.h
lib/avb/libavb_ab/avb_ab_flow.h
+8
-35
avb_ab_ops.h
lib/avb/libavb_ab/avb_ab_ops.h
+3
-4
No files found.
drivers/usb/gadget/f_fastboot.c
View file @
71dc860a
...
...
@@ -1822,26 +1822,6 @@ void board_fastboot_setup(void) \
__attribute__
((
weak
,
alias
(
"__def_fastboot_setup"
)));
#if defined(CONFIG_AVB_SUPPORT) && defined(CONFIG_MMC)
static
AvbABOps
fsl_avb_ab_ops
=
{
.
read_ab_metadata
=
fsl_read_ab_metadata
,
.
write_ab_metadata
=
fsl_write_ab_metadata
,
.
ops
=
NULL
};
static
AvbOps
fsl_avb_ops
=
{
.
ab_ops
=
&
fsl_avb_ab_ops
,
.
read_from_partition
=
fsl_read_from_partition_multi
,
.
write_to_partition
=
fsl_write_to_partition
,
.
validate_vbmeta_public_key
=
fsl_validate_vbmeta_public_key_rpmb
,
.
read_rollback_index
=
fsl_read_rollback_index_rpmb
,
.
write_rollback_index
=
fsl_write_rollback_index_rpmb
,
.
read_is_device_unlocked
=
fsl_read_is_device_unlocked
,
.
get_unique_guid_for_partition
=
fsl_get_unique_guid_for_partition
};
#endif
void
fastboot_setup
(
void
)
{
struct
tag_serialnr
serialnr
;
...
...
@@ -1861,10 +1841,6 @@ void fastboot_setup(void)
_fastboot_load_partitions
();
parameters_setup
();
#ifdef CONFIG_AVB_SUPPORT
fsl_avb_ab_ops
.
ops
=
&
fsl_avb_ops
;
#endif
}
/* Write the bcb with fastboot bootloader commands */
...
...
@@ -2011,6 +1987,20 @@ bootimg_print_image_hdr(struct andr_img_hdr *hdr)
static
struct
andr_img_hdr
boothdr
__aligned
(
ARCH_DMA_MINALIGN
);
#if defined(CONFIG_AVB_SUPPORT) && defined(CONFIG_MMC)
static
AvbABOps
fsl_avb_ab_ops
=
{
.
ops
=
{
.
read_from_partition
=
fsl_read_from_partition_multi
,
.
write_to_partition
=
fsl_write_to_partition
,
.
validate_vbmeta_public_key
=
fsl_validate_vbmeta_public_key_rpmb
,
.
read_rollback_index
=
fsl_read_rollback_index_rpmb
,
.
write_rollback_index
=
fsl_write_rollback_index_rpmb
,
.
read_is_device_unlocked
=
fsl_read_is_device_unlocked
,
.
get_unique_guid_for_partition
=
fsl_get_unique_guid_for_partition
},
.
read_ab_metadata
=
fsl_read_ab_metadata
,
.
write_ab_metadata
=
fsl_write_ab_metadata
};
/* we can use avb to verify Trusty if we want */
const
char
*
requested_partitions
[]
=
{
"boot"
,
0
};
...
...
@@ -2024,6 +2014,7 @@ int do_boota(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) {
AvbABFlowResult
avb_result
;
AvbSlotVerifyData
*
avb_out_data
;
AvbPartitionData
*
avb_loadpart
;
AvbOps
fsl_avb_ops
=
fsl_avb_ab_ops
.
ops
;
#ifdef CONFIG_FASTBOOT_LOCK
/* check lock state */
...
...
@@ -2033,9 +2024,8 @@ int do_boota(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) {
fastboot_set_lock_stat
(
FASTBOOT_LOCK
);
lock_status
=
FASTBOOT_LOCK
;
}
bool
allow_fail
=
(
lock_status
==
FASTBOOT_UNLOCK
?
true
:
false
);
/* if in lock state, do avb verify */
avb_result
=
avb_ab_flow
(
&
fsl_avb_ab_ops
,
requested_partitions
,
allow_fail
,
&
avb_out_data
);
avb_result
=
avb_ab_flow
(
&
fsl_avb_ab_ops
,
requested_partitions
,
&
avb_out_data
);
if
(
avb_result
==
AVB_AB_FLOW_RESULT_OK
)
{
assert
(
avb_out_data
!=
NULL
);
/* load the first partition */
...
...
include/fsl_avb.h
View file @
71dc860a
...
...
@@ -88,8 +88,6 @@ AvbIOResult fsl_write_ab_metadata(AvbABOps* ab_ops, const struct AvbABData* data
AvbIOResult
fsl_validate_vbmeta_public_key_rpmb
(
AvbOps
*
ops
,
const
uint8_t
*
public_key_data
,
size_t
public_key_length
,
const
uint8_t
*
public_key_metadata
,
size_t
public_key_metadata_length
,
bool
*
out_is_trusted
);
/* Gets the rollback index corresponding to the slot given by
...
...
lib/avb/fsl/fsl_avbkey.c
View file @
71dc860a
...
...
@@ -405,7 +405,7 @@ int rbkidx_erase(void) {
return
-
1
;
memset
(
rbidx
,
0
,
rbidx_len
);
*
(
uint64_t
*
)
rbidx
=
AVB_RBIDX_INITVAL
;
for
(
i
=
0
;
i
<
AVB_MAX_NUMBER_OF_ROLLBACK_INDEX_
LOCATION
S
;
i
++
)
{
for
(
i
=
0
;
i
<
AVB_MAX_NUMBER_OF_ROLLBACK_INDEX_
SLOT
S
;
i
++
)
{
tag
=
&
hdr
.
rbk_tags
[
i
];
tag
->
flag
=
AVB_RBIDX_FLAG
;
tag
->
offset
=
offset
;
...
...
@@ -490,7 +490,7 @@ int avbkey_init(uint8_t *plainkey, uint32_t keylen) {
return
-
1
;
memset
(
rbidx
,
0
,
rbidx_len
);
*
(
uint64_t
*
)
rbidx
=
AVB_RBIDX_INITVAL
;
for
(
i
=
0
;
i
<
AVB_MAX_NUMBER_OF_ROLLBACK_INDEX_
LOCATION
S
;
i
++
)
{
for
(
i
=
0
;
i
<
AVB_MAX_NUMBER_OF_ROLLBACK_INDEX_
SLOT
S
;
i
++
)
{
tag
=
&
hdr
.
rbk_tags
[
i
];
tag
->
flag
=
AVB_RBIDX_FLAG
;
tag
->
offset
=
offset
;
...
...
@@ -525,8 +525,6 @@ int avbkey_init(uint8_t *plainkey, uint32_t keylen) {
AvbIOResult
fsl_validate_vbmeta_public_key_rpmb
(
AvbOps
*
ops
,
const
uint8_t
*
public_key_data
,
size_t
public_key_length
,
const
uint8_t
*
public_key_metadata
,
size_t
public_key_metadata_length
,
bool
*
out_is_trusted
)
{
kblb_hdr_t
hdr
;
kblb_tag_t
*
pubk
;
...
...
@@ -611,7 +609,7 @@ AvbIOResult fsl_read_rollback_index_rpmb(AvbOps* ops, size_t rollback_index_slot
DEBUGAVB
(
"[rpmb] read rollback slot: %zu
\n
"
,
rollback_index_slot
);
if
(
rollback_index_slot
>=
AVB_MAX_NUMBER_OF_ROLLBACK_INDEX_
LOCATION
S
)
if
(
rollback_index_slot
>=
AVB_MAX_NUMBER_OF_ROLLBACK_INDEX_
SLOT
S
)
return
AVB_IO_RESULT_ERROR_IO
;
if
((
mmc_dev
=
get_mmc
())
==
NULL
)
{
...
...
@@ -678,7 +676,7 @@ AvbIOResult fsl_write_rollback_index_rpmb(AvbOps* ops, size_t rollback_index_slo
assert
(
ops
!=
NULL
);
if
(
rollback_index_slot
>=
AVB_MAX_NUMBER_OF_ROLLBACK_INDEX_
LOCATION
S
)
if
(
rollback_index_slot
>=
AVB_MAX_NUMBER_OF_ROLLBACK_INDEX_
SLOT
S
)
return
AVB_IO_RESULT_ERROR_IO
;
if
((
mmc_dev
=
get_mmc
())
==
NULL
)
{
...
...
lib/avb/fsl/fsl_avbkey.h
View file @
71dc860a
...
...
@@ -37,7 +37,7 @@ struct kblb_hdr {
/* public key keyblb tag */
kblb_tag_t
pubk_tag
;
/* rollback index keyblb tag */
kblb_tag_t
rbk_tags
[
AVB_MAX_NUMBER_OF_ROLLBACK_INDEX_
LOCATION
S
];
kblb_tag_t
rbk_tags
[
AVB_MAX_NUMBER_OF_ROLLBACK_INDEX_
SLOT
S
];
};
typedef
struct
kblb_hdr
kblb_hdr_t
;
...
...
lib/avb/libavb/avb_chain_partition_descriptor.c
View file @
71dc860a
...
...
@@ -40,12 +40,12 @@ bool avb_chain_partition_descriptor_validate_and_byteswap(
return
false
;
}
dest
->
rollback_index_
location
=
avb_be32toh
(
dest
->
rollback_index_location
);
dest
->
rollback_index_
slot
=
avb_be32toh
(
dest
->
rollback_index_slot
);
dest
->
partition_name_len
=
avb_be32toh
(
dest
->
partition_name_len
);
dest
->
public_key_len
=
avb_be32toh
(
dest
->
public_key_len
);
if
(
dest
->
rollback_index_
location
<
1
)
{
avb_error
(
"Invalid rollback index
location
value.
\n
"
);
if
(
dest
->
rollback_index_
slot
<
1
)
{
avb_error
(
"Invalid rollback index
slot
value.
\n
"
);
return
false
;
}
...
...
lib/avb/libavb/avb_chain_partition_descriptor.h
View file @
71dc860a
...
...
@@ -38,7 +38,7 @@ extern "C" {
/* A descriptor containing a pointer to signed integrity data stored
* on another partition. The descriptor contains the partition name in
* question (without the A/B suffix), the public key used to sign the
* integrity data, and rollback index
location
to use for rollback
* integrity data, and rollback index
slot
to use for rollback
* protection.
*
* Following this struct are |partition_name_len| bytes of the
...
...
@@ -50,7 +50,7 @@ extern "C" {
*/
typedef
struct
AvbChainPartitionDescriptor
{
AvbDescriptor
parent_descriptor
;
uint32_t
rollback_index_
location
;
uint32_t
rollback_index_
slot
;
uint32_t
partition_name_len
;
uint32_t
public_key_len
;
uint8_t
reserved
[
64
];
...
...
lib/avb/libavb/avb_crc32.c
View file @
71dc860a
...
...
@@ -98,16 +98,15 @@ static uint32_t crc32_tab[] = {
* in sys/libkern.h, where it can be inlined.
*/
static
uint32_t
_
crc32
(
uint32_t
crc_in
,
const
uint8_t
*
buf
,
int
size
)
{
static
uint32_t
crc32
(
uint32_t
crc_in
,
const
uint8_t
*
buf
,
int
size
)
{
const
uint8_t
*
p
=
buf
;
uint32_t
crc
;
crc
=
crc_in
^
~
0U
;
while
(
size
--
)
crc
=
crc32_tab
[(
crc
^
*
p
++
)
&
0xFF
]
^
(
crc
>>
8
);
while
(
size
--
)
crc
=
crc32_tab
[(
crc
^
*
p
++
)
&
0xFF
]
^
(
crc
>>
8
);
return
crc
^
~
0U
;
}
uint32_t
avb_crc32
(
const
uint8_t
*
buf
,
size_t
size
)
{
return
_
crc32
(
0
,
buf
,
size
);
return
crc32
(
0
,
buf
,
size
);
}
lib/avb/libavb/avb_crypto.c
View file @
71dc860a
This diff is collapsed.
Click to expand it.
lib/avb/libavb/avb_crypto.h
View file @
71dc860a
...
...
@@ -35,21 +35,6 @@
extern
"C"
{
#endif
/* Size of a RSA-2048 signature. */
#define AVB_RSA2048_NUM_BYTES 256
/* Size of a RSA-4096 signature. */
#define AVB_RSA4096_NUM_BYTES 512
/* Size of a RSA-8192 signature. */
#define AVB_RSA8192_NUM_BYTES 1024
/* Size in bytes of a SHA-256 digest. */
#define AVB_SHA256_DIGEST_SIZE 32
/* Size in bytes of a SHA-512 digest. */
#define AVB_SHA512_DIGEST_SIZE 64
/* Algorithms that can be used in the vbmeta image for
* verification. An algorithm consists of a hash type and a signature
* type.
...
...
@@ -103,19 +88,6 @@ typedef enum {
_AVB_ALGORITHM_NUM_TYPES
}
AvbAlgorithmType
;
/* Holds algorithm-specific data. The |padding| is needed by avb_rsa_verify. */
typedef
struct
{
const
uint8_t
*
padding
;
size_t
padding_len
;
size_t
hash_len
;
}
AvbAlgorithmData
;
/* Provides algorithm-specific data for a given |algorithm|. Returns NULL if
* |algorithm| is invalid.
*/
const
AvbAlgorithmData
*
avb_get_algorithm_data
(
AvbAlgorithmType
algorithm
)
AVB_ATTR_WARN_UNUSED_RESULT
;
/* The header for a serialized RSA public key.
*
* The size of the key is given by |key_num_bits|, for example 2048
...
...
lib/avb/libavb/avb_descriptor.c
View file @
71dc860a
...
...
@@ -38,8 +38,7 @@ bool avb_descriptor_validate_and_byteswap(const AvbDescriptor* src,
return
true
;
}
bool
avb_descriptor_foreach
(
const
uint8_t
*
image_data
,
size_t
image_size
,
bool
avb_descriptor_foreach
(
const
uint8_t
*
image_data
,
size_t
image_size
,
AvbDescriptorForeachFunc
foreach_func
,
void
*
user_data
)
{
const
AvbVBMetaImageHeader
*
header
=
NULL
;
...
...
@@ -71,7 +70,7 @@ bool avb_descriptor_foreach(const uint8_t* image_data,
}
/* Careful, not byteswapped - also ensure it's aligned properly. */
avb_assert_aligned
(
image_data
);
avb_assert_
word_
aligned
(
image_data
);
header
=
(
const
AvbVBMetaImageHeader
*
)
image_data
;
image_end
=
image_data
+
image_size
;
...
...
@@ -89,7 +88,7 @@ bool avb_descriptor_foreach(const uint8_t* image_data,
for
(
p
=
desc_start
;
p
<
desc_end
;)
{
const
AvbDescriptor
*
dh
=
(
const
AvbDescriptor
*
)
p
;
avb_assert_aligned
(
dh
);
avb_assert_
word_
aligned
(
dh
);
uint64_t
nb_following
=
avb_be64toh
(
dh
->
num_bytes_following
);
uint64_t
nb_total
=
sizeof
(
AvbDescriptor
)
+
nb_following
;
...
...
@@ -140,8 +139,8 @@ const AvbDescriptor** avb_descriptor_get_all(const uint8_t* image_data,
size_t
num_descriptors
=
0
;
SetDescriptorData
data
;
avb_descriptor_foreach
(
image_data
,
image_size
,
count_descriptors
,
&
num_descriptors
);
avb_descriptor_foreach
(
image_data
,
image_size
,
count_descriptors
,
&
num_descriptors
);
data
.
descriptor_number
=
0
;
data
.
descriptors
=
...
...
lib/avb/libavb/avb_descriptor.h
View file @
71dc860a
...
...
@@ -100,8 +100,7 @@ typedef bool AvbDescriptorForeachFunc(const AvbDescriptor* descriptor,
* avb_vbmeta_image_verify() and reject it unless it's signed by a known
* good public key. Additionally, |image_data| must be word-aligned.
*/
bool
avb_descriptor_foreach
(
const
uint8_t
*
image_data
,
size_t
image_size
,
bool
avb_descriptor_foreach
(
const
uint8_t
*
image_data
,
size_t
image_size
,
AvbDescriptorForeachFunc
foreach_func
,
void
*
user_data
);
...
...
@@ -119,10 +118,9 @@ bool avb_descriptor_foreach(const uint8_t* image_data,
* avb_vbmeta_image_verify() and reject it unless it's signed by a known
* good public key. Additionally, |image_data| must be word-aligned.
*/
const
AvbDescriptor
**
avb_descriptor_get_all
(
const
uint8_t
*
image_data
,
size_t
image_size
,
size_t
*
out_num_descriptors
)
AVB_ATTR_WARN_UNUSED_RESULT
;
const
AvbDescriptor
**
avb_descriptor_get_all
(
const
uint8_t
*
image_data
,
size_t
image_size
,
size_t
*
out_num_descriptors
)
AVB_ATTR_WARN_UNUSED_RESULT
;
#ifdef __cplusplus
}
...
...
lib/avb/libavb/avb_footer.c
View file @
71dc860a
...
...
@@ -45,7 +45,7 @@ bool avb_footer_validate_and_byteswap(const AvbFooter* src, AvbFooter* dest) {
/* Ensure we don't attempt to access any fields if the footer major
* version is not supported.
*/
if
(
dest
->
version_major
>
AVB_FOOTER_
VERSION_MAJOR
)
{
if
(
dest
->
version_major
>
AVB_FOOTER_
MAJOR_VERSION
)
{
avb_error
(
"No support for footer version.
\n
"
);
return
false
;
}
...
...
lib/avb/libavb/avb_footer.h
View file @
71dc860a
...
...
@@ -42,9 +42,9 @@ extern "C" {
/* Size of the footer. */
#define AVB_FOOTER_SIZE 64
/* The current
footer version
used - keep in sync with avbtool. */
#define AVB_FOOTER_
VERSION_MAJOR
1
#define AVB_FOOTER_
VERSION_MINOR
0
/* The current
MAJOR and MINOR versions
used - keep in sync with avbtool. */
#define AVB_FOOTER_
MAJOR_VERSION
1
#define AVB_FOOTER_
MINOR_VERSION
0
/* The struct used as a footer used on partitions, used to find the
* AvbVBMetaImageHeader struct. This struct is always stored at the
...
...
lib/avb/libavb/avb_kernel_cmdline_descriptor.c
View file @
71dc860a
...
...
@@ -40,7 +40,6 @@ bool avb_kernel_cmdline_descriptor_validate_and_byteswap(
return
false
;
}
dest
->
flags
=
avb_be32toh
(
dest
->
flags
);
dest
->
kernel_cmdline_length
=
avb_be32toh
(
dest
->
kernel_cmdline_length
);
/* Check that kernel_cmdline is fully contained. */
...
...
lib/avb/libavb/avb_kernel_cmdline_descriptor.h
View file @
71dc860a
...
...
@@ -35,33 +35,14 @@
extern
"C"
{
#endif
/* Flags for kernel command-line descriptors.
*
* AVB_KERNEL_CMDLINE_FLAGS_USE_ONLY_IF_HASHTREE_NOT_DISABLED: The
* cmdline will only be applied if hashtree verification is not
* disabled (cf. AVB_VBMETA_IMAGE_FLAGS_HASHTREE_DISABLED).
*
* AVB_KERNEL_CMDLINE_FLAGS_USE_ONLY_IF_HASHTREE_DISABLED: The cmdline
* will only be applied if hashtree verification is disabled
* (cf. AVB_VBMETA_IMAGE_FLAGS_HASHTREE_DISABLED).
*/
typedef
enum
{
AVB_KERNEL_CMDLINE_FLAGS_USE_ONLY_IF_HASHTREE_NOT_DISABLED
=
(
1
<<
0
),
AVB_KERNEL_CMDLINE_FLAGS_USE_ONLY_IF_HASHTREE_DISABLED
=
(
1
<<
1
)
}
AvbKernelCmdlineFlags
;
/* A descriptor containing information to be appended to the kernel
* command-line.
*
* The |flags| field contains flags from the AvbKernelCmdlineFlags
* enumeration.
*
* Following this struct are |kernel_cmdline_len| bytes with the
* kernel command-line (UTF-8 encoded).
*/
typedef
struct
AvbKernelCmdlineDescriptor
{
AvbDescriptor
parent_descriptor
;
uint32_t
flags
;
uint32_t
kernel_cmdline_length
;
}
AVB_ATTR_PACKED
AvbKernelCmdlineDescriptor
;
...
...
lib/avb/libavb/avb_ops.h
View file @
71dc860a
...
...
@@ -63,32 +63,12 @@ typedef enum {
struct
AvbOps
;
typedef
struct
AvbOps
AvbOps
;
/* Forward-declaration of operations in libavb_ab. */
struct
AvbABOps
;
/* Forward-declaration of operations in libavb_atx. */
struct
AvbAtxOps
;
struct
AvbABData
;
/* High-level operations/functions/methods that are platform
* dependent.
*/
struct
AvbOps
{
/* This pointer can be used by the application/bootloader using
* libavb and is typically used in each operation to get a pointer
* to platform-specific resources. It cannot be used by libraries.
*/
void
*
user_data
;
/* If libavb_ab is used, this should point to the
* AvbABOps. Otherwise it must be set to NULL.
*/
struct
AvbABOps
*
ab_ops
;
/* If libavb_atx is used, this should point to the
* AvbAtxOps. Otherwise it must be set to NULL.
*/
struct
AvbAtxOps
*
atx_ops
;
/* Reads |num_bytes| from offset |offset| from partition with name
* |partition| (NUL-terminated UTF-8 string). If |offset| is
* negative, its absolute value should be interpreted as the number
...
...
@@ -106,12 +86,9 @@ struct AvbOps {
* of the partition. In this case the value returned in
* |out_num_read| may be smaller than |num_bytes|.
*/
AvbIOResult
(
*
read_from_partition
)(
AvbOps
*
ops
,
const
char
*
partition
,
int64_t
offset
,
size_t
num_bytes
,
void
*
buffer
,
size_t
*
out_num_read
);
AvbIOResult
(
*
read_from_partition
)(
AvbOps
*
ops
,
const
char
*
partition
,
int64_t
offset
,
size_t
num_bytes
,
void
*
buffer
,
size_t
*
out_num_read
);
/* Writes |num_bytes| from |bffer| at offset |offset| to partition
* with name |partition| (NUL-terminated UTF-8 string). If |offset|
...
...
@@ -129,10 +106,8 @@ struct AvbOps {
* This function never does any partial I/O, it either transfers all
* of the requested bytes or returns an error.
*/
AvbIOResult
(
*
write_to_partition
)(
AvbOps
*
ops
,
const
char
*
partition
,
int64_t
offset
,
size_t
num_bytes
,
AvbIOResult
(
*
write_to_partition
)(
AvbOps
*
ops
,
const
char
*
partition
,
int64_t
offset
,
size_t
num_bytes
,
const
void
*
buffer
);
/* Checks if the given public key used to sign the 'vbmeta'
...
...
@@ -140,48 +115,36 @@ struct AvbOps {
* embedded key material generated with 'avbtool
* extract_public_key'.
*
* The public key is in the array pointed to by |public_key_data|
* and is of |public_key_length| bytes.
*
* If there is no public key metadata (set with the avbtool option
* --public_key_metadata) then |public_key_metadata| will be set to
* NULL. Otherwise this field points to the data which is
* |public_key_metadata_length| bytes long.
*
* If AVB_IO_RESULT_OK is returned then |out_is_trusted| is set -
* true if trusted or false if untrusted.
*/
AvbIOResult
(
*
validate_vbmeta_public_key
)(
AvbOps
*
ops
,
const
uint8_t
*
public_key_data
,
size_t
public_key_length
,
const
uint8_t
*
public_key_metadata
,
size_t
public_key_metadata_length
,
bool
*
out_is_trusted
);
/* Gets the rollback index corresponding to the
location
given by
* |rollback_index_
location
|. The value is returned in
/* Gets the rollback index corresponding to the
slot
given by
* |rollback_index_
slot
|. The value is returned in
* |out_rollback_index|. Returns AVB_IO_RESULT_OK if the rollback
* index was retrieved, otherwise an error code.
*
* A device may have a limited amount of rollback index
location
s (say,
* one or four) so may error out if |rollback_index_
location
| exceeds
* A device may have a limited amount of rollback index
slot
s (say,
* one or four) so may error out if |rollback_index_
slot
| exceeds
* this number.
*/
AvbIOResult
(
*
read_rollback_index
)(
AvbOps
*
ops
,
size_t
rollback_index_location
,
AvbIOResult
(
*
read_rollback_index
)(
AvbOps
*
ops
,
size_t
rollback_index_slot
,
uint64_t
*
out_rollback_index
);
/* Sets the rollback index corresponding to the
location
given by
* |rollback_index_
location
| to |rollback_index|. Returns
/* Sets the rollback index corresponding to the
slot
given by
* |rollback_index_
slot
| to |rollback_index|. Returns
* AVB_IO_RESULT_OK if the rollback index was set, otherwise an
* error code.
*
* A device may have a limited amount of rollback index
location
s (say,
* one or four) so may error out if |rollback_index_
location
| exceeds
* A device may have a limited amount of rollback index
slot
s (say,
* one or four) so may error out if |rollback_index_
slot
| exceeds
* this number.
*/
AvbIOResult
(
*
write_rollback_index
)(
AvbOps
*
ops
,
size_t
rollback_index_location
,
AvbIOResult
(
*
write_rollback_index
)(
AvbOps
*
ops
,
size_t
rollback_index_slot
,
uint64_t
rollback_index
);
/* Gets whether the device is unlocked. The value is returned in
...
...
lib/avb/libavb/avb_property_descriptor.c
View file @
71dc860a
...
...
@@ -72,14 +72,11 @@ static bool property_lookup_desc_foreach(const AvbDescriptor* header,
const
uint8_t
*
p
;
bool
ret
=
true
;
if
(
header
->
tag
!=
AVB_DESCRIPTOR_TAG_PROPERTY
)
{
goto
out
;
}
if
(
header
->
tag
!=
AVB_DESCRIPTOR_TAG_PROPERTY
)
goto
out
;
if
(
!
avb_property_descriptor_validate_and_byteswap
(
(
const
AvbPropertyDescriptor
*
)
header
,
&
prop_desc
))
{
(
const
AvbPropertyDescriptor
*
)
header
,
&
prop_desc
))
goto
out
;
}
p
=
(
const
uint8_t
*
)
header
;
if
(
p
[
sizeof
(
AvbPropertyDescriptor
)
+
prop_desc
.
key_num_bytes
]
!=
0
)
{
...
...
@@ -88,8 +85,7 @@ static bool property_lookup_desc_foreach(const AvbDescriptor* header,
}
if
(
data
->
key_size
==
prop_desc
.
key_num_bytes
)
{
if
(
avb_memcmp
(
p
+
sizeof
(
AvbPropertyDescriptor
),
data
->
key
,
if
(
avb_memcmp
(
p
+
sizeof
(
AvbPropertyDescriptor
),
data
->
key
,
data
->
key_size
)
==
0
)
{
data
->
ret_value
=
(
const
char
*
)(
p
+
sizeof
(
AvbPropertyDescriptor
)
+
prop_desc
.
key_num_bytes
+
1
);
...
...
@@ -104,38 +100,28 @@ out:
return
ret
;
}
const
char
*
avb_property_lookup
(
const
uint8_t
*
image_data
,
size_t
image_size
,
const
char
*
key
,
size_t
key_size
,
const
char
*
avb_property_lookup
(
const
uint8_t
*
image_data
,
size_t
image_size
,
const
char
*
key
,
size_t
key_size
,
size_t
*
out_value_size
)
{
PropertyIteratorData
data
;
if
(
key_size
==
0
)
{
key_size
=
avb_strlen
(
key
);
}
if
(
key_size
==
0
)
key_size
=
avb_strlen
(
key
);
data
.
key
=
key
;
data
.
key_size
=
key_size
;
if
(
avb_descriptor_foreach
(
image_data
,
image_size
,
property_lookup_desc_foreach
,
&
data
)
==
0
)
{
if
(
out_value_size
!=
NULL
)
{
*
out_value_size
=
data
.
ret_value_size
;
}
if
(
avb_descriptor_foreach
(
image_data
,
image_size
,
property_lookup_desc_foreach
,
&
data
)
==
0
)
{
if
(
out_value_size
!=
NULL
)
*
out_value_size
=
data
.
ret_value_size
;
return
data
.
ret_value
;
}
if
(
out_value_size
!=
NULL
)
{
*
out_value_size
=
0
;
}
if
(
out_value_size
!=
NULL
)
*
out_value_size
=
0
;
return
NULL
;
}
bool
avb_property_lookup_uint64
(
const
uint8_t
*
image_data
,
size_t
image_size
,
const
char
*
key
,
size_t
key_size
,
bool
avb_property_lookup_uint64
(
const
uint8_t
*
image_data
,
size_t
image_size
,
const
char
*
key
,
size_t
key_size
,
uint64_t
*
out_value
)
{
const
char
*
value
;
bool
ret
=
false
;
...
...
@@ -144,9 +130,7 @@ bool avb_property_lookup_uint64(const uint8_t* image_data,
int
n
;
value
=
avb_property_lookup
(
image_data
,
image_size
,
key
,
key_size
,
NULL
);
if
(
value
==
NULL
)
{
goto
out
;
}
if
(
value
==
NULL
)
goto
out
;
base
=
10
;
if
(
avb_memcmp
(
value
,
"0x"
,
2
)
==
0
)
{
...
...
@@ -176,9 +160,7 @@ bool avb_property_lookup_uint64(const uint8_t* image_data,
}
ret
=
true
;
if
(
out_value
!=
NULL
)
{
*
out_value
=
parsed_val
;
}
if
(
out_value
!=
NULL
)
*
out_value
=
parsed_val
;
out:
return
ret
;
...
...
lib/avb/libavb/avb_property_descriptor.h
View file @
71dc860a
...
...
@@ -80,12 +80,9 @@ bool avb_property_descriptor_validate_and_byteswap(
* avb_vbmeta_image_verify() and reject it unless it's signed by a
* known good public key.
*/
const
char
*
avb_property_lookup
(
const
uint8_t
*
image_data
,
size_t
image_size
,
const
char
*
key
,
size_t
key_size
,
size_t
*
out_value_size
)
AVB_ATTR_WARN_UNUSED_RESULT
;
const
char
*
avb_property_lookup
(
const
uint8_t
*
image_data
,
size_t
image_size
,
const
char
*
key
,
size_t
key_size
,
size_t
*
out_value_size
)
AVB_ATTR_WARN_UNUSED_RESULT
;
/* Like avb_property_lookup() but parses the intial portions of the
* value as an unsigned 64-bit integer. Both decimal and hexadecimal
...
...
@@ -93,12 +90,9 @@ const char* avb_property_lookup(const uint8_t* image_data,
* failure and true on success. On success, the parsed value is
* returned in |out_value|.
*/
bool
avb_property_lookup_uint64
(
const
uint8_t
*
image_data
,
size_t
image_size
,
const
char
*
key
,
size_t
key_size
,
uint64_t
*
out_value
)
AVB_ATTR_WARN_UNUSED_RESULT
;
bool
avb_property_lookup_uint64
(
const
uint8_t
*
image_data
,
size_t
image_size
,
const
char
*
key
,
size_t
key_size
,
uint64_t
*
out_value
)
AVB_ATTR_WARN_UNUSED_RESULT
;
#ifdef __cplusplus
}
...
...
lib/avb/libavb/avb_rsa.c
View file @
71dc860a
...
...
@@ -77,9 +77,7 @@ Key* parse_key_data(const uint8_t* data, size_t length) {
* allocation.
*/
key
=
(
Key
*
)(
avb_malloc
(
sizeof
(
Key
)
+
2
*
h
.
key_num_bits
/
8
));
if
(
key
==
NULL
)
{
goto
fail
;
}
if
(
key
==
NULL
)
goto
fail
;
key
->
len
=
h
.
key_num_bits
/
32
;
key
->
n0inv
=
h
.
n0inv
;
...
...
@@ -97,15 +95,11 @@ Key* parse_key_data(const uint8_t* data, size_t length) {
return
key
;
fail:
if
(
key
!=
NULL
)
{
avb_free
(
key
);
}
if
(
key
!=
NULL
)
avb_free
(
key
);
return
NULL
;
}
void
free_parsed_key
(
Key
*
key
)
{
avb_free
(
key
);
}
void
free_parsed_key
(
Key
*
key
)
{
avb_free
(
key
);
}
/* a[] -= mod */
static
void
subM
(
const
Key
*
key
,
uint32_t
*
a
)
{
...
...
@@ -123,20 +117,14 @@ static int geM(const Key* key, uint32_t* a) {
uint32_t
i
;
for
(
i
=
key
->
len
;
i
;)
{
--
i
;
if
(
a
[
i
]
<
key
->
n
[
i
])
{
return
0
;
}
if
(
a
[
i
]
>
key
->
n
[
i
])
{
return
1
;
}
if
(
a
[
i
]
<
key
->
n
[
i
])
return
0
;
if
(
a
[
i
]
>
key
->
n
[
i
])
return
1
;
}
return
1
;
/* equal */
}
/* montgomery c[] += a * b[] / R % mod */
static
void
montMulAdd
(
const
Key
*
key
,
uint32_t
*
c
,
const
uint32_t
a
,
static
void
montMulAdd
(
const
Key
*
key
,
uint32_t
*
c
,
const
uint32_t
a
,
const
uint32_t
*
b
)
{
uint64_t
A
=
(
uint64_t
)
a
*
b
[
0
]
+
c
[
0
];
uint32_t
d0
=
(
uint32_t
)
A
*
key
->
n0inv
;
...
...
@@ -176,9 +164,7 @@ static void modpowF4(const Key* key, uint8_t* inout) {
uint32_t
*
a
=
(
uint32_t
*
)
avb_malloc
(
key
->
len
*
sizeof
(
uint32_t
));
uint32_t
*
aR
=
(
uint32_t
*
)
avb_malloc
(
key
->
len
*
sizeof
(
uint32_t
));
uint32_t
*
aaR
=
(
uint32_t
*
)
avb_malloc
(
key
->
len
*
sizeof
(
uint32_t
));
if
(
a
==
NULL
||
aR
==
NULL
||
aaR
==
NULL
)
{
goto
out
;
}
if
(
a
==
NULL
||
aR
==
NULL
||
aaR
==
NULL
)
goto
out
;
uint32_t
*
aaa
=
aaR
;
/* Re-use location. */
int
i
;
...
...
@@ -214,28 +200,18 @@ static void modpowF4(const Key* key, uint8_t* inout) {
}
out:
if
(
a
!=
NULL
)
{
avb_free
(
a
);
}
if
(
aR
!=
NULL
)
{
avb_free
(
aR
);
}
if
(
aaR
!=
NULL
)
{
avb_free
(
aaR
);
}
if
(
a
!=
NULL
)
avb_free
(
a
);
if
(
aR
!=
NULL
)
avb_free
(
aR
);
if
(
aaR
!=
NULL
)
avb_free
(
aaR
);
}
/* Verify a RSA PKCS1.5 signature against an expected hash.
* Returns false on failure, true on success.
*/
bool
avb_rsa_verify
(
const
uint8_t
*
key
,
size_t
key_num_bytes
,
const
uint8_t
*
sig
,
size_t
sig_num_bytes
,
const
uint8_t
*
hash
,
size_t
hash_num_bytes
,
const
uint8_t
*
padding
,
size_t
padding_num_bytes
)
{
bool
avb_rsa_verify
(
const
uint8_t
*
key
,
size_t
key_num_bytes
,
const
uint8_t
*
sig
,
size_t
sig_num_bytes
,
const
uint8_t
*
hash
,
size_t
hash_num_bytes
,
const
uint8_t
*
padding
,
size_t
padding_num_bytes
)
{
uint8_t
*
buf
=
NULL
;