Tom Rini | 897a1d9 | 2018-06-19 11:21:44 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: MIT |
Igor Opaniuk | d8f9d2a | 2018-06-03 21:56:36 +0300 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016 The Android Open Source Project |
Igor Opaniuk | d8f9d2a | 2018-06-03 21:56:36 +0300 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include "avb_footer.h" |
| 7 | #include "avb_util.h" |
| 8 | |
| 9 | bool avb_footer_validate_and_byteswap(const AvbFooter* src, AvbFooter* dest) { |
| 10 | avb_memcpy(dest, src, sizeof(AvbFooter)); |
| 11 | |
| 12 | dest->version_major = avb_be32toh(dest->version_major); |
| 13 | dest->version_minor = avb_be32toh(dest->version_minor); |
| 14 | |
| 15 | dest->original_image_size = avb_be64toh(dest->original_image_size); |
| 16 | dest->vbmeta_offset = avb_be64toh(dest->vbmeta_offset); |
| 17 | dest->vbmeta_size = avb_be64toh(dest->vbmeta_size); |
| 18 | |
| 19 | /* Check that magic is correct. */ |
| 20 | if (avb_safe_memcmp(dest->magic, AVB_FOOTER_MAGIC, AVB_FOOTER_MAGIC_LEN) != |
| 21 | 0) { |
| 22 | avb_error("Footer magic is incorrect.\n"); |
| 23 | return false; |
| 24 | } |
| 25 | |
| 26 | /* Ensure we don't attempt to access any fields if the footer major |
| 27 | * version is not supported. |
| 28 | */ |
| 29 | if (dest->version_major > AVB_FOOTER_VERSION_MAJOR) { |
| 30 | avb_error("No support for footer version.\n"); |
| 31 | return false; |
| 32 | } |
| 33 | |
| 34 | return true; |
| 35 | } |