diff --git a/precursors/rom.db b/precursors/rom.db index 57516aeed..7b0cb51d5 100644 --- a/precursors/rom.db +++ b/precursors/rom.db @@ -1,128 +1,128 @@ -KEYROM 0 A SLICE_X36Y50 b'df14e1bb410df3a1' -KEYROM 0 B SLICE_X36Y50 b'd04dff21f89ee8bf' -KEYROM 0 C SLICE_X36Y50 b'416c1a28fd83c77b' -KEYROM 0 D SLICE_X36Y50 b'ba0269ba89e641d7' -KEYROM 1 A SLICE_X37Y50 b'9c44df255fd2a5da' -KEYROM 1 B SLICE_X37Y50 b'aea94847e5f2cd0c' -KEYROM 1 C SLICE_X37Y50 b'8b92e766041d2215' -KEYROM 1 D SLICE_X37Y50 b'a0d520564ff78a60' -KEYROM 2 A SLICE_X36Y51 b'f3cb7a1101eeaf6c' -KEYROM 2 B SLICE_X36Y51 b'ab6ac834e19baefc' -KEYROM 2 C SLICE_X36Y51 b'00b12075b2185b18' -KEYROM 2 D SLICE_X36Y51 b'7d4eae2b7c7b0778' -KEYROM 3 A SLICE_X37Y51 b'cc668b73dc5b20ed' -KEYROM 3 B SLICE_X37Y51 b'a5b8b7120edeb93c' -KEYROM 3 C SLICE_X37Y51 b'597f101f0a33972c' -KEYROM 3 D SLICE_X37Y51 b'6469cc5379d26720' -KEYROM 4 A SLICE_X36Y52 b'aeb1bc7732636490' -KEYROM 4 B SLICE_X36Y52 b'eb882878da9c7943' -KEYROM 4 C SLICE_X36Y52 b'71f37802768585ae' -KEYROM 4 D SLICE_X36Y52 b'3e0a50c473a23418' -KEYROM 5 A SLICE_X37Y52 b'bf85b47bebbd4ed0' -KEYROM 5 B SLICE_X37Y52 b'6c3c2429eda490ae' -KEYROM 5 C SLICE_X37Y52 b'1b37ffc31fdfdfcc' -KEYROM 5 D SLICE_X37Y52 b'04a6c3992e50fc67' -KEYROM 6 A SLICE_X36Y53 b'e4d8253303f260ad' -KEYROM 6 B SLICE_X36Y53 b'94213ab1b2d87176' -KEYROM 6 C SLICE_X36Y53 b'd928e7243d13ee32' -KEYROM 6 D SLICE_X36Y53 b'1baf76b1bae5dd35' -KEYROM 7 A SLICE_X37Y53 b'f94f5b910a3adfd5' -KEYROM 7 B SLICE_X37Y53 b'37a5ab15c01e20e4' -KEYROM 7 C SLICE_X37Y53 b'6baa138e51b37fea' -KEYROM 7 D SLICE_X37Y53 b'28270dc201771b62' -KEYROM 8 A SLICE_X36Y54 b'ff84d4a63041c516' -KEYROM 8 B SLICE_X36Y54 b'52918b89290e53ef' -KEYROM 8 C SLICE_X36Y54 b'c6f32dcdec7b8cc9' -KEYROM 8 D SLICE_X36Y54 b'4bf983b124ea3e62' -KEYROM 9 A SLICE_X37Y54 b'c18b0d2924202e43' -KEYROM 9 B SLICE_X37Y54 b'75a403a06a95f69b' -KEYROM 9 C SLICE_X37Y54 b'0e6c4c529690213d' -KEYROM 9 D SLICE_X37Y54 b'105b5014c6ff9172' -KEYROM 10 A SLICE_X36Y55 b'2818d6b10fcc1315' -KEYROM 10 B SLICE_X36Y55 b'332f6d00f603bb50' -KEYROM 10 C SLICE_X36Y55 b'32332a423e3e7c1a' -KEYROM 10 D SLICE_X36Y55 b'b1643077491b5e06' -KEYROM 11 A SLICE_X37Y55 b'361bab4ce8b57fee' -KEYROM 11 B SLICE_X37Y55 b'92edf70b9cfe0098' -KEYROM 11 C SLICE_X37Y55 b'63039a3ecc72f58d' -KEYROM 11 D SLICE_X37Y55 b'733ba57f04b75284' -KEYROM 12 A SLICE_X36Y56 b'765767c682d26569' -KEYROM 12 B SLICE_X36Y56 b'497992efc3776d79' -KEYROM 12 C SLICE_X36Y56 b'7d95ac30fbb5d34b' -KEYROM 12 D SLICE_X36Y56 b'89f54d6c6492b724' -KEYROM 13 A SLICE_X37Y56 b'f5eb153c883b6b6a' -KEYROM 13 B SLICE_X37Y56 b'b97af3b9d2c75292' -KEYROM 13 C SLICE_X37Y56 b'be705ea0031d0e71' -KEYROM 13 D SLICE_X37Y56 b'0dd907c101fddb1e' -KEYROM 14 A SLICE_X36Y57 b'3a773992ffd19035' -KEYROM 14 B SLICE_X36Y57 b'39540ab5ad9029a4' -KEYROM 14 C SLICE_X36Y57 b'fe6a6748030621db' -KEYROM 14 D SLICE_X36Y57 b'037296f110144ae4' -KEYROM 15 A SLICE_X37Y57 b'62e89c33394dcb13' -KEYROM 15 B SLICE_X37Y57 b'a0d90f274ca934b0' -KEYROM 15 C SLICE_X37Y57 b'd3321d7e3d0817f4' -KEYROM 15 D SLICE_X37Y57 b'0f89feb7554feb88' -KEYROM 16 A SLICE_X36Y58 b'6144cb3338715f56' -KEYROM 16 B SLICE_X36Y58 b'e8b7136a67dd63dc' -KEYROM 16 C SLICE_X36Y58 b'1915eb8794f26e06' -KEYROM 16 D SLICE_X36Y58 b'7e06c5e6258396b7' -KEYROM 17 A SLICE_X37Y58 b'1cd1cb5102979c09' -KEYROM 17 B SLICE_X37Y58 b'7e390dd426f32f6b' -KEYROM 17 C SLICE_X37Y58 b'cd796e3604b1f665' -KEYROM 17 D SLICE_X37Y58 b'd6d3a0d503744352' -KEYROM 18 A SLICE_X36Y59 b'7838fefdfeff0caf' -KEYROM 18 B SLICE_X36Y59 b'39937d76a02e55b2' -KEYROM 18 C SLICE_X36Y59 b'a74ce365e488fb5c' -KEYROM 18 D SLICE_X36Y59 b'5ff47e2ad8f8c727' -KEYROM 19 A SLICE_X37Y59 b'24877ab3b82cfb60' -KEYROM 19 B SLICE_X37Y59 b'0997e1bd2730dc92' -KEYROM 19 C SLICE_X37Y59 b'22cb622b3807b997' -KEYROM 19 D SLICE_X37Y59 b'305a1a9722c36348' -KEYROM 20 A SLICE_X36Y60 b'ed417bdc093cc6e5' -KEYROM 20 B SLICE_X36Y60 b'368c101fbe4593f9' -KEYROM 20 C SLICE_X36Y60 b'f524fe658b30c5ff' -KEYROM 20 D SLICE_X36Y60 b'427894ffe12ea152' -KEYROM 21 A SLICE_X37Y60 b'8d6628875ae19e43' -KEYROM 21 B SLICE_X37Y60 b'1e3d36077f35ebed' -KEYROM 21 C SLICE_X37Y60 b'55cbcc5900fbe0fa' -KEYROM 21 D SLICE_X37Y60 b'b3576c48e96b040f' -KEYROM 22 A SLICE_X36Y61 b'0c1baa89112852b0' -KEYROM 22 B SLICE_X36Y61 b'39483bee52dceb4c' -KEYROM 22 C SLICE_X36Y61 b'd9b21bb5703e5abc' -KEYROM 22 D SLICE_X36Y61 b'707e78d4d0a3fd99' -KEYROM 23 A SLICE_X37Y61 b'06b27a972f8fac72' -KEYROM 23 B SLICE_X37Y61 b'5d6a42a77b856df6' -KEYROM 23 C SLICE_X37Y61 b'f48aeab4a59dcd34' -KEYROM 23 D SLICE_X37Y61 b'c210bd1111f5513f' -KEYROM 24 A SLICE_X36Y62 b'5a8d01dc3c48c365' -KEYROM 24 B SLICE_X36Y62 b'550604e502c4b51e' -KEYROM 24 C SLICE_X36Y62 b'196e9d00a1dddb36' -KEYROM 24 D SLICE_X36Y62 b'56fcd1ec8b205a60' -KEYROM 25 A SLICE_X37Y62 b'b278f2eeab6f1eb6' -KEYROM 25 B SLICE_X37Y62 b'daf87a1c092d4d95' -KEYROM 25 C SLICE_X37Y62 b'7e2e704497c71ad4' -KEYROM 25 D SLICE_X37Y62 b'81fe60c9b947f5cc' -KEYROM 26 A SLICE_X36Y63 b'aaf0eab1eb9a4390' -KEYROM 26 B SLICE_X36Y63 b'44b81cf224548463' -KEYROM 26 C SLICE_X36Y63 b'50445f9b117caeaf' -KEYROM 26 D SLICE_X36Y63 b'80ea15490c51a616' -KEYROM 27 A SLICE_X37Y63 b'0c3cd10b73427f91' -KEYROM 27 B SLICE_X37Y63 b'a2d60f9a2e16eff3' -KEYROM 27 C SLICE_X37Y63 b'07a7dd73948f0bf6' -KEYROM 27 D SLICE_X37Y63 b'4e84fc06d10dd094' -KEYROM 28 A SLICE_X36Y64 b'3f371180b689d79c' -KEYROM 28 B SLICE_X36Y64 b'8aab4a1aafd06b10' -KEYROM 28 C SLICE_X36Y64 b'2e2bc7d70388afab' -KEYROM 28 D SLICE_X36Y64 b'f84c176996b25a8a' -KEYROM 29 A SLICE_X37Y64 b'adedccab0cf1047d' -KEYROM 29 B SLICE_X37Y64 b'dc944b65364129e4' -KEYROM 29 C SLICE_X37Y64 b'4c71b98fc479b286' -KEYROM 29 D SLICE_X37Y64 b'9be04f29153ca694' -KEYROM 30 A SLICE_X36Y65 b'aa98cf138633738d' -KEYROM 30 B SLICE_X36Y65 b'fdf766fd0e5a46d0' -KEYROM 30 C SLICE_X36Y65 b'5230ebd643274b37' -KEYROM 30 D SLICE_X36Y65 b'e96126419731faa4' -KEYROM 31 A SLICE_X37Y65 b'29277868d4660ffa' -KEYROM 31 B SLICE_X37Y65 b'e8a0b6dbe77de21c' -KEYROM 31 C SLICE_X37Y65 b'feaacc3708396854' -KEYROM 31 D SLICE_X37Y65 b'a43e6b13f2017b0f' +KEYROM 0 A SLICE_X36Y50 b'2253afe6ef9575fb' +KEYROM 0 B SLICE_X36Y50 b'd7a7360d5f354148' +KEYROM 0 C SLICE_X36Y50 b'cd35270191ed0296' +KEYROM 0 D SLICE_X36Y50 b'677bccac8c854b80' +KEYROM 1 A SLICE_X37Y50 b'be530e5c8f3c4974' +KEYROM 1 B SLICE_X37Y50 b'5f6e609627b7e0c8' +KEYROM 1 C SLICE_X37Y50 b'6e9b2b527ee1580f' +KEYROM 1 D SLICE_X37Y50 b'2108b5666987a290' +KEYROM 2 A SLICE_X36Y51 b'd2ce61c675aff795' +KEYROM 2 B SLICE_X36Y51 b'eb1ef14b699919c0' +KEYROM 2 C SLICE_X36Y51 b'46f2c8c59d5f1ba1' +KEYROM 2 D SLICE_X36Y51 b'cd80cfaa878e0180' +KEYROM 3 A SLICE_X37Y51 b'0c51f2e27045d192' +KEYROM 3 B SLICE_X37Y51 b'77b5a6da36ef4e1f' +KEYROM 3 C SLICE_X37Y51 b'f8a08063a4f3ed92' +KEYROM 3 D SLICE_X37Y51 b'99f7211d54ddb6c7' +KEYROM 4 A SLICE_X36Y52 b'718a31cc9ee39a05' +KEYROM 4 B SLICE_X36Y52 b'5fd9d20624321ef8' +KEYROM 4 C SLICE_X36Y52 b'471c91be68c93189' +KEYROM 4 D SLICE_X36Y52 b'0629ab62709ed8c3' +KEYROM 5 A SLICE_X37Y52 b'39437ee930c1cb51' +KEYROM 5 B SLICE_X37Y52 b'39e23cac2cac61a4' +KEYROM 5 C SLICE_X37Y52 b'4c59e99b64641d54' +KEYROM 5 D SLICE_X37Y52 b'b2ac7dcf09f95bc9' +KEYROM 6 A SLICE_X36Y53 b'04863a46de78bb00' +KEYROM 6 B SLICE_X36Y53 b'93c8c73315aa91b7' +KEYROM 6 C SLICE_X36Y53 b'350559ee3b7c5a20' +KEYROM 6 D SLICE_X36Y53 b'b5133117630b39e7' +KEYROM 7 A SLICE_X37Y53 b'4294e882a04e56ba' +KEYROM 7 B SLICE_X37Y53 b'c7ff1f45d08b9ca0' +KEYROM 7 C SLICE_X37Y53 b'66d9ae43b2039467' +KEYROM 7 D SLICE_X37Y53 b'524bdf2a1966c7c3' +KEYROM 8 A SLICE_X36Y54 b'd1476a22da9f278e' +KEYROM 8 B SLICE_X36Y54 b'f05270c26650743d' +KEYROM 8 C SLICE_X36Y54 b'28902e6d244dae0c' +KEYROM 8 D SLICE_X36Y54 b'566f5bb0134e0148' +KEYROM 9 A SLICE_X37Y54 b'a5302e52dbe88445' +KEYROM 9 B SLICE_X37Y54 b'4b8f67a43520b2d0' +KEYROM 9 C SLICE_X37Y54 b'44fd3624d3331f52' +KEYROM 9 D SLICE_X37Y54 b'856da7c86a5b3074' +KEYROM 10 A SLICE_X36Y55 b'08586053fb439e8a' +KEYROM 10 B SLICE_X36Y55 b'13497280447028fc' +KEYROM 10 C SLICE_X36Y55 b'c48584b5b5b87eac' +KEYROM 10 D SLICE_X36Y55 b'86b02ea381d479e7' +KEYROM 11 A SLICE_X37Y55 b'f360ab86140d2b49' +KEYROM 11 B SLICE_X37Y55 b'66f18a9de97cc12b' +KEYROM 11 C SLICE_X37Y55 b'612f4c5e7721fa81' +KEYROM 11 D SLICE_X37Y55 b'7e44dc2e8baa33f4' +KEYROM 12 A SLICE_X36Y56 b'64db34a1ca57dff1' +KEYROM 12 B SLICE_X36Y56 b'28685c8c97479bf9' +KEYROM 12 C SLICE_X36Y56 b'5f6947f723bf5916' +KEYROM 12 D SLICE_X36Y56 b'886b36cfdd4a02dd' +KEYROM 13 A SLICE_X37Y56 b'8b0a0a4ee719e0da' +KEYROM 13 B SLICE_X37Y56 b'1c17af721fc23adc' +KEYROM 13 C SLICE_X37Y56 b'08a6d62f007312f0' +KEYROM 13 D SLICE_X37Y56 b'98375538659f662f' +KEYROM 14 A SLICE_X36Y57 b'3b95c9d486da6015' +KEYROM 14 B SLICE_X36Y57 b'd6214d19e434f1ee' +KEYROM 14 C SLICE_X36Y57 b'e3b5fcf0629c3760' +KEYROM 14 D SLICE_X36Y57 b'da5bf495cd79a9a4' +KEYROM 15 A SLICE_X37Y57 b'f0ffd0f51557ed10' +KEYROM 15 B SLICE_X37Y57 b'799568e1f278c442' +KEYROM 15 C SLICE_X37Y57 b'88ae4b1b805ce08d' +KEYROM 15 D SLICE_X37Y57 b'e79b9412723d8069' +KEYROM 16 A SLICE_X36Y58 b'9cc476c6386d531f' +KEYROM 16 B SLICE_X36Y58 b'58f3aae6bb9e16e8' +KEYROM 16 C SLICE_X36Y58 b'725cf041a326db93' +KEYROM 16 D SLICE_X36Y58 b'b387bcb61b5c423c' +KEYROM 17 A SLICE_X37Y58 b'c115a65674534d4b' +KEYROM 17 B SLICE_X37Y58 b'1130f37503837f8f' +KEYROM 17 C SLICE_X37Y58 b'1468172d24b1ead7' +KEYROM 17 D SLICE_X37Y58 b'792442338c128d22' +KEYROM 18 A SLICE_X36Y59 b'9c617ee9ba38a501' +KEYROM 18 B SLICE_X36Y59 b'6d984069c95e4ef9' +KEYROM 18 C SLICE_X36Y59 b'f10beff31109d25b' +KEYROM 18 D SLICE_X36Y59 b'f9b4d041e7ca503c' +KEYROM 19 A SLICE_X37Y59 b'd4ba8f06f06b4fb7' +KEYROM 19 B SLICE_X37Y59 b'3ce9a9b357086462' +KEYROM 19 C SLICE_X37Y59 b'a2a225576026700a' +KEYROM 19 D SLICE_X37Y59 b'aff7b790a55eb8de' +KEYROM 20 A SLICE_X36Y60 b'704409bc903ef405' +KEYROM 20 B SLICE_X36Y60 b'c18b95e0171e54ff' +KEYROM 20 C SLICE_X36Y60 b'359e818020171bff' +KEYROM 20 D SLICE_X36Y60 b'db1956d85b3ac72b' +KEYROM 21 A SLICE_X37Y60 b'f4a5bd2a85da7ad6' +KEYROM 21 B SLICE_X37Y60 b'7b34842435ad6643' +KEYROM 21 C SLICE_X37Y60 b'680555e38333b824' +KEYROM 21 D SLICE_X37Y60 b'f52238f3a23f6823' +KEYROM 22 A SLICE_X36Y61 b'e66acde30283926c' +KEYROM 22 B SLICE_X36Y61 b'fa1d856c53476c3e' +KEYROM 22 C SLICE_X36Y61 b'85c7e56acc617a6c' +KEYROM 22 D SLICE_X36Y61 b'80eb2e91c11cc50a' +KEYROM 23 A SLICE_X37Y61 b'dd72ae20a782b480' +KEYROM 23 B SLICE_X37Y61 b'abff67507d431c8a' +KEYROM 23 C SLICE_X37Y61 b'f7777938b277aea2' +KEYROM 23 D SLICE_X37Y61 b'634726cedd3b5537' +KEYROM 24 A SLICE_X36Y62 b'e6506582408d39ce' +KEYROM 24 B SLICE_X36Y62 b'2a7511e97c36dd0a' +KEYROM 24 C SLICE_X36Y62 b'3612f35d7ec66f41' +KEYROM 24 D SLICE_X36Y62 b'b2df7104b89c57c0' +KEYROM 25 A SLICE_X37Y62 b'ba82d0bafa114fc8' +KEYROM 25 B SLICE_X37Y62 b'd53e0d2f4ef1be85' +KEYROM 25 C SLICE_X37Y62 b'0505b902ee81679d' +KEYROM 25 D SLICE_X37Y62 b'e5642bedf9d64049' +KEYROM 26 A SLICE_X36Y63 b'3273253b029bbd31' +KEYROM 26 B SLICE_X36Y63 b'd835604661c9c2d6' +KEYROM 26 C SLICE_X36Y63 b'd745ce6225442b0b' +KEYROM 26 D SLICE_X36Y63 b'721ccebdbb3ac8f6' +KEYROM 27 A SLICE_X37Y63 b'cf49dd20a62e6b8d' +KEYROM 27 B SLICE_X37Y63 b'7b972b0d3c859700' +KEYROM 27 C SLICE_X37Y63 b'cce695c18121cc17' +KEYROM 27 D SLICE_X37Y63 b'38e80e3cda01e93e' +KEYROM 28 A SLICE_X36Y64 b'13c52ea98ae5b7c8' +KEYROM 28 B SLICE_X36Y64 b'f3df5eaf7d98a7d4' +KEYROM 28 C SLICE_X36Y64 b'3f630ad83ca51d6b' +KEYROM 28 D SLICE_X36Y64 b'a9cf6962c7bc9511' +KEYROM 29 A SLICE_X37Y64 b'8afc60b2d3835958' +KEYROM 29 B SLICE_X37Y64 b'594fddca4fef1ceb' +KEYROM 29 C SLICE_X37Y64 b'e0e2c4baf29e66dc' +KEYROM 29 D SLICE_X37Y64 b'5fdcfd6d8b5511cf' +KEYROM 30 A SLICE_X36Y65 b'ca31c936cf2c0ccb' +KEYROM 30 B SLICE_X36Y65 b'71bd727cb1666975' +KEYROM 30 C SLICE_X36Y65 b'8104235008036fbb' +KEYROM 30 D SLICE_X36Y65 b'e26362ee08a04dc1' +KEYROM 31 A SLICE_X37Y65 b'c2d7ed7a1dd05b59' +KEYROM 31 B SLICE_X37Y65 b'd99dbec6e439a61f' +KEYROM 31 C SLICE_X37Y65 b'172a205e659acfa6' +KEYROM 31 D SLICE_X37Y65 b'6306a15e5c9c3467' diff --git a/precursors/soc.svd b/precursors/soc.svd index 2ea2e6aa7..de6be1dd9 100644 --- a/precursors/soc.svd +++ b/precursors/soc.svd @@ -3,7 +3,7 @@ litex SOC - + 8 32 @@ -1238,10 +1238,10 @@ register to disable individual events.]]> GIT_GITREV 0x0014 - 0x5ac27d00 + 0x1f5d7406 32 @@ -1258,7 +1258,7 @@ the exact git version used to build this firmware.]]> is ``1``, then the repository this was built from has one additional commit beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]> 0x0018 - 0x08 + 0x0a 32 @@ -3593,7 +3593,7 @@ inject too fast.]]> SEED1 0x0000 - 0x6ef8973c + 0x1eaac4e 32 @@ -3608,7 +3608,7 @@ inject too fast.]]> SEED0 0x0004 - 0x5df014e4 + 0x12142066 32 diff --git a/precursors/soc_csr.bin b/precursors/soc_csr.bin index 046216ddd..2076fe961 100644 Binary files a/precursors/soc_csr.bin and b/precursors/soc_csr.bin differ diff --git a/services/root-keys/src/implementation.rs b/services/root-keys/src/implementation.rs index 4c43cbce5..d4654ac34 100644 --- a/services/root-keys/src/implementation.rs +++ b/services/root-keys/src/implementation.rs @@ -16,7 +16,7 @@ use crate::bcrypt::*; use crate::api::PasswordType; use core::convert::TryInto; -use ed25519_dalek::{Keypair, Signature, PublicKey, Signer, ExpandedSecretKey}; +use ed25519_dalek::{Keypair, Signature, PublicKey, Signer, ExpandedSecretKey, SecretKey}; use curve25519_dalek::scalar::Scalar; use curve25519_dalek::constants; use sha2::{FallbackStrategy, Sha256, Sha512, Sha512Trunc256}; @@ -24,6 +24,7 @@ use digest::Digest; use graphics_server::BulkRead; use core::mem::size_of; use core::cell::RefCell; +use rand_core::RngCore; use aes::{Aes256, NewBlockCipher, BlockDecrypt, BlockEncrypt}; use cipher::generic_array::GenericArray; @@ -35,6 +36,13 @@ use root_keys::key2bits::*; // TODO: add hardware acceleration for BCRYPT so we can hit the OWASP target without excessive UX delay const BCRYPT_COST: u32 = 7; // 10 is the minimum recommended by OWASP; takes 5696 ms to verify @ 10 rounds; 804 ms to verify 7 rounds +/// Maximum number of times the global rollback limiter can be updated. Every time this is updated, +/// the firmware has to be re-signed, the gateware ROM re-injected, and the PDDB system key updated. +/// +/// N.B.: As of Xous 0.9.6 we don't have a call to update the anti-rollback count, we have only provisioned for +/// that call to exist sometime in the future. +const MAX_ROLLBACK_LIMIT: u8 = 255; + /// Size of the total area allocated for signatures. It is equal to the size of one FLASH sector, which is the smallest /// increment that can be erased. const SIGBLOCK_SIZE: u32 = 0x1000; @@ -86,6 +94,7 @@ impl KeyRomLocs { const PEPPER: u8 = 0xf8; const FPGA_MIN_REV: u8 = 0xfc; const LOADER_MIN_REV: u8 = 0xfd; + const GLOBAL_ROLLBACK: u8 = 0xfe; const CONFIG: u8 = 0xff; } @@ -277,13 +286,33 @@ impl<'a> RootKeys { } pub fn kernel_base(&self) -> u32 { self.kernel_base } + /// takes a root key and computes the current rollback state of the key by hashing it + /// MAX_ROLLBACK_LIMIT - GLOBAL_ROLLBACK times. + fn compute_key_rollback(&mut self, key: &mut [u8]) { + assert!(key.len() == 32, "Key length is incorrect"); + self.keyrom.wfo(utra::keyrom::ADDRESS_ADDRESS, KeyRomLocs::GLOBAL_ROLLBACK as u32); + let mut rollback_limit = self.keyrom.rf(utra::keyrom::DATA_DATA); + if rollback_limit > 255 { rollback_limit = 255; } // prevent increment-up attacks that roll over + log::debug!("rollback_limit: {}", rollback_limit); + for _i in 0..MAX_ROLLBACK_LIMIT - rollback_limit as u8 { + let mut hasher = Sha512Trunc256::new_with_strategy(FallbackStrategy::SoftwareOnly); + hasher.update(&key); + let digest = hasher.finalize(); + assert!(digest.len() == 32, "Digest had an incorrect length"); + key.copy_from_slice(&digest); + #[cfg(feature = "hazardous-debug")] + if _i >= (MAX_ROLLBACK_LIMIT - 3) { + log::info!("iter {} key {:x?}", _i, key); + } + } + } /// This implementation creates and destroys the AES key schedule on every function call /// However, Rootkey operations are not meant to be used for streaming operations; they are typically /// used to secure subkeys, so a bit of overhead on each call is OK in order to not keep excess secret /// data laying around. /// ASSUME: the caller has confirmed that the user password is valid and in cache pub fn aes_op(&mut self, key_index: u8, op_type: AesOpType, block: &mut [u8; 16]) { - let key = match key_index { + let mut key = match key_index { KeyRomLocs::USER_KEY => { let mut key_enc = self.read_key_256(KeyRomLocs::USER_KEY); let pcache: &PasswordCache = unsafe{& *(self.pass_cache.as_ptr() as *const PasswordCache)}; @@ -308,6 +337,7 @@ impl<'a> RootKeys { self.fake_key } }; + self.compute_key_rollback(&mut key); let cipher = Aes256::new(GenericArray::from_slice(&key)); match op_type { AesOpType::Decrypt => cipher.decrypt_block(block.try_into().unwrap()), @@ -315,7 +345,7 @@ impl<'a> RootKeys { } } pub fn aes_par_op(&mut self, key_index: u8, op_type: AesOpType, blocks: &mut[[u8; 16]; PAR_BLOCKS]) { - let key = match key_index { + let mut key = match key_index { KeyRomLocs::USER_KEY => { let mut key_enc = self.read_key_256(KeyRomLocs::USER_KEY); let pcache: &PasswordCache = unsafe{& *(self.pass_cache.as_ptr() as *const PasswordCache)}; @@ -337,6 +367,7 @@ impl<'a> RootKeys { self.fake_key } }; + self.compute_key_rollback(&mut key); let cipher = Aes256::new(GenericArray::from_slice(&key)); match op_type { AesOpType::Decrypt => { @@ -352,7 +383,7 @@ impl<'a> RootKeys { } } pub fn kwp_op(&mut self, kwp: &mut KeyWrapper) { - let key = match kwp.key_index { + let mut key = match kwp.key_index { KeyRomLocs::USER_KEY => { let mut key_enc = self.read_key_256(KeyRomLocs::USER_KEY); let pcache: &PasswordCache = unsafe{& *(self.pass_cache.as_ptr() as *const PasswordCache)}; @@ -374,6 +405,11 @@ impl<'a> RootKeys { self.fake_key } }; + #[cfg(feature = "hazardous-debug")] + log::debug!("root user key: {:x?}", key); + self.compute_key_rollback(&mut key); + #[cfg(feature = "hazardous-debug")] + log::debug!("root user key (anti-rollback): {:x?}", key); let keywrapper = Aes256KeyWrap::new(&key); match kwp.op { KeyWrapOp::Wrap => { @@ -810,9 +846,37 @@ impl<'a> RootKeys { // get access to the pcache and generate a keypair let pcache: &mut PasswordCache = unsafe{&mut *(self.pass_cache.as_mut_ptr() as *mut PasswordCache)}; + // initialize the global rollback constant to 0 + self.sensitive_data.borrow_mut().as_slice_mut::()[KeyRomLocs::GLOBAL_ROLLBACK as usize] = 0; + let mut root_sk = [0u8; ed25519_dalek::SECRET_KEY_LENGTH]; + self.trng.fill_bytes(&mut root_sk); + #[cfg(feature = "hazardous-debug")] + log::debug!("root privkey: {:x?}", root_sk); let keypair = if true { // true for production, false for debug (uses dev keys, so we can compare results) + // we use software hashing because for short keys its faster + let mut derived_sk = [0u8; ed25519_dalek::SECRET_KEY_LENGTH]; + derived_sk.copy_from_slice(&root_sk); + // hash a derived secret key based on the maximum rollback limit we anticipate less the current global rollback limit (which is 0) + // this allows us to work with a "final" key that generates a private signing key, which can't be predicted to future versions + // given the current key (due to the irreversability of Sha512/256), but once derived to a more recent version can be willfullly + // computed to an older version to recover e.g. old data encrypted with a prior key + // + // We don't use the `compute_key_rollback` function because the value of the GLOBAL_ROLLBACK in the KeyROM + // has not yet been set (it should be zero, but there is no reason for it to be at this point). + for _i in 0..MAX_ROLLBACK_LIMIT { + let mut hasher = Sha512Trunc256::new_with_strategy(FallbackStrategy::SoftwareOnly); + hasher.update(&derived_sk); + let digest = hasher.finalize(); + derived_sk.copy_from_slice(&digest); + #[cfg(feature = "hazardous-debug")] + if _i >= (MAX_ROLLBACK_LIMIT - 3) { + log::info!("iter {} key {:x?}", _i, derived_sk); + } + } + let sk: SecretKey = SecretKey::from_bytes(&derived_sk).expect("couldn't construct secret key"); + let pk: PublicKey = (&sk).into(); // keypair zeroizes on drop - Keypair::generate(&mut self.trng) + Keypair{public: pk, secret: sk} } else { Keypair::from_bytes( &[168, 167, 118, 92, 141, 162, 215, 147, 134, 43, 8, 176, 0, 222, 188, 167, 178, 14, 137, 237, 82, 199, 133, 162, 179, 235, 161, 219, 156, 182, 42, 39, @@ -825,7 +889,7 @@ impl<'a> RootKeys { #[cfg(feature = "hazardous-debug")] log::debug!("keypair privkey: {:?}", keypair.secret.to_bytes()); #[cfg(feature = "hazardous-debug")] - log::debug!("keypair privkey: {:x?}", keypair.secret.to_bytes()); + log::debug!("keypair privkey (after anti-rollback): {:x?}", keypair.secret.to_bytes()); // encrypt the FPGA key using the update password. in an un-init system, it is provided to us in plaintext format // e.g. in the case that we're doing a BBRAM boot (eFuse flow would give us a 0's key and we'd later on set it) @@ -876,7 +940,7 @@ impl<'a> RootKeys { // I don't think this loop should make any extra copies of the secret key, but might be good to check in godbolt! for (dst, (plain, key)) in private_key_enc.iter_mut() - .zip(keypair.secret.to_bytes().iter() + .zip(root_sk.iter() // we encrypt the root sk, not the derived sk .zip(pcache.hashed_update_pw.iter())) { *dst = plain ^ key; } @@ -1071,16 +1135,27 @@ impl<'a> RootKeys { // derive signing key let mut keypair_bytes: [u8; ed25519_dalek::KEYPAIR_LENGTH] = [0; ed25519_dalek::KEYPAIR_LENGTH]; let enc_signing_key = self.read_key_256(KeyRomLocs::SELFSIGN_PRIVKEY); + #[cfg(feature = "hazardous-debug")] + log::debug!("encrypted root privkey: {:x?}", enc_signing_key); for (key, (&enc_key, &pw)) in keypair_bytes[..ed25519_dalek::SECRET_KEY_LENGTH].iter_mut() .zip(enc_signing_key.iter().zip(pcache.hashed_update_pw.iter())) { *key = enc_key ^ pw; } + #[cfg(feature = "hazardous-debug")] + log::debug!("decrypted root privkey: {:x?}", &keypair_bytes[..ed25519_dalek::SECRET_KEY_LENGTH]); + // derived_sk now holds the "Root" secret key. It needs to be hashed (MAX_ROLLBACK_LIMIT - GLOBAL_ROLLBACK) times to get the current signing key. + self.compute_key_rollback(&mut keypair_bytes[..ed25519_dalek::SECRET_KEY_LENGTH]); + // now populate the public key portion. that's just in the plain. + // note that this would have been updated in the case of an update to GLOBAL_ROLLBACK -- the purpose of + // this routine is to sign software in the current rollback count, not to increment the rollback count for (key, &src) in keypair_bytes[ed25519_dalek::SECRET_KEY_LENGTH..].iter_mut() .zip(self.read_key_256(KeyRomLocs::SELFSIGN_PUBKEY).iter()) { *key = src; } #[cfg(feature = "hazardous-debug")] + log::debug!("anti-rollback privkey: {:x?}", &keypair_bytes[..ed25519_dalek::SECRET_KEY_LENGTH]); + #[cfg(feature = "hazardous-debug")] log::debug!("trying to make a keypair from {:x?}", keypair_bytes); // Keypair zeroizes on drop let keypair: Option = if provision_bbram && !self.is_initialized() { @@ -1090,6 +1165,8 @@ impl<'a> RootKeys { Some(Keypair::from_bytes(&keypair_bytes).map_err(|_| RootkeyResult::KeyError)?) }; log::debug!("keypair success"); + #[cfg(feature = "hazardous-debug")] + log::debug!("keypair privkey (after anti-rollback): {:x?}", keypair.as_ref().unwrap().secret.to_bytes()); // stage the keyrom data for patching self.populate_sensitive_data(); @@ -1286,12 +1363,17 @@ impl<'a> RootKeys { .zip(enc_signing_key.iter().zip(pcache.hashed_update_pw.iter())) { *key = enc_key ^ pw; } + self.compute_key_rollback(&mut keypair_bytes[..ed25519_dalek::SECRET_KEY_LENGTH]); + #[cfg(feature = "hazardous-debug")] + log::debug!("keypair privkey (after anti-rollback): {:x?}", &keypair_bytes[..ed25519_dalek::SECRET_KEY_LENGTH]); for (key, &src) in keypair_bytes[ed25519_dalek::SECRET_KEY_LENGTH..].iter_mut() .zip(self.read_key_256(KeyRomLocs::SELFSIGN_PUBKEY).iter()) { *key = src; } // Keypair zeroizes the secret key on drop. let keypair = Keypair::from_bytes(&keypair_bytes).map_err(|_| RootkeyResult::KeyError)?; + #[cfg(feature = "hazardous-debug")] + log::debug!("keypair privkey (after anti-rollback + conversion): {:x?}", keypair.secret.to_bytes()); // check if the keypair is valid by signing and verifying a short message let test_data = "whiskey made me do it"; @@ -1755,6 +1837,7 @@ impl<'a> RootKeys { self.debug_print_key(KeyRomLocs::USER_KEY as usize, 256, "Boot key: "); self.debug_print_key(KeyRomLocs::PEPPER as usize, 128, "Pepper: "); self.debug_print_key(KeyRomLocs::CONFIG as usize, 32, "Config (as BE): "); + self.debug_print_key(KeyRomLocs::GLOBAL_ROLLBACK as usize, 32, "Global rollback state: "); } #[cfg(feature = "hazardous-debug")] diff --git a/services/root-keys/src/main.rs b/services/root-keys/src/main.rs index 44c3a1045..d58b72a0b 100644 --- a/services/root-keys/src/main.rs +++ b/services/root-keys/src/main.rs @@ -298,7 +298,7 @@ fn xmain() -> ! { use crate::implementation::RootKeys; log_server::init_wait().unwrap(); - log::set_max_level(log::LevelFilter::Info); + log::set_max_level(log::LevelFilter::Debug); log::info!("my PID is {}", xous::process::id()); let xns = xous_names::XousNames::new().unwrap(); diff --git a/tools/usb_update.py b/tools/usb_update.py index b1ce7492a..4de24216b 100755 --- a/tools/usb_update.py +++ b/tools/usb_update.py @@ -583,14 +583,19 @@ def main(): with open(args.soc, "rb") as f: image = f.read() pc_usb.flash_program(locs['LOC_SOC'][0], image, verify=verify) + print("Erasing PDDB root structures") + pc_usb.erase_region(locs['LOC_PDDB'][0], 1024 * 1024) else: - print("This will overwrite any secret keys in your device. Continue? (y/n)") + print("This will overwrite any secret keys in your device and erase PDDB keys. Continue? (y/n)") confirm = input() if len(confirm) > 0 and confirm.lower()[:1] == 'y': print("Programming SoC gateware {}".format(args.soc)) with open(args.soc, "rb") as f: image = f.read() pc_usb.flash_program(locs['LOC_SOC'][0], image, verify=verify) + print("Erasing PDDB root structures") + pc_usb.erase_region(locs['LOC_PDDB'][0], 1024 * 1024) + if args.audiotest != None: print("Loading audio test clip {}".format(args.audiotest))