diff --git a/precursors/rom.db b/precursors/rom.db index 1be535f35..b1f179960 100755 --- a/precursors/rom.db +++ b/precursors/rom.db @@ -1,128 +1,128 @@ -KEYROM 0 A SLICE_X36Y50 b'f5032e36c22badb3' -KEYROM 0 B SLICE_X36Y50 b'97c459376bbc779d' -KEYROM 0 C SLICE_X36Y50 b'b35296554c2a44c7' -KEYROM 0 D SLICE_X36Y50 b'3cbb3d2cfcc0fce1' -KEYROM 1 A SLICE_X37Y50 b'18da3e2879bddd7b' -KEYROM 1 B SLICE_X37Y50 b'700d0d7c792a18df' -KEYROM 1 C SLICE_X37Y50 b'9dd0c0e54a563e68' -KEYROM 1 D SLICE_X37Y50 b'28dfc2af77ebc1e2' -KEYROM 2 A SLICE_X36Y51 b'76bcfe80ae27e2ba' -KEYROM 2 B SLICE_X36Y51 b'e71840c586e9b9cb' -KEYROM 2 C SLICE_X36Y51 b'be6db324fcd23263' -KEYROM 2 D SLICE_X36Y51 b'59f99bcc77a8bd21' -KEYROM 3 A SLICE_X37Y51 b'bf5ceb1ab4cf92e1' -KEYROM 3 B SLICE_X37Y51 b'3badf5f230f816c3' -KEYROM 3 C SLICE_X37Y51 b'eeba2922233aca7d' -KEYROM 3 D SLICE_X37Y51 b'29631efba2041c45' -KEYROM 4 A SLICE_X36Y52 b'f951f10c3939bde8' -KEYROM 4 B SLICE_X36Y52 b'a404d45212e2766d' -KEYROM 4 C SLICE_X36Y52 b'6154b4ac03c65918' -KEYROM 4 D SLICE_X36Y52 b'd67a854d527cecea' -KEYROM 5 A SLICE_X37Y52 b'dbe1e94cddd01767' -KEYROM 5 B SLICE_X37Y52 b'2f827c76299ade33' -KEYROM 5 C SLICE_X37Y52 b'27599f5202e88450' -KEYROM 5 D SLICE_X37Y52 b'cf0546d3b774e279' -KEYROM 6 A SLICE_X36Y53 b'3c8f4269b1c8a1e0' -KEYROM 6 B SLICE_X36Y53 b'5d1be0bcdd10dcef' -KEYROM 6 C SLICE_X36Y53 b'7d5506360ba57379' -KEYROM 6 D SLICE_X36Y53 b'06650b2220f76735' -KEYROM 7 A SLICE_X37Y53 b'14e6f7ae586714cd' -KEYROM 7 B SLICE_X37Y53 b'8ce57cb7955975d9' -KEYROM 7 C SLICE_X37Y53 b'80343db9d9ef67c5' -KEYROM 7 D SLICE_X37Y53 b'886f3490f33df804' -KEYROM 8 A SLICE_X36Y54 b'9416feb420bb0251' -KEYROM 8 B SLICE_X36Y54 b'87ddc634e0d5ef83' -KEYROM 8 C SLICE_X36Y54 b'fc65ec1d0fb42be0' -KEYROM 8 D SLICE_X36Y54 b'9fc4ffd88f65fb49' -KEYROM 9 A SLICE_X37Y54 b'f61857c0a1bbf395' -KEYROM 9 B SLICE_X37Y54 b'4ffdef7594c903ca' -KEYROM 9 C SLICE_X37Y54 b'530bc672703b51e0' -KEYROM 9 D SLICE_X37Y54 b'2e129bd793279c0f' -KEYROM 10 A SLICE_X36Y55 b'53145df3a8920c86' -KEYROM 10 B SLICE_X36Y55 b'30de635ce9031e49' -KEYROM 10 C SLICE_X36Y55 b'67afa8dd5af8e472' -KEYROM 10 D SLICE_X36Y55 b'b5f8b34728e659dd' -KEYROM 11 A SLICE_X37Y55 b'4b621e067571550a' -KEYROM 11 B SLICE_X37Y55 b'505a0935a7367ce2' -KEYROM 11 C SLICE_X37Y55 b'3733c9e19c6467c6' -KEYROM 11 D SLICE_X37Y55 b'e26322fb994ce75a' -KEYROM 12 A SLICE_X36Y56 b'e927d1871c084da2' -KEYROM 12 B SLICE_X36Y56 b'0cfe817116c92a46' -KEYROM 12 C SLICE_X36Y56 b'532a42ce1272859b' -KEYROM 12 D SLICE_X36Y56 b'65420f79a00c85db' -KEYROM 13 A SLICE_X37Y56 b'ad36100534dda463' -KEYROM 13 B SLICE_X37Y56 b'caa3c50263cc74e0' -KEYROM 13 C SLICE_X37Y56 b'fd8a2be36f092538' -KEYROM 13 D SLICE_X37Y56 b'b0fd5330609733d1' -KEYROM 14 A SLICE_X36Y57 b'baa53a4843edd51d' -KEYROM 14 B SLICE_X36Y57 b'c7149946f7a05a13' -KEYROM 14 C SLICE_X36Y57 b'60a734f2f24b9db6' -KEYROM 14 D SLICE_X36Y57 b'8f3a488502253383' -KEYROM 15 A SLICE_X37Y57 b'9486133f4dfd9bbd' -KEYROM 15 B SLICE_X37Y57 b'8c71fcb31480917f' -KEYROM 15 C SLICE_X37Y57 b'6ebc9318e34aedd0' -KEYROM 15 D SLICE_X37Y57 b'b0be54f33be2ba74' -KEYROM 16 A SLICE_X36Y58 b'295e2b2575cc6019' -KEYROM 16 B SLICE_X36Y58 b'abc807fe55f3b188' -KEYROM 16 C SLICE_X36Y58 b'df904e5946e6b658' -KEYROM 16 D SLICE_X36Y58 b'f47e26797d693b74' -KEYROM 17 A SLICE_X37Y58 b'283a224c53fe9cea' -KEYROM 17 B SLICE_X37Y58 b'786799d427ac080e' -KEYROM 17 C SLICE_X37Y58 b'b191370ed36a012b' -KEYROM 17 D SLICE_X37Y58 b'f97389b2bc29798c' -KEYROM 18 A SLICE_X36Y59 b'71e24c88040dfd67' -KEYROM 18 B SLICE_X36Y59 b'a482cc7490e291a0' -KEYROM 18 C SLICE_X36Y59 b'9010759ced69f991' -KEYROM 18 D SLICE_X36Y59 b'173e3124f647b4ba' -KEYROM 19 A SLICE_X37Y59 b'359dacef6bd866a3' -KEYROM 19 B SLICE_X37Y59 b'd82c698b4daca5f7' -KEYROM 19 C SLICE_X37Y59 b'cd32990f4f8c2270' -KEYROM 19 D SLICE_X37Y59 b'51da0b72d650350f' -KEYROM 20 A SLICE_X36Y60 b'994d0ec3a075e7af' -KEYROM 20 B SLICE_X36Y60 b'128a2692eab6c5b5' -KEYROM 20 C SLICE_X36Y60 b'f4a6a2d55c2a4933' -KEYROM 20 D SLICE_X36Y60 b'66dc27964f942400' -KEYROM 21 A SLICE_X37Y60 b'b57b754e1bae2a14' -KEYROM 21 B SLICE_X37Y60 b'2ad4e48d17237b11' -KEYROM 21 C SLICE_X37Y60 b'710b2e56c4fad051' -KEYROM 21 D SLICE_X37Y60 b'3b0e049bebdac174' -KEYROM 22 A SLICE_X36Y61 b'56ea6ee30428b9c8' -KEYROM 22 B SLICE_X36Y61 b'24e3cc9c8fea184a' -KEYROM 22 C SLICE_X36Y61 b'e33f2a504311d9e0' -KEYROM 22 D SLICE_X36Y61 b'ac8feb413513a46b' -KEYROM 23 A SLICE_X37Y61 b'85d03e4bc9d665cd' -KEYROM 23 B SLICE_X37Y61 b'7112db9d2d7f6154' -KEYROM 23 C SLICE_X37Y61 b'46e22da54c5f479b' -KEYROM 23 D SLICE_X37Y61 b'8e3d1c6c70ff2258' -KEYROM 24 A SLICE_X36Y62 b'0764b67c5605acae' -KEYROM 24 B SLICE_X36Y62 b'0cc85b1e261b81e9' -KEYROM 24 C SLICE_X36Y62 b'5be0c4d20bd5fdf4' -KEYROM 24 D SLICE_X36Y62 b'5567ae01770be278' -KEYROM 25 A SLICE_X37Y62 b'8d515e1a1e29a6ad' -KEYROM 25 B SLICE_X37Y62 b'b7d7246bab95967d' -KEYROM 25 C SLICE_X37Y62 b'1fb38b0d689a9a9c' -KEYROM 25 D SLICE_X37Y62 b'e443fb4977de7443' -KEYROM 26 A SLICE_X36Y63 b'5549e97f573a2b46' -KEYROM 26 B SLICE_X36Y63 b'5463e10a11c1343b' -KEYROM 26 C SLICE_X36Y63 b'89cb1f0dfa5b926f' -KEYROM 26 D SLICE_X36Y63 b'344249847cbbe2de' -KEYROM 27 A SLICE_X37Y63 b'17bda787811ef1e6' -KEYROM 27 B SLICE_X37Y63 b'b1164661fe8aee33' -KEYROM 27 C SLICE_X37Y63 b'40de3494e23f6fb3' -KEYROM 27 D SLICE_X37Y63 b'36545bdd38024420' -KEYROM 28 A SLICE_X36Y64 b'c2e149ac47c1d8da' -KEYROM 28 B SLICE_X36Y64 b'daa5dd2e59ee1310' -KEYROM 28 C SLICE_X36Y64 b'2f3539b88cd8265f' -KEYROM 28 D SLICE_X36Y64 b'f62f156563b16aab' -KEYROM 29 A SLICE_X37Y64 b'fd128253b2d57a90' -KEYROM 29 B SLICE_X37Y64 b'e0aeeb8875660a32' -KEYROM 29 C SLICE_X37Y64 b'9dd8a72708bb02d9' -KEYROM 29 D SLICE_X37Y64 b'c6622a74e66114ce' -KEYROM 30 A SLICE_X36Y65 b'ebc640c6b608ee03' -KEYROM 30 B SLICE_X36Y65 b'29fcd7f24804d91a' -KEYROM 30 C SLICE_X36Y65 b'cff9bcddb9ff8bf4' -KEYROM 30 D SLICE_X36Y65 b'd160014d3c2e9f73' -KEYROM 31 A SLICE_X37Y65 b'e1c3ae9493e22900' -KEYROM 31 B SLICE_X37Y65 b'96aaefd3d511097d' -KEYROM 31 C SLICE_X37Y65 b'5ce5cda211b81874' -KEYROM 31 D SLICE_X37Y65 b'6a98961a3a452b9e' +KEYROM 0 A SLICE_X36Y50 b'a53b8633d2c09768' +KEYROM 0 B SLICE_X36Y50 b'000a2582e07fb2a7' +KEYROM 0 C SLICE_X36Y50 b'eab8658a4f0826da' +KEYROM 0 D SLICE_X36Y50 b'3cf98bd03b4b1050' +KEYROM 1 A SLICE_X37Y50 b'95555fc361e34d76' +KEYROM 1 B SLICE_X37Y50 b'f8364f67375aa368' +KEYROM 1 C SLICE_X37Y50 b'5b4b2dfa1d71e615' +KEYROM 1 D SLICE_X37Y50 b'0504321052f4306e' +KEYROM 2 A SLICE_X36Y51 b'430b2ed15cce537a' +KEYROM 2 B SLICE_X36Y51 b'907f4d383fe37e03' +KEYROM 2 C SLICE_X36Y51 b'09f0aa1bd51e79a7' +KEYROM 2 D SLICE_X36Y51 b'8a6afc3066217e2f' +KEYROM 3 A SLICE_X37Y51 b'0b46302457bd2475' +KEYROM 3 B SLICE_X37Y51 b'36bd83fa3428e283' +KEYROM 3 C SLICE_X37Y51 b'4e7c398d0ff910dc' +KEYROM 3 D SLICE_X37Y51 b'07c8ddeb2f2b822d' +KEYROM 4 A SLICE_X36Y52 b'dcff079e9aa6883f' +KEYROM 4 B SLICE_X36Y52 b'e1c96fa999e04bf3' +KEYROM 4 C SLICE_X36Y52 b'50ddaab5d3cc886b' +KEYROM 4 D SLICE_X36Y52 b'31597c554ae9513b' +KEYROM 5 A SLICE_X37Y52 b'1723fcd07a090afa' +KEYROM 5 B SLICE_X37Y52 b'd4493e4b32337f73' +KEYROM 5 C SLICE_X37Y52 b'd6a90c9b5d125269' +KEYROM 5 D SLICE_X37Y52 b'540c8ad444381c64' +KEYROM 6 A SLICE_X36Y53 b'131410857fd2c11c' +KEYROM 6 B SLICE_X36Y53 b'd0b890fd8d16e411' +KEYROM 6 C SLICE_X36Y53 b'3911b198a9a9df05' +KEYROM 6 D SLICE_X36Y53 b'9fd7df5d32bf99b3' +KEYROM 7 A SLICE_X37Y53 b'2044902459eb1a89' +KEYROM 7 B SLICE_X37Y53 b'15a0a1748b564e80' +KEYROM 7 C SLICE_X37Y53 b'a0eee6c61a63ae66' +KEYROM 7 D SLICE_X37Y53 b'0893ed8f379d35a6' +KEYROM 8 A SLICE_X36Y54 b'b0eb832024c6e26d' +KEYROM 8 B SLICE_X36Y54 b'2d61f11d78c4a812' +KEYROM 8 C SLICE_X36Y54 b'65c55158e0c0c052' +KEYROM 8 D SLICE_X36Y54 b'a3bf2d57009664d8' +KEYROM 9 A SLICE_X37Y54 b'6bdc1266af68f2dd' +KEYROM 9 B SLICE_X37Y54 b'a31f6c2d2ee1d9e5' +KEYROM 9 C SLICE_X37Y54 b'a534bb5f89e590d6' +KEYROM 9 D SLICE_X37Y54 b'be51d1c9d5e24227' +KEYROM 10 A SLICE_X36Y55 b'97e21e8706f9d38b' +KEYROM 10 B SLICE_X36Y55 b'e16e50b2369d1267' +KEYROM 10 C SLICE_X36Y55 b'49a8ce00643d607b' +KEYROM 10 D SLICE_X36Y55 b'3955603a77a89d49' +KEYROM 11 A SLICE_X37Y55 b'7d48fb9cba80842b' +KEYROM 11 B SLICE_X37Y55 b'8942a124650a82db' +KEYROM 11 C SLICE_X37Y55 b'9a7d9e222c28954b' +KEYROM 11 D SLICE_X37Y55 b'da1f40223f431251' +KEYROM 12 A SLICE_X36Y56 b'21a2a389755b5979' +KEYROM 12 B SLICE_X36Y56 b'dbdda74b44f3776d' +KEYROM 12 C SLICE_X36Y56 b'a1b28af0f2232f2c' +KEYROM 12 D SLICE_X36Y56 b'1b1e5e8736ebbf47' +KEYROM 13 A SLICE_X37Y56 b'2506be42ce574822' +KEYROM 13 B SLICE_X37Y56 b'751e6c19b2b464f2' +KEYROM 13 C SLICE_X37Y56 b'cf6cdd5226cad6ae' +KEYROM 13 D SLICE_X37Y56 b'9873d5c1d8417584' +KEYROM 14 A SLICE_X36Y57 b'88507da694e0b692' +KEYROM 14 B SLICE_X36Y57 b'0560ea7a267b9335' +KEYROM 14 C SLICE_X36Y57 b'bcacd97b1df85841' +KEYROM 14 D SLICE_X36Y57 b'8180d12a1b7fe354' +KEYROM 15 A SLICE_X37Y57 b'f141d1ff7fa02577' +KEYROM 15 B SLICE_X37Y57 b'a3ae7dde9824dab1' +KEYROM 15 C SLICE_X37Y57 b'5370fece53e06f0f' +KEYROM 15 D SLICE_X37Y57 b'92cb97143fb66dbc' +KEYROM 16 A SLICE_X36Y58 b'ff7ab99e397fbcb6' +KEYROM 16 B SLICE_X36Y58 b'075984b3c54a250c' +KEYROM 16 C SLICE_X36Y58 b'b855986030bd05ea' +KEYROM 16 D SLICE_X36Y58 b'2e55e4fbe27a5bc4' +KEYROM 17 A SLICE_X37Y58 b'59f6fddba2b559ad' +KEYROM 17 B SLICE_X37Y58 b'abe5c8c09acc9a01' +KEYROM 17 C SLICE_X37Y58 b'db4a2abe695911b8' +KEYROM 17 D SLICE_X37Y58 b'9489c9be95e5097c' +KEYROM 18 A SLICE_X36Y59 b'0ca2be4e5cd78da4' +KEYROM 18 B SLICE_X36Y59 b'bcedf30ece888c8c' +KEYROM 18 C SLICE_X36Y59 b'df9e73348c5775c0' +KEYROM 18 D SLICE_X36Y59 b'1a453dabd385b948' +KEYROM 19 A SLICE_X37Y59 b'951987a46fa22546' +KEYROM 19 B SLICE_X37Y59 b'711c9ecb07bec539' +KEYROM 19 C SLICE_X37Y59 b'6d2a9f731b870280' +KEYROM 19 D SLICE_X37Y59 b'74bac6391a450417' +KEYROM 20 A SLICE_X36Y60 b'0c98ba8070a4afe7' +KEYROM 20 B SLICE_X36Y60 b'c3816905d3cb77c9' +KEYROM 20 C SLICE_X36Y60 b'9b93d69434ca96e0' +KEYROM 20 D SLICE_X36Y60 b'2ff910e69c27284d' +KEYROM 21 A SLICE_X37Y60 b'febc1d4f3222bfd6' +KEYROM 21 B SLICE_X37Y60 b'267d2d4c9191788d' +KEYROM 21 C SLICE_X37Y60 b'be499c76068eb9f9' +KEYROM 21 D SLICE_X37Y60 b'91043684500de6e7' +KEYROM 22 A SLICE_X36Y61 b'b73893e69dad4960' +KEYROM 22 B SLICE_X36Y61 b'4eba5a8bb1a30ea2' +KEYROM 22 C SLICE_X36Y61 b'37902177f14f1dfa' +KEYROM 22 D SLICE_X36Y61 b'129dae53c81b1506' +KEYROM 23 A SLICE_X37Y61 b'6bae766c10b10680' +KEYROM 23 B SLICE_X37Y61 b'47669a1117b676d4' +KEYROM 23 C SLICE_X37Y61 b'90f875251c8e5d9d' +KEYROM 23 D SLICE_X37Y61 b'c89205babd9838dc' +KEYROM 24 A SLICE_X36Y62 b'b68574734a3c24a9' +KEYROM 24 B SLICE_X36Y62 b'382dfc2de0b218ce' +KEYROM 24 C SLICE_X36Y62 b'aa0b1cf4c9a5895a' +KEYROM 24 D SLICE_X36Y62 b'c5917faec84f1889' +KEYROM 25 A SLICE_X37Y62 b'23b497865f28312f' +KEYROM 25 B SLICE_X37Y62 b'5da62242a22c270f' +KEYROM 25 C SLICE_X37Y62 b'3cfa3dcca6c4f240' +KEYROM 25 D SLICE_X37Y62 b'fa5b52d200f3dc50' +KEYROM 26 A SLICE_X36Y63 b'8de0d214da1d8323' +KEYROM 26 B SLICE_X36Y63 b'54f6556ba4e72cd7' +KEYROM 26 C SLICE_X36Y63 b'834499109fa776fa' +KEYROM 26 D SLICE_X36Y63 b'bf28468b240bbd71' +KEYROM 27 A SLICE_X37Y63 b'4323421f948c41f0' +KEYROM 27 B SLICE_X37Y63 b'0a4dde22e6739a84' +KEYROM 27 C SLICE_X37Y63 b'e052214ce2c176e2' +KEYROM 27 D SLICE_X37Y63 b'7df27f6c65444ea8' +KEYROM 28 A SLICE_X36Y64 b'9be790d58acd08c9' +KEYROM 28 B SLICE_X36Y64 b'b3d03fe04906c456' +KEYROM 28 C SLICE_X36Y64 b'387a602f04c2384d' +KEYROM 28 D SLICE_X36Y64 b'9e3f9943585ddfc9' +KEYROM 29 A SLICE_X37Y64 b'6676183ef4ec2edd' +KEYROM 29 B SLICE_X37Y64 b'b1d9049384da3a25' +KEYROM 29 C SLICE_X37Y64 b'7a5f4d6d242d4dca' +KEYROM 29 D SLICE_X37Y64 b'1f9a9a9650f463bc' +KEYROM 30 A SLICE_X36Y65 b'15203380289dc785' +KEYROM 30 B SLICE_X36Y65 b'dab6a33bf63094d9' +KEYROM 30 C SLICE_X36Y65 b'522eca1d31763894' +KEYROM 30 D SLICE_X36Y65 b'06102b836f01dab8' +KEYROM 31 A SLICE_X37Y65 b'27074622e91010d5' +KEYROM 31 B SLICE_X37Y65 b'6dcbea83723e86c6' +KEYROM 31 C SLICE_X37Y65 b'6222fec8855f940f' +KEYROM 31 D SLICE_X37Y65 b'a3221ebc55b0807f' diff --git a/precursors/soc.svd b/precursors/soc.svd index 7b49d816e..fc7244ba5 100755 --- a/precursors/soc.svd +++ b/precursors/soc.svd @@ -3,7 +3,7 @@ litex SOC - + 8 32 @@ -3584,7 +3584,7 @@ inject too fast.]]> SEED1 0x0000 - 0x3af77e74 + 0x15cba767 32 @@ -3599,7 +3599,7 @@ inject too fast.]]> SEED0 0x0004 - 0x1d5853f8 + 0x77beb5af 32 diff --git a/precursors/soc_csr.bin b/precursors/soc_csr.bin index ca4627b38..2fa20ed30 100755 Binary files a/precursors/soc_csr.bin and b/precursors/soc_csr.bin differ diff --git a/services/root-keys/locales/i18n.json b/services/root-keys/locales/i18n.json index 17a806262..d96b363ac 100644 --- a/services/root-keys/locales/i18n.json +++ b/services/root-keys/locales/i18n.json @@ -90,9 +90,9 @@ "en-audio": "Verification failed, aborting" }, "rootkeys.init.fail_key": { - "en": "FPGA key is wrong,\naborting!", + "en": "FPGA key is wrong:\nPerhaps the update password\nwas entered incorrectly?", "zh": "*missing*正在初始化失败,中止!", - "en-audio": "FPGA key is wrong, aborting" + "en-audio": "FPGA key is wrong, perhaps the update password was entered incorrectly?" }, "rootkeys.init.fail_burn": { "en": "FLASH write problem,\naborting!", diff --git a/services/root-keys/src/implementation.rs b/services/root-keys/src/implementation.rs index 128e7bfe4..378d7f4d5 100644 --- a/services/root-keys/src/implementation.rs +++ b/services/root-keys/src/implementation.rs @@ -130,7 +130,21 @@ fn bitflip(input: &[u8], output: &mut [u8]) { } } +#[derive(Debug, Copy, Clone)] +enum FpgaKeySource { + Bbram, + Efuse, +} + const AES_BLOCKSIZE: usize = 16; +// a "slight" lie in that it's not literally the bitstream command, it's the fully encoded word + length of args. +const BITSTREAM_CTL0_CMD: u32 = 0x3000_a001; +const BITSTREAM_CTL0_CMD_FLIP: u32 = 0x8005_000c; +const BITSTREAM_MASK_CMD: u32 = 0x3000_c001; +#[allow(dead_code)] +const BITSTREAM_MASK_CMD_FLIP: u32 = 0x8005_000c; +const BITSTREAM_IV_CMD: u32 = 0x3001_6004; +const BITSTREAM_CIPHERTEXT_CMD: u32 = 0x3003_4001; /// This structure encapsulates the tools necessary to create an Oracle that can go from /// the encrypted bitstream to plaintext and back again, based on the position in the bitstream. /// It is a partial re-implementation of the Cbc crate from block-ciphers, and the reason we're @@ -151,12 +165,16 @@ struct BitstreamOracle<'a> { /// start of type2 data as an offset relative to the start of ciphertext type2_ciphertext_offset: usize, /// length of the undifferentiated plaintext header -- this is right up to the IV specifier + #[allow(dead_code)] pt_header_len: usize, + enc_to_key: FpgaKeySource, + dec_from_key: FpgaKeySource, } impl<'a> BitstreamOracle<'a> { /// oracle supports separate encryption and decryption keys, so that it may /// be used for re-encryption of bitstreams to a new key. If using it for patching, /// set the keys to the same value. + /// key_target selects what we want the encrypted target to be for boot key source; if None, we retain the bitstream settings pub fn new(dec_key: &'a[u8], enc_key: &'a[u8], bitstream: &'a[u8], base: u32) -> Result, RootkeyResult> { let mut position: usize = 0; @@ -166,10 +184,10 @@ impl<'a> BitstreamOracle<'a> { let mut cwd = 0; while position < bitstream.len() { cwd = u32::from_be_bytes(bitstream[position..position+4].try_into().unwrap()); - if cwd == 0x3001_6004 { + if cwd == BITSTREAM_IV_CMD { iv_pos = position + 4 } - if cwd == 0x3003_4001 { + if cwd == BITSTREAM_CIPHERTEXT_CMD { break; } position += 1; @@ -190,7 +208,9 @@ impl<'a> BitstreamOracle<'a> { log::info!("recovered iv (pre-flip): {:x?}", &bitstream[iv_pos..iv_pos + AES_BLOCKSIZE]); log::info!("recovered iv : {:x?}", &iv_bytes); + log::info!("AES decryption key: {:x?}", dec_key); let dec_cipher = Aes256::new(dec_key.try_into().unwrap()); + log::info!("AES encryption key: {:x?}", enc_key); let enc_cipher = Aes256::new(enc_key.try_into().unwrap()); let mut oracle = BitstreamOracle { @@ -205,6 +225,8 @@ impl<'a> BitstreamOracle<'a> { type2_absolute_offset: 0, type2_ciphertext_offset: 0, pt_header_len: iv_pos, // plaintext header goes all the way up to the IV + enc_to_key: FpgaKeySource::Efuse, // these get set later + dec_from_key: FpgaKeySource::Efuse, }; // search forward for the "type 2" region in the first kilobyte of plaintext @@ -245,8 +267,40 @@ impl<'a> BitstreamOracle<'a> { oracle.type2_ciphertext_offset = pt_pos; log::info!("type2 absolute: {}, relative to ct start: {}", oracle.type2_absolute_offset, oracle.type2_ciphertext_offset); + // read the boot source out of the ciphertext + let mut bytes = first_block.chunks(4).into_iter(); + let mut ctl0_enc: Option = None; + loop { + if let Some(b) = bytes.next() { + let word = u32::from_be_bytes(b.try_into().unwrap()); + if word == BITSTREAM_CTL0_CMD_FLIP { + if let Some(val) = bytes.next() { + let mut flip: [u8; 4] = [0; 4]; + bitflip(val, &mut flip); + let w = u32::from_be_bytes(flip.try_into().unwrap()); + ctl0_enc = Some(w); + } else { + log::error!("didn't decrypt enough memory to find the ctl0 encrypted settings"); + return Err(RootkeyResult::IntegrityError); + } + break; + } + } else { + break; + } + } + if (ctl0_enc.unwrap() & 0x8000_0000) == 0x8000_0000 { + oracle.dec_from_key = FpgaKeySource::Efuse; + } else { + oracle.dec_from_key = FpgaKeySource::Bbram; + } + // by default, we always re-encrypt to the same key type + oracle.enc_to_key = oracle.dec_from_key; + Ok(oracle) } + + #[allow(dead_code)] pub fn pt_header_len(&self) -> usize {self.pt_header_len as usize} pub fn base(&self) -> u32 {self.base} pub fn ciphertext_offset(&self) -> usize { @@ -255,6 +309,12 @@ impl<'a> BitstreamOracle<'a> { pub fn ciphertext(&self) -> &[u8] { self.ciphertext } + pub fn get_original_key_type(&self) -> FpgaKeySource {self.dec_from_key} + /// the main use case for this API is changing from a BBRAM->eFuse source + /// we can't go eFuse->BBRAM because, unfortunately, we can't program BBRAM keys natively; the bitstream will have to have been constructed for BBRAM already for a good boot + pub fn set_target_key_type(&mut self, keytype: FpgaKeySource) { + self.enc_to_key = keytype; + } pub fn ciphertext_offset_to_frame(&self, offset: usize) -> (usize, usize) { let type2_offset = offset - self.type2_ciphertext_offset; @@ -320,7 +380,8 @@ impl<'a> BitstreamOracle<'a> { /// chaining value. It is up to the caller to manage the linear order of the calls. /// ASSUME: `from` + `self.ct_absolute_offset` is a multiple of an erase block /// returns the actual number of bytes processed - pub fn encrypt_sector(&self, from: i32, input_plaintext: &[u8], output_sector: &mut [u8]) -> usize { + /// NOTE: input plaintext can be changed by this function -- the first block is modified based on the requested encryption type + pub fn encrypt_sector(&self, from: i32, input_plaintext: &mut [u8], output_sector: &mut [u8]) -> usize { assert!(output_sector.len() & (AES_BLOCKSIZE - 1) == 0, "output length must be a multiple of AES block size"); assert!(input_plaintext.len() & (AES_BLOCKSIZE - 1) == 0, "input length must be a multiple of AES block size"); assert!((from + self.ct_absolute_offset as i32) & (spinor::SPINOR_ERASE_SIZE as i32 - 1) == 0, "request address must line up with an erase block boundary"); @@ -333,28 +394,122 @@ impl<'a> BitstreamOracle<'a> { let mut out_start_offset = 0; if from < 0 { - // copy the plaintext header as-is: we don't modify it, once it's in the device (e.g. we won't switch - // from eFuse to BBRAM or back again). Later on if such a switching is desired, I believe it's just a couple - // bytes patched in the plaintext header to change this, but, for now, let's assume once you're on a given - // encryption train, you're staying on it. BBRAM requires external provisioning anyways, and BBRAM users - // would be using this feature because they don't trust eFuse. eFuse users can't switch to BBRAM without an - // external programmer that would burn the key in the first place. + // A bit of a nightmare, but we have to patch over the efuse/bbram selection settings + // on the fly, because a user might be using bbram, but updates are by default set to use efuse. + // // the plaintext header already has: - // - all the fuse and config settings + // - one copy of the fuse and config settings // - padding // - IV for cipher // - length of ciphertext region + // slightly into the ciphertext region is another set of bits that re-confirm the key settings. + // we need to flip the bits that control bbram vs aes key boot as part of the re-encryption process. + // + // So: 1. check to see what type of boot we are doing + // 2. update the header bits to match it. + // 3. update the ciphertext (in two places) to match. + // + // The instruction that selects eFuse/BBRAM is 'Control Register 0' (00101) + // It has the in-bitstream hex code of 0x3000a001 and is set to 0x80000040 for efuse boot and + // 0x00000040 for bbram boot. The byte to patch is at offset 88 decimal in the bitstream headers + // generated by our tools, but it would be more reliable to search for the instruction and patch the + // byte after it. The `mask` register (00110) is also set, hex code 0x3000c001, set to 0x80000040 + // to allow for the control register write to "take" + + // copy the plaintext header over to the destination, as-is for (&src, dst) in self.bitstream[..self.ct_absolute_offset].iter() .zip(output_sector[..self.ct_absolute_offset].iter_mut()) { *dst = src; } out_start_offset = self.ct_absolute_offset; + + // now, make sure that the new settings match the settings indicated by the oracle. + // 1. patch the plaintext header + let mut pos = 0; + let mut patchcount = 0; + while pos < self.ct_absolute_offset { + let cwd = u32::from_be_bytes(output_sector[pos..pos+4].try_into().unwrap()); + if (cwd == BITSTREAM_CTL0_CMD) || (cwd == BITSTREAM_MASK_CMD) { + pos += 4; + // the bit we want to patch is in MSB of the value, just patch it directly since + // the pos pointer is at this byte. + log::info!("patching pt header orig: {:x}", output_sector[pos]); + log::info!("output_sector: {:x?}", &output_sector[pos..pos+4]); + log::info!("source {:?}", self.dec_from_key); + log::info!("target {:?}", self.enc_to_key); + match self.enc_to_key { + FpgaKeySource::Bbram => output_sector[pos] &= 0x7f, + FpgaKeySource::Efuse => output_sector[pos] |= 0x80, + } + log::info!("patching pt header patched: {:x}", output_sector[pos]); + log::info!("{:x?}", &output_sector[pos..pos+4]); + patchcount += 1; + if patchcount >= 2 { + break; // short circuit the checking when we're done + } + } + pos += 4; + } + + // 2. set the commands that will eventually be encrypted, by patching the input plaintext + pos = 64; // start from after the hmac header + while pos < input_plaintext.len() { + let cwd = u32::from_be_bytes(input_plaintext[pos..pos+4].try_into().unwrap()); + // the mask is always 0xffff_ffff for the bitstreams as generated by vivado...so need to modify that + if cwd == BITSTREAM_CTL0_CMD_FLIP { + pos += 4; + // the bit we want to patch is in MSB of the value, just patch it directly since + // the pos pointer is at this byte. + log::info!("patching ct header orig: {:x}", input_plaintext[pos+3]); + log::info!("{:x?}", &input_plaintext[pos..pos+4]); + log::info!("source {:?}", self.dec_from_key); + log::info!("target {:?}", self.enc_to_key); + if cwd == BITSTREAM_CTL0_CMD_FLIP { + match self.enc_to_key { + FpgaKeySource::Bbram => input_plaintext[pos+3] &= 0xfe, + FpgaKeySource::Efuse => input_plaintext[pos+3] |= 0x01, // bit 31 is at byte 3 "lsb" in the flipped version + } + } + log::info!("patching ct header patched: {:x}", input_plaintext[pos+3]); + log::info!("{:x?}", &input_plaintext[pos..pos+4]); + break; + } + pos += 4; + } } let mut chain: [u8; AES_BLOCKSIZE] = self.iv; if from > 0 { bitflip(&self.ciphertext[from as usize - AES_BLOCKSIZE..from as usize], &mut chain); } + // 3. search for the encryption key source setting only in the last blocks + if from > 0x21_5000 { + log::info!("type2 count: {} offset: {}", self.type2_count, self.type2_ciphertext_offset); + log::info!("searching for second key setting starting from 0x{:x}", from); + let mut bytes = input_plaintext.chunks_mut(4).into_iter(); + loop { + if let Some(b) = bytes.next() { + let word = u32::from_be_bytes(b[..4].try_into().unwrap()); + if word == BITSTREAM_CTL0_CMD_FLIP { + log::info!("patching the second key setting inside block starting at 0x{:x}", from); + if let Some(val) = bytes.next() { + log::info!("{:x?}", val); + match self.enc_to_key { + FpgaKeySource::Bbram => val[3] &= 0xfe, + FpgaKeySource::Efuse => val[3] |= 0x01, // bit 31 is at byte 3 "lsb" in the flipped version + } + log::info!("{:x?}", val); + } else { + log::error!("didn't decrypt enough memory to find the ctl0 encrypted settings"); + } + break; + } + } else { + break; + } + } + } + let mut bytes_processed = 0; let mut temp_block = [0; AES_BLOCKSIZE]; for (iblock, oblock) in input_plaintext.chunks(AES_BLOCKSIZE).into_iter() @@ -550,7 +705,7 @@ impl<'a> RootKeys { } } } - fn purge_password(&mut self, pw_type: PasswordType) { + pub fn purge_password(&mut self, pw_type: PasswordType) { unsafe { let pcache_ptr: *mut PasswordCache = self.pass_cache.as_mut_ptr() as *mut PasswordCache; match pw_type { @@ -575,12 +730,22 @@ impl<'a> RootKeys { } core::sync::atomic::compiler_fence(core::sync::atomic::Ordering::SeqCst); } - fn purge_sensitive_data(&mut self) { + pub fn purge_sensitive_data(&mut self) { for d in self.sensitive_data.borrow_mut().as_slice_mut::().iter_mut() { *d = 0; } core::sync::atomic::compiler_fence(core::sync::atomic::Ordering::SeqCst); } + fn populate_sensitive_data(&mut self) { + for (addr, d) in self.sensitive_data.borrow_mut().as_slice_mut::().iter_mut().enumerate() { + if addr > 255 { + break; + } + self.keyrom.wfo(utra::keyrom::ADDRESS_ADDRESS, addr as u32); + let keyword = self.keyrom.rf(utra::keyrom::DATA_DATA); + *d = keyword; + } + } pub fn suspend(&mut self) { match self.boot_password_policy { @@ -869,6 +1034,7 @@ impl<'a> RootKeys { // allocate a decryption oracle for the FPGA bitstream. This will fail early if the FPGA key is wrong. assert!(pcache.fpga_key_valid == 1); + log::info!("making destination oracle"); let mut dst_oracle = match BitstreamOracle::new(&pcache.fpga_key, &pcache.fpga_key, self.gateware(), self.gateware_base()) { Ok(o) => o, Err(e) => { @@ -953,8 +1119,8 @@ impl<'a> RootKeys { #[cfg(feature = "hazardous-debug")] { - log::debug!("Self private key: {:x?}", keypair.secret.to_bytes()); - log::debug!("Self public key: {:x?}", keypair.public.to_bytes()); + log::info!("Self private key: {:x?}", keypair.secret.to_bytes()); + log::info!("Self public key: {:x?}", keypair.public.to_bytes()); self.debug_staging(); } @@ -965,6 +1131,7 @@ impl<'a> RootKeys { pb.rebase_subtask_percentage(30, 50); self.make_gateware_backup(Some(&mut pb))?; + log::info!("making source oracle"); let mut src_oracle = match BitstreamOracle::new(&pcache.fpga_key, &pcache.fpga_key, self.staging(), self.staging_base()) { Ok(o) => o, Err(e) => { @@ -1078,10 +1245,14 @@ impl<'a> RootKeys { for (&src, dst) in self.read_key_256(KeyRomLocs::FPGA_KEY).iter().zip(pcache.fpga_key.iter_mut()) { *dst = src; } + log::info!("fpga key (encrypted): {:x?}", &pcache.fpga_key); for (fkey, &pw) in pcache.fpga_key.iter_mut().zip(pcache.hashed_update_pw.iter()) { *fkey = *fkey ^ pw; } pcache.fpga_key_valid = 1; + #[cfg(feature = "hazardous-debug")] + log::info!("fpga key (reconstituted): {:x?}", &pcache.fpga_key); + // derive signing key // probably should consider a way to resolve the ed25519 temporaries and ensure they get cleared... let mut keypair_bytes: [u8; ed25519_dalek::KEYPAIR_LENGTH] = [0; ed25519_dalek::KEYPAIR_LENGTH]; @@ -1100,7 +1271,11 @@ impl<'a> RootKeys { let keypair = Keypair::from_bytes(&keypair_bytes).map_err(|_| RootkeyResult::KeyError)?; log::info!("keypair success"); + // stage the keyrom data for patching + self.populate_sensitive_data(); + pb.set_percentage(3); + log::info!("making destination oracle"); let mut dst_oracle = match BitstreamOracle::new(&pcache.fpga_key, &pcache.fpga_key, self.gateware(), self.gateware_base()) { Ok(o) => o, Err(e) => { @@ -1109,9 +1284,12 @@ impl<'a> RootKeys { } }; log::info!("destination oracle success"); + let keysource = dst_oracle.get_original_key_type(); + dst_oracle.set_target_key_type(keysource); pb.set_percentage(6); // updates are always encrypted with the null key. let dummy_key: [u8; 32] = [0; 32]; + log::info!("making source oracle"); let mut src_oracle = match BitstreamOracle::new(&dummy_key, &pcache.fpga_key, self.staging(), self.staging_base()) { Ok(o) => o, Err(e) => { @@ -1135,7 +1313,21 @@ impl<'a> RootKeys { // verify that the patch worked pb.update_text(t!("rootkeys.init.verifying_gateware", xous::LANG)); pb.rebase_subtask_percentage(60, 90); - self.verify_gateware(&dst_oracle, Some(&mut pb))?; + log::info!("making verification oracle"); + let verify_oracle = match BitstreamOracle::new(&pcache.fpga_key, &pcache.fpga_key, self.gateware(), self.gateware_base()) { + Ok(o) => o, + Err(e) => { + log::error!("couldn't create oracle (most likely FPGA key mismatch): {:?}", e); + return Err(e); + } + }; + // dump first page or so of data for checking + log::info!("check data"); + for b in self.gateware()[..4352].chunks(128).into_iter() { + log::info!("{:3?}", b); + } + + self.verify_gateware(&verify_oracle, Some(&mut pb))?; pb.set_percentage(92); @@ -1149,6 +1341,7 @@ impl<'a> RootKeys { pb.set_percentage(95); src_oracle.clear(); dst_oracle.clear(); + self.purge_sensitive_data(); self.spinor.set_staging_write_protect(false).expect("couldn't un-protect the staging area"); for b in keypair_bytes.iter_mut() { *b = 0; @@ -1255,7 +1448,7 @@ impl<'a> RootKeys { /// KEYROM patching data must previously have been staged in the sensitive area. /// failure to do so would result in the erasure of all secret data. /// ASSUME: CSR appendix does not change during the copy (it is not copied/updated) - fn gateware_copy_and_patch(& self, src_oracle: &BitstreamOracle, dst_oracle: &BitstreamOracle, + fn gateware_copy_and_patch(&self, src_oracle: &BitstreamOracle, dst_oracle: &BitstreamOracle, mut maybe_pb: Option<&mut ProgressBar>) -> Result<(), RootkeyResult> { log::info!("sanity checks: src_offset {}, dst_offset {}, src_len {}, dst_len {}", src_oracle.ciphertext_offset(), dst_oracle.ciphertext_offset(), src_oracle.ciphertext_len(), dst_oracle.ciphertext_len()); @@ -1284,28 +1477,23 @@ impl<'a> RootKeys { *dst = hm1 ^ mask; } log::info!("recovered hmac: {:x?}", hmac_code); - // hash the decrypt data; we assume we're not patching anything in the first sector. + log::info!("hmac constant: {:x?}", &pt_sector[32..64]); let mut bytes_hashed = spinor::SPINOR_ERASE_SIZE as usize - src_oracle.ciphertext_offset(); - bitflip(&pt_sector[..bytes_hashed], &mut flipper[..bytes_hashed]); - hasher.update(&flipper[..bytes_hashed]); - // now encrypt and patch the data to disk + // encrypt and patch the data to disk dst_oracle.encrypt_sector( -(dst_oracle.ciphertext_offset() as i32), - &pt_sector[..bytes_hashed], + &mut pt_sector[..bytes_hashed], &mut ct_sector // full array, for space for plaintext header ); - // restore the plaintext header from the *destination* -- in this case, the destination is the - // gateware boot location, and this contains the fuse configurations we need to boot from (e.g. eFuse - // or BBRAM). We also prefer our original header because we nominally trust in more than whatever header - // is being presented to us for the update. - assert!(src_oracle.pt_header_len() == dst_oracle.pt_header_len(), "source and destination gatewares have different header lengths. Check your vivado bitgen settings..."); - for (&src, dst) in dst_oracle.bitstream[..dst_oracle.pt_header_len()].iter().zip(ct_sector.iter_mut()) { - *dst = src; - } + // hash the first sector; the pt_sector could have been patched by encrypt_sector() to change the key soucre, + // so it must be done *after* we call encrypt_sector() + bitflip(&pt_sector[..bytes_hashed], &mut flipper[..bytes_hashed]); + hasher.update(&flipper[..bytes_hashed]); log::info!("sector 0 patch len: {}", bytes_hashed); + log::info!("sector 0 header: {:x?}", &ct_sector[..dst_oracle.ciphertext_offset()]); self.spinor.patch(dst_oracle.bitstream, dst_oracle.base(), &ct_sector, 0) .map_err(|_| RootkeyResult::FlashError)?; @@ -1329,6 +1517,14 @@ impl<'a> RootKeys { } else { hash_stop - bytes_hashed }; + + // encrypt before hashing, because a bit that selects the key type can be patched by the encryptor + dst_oracle.encrypt_sector( + from as i32, + &mut pt_sector[..decrypt_len], + &mut ct_sector[..decrypt_len], + ); + if hash_len > 0 { bitflip(&pt_sector[..hash_len], &mut flipper[..hash_len]); hasher.update(&flipper[..hash_len]); @@ -1338,11 +1534,6 @@ impl<'a> RootKeys { } } - dst_oracle.encrypt_sector( - from as i32, - &pt_sector[..decrypt_len], - &mut ct_sector[..decrypt_len], - ); self.spinor.patch(dst_oracle.bitstream, dst_oracle.base(), &ct_sector[..decrypt_len], from + dst_oracle.ciphertext_offset() as u32) .map_err(|_| RootkeyResult::FlashError)?; @@ -1401,7 +1592,7 @@ impl<'a> RootKeys { } log::debug!("last bytes patched: {:x?}", &pt_sector[pt_sector_len-256..pt_sector_len]); - dst_oracle.encrypt_sector(ct_last_block_loc as i32, &pt_sector[..pt_sector_len], &mut ct_sector[..pt_sector_len]); + dst_oracle.encrypt_sector(ct_last_block_loc as i32, &mut pt_sector[..pt_sector_len], &mut ct_sector[..pt_sector_len]); log::trace!("hash patching from 0x{:x} len {}", ct_last_block_loc, pt_sector_len); self.spinor.patch(dst_oracle.bitstream, dst_oracle.base(), &ct_sector[..pt_sector_len], ct_last_block_loc as u32 + dst_oracle.ciphertext_offset() as u32) @@ -1459,9 +1650,9 @@ impl<'a> RootKeys { .zip(hmac_area[0..32].iter().zip(hmac_area[32..64].iter())) { *dst = hm1 ^ mask; } - log::debug!("hmac code: {:x?}", hmac_code); + log::info!("hmac code: {:x?}", hmac_code); - log::debug!("verifying gateware"); + log::info!("verifying gateware"); let mut hasher = Sha256::new(); // magic number alert: // 160 = reserved space for the 2nd hash @@ -1484,7 +1675,7 @@ impl<'a> RootKeys { } } let h1_digest: [u8; 32] = hasher.finalize().try_into().unwrap(); - log::debug!("computed hash of {} bytes: {:x?}", tot_len, h1_digest); + log::info!("computed hash of {} bytes: {:x?}", tot_len, h1_digest); let mut hasher2 = Sha256::new(); let footer_mask: [u8; 32] = [0x3A; 32]; @@ -1494,8 +1685,8 @@ impl<'a> RootKeys { .zip(hmac_code.iter().zip(footer_mask.iter())) { *dst = hm2 ^ mask; } - log::debug!("masked_footer: {:x?}", masked_footer); - log::debug!("footer_mask: {:x?}", footer_mask); + log::info!("masked_footer: {:x?}", masked_footer); + log::info!("footer_mask: {:x?}", footer_mask); let mut masked_footer_flipped: [u8; 32] = [0; 32]; bitflip(&masked_footer, &mut masked_footer_flipped); let mut footer_mask_flipped: [u8; 32] = [0; 32]; @@ -1505,13 +1696,13 @@ impl<'a> RootKeys { hasher2.update(h1_digest); let h2_digest: [u8; 32] = hasher2.finalize().try_into().unwrap(); - log::debug!("h2 hash: {:x?}", h2_digest); + log::info!("h2 hash: {:x?}", h2_digest); let mut ref_digest_flipped: [u8; 32] = [0; 32]; oracle.decrypt(oracle.ciphertext_len() - 32, &mut ref_digest_flipped); let mut ref_digest: [u8; 32] = [0; 32]; - log::debug!("ref digest (flipped): {:x?}", ref_digest_flipped); + log::info!("ref digest (flipped): {:x?}", ref_digest_flipped); bitflip(&ref_digest_flipped, &mut ref_digest); - log::debug!("ref digest : {:x?}", ref_digest); + log::info!("ref digest : {:x?}", ref_digest); let mut matching = true; for (&l, &r) in ref_digest.iter().zip(h2_digest.iter()) { diff --git a/services/root-keys/src/main.rs b/services/root-keys/src/main.rs index 515bcb449..dcba7344e 100644 --- a/services/root-keys/src/main.rs +++ b/services/root-keys/src/main.rs @@ -686,9 +686,11 @@ fn xmain() -> ! { let payload = buffer.to_original::().unwrap(); if payload.as_str() == t!("rootkeys.gwup.yes", xous::LANG) { if keys.is_pcache_update_password_valid() { - send_message(main_cid, - xous::Message::new_scalar(Opcode::UxUpdateGwRun.to_usize().unwrap(), 0, 0, 0, 0) - ).unwrap(); + // indicate that there should be no change to the policy + let payload = gam::RadioButtonPayload::new("no change"); + let buf = Buffer::into_buf(payload).expect("couldn't convert message to payload"); + buf.send(main_cid, Opcode::UxUpdateGwRun.to_u32().unwrap()) + .map(|_| ()).expect("couldn't send action message"); } else { keys.set_ux_password_type(Some(PasswordType::Update)); password_action.set_action_opcode(Opcode::UxUpdateGwPasswordPolicy.to_u32().unwrap()); @@ -732,6 +734,8 @@ fn xmain() -> ! { keys.update_policy(Some(PasswordRetentionPolicy::AlwaysKeep)); } else if payload.as_str() == t!("rootkeys.policy_suspend", xous::LANG) { keys.update_policy(Some(PasswordRetentionPolicy::EraseOnSuspend)); + } else if payload.as_str() == "no change" { + // don't change the policy } else { keys.update_policy(Some(PasswordRetentionPolicy::AlwaysPurge)); // default to the most paranoid level } @@ -761,6 +765,8 @@ fn xmain() -> ! { xous::yield_slice(); } Err(RootkeyResult::KeyError) => { + // probably a bad password, purge it, so the user can try again + keys.purge_password(PasswordType::Update); dismiss_modal_action.set_action_opcode(Opcode::UxGutter.to_u32().unwrap()); rootkeys_modal.modify( Some(ActionType::Notification(dismiss_modal_action)),