2018-02-26 05:06:10 -08:00
|
|
|
/*
|
|
|
|
* This file is part of the TREZOR project, https://trezor.io/
|
|
|
|
*
|
|
|
|
* Copyright (c) SatoshiLabs
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-04-01 03:57:14 -07:00
|
|
|
#ifndef __TREZORHAL_IMAGE_H__
|
|
|
|
#define __TREZORHAL_IMAGE_H__
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2017-10-26 14:51:39 -07:00
|
|
|
#include "secbool.h"
|
2017-04-01 03:57:14 -07:00
|
|
|
|
2017-10-25 16:17:57 -07:00
|
|
|
#define BOARDLOADER_START 0x08000000
|
|
|
|
#define BOOTLOADER_START 0x08020000
|
|
|
|
#define FIRMWARE_START 0x08040000
|
2017-10-25 18:08:18 -07:00
|
|
|
|
2017-10-25 17:09:06 -07:00
|
|
|
#define IMAGE_HEADER_SIZE 0x400
|
|
|
|
#define IMAGE_SIG_SIZE 65
|
2017-10-25 18:08:18 -07:00
|
|
|
#define IMAGE_CHUNK_SIZE (128 * 1024)
|
2017-10-25 16:17:57 -07:00
|
|
|
|
2017-10-26 19:49:59 -07:00
|
|
|
#define BOOTLOADER_IMAGE_MAGIC 0x425A5254 // TRZB
|
2017-10-26 20:09:35 -07:00
|
|
|
#define BOOTLOADER_IMAGE_MAXSIZE (1 * IMAGE_CHUNK_SIZE)
|
2017-10-26 19:49:59 -07:00
|
|
|
|
2017-10-26 20:09:35 -07:00
|
|
|
#define FIRMWARE_IMAGE_MAGIC 0x465A5254 // TRZF
|
2018-02-12 05:51:41 -08:00
|
|
|
#define FIRMWARE_IMAGE_MAXSIZE (13 * IMAGE_CHUNK_SIZE)
|
2017-10-26 19:49:59 -07:00
|
|
|
|
2017-04-01 03:57:14 -07:00
|
|
|
typedef struct {
|
|
|
|
uint32_t magic;
|
|
|
|
uint32_t hdrlen;
|
|
|
|
uint32_t expiry;
|
|
|
|
uint32_t codelen;
|
|
|
|
uint32_t version;
|
2017-12-14 12:29:13 -08:00
|
|
|
uint32_t fix_version;
|
|
|
|
// uint8_t reserved[8];
|
2017-10-26 06:10:29 -07:00
|
|
|
uint8_t hashes[512];
|
|
|
|
// uint8_t reserved[415];
|
2017-04-01 03:57:14 -07:00
|
|
|
uint8_t sigmask;
|
|
|
|
uint8_t sig[64];
|
2017-12-15 10:22:59 -08:00
|
|
|
uint8_t fingerprint[32];
|
2017-04-01 03:57:14 -07:00
|
|
|
} image_header;
|
|
|
|
|
2017-04-05 08:41:10 -07:00
|
|
|
#define MAX_VENDOR_PUBLIC_KEYS 8
|
|
|
|
|
2017-12-15 11:53:29 -08:00
|
|
|
#define VTRUST_WAIT 0x000F
|
|
|
|
#define VTRUST_RED 0x0010
|
|
|
|
#define VTRUST_CLICK 0x0020
|
|
|
|
#define VTRUST_STRING 0x0040
|
|
|
|
#define VTRUST_ALL (VTRUST_WAIT | VTRUST_RED | VTRUST_CLICK | VTRUST_STRING)
|
2017-12-15 06:26:36 -08:00
|
|
|
|
2017-04-01 10:24:41 -07:00
|
|
|
typedef struct {
|
|
|
|
uint32_t magic;
|
|
|
|
uint32_t hdrlen;
|
|
|
|
uint32_t expiry;
|
|
|
|
uint16_t version;
|
|
|
|
uint8_t vsig_m;
|
|
|
|
uint8_t vsig_n;
|
2017-11-06 07:06:01 -08:00
|
|
|
uint16_t vtrust;
|
|
|
|
// uint8_t reserved[14];
|
2017-04-05 08:41:10 -07:00
|
|
|
const uint8_t *vpub[MAX_VENDOR_PUBLIC_KEYS];
|
2017-04-01 10:24:41 -07:00
|
|
|
uint8_t vstr_len;
|
2018-01-25 07:29:05 -08:00
|
|
|
const char *vstr;
|
2017-04-01 10:24:41 -07:00
|
|
|
const uint8_t *vimg;
|
|
|
|
uint8_t sigmask;
|
|
|
|
uint8_t sig[64];
|
|
|
|
} vendor_header;
|
|
|
|
|
2017-12-16 08:54:04 -08:00
|
|
|
secbool __wur load_image_header(const uint8_t * const data, const uint32_t magic, const uint32_t maxsize, uint8_t key_m, uint8_t key_n, const uint8_t * const *keys, image_header * const hdr);
|
2017-04-01 03:57:14 -07:00
|
|
|
|
2017-12-16 08:54:04 -08:00
|
|
|
secbool __wur load_vendor_header(const uint8_t * const data, uint8_t key_m, uint8_t key_n, const uint8_t * const *keys, vendor_header * const vhdr);
|
2017-04-01 10:24:41 -07:00
|
|
|
|
2017-12-13 13:50:48 -08:00
|
|
|
void vendor_keys_hash(const vendor_header * const vhdr, uint8_t *hash);
|
|
|
|
|
2017-12-16 08:54:04 -08:00
|
|
|
secbool __wur check_single_hash(const uint8_t * const hash, const uint8_t * const data, int len);
|
2017-10-26 20:09:35 -07:00
|
|
|
|
2017-12-16 08:54:04 -08:00
|
|
|
secbool __wur check_image_contents(const image_header * const hdr, uint32_t firstskip, const uint8_t *sectors, int blocks);
|
2017-10-26 08:16:59 -07:00
|
|
|
|
2017-04-01 03:57:14 -07:00
|
|
|
#endif
|