amebazii/
keys.rs

1//! Default keys used to sign and verify images/ partition tables.
2
3/// Represents a pair of cryptographic keys: a private key and a public key.
4pub struct ConstKeyPair<'s> {
5    priv_key: &'s [u8; 32], // The private key (32 bytes)
6    pub_key: &'s [u8; 32],  // The public key (32 bytes)
7}
8
9impl<'s> ConstKeyPair<'s> {
10    /// Creates a new `KeyPair` instance with the provided private and public keys.
11    ///
12    /// # Parameters
13    /// - `priv_key`: A reference to a 32-byte array representing the private key.
14    /// - `pub_key`: A reference to a 32-byte array representing the public key.
15    ///
16    /// # Returns
17    /// Returns a new `KeyPair` instance containing the provided keys.
18    pub const fn new(priv_key: &'s [u8; 32], pub_key: &'s [u8; 32]) -> Self {
19        ConstKeyPair { priv_key, pub_key }
20    }
21
22    /// Returns a reference to the private key.
23    ///
24    /// # Returns
25    /// Returns a reference to the 32-byte private key.
26    pub const fn get_priv_key(&self) -> &'s [u8; 32] {
27        self.priv_key
28    }
29
30    /// Returns a reference to the public key.
31    ///
32    /// # Returns
33    /// Returns a reference to the 32-byte public key.
34    pub const fn get_pub_key(&self) -> &'s [u8; 32] {
35        self.pub_key
36    }
37}
38
39// Default values for cryptographic keys and patterns used throughout the system.
40
41/// The default hash key used to generate signatures for the partition table.
42///
43/// This constant represents a 32-byte hash key used for generating signatures in the partition
44/// table. The key is employed during processes such as OTA firmware image generation or partition
45/// verification, ensuring the integrity and authenticity of the partition table. The key itself
46/// is predefined and utilized as a default.
47///
48/// ## Hexadecimal Representation
49///
50/// ```text
51/// 47e5661335a4c5e0a94d69f3c737d54f2383791332939753ef24279608f6d72b
52/// ```
53pub const HASH_KEY: &[u8; 32] =
54    b"\x47\xe5\x66\x13\x35\xa4\xc5\xe0\xa9\x4d\x69\xf3\xc7\x37\xd5\x4f\x23\x83\x79\x13\x32\x93\x97\x53\xef\x24\x27\x96\x08\xf6\xd7\x2b";
55
56/// The default Initialization Vector (IV) used for encryption/decryption operations.
57pub const DEFAULT_IV: &[u8; 16] =
58    b"\xe7\x91\x9e\xe6\x98\xb1\xe5\x8d\x8a\xe5\xb0\x8e\xe9\xab\x94\x38";
59
60/// Default second key used in the application subimage.
61///
62/// This constant represents a 32-byte encryption key, which is used as the second user key (key2)
63/// in the application subimage. The key is defined here as a default, though its exact purpose
64/// is not explicitly documented. It is worth noting that the first byte of the original key has
65/// been replaced with `\xBB`. This key may be used during OTA firmware image generation or
66/// other encryption tasks where a second key is required.
67pub const APP_DEFAULT_USER_KEY2: &[u8; 32] =
68    b"\xbb\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f";
69
70/// Default first key used in the boot image.
71///
72/// This constant represents a 32-byte encryption key used as the first user key (key1) in the boot
73/// image. The exact purpose of this key is not explicitly defined in the documentation. Similar to
74/// the second key, the first byte of the original key has been replaced with `\xAA`. This key
75/// might be involved in encryption tasks, such as generating OTA firmware images, but its specific
76/// usage is not clearly documented.
77pub const BOOT_DEFAULT_USER_KEY1: &[u8; 32] =
78    b"\xaa\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f";
79
80/// Default AES encryption key used for encrypting/decrypting XIP section data.
81pub const XIP_KEY: &[u8; 16] = b"\xa0\xd6\xda\xe7\xe0b\xca\x94\xcb\xb2\x94\xbf\x89k\x9fh";
82
83/// Default IV used for encrypting/decrypting XIP section data.
84pub const XIP_IV: &[u8; 16] = b"\x94\x87\x94\x87\x94\x87\x94\x87\x94\x87\x94\x87\x94\x87\x94\x87";
85
86/// Default flash calibration pattern used in flash
87pub const FLASH_PATTERN: &[u8; 16] =
88    b"\x99\x99\x96\x96\x3f\xcc\x66\xfc\xc0\x33\xcc\x03\xe5\xdc\x31\x62";
89
90pub const DEFAULT_VALID_PATTERN: &[u8; 8] = &[0, 1, 2, 3, 4, 5, 6, 7];
91
92/// Default cryptographic key pair for general use in encryption/decryption images.
93pub const KEY_PAIR_000: ConstKeyPair = ConstKeyPair::new(
94    b"\xa0\xd6\xda\xe7\xe0b\xca\x94\xcb\xb2\x94\xbf\x89k\x9fh\xcf\x848wBV\xact\x03\xcaO\xd9\xa1\xc9VO",
95    b"hQ>\xf8>9k\x12\xba\x05\x9a\x90\x0f6\xb6\xd3\x1d\x11\xfe\x1c]%\xeb\x8a\xa7\xc5P0\x7f\x9c$\x05",
96);
97
98/// Default hash key pair used for hashing operations (not seen).
99pub const KEY_PAIR_001: ConstKeyPair = ConstKeyPair::new(
100    b"\x88*\xa1l\x8cD\xa7v\n\xa8\xc9\xab\"\xe3V\x8co\xa1l*\xfaO\x0c\xea)\xa1\n\xbc\xdf`\xe4O",
101    b"H\xad#\xdd\xbd\xac\x9eeq\x9d\xb7\xd3\x94\xd4Mb\x82\r\x19\xe5\rh7gt#~\x98\xd20^j",
102);
103
104/// Unused key pair; not seen
105pub const KEY_PAIR_002: ConstKeyPair = ConstKeyPair::new(
106    b"X\xa3\xd9\x15ph5!\"`\xc2-b\x8b3m\x13\x19\x0bS\x97\x14\xe3\xdb$\x9d\x82<\xa5wDS",
107    b"\xfd\x8d?>Qm\x96\x18n\x10\xf0zd\xb2L}\xe76\x82j$\xfa\xfe6~y\xf1\xfb\xb2\xf1\xc82",
108);
109
110/// Default key pair used for firmware signature generation (used in OTA operations).
111pub const KEY_PAIR_003: ConstKeyPair = ConstKeyPair::new(
112    b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e_",
113    b"\x8f@\xc5\xad\xb6\x8f%bJ\xe5\xb2\x14\xeavzn\xc9M\x82\x9d={^\x1a\xd1\xbao>!8(_"
114);