2020-03-03 04:58:57 +03:00
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
// Licensed under the MIT license.
|
|
|
|
|
|
|
|
#ifndef APP_IMAGE_H_
|
|
|
|
#define APP_IMAGE_H_
|
|
|
|
|
|
|
|
#include <stddef.h>
|
2024-05-16 08:19:56 +03:00
|
|
|
#include <stdint.h>
|
2020-03-03 04:58:57 +03:00
|
|
|
#include "crypto/hash.h"
|
2024-05-16 08:19:56 +03:00
|
|
|
#include "crypto/rsa.h"
|
|
|
|
#include "flash/flash.h"
|
|
|
|
#include "status/rot_status.h"
|
2020-03-03 04:58:57 +03:00
|
|
|
|
|
|
|
|
2022-08-30 03:19:08 +03:00
|
|
|
/* NOTE: Firmware images wrapped as an app_image have a fixed structure that requires RSA2k signing
|
|
|
|
* with SHA256. For a more flexible mechanism for wrapping firmware image, use firmware_component. */
|
|
|
|
|
2020-03-03 04:58:57 +03:00
|
|
|
/**
|
|
|
|
* The length of the application image signature.
|
|
|
|
*/
|
|
|
|
#define APP_IMAGE_SIG_LENGTH 256
|
|
|
|
|
|
|
|
|
2022-10-17 19:49:31 +03:00
|
|
|
int app_image_verification (const struct flash *flash, uint32_t start_addr,
|
|
|
|
struct hash_engine *hash, struct rsa_engine *rsa, const struct rsa_public_key *pub_key,
|
|
|
|
uint8_t *hash_out, size_t hash_length);
|
|
|
|
int app_image_verification_with_header (const struct flash *flash, uint32_t start_addr,
|
2020-03-03 04:58:57 +03:00
|
|
|
size_t header_length, struct hash_engine *hash, struct rsa_engine *rsa,
|
|
|
|
const struct rsa_public_key *pub_key, uint8_t *hash_out, size_t hash_length);
|
|
|
|
|
2022-10-17 19:49:31 +03:00
|
|
|
int app_image_load (const struct flash *flash, uint32_t start_addr, uint8_t *load_addr,
|
|
|
|
size_t max_length, size_t *load_length);
|
|
|
|
int app_image_load_and_verify (const struct flash *flash, uint32_t start_addr, uint8_t *load_addr,
|
2020-03-03 04:58:57 +03:00
|
|
|
size_t max_length, struct hash_engine *hash, struct rsa_engine *rsa,
|
|
|
|
const struct rsa_public_key *pub_key, uint8_t *hash_out, size_t hash_length,
|
|
|
|
size_t *load_length);
|
2022-10-17 19:49:31 +03:00
|
|
|
int app_image_load_and_verify_with_header (const struct flash *flash, uint32_t start_addr,
|
2020-03-03 04:58:57 +03:00
|
|
|
size_t header_length, uint8_t *load_addr, size_t max_length, struct hash_engine *hash,
|
|
|
|
struct rsa_engine *rsa, const struct rsa_public_key *pub_key, uint8_t *hash_out,
|
|
|
|
size_t hash_length, size_t *load_length);
|
|
|
|
|
2022-10-17 19:49:31 +03:00
|
|
|
int app_image_get_signature (const struct flash *flash, uint32_t start_addr, uint8_t *sig_out,
|
2020-03-03 04:58:57 +03:00
|
|
|
size_t sig_length);
|
2022-10-17 19:49:31 +03:00
|
|
|
int app_image_get_hash (const struct flash *flash, uint32_t start_addr, struct hash_engine *hash,
|
2020-03-03 04:58:57 +03:00
|
|
|
uint8_t *hash_out, size_t hash_length);
|
2022-10-17 19:49:31 +03:00
|
|
|
int app_image_get_hash_with_header (const struct flash *flash, uint32_t start_addr,
|
|
|
|
size_t header_length, struct hash_engine *hash, uint8_t *hash_out, size_t hash_length);
|
2020-03-03 04:58:57 +03:00
|
|
|
|
2022-10-17 19:49:31 +03:00
|
|
|
int app_image_get_data_addr (const struct flash *flash, uint32_t start_addr, uint32_t *data_addr);
|
|
|
|
int app_image_get_length (const struct flash *flash, uint32_t start_addr, uint32_t *img_length);
|
|
|
|
int app_image_get_image_end (const struct flash *flash, uint32_t start_addr, uint32_t *end_addr);
|
2020-03-03 04:58:57 +03:00
|
|
|
|
|
|
|
|
|
|
|
#define APP_IMAGE_ERROR(code) ROT_ERROR (ROT_MODULE_APP_IMAGE, code)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Error codes that can be generated by the application image utilities.
|
|
|
|
*/
|
|
|
|
enum {
|
2020-05-12 03:36:57 +03:00
|
|
|
APP_IMAGE_INVALID_ARGUMENT = APP_IMAGE_ERROR (0x00), /**< Input parameter is null or not valid. */
|
|
|
|
APP_IMAGE_NO_MEMORY = APP_IMAGE_ERROR (0x01), /**< Memory allocation failed. */
|
|
|
|
APP_IMAGE_TOO_LARGE = APP_IMAGE_ERROR (0x02), /**< There is not enough space available to load the image. */
|
|
|
|
APP_IMAGE_HASH_BUFFER_TOO_SMALL = APP_IMAGE_ERROR (0x03), /**< The buffer for the image hash is not large enough. */
|
|
|
|
APP_IMAGE_SIG_BUFFER_TOO_SMALL = APP_IMAGE_ERROR (0x04), /**< The buffer for the signature is not large enough. */
|
2020-03-03 04:58:57 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2024-05-16 08:19:56 +03:00
|
|
|
#endif /* APP_IMAGE_H_ */
|