|
28 | 28 | #ifndef BOOTUTIL_ENC_KEY_PUBLIC_H
|
29 | 29 | #define BOOTUTIL_ENC_KEY_PUBLIC_H
|
30 | 30 | #include <mcuboot_config/mcuboot_config.h>
|
| 31 | +#include <bootutil/bootutil_macros.h> |
| 32 | + |
31 | 33 | #ifdef __cplusplus
|
32 | 34 | extern "C" {
|
33 | 35 | #endif
|
34 | 36 |
|
35 |
| -#ifndef ALIGN_UP |
36 |
| -#define ALIGN_UP(num, align) (((num) + ((align) - 1)) & ~((align) - 1)) |
37 |
| -#endif |
| 37 | +/* The unit provides following system wide definitions: |
| 38 | + * BOOT_ENC_TLV_SIZE -- is the complete size of TLV with encryption data. |
| 39 | + * BOOT_ENC_TLV -- is the encryption TLV type, should be given value |
| 40 | + * of one of IMAGE_TVL_ENC_ identifiers. |
| 41 | + * BOOT_ENC_KEY_SIZE -- is the encryption key size; this includes portion |
| 42 | + * of TLV data stream taken by key. |
| 43 | + * |
| 44 | + * For ECIES based key exchange there is additionally provided: |
| 45 | + * EC_PUBK_LEN -- is the length, in bytes, of a public key; depends |
| 46 | + * selected key exchange. |
| 47 | + * EC_PRIVK_LEN -- is the length, in bytes, of a private key; depends |
| 48 | + * on selected key exchange. |
| 49 | + * EC_SHARED_LEN -- is the length, in bytes, of a shared key resulting |
| 50 | + * from processing of private and public key; depends |
| 51 | + * on selected key exchange parameters. |
| 52 | + * |
| 53 | + * ECIES TLV processing uses following TLVs, from this header: |
| 54 | + * EC_TAG_INDEX -- is the HMAC tag of encryption key index within TLV data |
| 55 | + * stream. |
| 56 | + * EC_TAG_LEN -- is the HMAC tag length. |
| 57 | + * EC_PUBK_INDEX -- is the index of shared public key within TLV data stream; |
| 58 | + * EC_PUBK_LEN represents length in bytes. |
| 59 | + * EC_CIPHERKEY_INDEX -- is the encryption key index within TLV data stream. |
| 60 | + * EC_CIPHERKEY_LEN -- is the length of an encryption key; depends on selected |
| 61 | + * encryption. |
| 62 | + * |
| 63 | + * Note that in case of ECIES, the BOOT_ENC_TLV_SIZE will be defined as |
| 64 | + * a sum of EC_*_LEN TLV components, defined for selected key exchange. |
| 65 | + */ |
38 | 66 |
|
39 | 67 | #ifdef MCUBOOT_AES_256
|
40 |
| -#define BOOT_ENC_KEY_SIZE 32 |
| 68 | +# define BOOT_ENC_KEY_SIZE 32 |
41 | 69 | #else
|
42 |
| -#define BOOT_ENC_KEY_SIZE 16 |
| 70 | +# define BOOT_ENC_KEY_SIZE 16 |
43 | 71 | #endif
|
44 | 72 |
|
45 |
| -#define BOOT_ENC_KEY_ALIGN_SIZE ALIGN_UP(BOOT_ENC_KEY_SIZE, BOOT_MAX_ALIGN) |
46 |
| - |
47 |
| -#define TLV_ENC_RSA_SZ 256 |
48 |
| -#define TLV_ENC_KW_SZ (BOOT_ENC_KEY_SIZE + 8) |
49 |
| -#define TLV_ENC_EC256_SZ (65 + 32 + BOOT_ENC_KEY_SIZE) |
50 |
| -#define TLV_ENC_X25519_SZ (32 + 32 + BOOT_ENC_KEY_SIZE) |
51 |
| - |
52 | 73 | #if defined(MCUBOOT_ENCRYPT_RSA)
|
53 |
| -#define BOOT_ENC_TLV_SIZE TLV_ENC_RSA_SZ |
| 74 | +# define BOOT_ENC_TLV_SIZE (256) |
| 75 | +# define BOOT_ENC_TLV IMAGE_TLV_ENC_RSA2048 |
54 | 76 | #elif defined(MCUBOOT_ENCRYPT_EC256)
|
55 |
| -#define BOOT_ENC_TLV_SIZE TLV_ENC_EC256_SZ |
| 77 | +# define EC_PUBK_LEN (65) |
| 78 | +# define EC_PRIVK_LEN (32) |
| 79 | +# define EC_SHARED_LEN (32) |
| 80 | +# define BOOT_ENC_TLV IMAGE_TLV_ENC_EC256 |
56 | 81 | #elif defined(MCUBOOT_ENCRYPT_X25519)
|
57 |
| -#define BOOT_ENC_TLV_SIZE TLV_ENC_X25519_SZ |
58 |
| -#else |
59 |
| -#define BOOT_ENC_TLV_SIZE TLV_ENC_KW_SZ |
| 82 | +# define EC_PUBK_LEN (32) |
| 83 | +# define EC_PRIVK_LEN (32) |
| 84 | +# define EC_SHARED_LEN (32) |
| 85 | +# define BOOT_ENC_TLV IMAGE_TLV_ENC_X25519 |
| 86 | +#elif defined(MCUBOOT_ENCRYPT_KW) |
| 87 | +# define BOOT_ENC_TLV_SIZE (BOOT_ENC_KEY_SIZE + 8) |
| 88 | +# define BOOT_ENC_TLV IMAGE_TLV_ENC_KW |
60 | 89 | #endif
|
61 | 90 |
|
| 91 | +/* Common ECIES definitions */ |
| 92 | +#if defined(EC_PUBK_LEN) |
| 93 | +# define EC_PUBK_INDEX (0) |
| 94 | +# define EC_TAG_LEN (32) |
| 95 | +# define EC_TAG_INDEX (EC_PUBK_INDEX + EC_PUBK_LEN) |
| 96 | +# define EC_CIPHERKEY_INDEX (EC_TAG_INDEX + EC_TAG_LEN) |
| 97 | +# define EC_CIPHERKEY_LEN BOOT_ENC_KEY_SIZE |
| 98 | +# define EC_SHARED_KEY_LEN (32) |
| 99 | +# define BOOT_ENC_TLV_SIZE (EC_PUBK_LEN + EC_TAG_LEN + EC_CIPHERKEY_LEN) |
| 100 | +#endif |
| 101 | + |
| 102 | +#define BOOT_ENC_KEY_ALIGN_SIZE ALIGN_UP(BOOT_ENC_KEY_SIZE, BOOT_MAX_ALIGN) |
| 103 | +#define BOOT_ENC_TLV_ALIGN_SIZE ALIGN_UP(BOOT_ENC_TLV_SIZE, BOOT_MAX_ALIGN) |
| 104 | + |
62 | 105 | #ifdef __cplusplus
|
63 | 106 | }
|
64 | 107 | #endif
|
|
0 commit comments