rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | #ifndef _IMAGE_H_ |
| 2 | #define _IMAGE_H_ |
| 3 | |
| 4 | #include <libfdt.h> |
| 5 | #include <sys/types.h> |
| 6 | |
| 7 | #define SPEW_D 0 |
| 8 | #define FIT_MAX_HASH_LEN 32 |
| 9 | |
| 10 | #ifndef CHUNKSZ_SHA1 |
| 11 | #define CHUNKSZ_SHA1 (64 * 1024) |
| 12 | #endif |
| 13 | |
| 14 | #define IMAGE_ENABLE_TIMESTAMP 0 |
| 15 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
| 16 | |
| 17 | #define FIT_IMAGES_PATH "/images" |
| 18 | #define FIT_CONFIGS_PATH "/configurations" |
| 19 | |
| 20 | /* hash/signature node */ |
| 21 | #define FDT_HASH_NODE "hash" |
| 22 | #define FDT_ALGO_NODE "algo" |
| 23 | #define FDT_VAL_NODE "value" |
| 24 | #define FDT_SIG_NODE "signature" |
| 25 | #define FDT_HASHED_NODE "hashed-nodes" |
| 26 | #define FDT_HASHED_STR "hashed-strings" |
| 27 | |
| 28 | /*blob node */ |
| 29 | #define BLOB_REQ_NODE "required" |
| 30 | #define BLOB_NBITS_NODE "rsa,num-bits" |
| 31 | #define BLOB_N0INV_NODE "rsa,n0-inverse" |
| 32 | #define BLOB_RSQU_NODE "rsa,r-squared" |
| 33 | #define BLOB_MOD_NODE "rsa,modulus" |
| 34 | #define BLOB_EXP_NODE "rsa,exponent" |
| 35 | |
| 36 | /* image node */ |
| 37 | #define FDT_DATA_NODE "data" |
| 38 | |
| 39 | struct fdt_region { |
| 40 | int offset; |
| 41 | int size; |
| 42 | }; |
| 43 | |
| 44 | struct image_region { |
| 45 | const void *data; |
| 46 | int size; |
| 47 | }; |
| 48 | |
| 49 | struct sig_info { |
| 50 | void *fit_image; |
| 51 | const void *pubkey; |
| 52 | struct sig_algo *algo; |
| 53 | int req_offset; |
| 54 | }; |
| 55 | |
| 56 | struct verify_data { |
| 57 | const void *fit_image; |
| 58 | int noffset; |
| 59 | }; |
| 60 | |
| 61 | struct hash_algo { |
| 62 | const char *hash; |
| 63 | const int hash_len; |
| 64 | const int pad_len; |
| 65 | int (*hash_cal)(const struct image_region region[],int region_count, uint8_t *checksum, int hash_len); |
| 66 | const uint8_t *hash_padding; |
| 67 | }; |
| 68 | |
| 69 | struct sig_algo { |
| 70 | const char *rsa; |
| 71 | struct hash_algo *hash_info; |
| 72 | int (*sig_verify)(struct sig_info *info, |
| 73 | const struct fdt_region region[], |
| 74 | int region_count, uint8_t *sig, uint sig_len); |
| 75 | |
| 76 | }; |
| 77 | |
| 78 | static inline const char *fit_get_name(const void *fit_hdr, |
| 79 | int noffset, int *len) |
| 80 | { |
| 81 | return fdt_get_name(fit_hdr, noffset, len); |
| 82 | } |
| 83 | |
| 84 | struct sig_algo *image_get_sig_algo(const char *name); |
| 85 | |
| 86 | int fit_image_integrity_verify(const void *fit, int image_noffset); |
| 87 | |
| 88 | int rsa_check_enabled(void); |
| 89 | int hash_check_enabled(void); |
| 90 | int fit_verify_sign(const void *fit, int conf_noffset); |
| 91 | |
| 92 | #endif |