mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 22:38:08 +00:00
bootloader: add RNG test
This commit is contained in:
parent
9efc5bc93c
commit
bf374f1769
@ -347,6 +347,27 @@ static void hid_rx_callback(usbd_device *dev, uint8_t ep)
|
||||
|
||||
bool status_usb = (buf[9] == 0x0a) && (buf[10] == 53) && (0 == memcmp(buf + 11, "\x00\xFF\x55\xAA\x66\x99\x33\xCC" "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!" "\x00\xFF\x55\xAA\x66\x99\x33\xCC", 53));
|
||||
|
||||
// RNG TEST
|
||||
|
||||
layoutProgress("TESTING RNG ...", 0);
|
||||
uint32_t cnt[256];
|
||||
memset(cnt, 0, sizeof(cnt));
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int j = 0; j < 256000; j++) {
|
||||
uint32_t r = random32();
|
||||
cnt[r & 0xFF]++;
|
||||
cnt[(r >> 8)& 0xFF]++;
|
||||
cnt[(r >> 16)& 0xFF]++;
|
||||
cnt[(r >> 24)& 0xFF]++;
|
||||
}
|
||||
layoutProgress("TESTING RNG ...", 100 + (i * 100));
|
||||
}
|
||||
|
||||
bool status_rng = true;
|
||||
for (int i = 0; i < 256; i++) {
|
||||
status_rng = status_rng && (cnt[i] >= 39000) && (cnt[i] <= 41000);
|
||||
}
|
||||
|
||||
// CPU TEST
|
||||
|
||||
layoutProgress("TESTING CPU ...", 0);
|
||||
@ -360,7 +381,7 @@ static void hid_rx_callback(usbd_device *dev, uint8_t ep)
|
||||
// digest : c84a4cc264100070c8be2acf4072efaadaedfef3d6209c0fe26387e6b1262bbf
|
||||
// sig: : f7869c679bbed1817052affd0264ccc6486795f6d06d0c187651b8f3863670c8
|
||||
// 2ccf89be32a53eb65ea7c007859783d46717986fead0833ec60c5729cdc4a9ee
|
||||
status_cpu &= (0 == ecdsa_verify_digest(&secp256k1,
|
||||
status_cpu = status_cpu && (0 == ecdsa_verify_digest(&secp256k1,
|
||||
(const uint8_t *)"\x04\xa3\x4b\x99\xf2\x2c\x79\x0c\x4e\x36\xb2\xb3\xc2\xc3\x5a\x36\xdb\x06\x22\x6e\x41\xc6\x92\xfc\x82\xb8\xb5\x6a\xc1\xc5\x40\xc5\xbd\x5b\x8d\xec\x52\x35\xa0\xfa\x87\x22\x47\x6c\x77\x09\xc0\x25\x59\xe3\xaa\x73\xaa\x03\x91\x8b\xa2\xd4\x92\xee\xa7\x5a\xbe\xa2\x35",
|
||||
(const uint8_t *)"\xf7\x86\x9c\x67\x9b\xbe\xd1\x81\x70\x52\xaf\xfd\x02\x64\xcc\xc6\x48\x67\x95\xf6\xd0\x6d\x0c\x18\x76\x51\xb8\xf3\x86\x36\x70\xc8\x2c\xcf\x89\xbe\x32\xa5\x3e\xb6\x5e\xa7\xc0\x07\x85\x97\x83\xd4\x67\x17\x98\x6f\xea\xd0\x83\x3e\xc6\x0c\x57\x29\xcd\xc4\xa9\xee",
|
||||
(const uint8_t *)"\xc8\x4a\x4c\xc2\x64\x10\x00\x70\xc8\xbe\x2a\xcf\x40\x72\xef\xaa\xda\xed\xfe\xf3\xd6\x20\x9c\x0f\xe2\x63\x87\xe6\xb1\x26\x2b\xbf"));
|
||||
@ -405,7 +426,7 @@ static void hid_rx_callback(usbd_device *dev, uint8_t ep)
|
||||
|
||||
bool status_flash = (0 == memcmp(hash, "\x49\x46\xe9\xa5\xf4\xc2\x57\xe9\xcf\xd1\x88\x78\xe9\x66\x9b\x0d\xcd\x4e\x82\x41\xb3\x9c\xee\xb7\x2c\x1d\x14\x4a\xe1\xe4\xcb\xd7", 32));
|
||||
|
||||
bool status_all = status_usb && status_cpu && status_flash;
|
||||
bool status_all = status_usb && status_rng && status_cpu && status_flash;
|
||||
|
||||
if (status_all) {
|
||||
send_msg_success(dev);
|
||||
@ -415,10 +436,10 @@ static void hid_rx_callback(usbd_device *dev, uint8_t ep)
|
||||
layoutDialog(status_all ? &bmp_icon_info : &bmp_icon_error,
|
||||
NULL, NULL, NULL,
|
||||
status_usb ? "Test USB ... OK" : "Test USB ... Failed",
|
||||
status_rng ? "Test RNG ... OK" : "Test RNG ... Failed",
|
||||
status_cpu ? "Test CPU ... OK" : "Test CPU ... Failed",
|
||||
status_flash ? "Test FLASH ... OK" : "Test FLASH ... Failed",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user