mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-08 05:39:09 -07:00
Merge branch 'dev' of https://github.com/DarkFlippers/unleashed-firmware into xfw-dev --nobuild
This commit is contained in:
602
applications/debug/unit_tests/furi_hal/furi_hal_crypto_tests.c
Normal file
602
applications/debug/unit_tests/furi_hal/furi_hal_crypto_tests.c
Normal file
@@ -0,0 +1,602 @@
|
||||
#include <stdio.h>
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include "../minunit.h"
|
||||
|
||||
static const uint8_t key_ctr_1[32] = {
|
||||
0x77, 0x6B, 0xEF, 0xF2, 0x85, 0x1D, 0xB0, 0x6F, 0x4C, 0x8A, 0x05, 0x42, 0xC8, 0x69, 0x6F, 0x6C,
|
||||
0x6A, 0x81, 0xAF, 0x1E, 0xEC, 0x96, 0xB4, 0xD3, 0x7F, 0xC1, 0xD6, 0x89, 0xE6, 0xC1, 0xC1, 0x04,
|
||||
};
|
||||
static const uint8_t iv_ctr_1[16] = {
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x60,
|
||||
0xDB,
|
||||
0x56,
|
||||
0x72,
|
||||
0xC9,
|
||||
0x7A,
|
||||
0xA8,
|
||||
0xF0,
|
||||
0xB2,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x01,
|
||||
};
|
||||
static const uint8_t pt_ctr_1[16] = {
|
||||
0x53,
|
||||
0x69,
|
||||
0x6E,
|
||||
0x67,
|
||||
0x6C,
|
||||
0x65,
|
||||
0x20,
|
||||
0x62,
|
||||
0x6C,
|
||||
0x6F,
|
||||
0x63,
|
||||
0x6B,
|
||||
0x20,
|
||||
0x6D,
|
||||
0x73,
|
||||
0x67,
|
||||
};
|
||||
static const uint8_t tv_ctr_ct_1[16] = {
|
||||
0x14,
|
||||
0x5A,
|
||||
0xD0,
|
||||
0x1D,
|
||||
0xBF,
|
||||
0x82,
|
||||
0x4E,
|
||||
0xC7,
|
||||
0x56,
|
||||
0x08,
|
||||
0x63,
|
||||
0xDC,
|
||||
0x71,
|
||||
0xE3,
|
||||
0xE0,
|
||||
0xC0,
|
||||
};
|
||||
|
||||
static const uint8_t key_ctr_2[32] = {
|
||||
0x77, 0x6B, 0xEF, 0xF2, 0x85, 0x1D, 0xB0, 0x6F, 0x4C, 0x8A, 0x05, 0x42, 0xC8, 0x69, 0x6F, 0x6C,
|
||||
0x6A, 0x81, 0xAF, 0x1E, 0xEC, 0x96, 0xB4, 0xD3, 0x7F, 0xC1, 0xD6, 0x89, 0xE6, 0xC1, 0xC1, 0x04,
|
||||
};
|
||||
static const uint8_t iv_ctr_2[16] = {
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x60,
|
||||
0xDB,
|
||||
0x56,
|
||||
0x72,
|
||||
0xC9,
|
||||
0x7A,
|
||||
0xA8,
|
||||
0xF0,
|
||||
0xB2,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x01,
|
||||
};
|
||||
static const uint8_t pt_ctr_2[0] = {};
|
||||
//static const uint8_t tv_ctr_ct_2[0] = {};
|
||||
|
||||
static const uint8_t key_ctr_3[32] = {
|
||||
0xF6, 0xD6, 0x6D, 0x6B, 0xD5, 0x2D, 0x59, 0xBB, 0x07, 0x96, 0x36, 0x58, 0x79, 0xEF, 0xF8, 0x86,
|
||||
0xC6, 0x6D, 0xD5, 0x1A, 0x5B, 0x6A, 0x99, 0x74, 0x4B, 0x50, 0x59, 0x0C, 0x87, 0xA2, 0x38, 0x84,
|
||||
};
|
||||
static const uint8_t iv_ctr_3[16] = {
|
||||
0x00,
|
||||
0xFA,
|
||||
0xAC,
|
||||
0x24,
|
||||
0xC1,
|
||||
0x58,
|
||||
0x5E,
|
||||
0xF1,
|
||||
0x5A,
|
||||
0x43,
|
||||
0xD8,
|
||||
0x75,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x01,
|
||||
};
|
||||
static const uint8_t pt_ctr_3[32] = {
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
|
||||
};
|
||||
static const uint8_t tv_ctr_ct_3[32] = {
|
||||
0xF0, 0x5E, 0x23, 0x1B, 0x38, 0x94, 0x61, 0x2C, 0x49, 0xEE, 0x00, 0x0B, 0x80, 0x4E, 0xB2, 0xA9,
|
||||
0xB8, 0x30, 0x6B, 0x50, 0x8F, 0x83, 0x9D, 0x6A, 0x55, 0x30, 0x83, 0x1D, 0x93, 0x44, 0xAF, 0x1C,
|
||||
};
|
||||
|
||||
static const uint8_t key_ctr_4[32] = {
|
||||
0xFF, 0x7A, 0x61, 0x7C, 0xE6, 0x91, 0x48, 0xE4, 0xF1, 0x72, 0x6E, 0x2F, 0x43, 0x58, 0x1D, 0xE2,
|
||||
0xAA, 0x62, 0xD9, 0xF8, 0x05, 0x53, 0x2E, 0xDF, 0xF1, 0xEE, 0xD6, 0x87, 0xFB, 0x54, 0x15, 0x3D,
|
||||
};
|
||||
static const uint8_t iv_ctr_4[16] = {
|
||||
0x00,
|
||||
0x1C,
|
||||
0xC5,
|
||||
0xB7,
|
||||
0x51,
|
||||
0xA5,
|
||||
0x1D,
|
||||
0x70,
|
||||
0xA1,
|
||||
0xC1,
|
||||
0x11,
|
||||
0x48,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x01,
|
||||
};
|
||||
static const uint8_t pt_ctr_4[36] = {
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
|
||||
0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23,
|
||||
};
|
||||
static const uint8_t tv_ctr_ct_4[36] = {
|
||||
0xEB, 0x6C, 0x52, 0x82, 0x1D, 0x0B, 0xBB, 0xF7, 0xCE, 0x75, 0x94, 0x46,
|
||||
0x2A, 0xCA, 0x4F, 0xAA, 0xB4, 0x07, 0xDF, 0x86, 0x65, 0x69, 0xFD, 0x07,
|
||||
0xF4, 0x8C, 0xC0, 0xB5, 0x83, 0xD6, 0x07, 0x1F, 0x1E, 0xC0, 0xE6, 0xB8,
|
||||
};
|
||||
|
||||
static const uint8_t key_ctr_5[32] = {
|
||||
0xFF, 0x7A, 0x61, 0x7C, 0xE6, 0x91, 0x48, 0xE4, 0xF1, 0x72, 0x6E, 0x2F, 0x43, 0x58, 0x1D, 0xE2,
|
||||
0xAA, 0x62, 0xD9, 0xF8, 0x05, 0x53, 0x2E, 0xDF, 0xF1, 0xEE, 0xD6, 0x87, 0xFB, 0x54, 0x15, 0x3D,
|
||||
};
|
||||
static const uint8_t iv_ctr_5[16] = {
|
||||
0x00,
|
||||
0x1C,
|
||||
0xC5,
|
||||
0xB7,
|
||||
0x51,
|
||||
0xA5,
|
||||
0x1D,
|
||||
0x70,
|
||||
0xA1,
|
||||
0xC1,
|
||||
0x11,
|
||||
0x48,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x01,
|
||||
};
|
||||
static const uint8_t pt_ctr_5[0] = {};
|
||||
//static const uint8_t tv_ctr_ct_5[0] = {};
|
||||
|
||||
static const uint8_t key_gcm_1[32] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
static const uint8_t iv_gcm_1[16] = {
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
static const uint8_t pt_gcm_1[0] = {};
|
||||
//static const uint8_t tv_gcm_ct_1[0] = {};
|
||||
static const uint8_t aad_gcm_1[0] = {};
|
||||
static const uint8_t tv_gcm_tag_1[16] = {
|
||||
0x53,
|
||||
0x0F,
|
||||
0x8A,
|
||||
0xFB,
|
||||
0xC7,
|
||||
0x45,
|
||||
0x36,
|
||||
0xB9,
|
||||
0xA9,
|
||||
0x63,
|
||||
0xB4,
|
||||
0xF1,
|
||||
0xC4,
|
||||
0xCB,
|
||||
0x73,
|
||||
0x8B,
|
||||
};
|
||||
|
||||
static const uint8_t key_gcm_2[32] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
static const uint8_t iv_gcm_2[16] = {
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
static const uint8_t pt_gcm_2[16] = {
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
static const uint8_t tv_gcm_ct_2[16] = {
|
||||
0xCE,
|
||||
0xA7,
|
||||
0x40,
|
||||
0x3D,
|
||||
0x4D,
|
||||
0x60,
|
||||
0x6B,
|
||||
0x6E,
|
||||
0x07,
|
||||
0x4E,
|
||||
0xC5,
|
||||
0xD3,
|
||||
0xBA,
|
||||
0xF3,
|
||||
0x9D,
|
||||
0x18,
|
||||
};
|
||||
static const uint8_t aad_gcm_2[0] = {};
|
||||
static const uint8_t tv_gcm_tag_2[16] = {
|
||||
0xD0,
|
||||
0xD1,
|
||||
0xC8,
|
||||
0xA7,
|
||||
0x99,
|
||||
0x99,
|
||||
0x6B,
|
||||
0xF0,
|
||||
0x26,
|
||||
0x5B,
|
||||
0x98,
|
||||
0xB5,
|
||||
0xD4,
|
||||
0x8A,
|
||||
0xB9,
|
||||
0x19,
|
||||
};
|
||||
|
||||
static const uint8_t key_gcm_3[32] = {
|
||||
0xFE, 0xFF, 0xE9, 0x92, 0x86, 0x65, 0x73, 0x1C, 0x6D, 0x6A, 0x8F, 0x94, 0x67, 0x30, 0x83, 0x08,
|
||||
0xFE, 0xFF, 0xE9, 0x92, 0x86, 0x65, 0x73, 0x1C, 0x6D, 0x6A, 0x8F, 0x94, 0x67, 0x30, 0x83, 0x08,
|
||||
};
|
||||
static const uint8_t iv_gcm_3[16] = {
|
||||
0xCA,
|
||||
0xFE,
|
||||
0xBA,
|
||||
0xBE,
|
||||
0xFA,
|
||||
0xCE,
|
||||
0xDB,
|
||||
0xAD,
|
||||
0xDE,
|
||||
0xCA,
|
||||
0xF8,
|
||||
0x88,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
static const uint8_t pt_gcm_3[64] = {
|
||||
0xD9, 0x31, 0x32, 0x25, 0xF8, 0x84, 0x06, 0xE5, 0xA5, 0x59, 0x09, 0xC5, 0xAF, 0xF5, 0x26, 0x9A,
|
||||
0x86, 0xA7, 0xA9, 0x53, 0x15, 0x34, 0xF7, 0xDA, 0x2E, 0x4C, 0x30, 0x3D, 0x8A, 0x31, 0x8A, 0x72,
|
||||
0x1C, 0x3C, 0x0C, 0x95, 0x95, 0x68, 0x09, 0x53, 0x2F, 0xCF, 0x0E, 0x24, 0x49, 0xA6, 0xB5, 0x25,
|
||||
0xB1, 0x6A, 0xED, 0xF5, 0xAA, 0x0D, 0xE6, 0x57, 0xBA, 0x63, 0x7B, 0x39, 0x1A, 0xAF, 0xD2, 0x55,
|
||||
};
|
||||
static const uint8_t tv_gcm_ct_3[64] = {
|
||||
0x52, 0x2D, 0xC1, 0xF0, 0x99, 0x56, 0x7D, 0x07, 0xF4, 0x7F, 0x37, 0xA3, 0x2A, 0x84, 0x42, 0x7D,
|
||||
0x64, 0x3A, 0x8C, 0xDC, 0xBF, 0xE5, 0xC0, 0xC9, 0x75, 0x98, 0xA2, 0xBD, 0x25, 0x55, 0xD1, 0xAA,
|
||||
0x8C, 0xB0, 0x8E, 0x48, 0x59, 0x0D, 0xBB, 0x3D, 0xA7, 0xB0, 0x8B, 0x10, 0x56, 0x82, 0x88, 0x38,
|
||||
0xC5, 0xF6, 0x1E, 0x63, 0x93, 0xBA, 0x7A, 0x0A, 0xBC, 0xC9, 0xF6, 0x62, 0x89, 0x80, 0x15, 0xAD,
|
||||
};
|
||||
static const uint8_t aad_gcm_3[0] = {};
|
||||
static const uint8_t tv_gcm_tag_3[16] = {
|
||||
0xB0,
|
||||
0x94,
|
||||
0xDA,
|
||||
0xC5,
|
||||
0xD9,
|
||||
0x34,
|
||||
0x71,
|
||||
0xBD,
|
||||
0xEC,
|
||||
0x1A,
|
||||
0x50,
|
||||
0x22,
|
||||
0x70,
|
||||
0xE3,
|
||||
0xCC,
|
||||
0x6C,
|
||||
};
|
||||
|
||||
static const uint8_t key_gcm_4[32] = {
|
||||
0xFE, 0xFF, 0xE9, 0x92, 0x86, 0x65, 0x73, 0x1C, 0x6D, 0x6A, 0x8F, 0x94, 0x67, 0x30, 0x83, 0x08,
|
||||
0xFE, 0xFF, 0xE9, 0x92, 0x86, 0x65, 0x73, 0x1C, 0x6D, 0x6A, 0x8F, 0x94, 0x67, 0x30, 0x83, 0x08,
|
||||
};
|
||||
static const uint8_t iv_gcm_4[16] = {
|
||||
0xCA,
|
||||
0xFE,
|
||||
0xBA,
|
||||
0xBE,
|
||||
0xFA,
|
||||
0xCE,
|
||||
0xDB,
|
||||
0xAD,
|
||||
0xDE,
|
||||
0xCA,
|
||||
0xF8,
|
||||
0x88,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
static const uint8_t pt_gcm_4[60] = {
|
||||
0xD9, 0x31, 0x32, 0x25, 0xF8, 0x84, 0x06, 0xE5, 0xA5, 0x59, 0x09, 0xC5, 0xAF, 0xF5, 0x26,
|
||||
0x9A, 0x86, 0xA7, 0xA9, 0x53, 0x15, 0x34, 0xF7, 0xDA, 0x2E, 0x4C, 0x30, 0x3D, 0x8A, 0x31,
|
||||
0x8A, 0x72, 0x1C, 0x3C, 0x0C, 0x95, 0x95, 0x68, 0x09, 0x53, 0x2F, 0xCF, 0x0E, 0x24, 0x49,
|
||||
0xA6, 0xB5, 0x25, 0xB1, 0x6A, 0xED, 0xF5, 0xAA, 0x0D, 0xE6, 0x57, 0xBA, 0x63, 0x7B, 0x39,
|
||||
};
|
||||
static const uint8_t tv_gcm_ct_4[60] = {
|
||||
0x52, 0x2D, 0xC1, 0xF0, 0x99, 0x56, 0x7D, 0x07, 0xF4, 0x7F, 0x37, 0xA3, 0x2A, 0x84, 0x42,
|
||||
0x7D, 0x64, 0x3A, 0x8C, 0xDC, 0xBF, 0xE5, 0xC0, 0xC9, 0x75, 0x98, 0xA2, 0xBD, 0x25, 0x55,
|
||||
0xD1, 0xAA, 0x8C, 0xB0, 0x8E, 0x48, 0x59, 0x0D, 0xBB, 0x3D, 0xA7, 0xB0, 0x8B, 0x10, 0x56,
|
||||
0x82, 0x88, 0x38, 0xC5, 0xF6, 0x1E, 0x63, 0x93, 0xBA, 0x7A, 0x0A, 0xBC, 0xC9, 0xF6, 0x62,
|
||||
};
|
||||
static const uint8_t aad_gcm_4[20] = {
|
||||
0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED,
|
||||
0xFA, 0xCE, 0xDE, 0xAD, 0xBE, 0xEF, 0xAB, 0xAD, 0xDA, 0xD2,
|
||||
};
|
||||
static const uint8_t tv_gcm_tag_4[16] = {
|
||||
0x76,
|
||||
0xFC,
|
||||
0x6E,
|
||||
0xCE,
|
||||
0x0F,
|
||||
0x4E,
|
||||
0x17,
|
||||
0x68,
|
||||
0xCD,
|
||||
0xDF,
|
||||
0x88,
|
||||
0x53,
|
||||
0xBB,
|
||||
0x2D,
|
||||
0x55,
|
||||
0x1B,
|
||||
};
|
||||
|
||||
static void furi_hal_crypto_ctr_setup() {
|
||||
}
|
||||
|
||||
static void furi_hal_crypto_ctr_teardown() {
|
||||
}
|
||||
|
||||
static void furi_hal_crypto_gcm_setup() {
|
||||
}
|
||||
|
||||
static void furi_hal_crypto_gcm_teardown() {
|
||||
}
|
||||
|
||||
MU_TEST(furi_hal_crypto_ctr_1) {
|
||||
bool ret = false;
|
||||
uint8_t ct[sizeof(pt_ctr_1)];
|
||||
|
||||
ret = furi_hal_crypto_ctr(key_ctr_1, iv_ctr_1, pt_ctr_1, ct, sizeof(pt_ctr_1));
|
||||
mu_assert(ret, "CTR 1 failed");
|
||||
mu_assert_mem_eq(tv_ctr_ct_1, ct, sizeof(pt_ctr_1));
|
||||
}
|
||||
|
||||
MU_TEST(furi_hal_crypto_ctr_2) {
|
||||
bool ret = false;
|
||||
uint8_t ct[sizeof(pt_ctr_2)];
|
||||
|
||||
ret = furi_hal_crypto_ctr(key_ctr_2, iv_ctr_2, pt_ctr_2, ct, sizeof(pt_ctr_2));
|
||||
mu_assert(ret, "CTR 2 failed");
|
||||
//mu_assert_mem_eq(tv_ctr_ct_2, ct, sizeof(pt_ctr_2));
|
||||
}
|
||||
|
||||
MU_TEST(furi_hal_crypto_ctr_3) {
|
||||
bool ret = false;
|
||||
uint8_t ct[sizeof(pt_ctr_3)];
|
||||
|
||||
ret = furi_hal_crypto_ctr(key_ctr_3, iv_ctr_3, pt_ctr_3, ct, sizeof(pt_ctr_3));
|
||||
mu_assert(ret, "CTR 3 failed");
|
||||
mu_assert_mem_eq(tv_ctr_ct_3, ct, sizeof(pt_ctr_3));
|
||||
}
|
||||
|
||||
MU_TEST(furi_hal_crypto_ctr_4) {
|
||||
bool ret = false;
|
||||
uint8_t ct[sizeof(pt_ctr_4)];
|
||||
|
||||
ret = furi_hal_crypto_ctr(key_ctr_4, iv_ctr_4, pt_ctr_4, ct, sizeof(pt_ctr_4));
|
||||
mu_assert(ret, "CTR 4 failed");
|
||||
mu_assert_mem_eq(tv_ctr_ct_4, ct, sizeof(pt_ctr_4));
|
||||
}
|
||||
|
||||
MU_TEST(furi_hal_crypto_ctr_5) {
|
||||
bool ret = false;
|
||||
uint8_t ct[sizeof(pt_ctr_5)];
|
||||
|
||||
ret = furi_hal_crypto_ctr(key_ctr_5, iv_ctr_5, pt_ctr_5, ct, sizeof(pt_ctr_5));
|
||||
mu_assert(ret, "CTR 5 failed");
|
||||
//mu_assert_mem_eq(tv_ctr_ct_5, ct, sizeof(pt_ctr_5));
|
||||
}
|
||||
|
||||
MU_TEST(furi_hal_crypto_gcm_1) {
|
||||
bool ret = false;
|
||||
uint8_t pt[sizeof(pt_gcm_1)];
|
||||
uint8_t ct[sizeof(pt_gcm_1)];
|
||||
uint8_t tag_enc[16];
|
||||
uint8_t tag_dec[16];
|
||||
|
||||
ret = furi_hal_crypto_gcm(
|
||||
key_gcm_1,
|
||||
iv_gcm_1,
|
||||
aad_gcm_1,
|
||||
sizeof(aad_gcm_1),
|
||||
pt_gcm_1,
|
||||
ct,
|
||||
sizeof(pt_gcm_1),
|
||||
tag_enc,
|
||||
false);
|
||||
mu_assert(ret, "GCM 1 encryption failed");
|
||||
//mu_assert_mem_eq(tv_gcm_ct_1, ct, sizeof(pt_gcm_1));
|
||||
mu_assert_mem_eq(tv_gcm_tag_1, tag_enc, 16);
|
||||
|
||||
ret = furi_hal_crypto_gcm(
|
||||
key_gcm_1, iv_gcm_1, aad_gcm_1, sizeof(aad_gcm_1), ct, pt, sizeof(pt_gcm_1), tag_dec, true);
|
||||
mu_assert(ret, "GCM 1 decryption failed");
|
||||
//mu_assert_mem_eq(pt_gcm_1, pt, sizeof(pt_gcm_1));
|
||||
mu_assert_mem_eq(tv_gcm_tag_1, tag_dec, 16);
|
||||
}
|
||||
|
||||
MU_TEST(furi_hal_crypto_gcm_2) {
|
||||
bool ret = false;
|
||||
uint8_t pt[sizeof(pt_gcm_2)];
|
||||
uint8_t ct[sizeof(pt_gcm_2)];
|
||||
uint8_t tag_enc[16];
|
||||
uint8_t tag_dec[16];
|
||||
|
||||
ret = furi_hal_crypto_gcm(
|
||||
key_gcm_2,
|
||||
iv_gcm_2,
|
||||
aad_gcm_2,
|
||||
sizeof(aad_gcm_2),
|
||||
pt_gcm_2,
|
||||
ct,
|
||||
sizeof(pt_gcm_2),
|
||||
tag_enc,
|
||||
false);
|
||||
mu_assert(ret, "GCM 2 encryption failed");
|
||||
mu_assert_mem_eq(tv_gcm_ct_2, ct, sizeof(pt_gcm_2));
|
||||
mu_assert_mem_eq(tv_gcm_tag_2, tag_enc, 16);
|
||||
|
||||
ret = furi_hal_crypto_gcm(
|
||||
key_gcm_2, iv_gcm_2, aad_gcm_2, sizeof(aad_gcm_2), ct, pt, sizeof(pt_gcm_2), tag_dec, true);
|
||||
mu_assert(ret, "GCM 2 decryption failed");
|
||||
mu_assert_mem_eq(pt_gcm_2, pt, sizeof(pt_gcm_2));
|
||||
mu_assert_mem_eq(tv_gcm_tag_2, tag_dec, 16);
|
||||
}
|
||||
|
||||
MU_TEST(furi_hal_crypto_gcm_3) {
|
||||
bool ret = false;
|
||||
uint8_t pt[sizeof(pt_gcm_3)];
|
||||
uint8_t ct[sizeof(pt_gcm_3)];
|
||||
uint8_t tag_enc[16];
|
||||
uint8_t tag_dec[16];
|
||||
|
||||
ret = furi_hal_crypto_gcm(
|
||||
key_gcm_3,
|
||||
iv_gcm_3,
|
||||
aad_gcm_3,
|
||||
sizeof(aad_gcm_3),
|
||||
pt_gcm_3,
|
||||
ct,
|
||||
sizeof(pt_gcm_3),
|
||||
tag_enc,
|
||||
false);
|
||||
mu_assert(ret, "GCM 3 encryption failed");
|
||||
mu_assert_mem_eq(tv_gcm_ct_3, ct, sizeof(pt_gcm_3));
|
||||
mu_assert_mem_eq(tv_gcm_tag_3, tag_enc, 16);
|
||||
|
||||
ret = furi_hal_crypto_gcm(
|
||||
key_gcm_3, iv_gcm_3, aad_gcm_3, sizeof(aad_gcm_3), ct, pt, sizeof(pt_gcm_3), tag_dec, true);
|
||||
mu_assert(ret, "GCM 3 decryption failed");
|
||||
mu_assert_mem_eq(pt_gcm_3, pt, sizeof(pt_gcm_3));
|
||||
mu_assert_mem_eq(tv_gcm_tag_3, tag_dec, 16);
|
||||
}
|
||||
|
||||
MU_TEST(furi_hal_crypto_gcm_4) {
|
||||
bool ret = false;
|
||||
uint8_t pt[sizeof(pt_gcm_4)];
|
||||
uint8_t ct[sizeof(pt_gcm_4)];
|
||||
uint8_t tag_enc[16];
|
||||
uint8_t tag_dec[16];
|
||||
|
||||
ret = furi_hal_crypto_gcm(
|
||||
key_gcm_4,
|
||||
iv_gcm_4,
|
||||
aad_gcm_4,
|
||||
sizeof(aad_gcm_4),
|
||||
pt_gcm_4,
|
||||
ct,
|
||||
sizeof(pt_gcm_4),
|
||||
tag_enc,
|
||||
false);
|
||||
mu_assert(ret, "GCM 4 encryption failed");
|
||||
mu_assert_mem_eq(tv_gcm_ct_4, ct, sizeof(pt_gcm_4));
|
||||
mu_assert_mem_eq(tv_gcm_tag_4, tag_enc, 16);
|
||||
|
||||
ret = furi_hal_crypto_gcm(
|
||||
key_gcm_4, iv_gcm_4, aad_gcm_4, sizeof(aad_gcm_4), ct, pt, sizeof(pt_gcm_4), tag_dec, true);
|
||||
mu_assert(ret, "GCM 4 decryption failed");
|
||||
mu_assert_mem_eq(pt_gcm_4, pt, sizeof(pt_gcm_4));
|
||||
mu_assert_mem_eq(tv_gcm_tag_4, tag_dec, 16);
|
||||
}
|
||||
|
||||
MU_TEST_SUITE(furi_hal_crypto_ctr_test) {
|
||||
MU_SUITE_CONFIGURE(&furi_hal_crypto_ctr_setup, &furi_hal_crypto_ctr_teardown);
|
||||
MU_RUN_TEST(furi_hal_crypto_ctr_1);
|
||||
MU_RUN_TEST(furi_hal_crypto_ctr_2);
|
||||
MU_RUN_TEST(furi_hal_crypto_ctr_3);
|
||||
MU_RUN_TEST(furi_hal_crypto_ctr_4);
|
||||
MU_RUN_TEST(furi_hal_crypto_ctr_5);
|
||||
}
|
||||
|
||||
MU_TEST_SUITE(furi_hal_crypto_gcm_test) {
|
||||
MU_SUITE_CONFIGURE(&furi_hal_crypto_gcm_setup, &furi_hal_crypto_gcm_teardown);
|
||||
MU_RUN_TEST(furi_hal_crypto_gcm_1);
|
||||
MU_RUN_TEST(furi_hal_crypto_gcm_2);
|
||||
MU_RUN_TEST(furi_hal_crypto_gcm_3);
|
||||
MU_RUN_TEST(furi_hal_crypto_gcm_4);
|
||||
}
|
||||
|
||||
int run_minunit_test_furi_hal_crypto() {
|
||||
MU_RUN_SUITE(furi_hal_crypto_ctr_test);
|
||||
MU_RUN_SUITE(furi_hal_crypto_gcm_test);
|
||||
return MU_EXIT_CODE;
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
int run_minunit_test_furi();
|
||||
int run_minunit_test_furi_hal();
|
||||
int run_minunit_test_furi_hal_crypto();
|
||||
int run_minunit_test_furi_string();
|
||||
int run_minunit_test_infrared();
|
||||
int run_minunit_test_rpc();
|
||||
@@ -39,6 +40,7 @@ typedef struct {
|
||||
const UnitTest unit_tests[] = {
|
||||
{.name = "furi", .entry = run_minunit_test_furi},
|
||||
{.name = "furi_hal", .entry = run_minunit_test_furi_hal},
|
||||
{.name = "furi_hal_crypto", .entry = run_minunit_test_furi_hal_crypto},
|
||||
{.name = "furi_string", .entry = run_minunit_test_furi_string},
|
||||
{.name = "storage", .entry = run_minunit_test_storage},
|
||||
{.name = "stream", .entry = run_minunit_test_stream},
|
||||
|
||||
@@ -7,6 +7,5 @@ App(
|
||||
requires=["gui"],
|
||||
stack_size=1 * 1024,
|
||||
order=60,
|
||||
fap_icon="mouse_10px.png",
|
||||
fap_category="Debug",
|
||||
)
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.6 KiB |
@@ -8,7 +8,7 @@
|
||||
#define TAG "U2F"
|
||||
|
||||
#define U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_FACTORY 2
|
||||
#define U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE 11
|
||||
#define U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE FURI_HAL_CRYPTO_ENCLAVE_UNIQUE_KEY_SLOT
|
||||
|
||||
#define U2F_CERT_STOCK 0 // Stock certificate, private key is encrypted with factory key
|
||||
#define U2F_CERT_USER 1 // User certificate, private key is encrypted with unique key
|
||||
@@ -130,7 +130,7 @@ static bool u2f_data_cert_key_encrypt(uint8_t* cert_key) {
|
||||
// Generate random IV
|
||||
furi_hal_random_fill_buf(iv, 16);
|
||||
|
||||
if(!furi_hal_crypto_store_load_key(U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE, iv)) {
|
||||
if(!furi_hal_crypto_enclave_load_key(U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE, iv)) {
|
||||
FURI_LOG_E(TAG, "Unable to load encryption key");
|
||||
return false;
|
||||
}
|
||||
@@ -139,7 +139,7 @@ static bool u2f_data_cert_key_encrypt(uint8_t* cert_key) {
|
||||
FURI_LOG_E(TAG, "Encryption failed");
|
||||
return false;
|
||||
}
|
||||
furi_hal_crypto_store_unload_key(U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE);
|
||||
furi_hal_crypto_enclave_unload_key(U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE);
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* flipper_format = flipper_format_file_alloc(storage);
|
||||
@@ -172,8 +172,8 @@ bool u2f_data_cert_key_load(uint8_t* cert_key) {
|
||||
uint8_t key_slot = 0;
|
||||
uint32_t version = 0;
|
||||
|
||||
// Check if unique key exists in secure eclave(typo?) and generate it if missing
|
||||
if(!furi_hal_crypto_verify_key(U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE)) return false;
|
||||
// Check if unique key exists in secure eclave and generate it if missing
|
||||
if(!furi_hal_crypto_enclave_ensure_key(U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE)) return false;
|
||||
|
||||
FuriString* filetype;
|
||||
filetype = furi_string_alloc();
|
||||
@@ -220,7 +220,7 @@ bool u2f_data_cert_key_load(uint8_t* cert_key) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(!furi_hal_crypto_store_load_key(key_slot, iv)) {
|
||||
if(!furi_hal_crypto_enclave_load_key(key_slot, iv)) {
|
||||
FURI_LOG_E(TAG, "Unable to load encryption key");
|
||||
break;
|
||||
}
|
||||
@@ -231,7 +231,7 @@ bool u2f_data_cert_key_load(uint8_t* cert_key) {
|
||||
FURI_LOG_E(TAG, "Decryption failed");
|
||||
break;
|
||||
}
|
||||
furi_hal_crypto_store_unload_key(key_slot);
|
||||
furi_hal_crypto_enclave_unload_key(key_slot);
|
||||
} else {
|
||||
if(!flipper_format_read_hex(flipper_format, "Data", cert_key, 32)) {
|
||||
FURI_LOG_E(TAG, "Missing data");
|
||||
@@ -286,7 +286,7 @@ bool u2f_data_key_load(uint8_t* device_key) {
|
||||
FURI_LOG_E(TAG, "Missing data");
|
||||
break;
|
||||
}
|
||||
if(!furi_hal_crypto_store_load_key(U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE, iv)) {
|
||||
if(!furi_hal_crypto_enclave_load_key(U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE, iv)) {
|
||||
FURI_LOG_E(TAG, "Unable to load encryption key");
|
||||
break;
|
||||
}
|
||||
@@ -296,7 +296,7 @@ bool u2f_data_key_load(uint8_t* device_key) {
|
||||
FURI_LOG_E(TAG, "Decryption failed");
|
||||
break;
|
||||
}
|
||||
furi_hal_crypto_store_unload_key(U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE);
|
||||
furi_hal_crypto_enclave_unload_key(U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE);
|
||||
state = true;
|
||||
} while(0);
|
||||
}
|
||||
@@ -318,7 +318,7 @@ bool u2f_data_key_generate(uint8_t* device_key) {
|
||||
furi_hal_random_fill_buf(iv, 16);
|
||||
furi_hal_random_fill_buf(key, 32);
|
||||
|
||||
if(!furi_hal_crypto_store_load_key(U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE, iv)) {
|
||||
if(!furi_hal_crypto_enclave_load_key(U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE, iv)) {
|
||||
FURI_LOG_E(TAG, "Unable to load encryption key");
|
||||
return false;
|
||||
}
|
||||
@@ -327,7 +327,7 @@ bool u2f_data_key_generate(uint8_t* device_key) {
|
||||
FURI_LOG_E(TAG, "Encryption failed");
|
||||
return false;
|
||||
}
|
||||
furi_hal_crypto_store_unload_key(U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE);
|
||||
furi_hal_crypto_enclave_unload_key(U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE);
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* flipper_format = flipper_format_file_alloc(storage);
|
||||
@@ -392,7 +392,7 @@ bool u2f_data_cnt_read(uint32_t* cnt_val) {
|
||||
FURI_LOG_E(TAG, "Missing data");
|
||||
break;
|
||||
}
|
||||
if(!furi_hal_crypto_store_load_key(U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE, iv)) {
|
||||
if(!furi_hal_crypto_enclave_load_key(U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE, iv)) {
|
||||
FURI_LOG_E(TAG, "Unable to load encryption key");
|
||||
break;
|
||||
}
|
||||
@@ -402,7 +402,7 @@ bool u2f_data_cnt_read(uint32_t* cnt_val) {
|
||||
FURI_LOG_E(TAG, "Decryption failed");
|
||||
break;
|
||||
}
|
||||
furi_hal_crypto_store_unload_key(U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE);
|
||||
furi_hal_crypto_enclave_unload_key(U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE);
|
||||
if(cnt.control == U2F_COUNTER_CONTROL_VAL) {
|
||||
*cnt_val = cnt.counter;
|
||||
state = true;
|
||||
@@ -434,7 +434,7 @@ bool u2f_data_cnt_write(uint32_t cnt_val) {
|
||||
cnt.control = U2F_COUNTER_CONTROL_VAL;
|
||||
cnt.counter = cnt_val;
|
||||
|
||||
if(!furi_hal_crypto_store_load_key(U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE, iv)) {
|
||||
if(!furi_hal_crypto_enclave_load_key(U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE, iv)) {
|
||||
FURI_LOG_E(TAG, "Unable to load encryption key");
|
||||
return false;
|
||||
}
|
||||
@@ -443,7 +443,7 @@ bool u2f_data_cnt_write(uint32_t cnt_val) {
|
||||
FURI_LOG_E(TAG, "Encryption failed");
|
||||
return false;
|
||||
}
|
||||
furi_hal_crypto_store_unload_key(U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE);
|
||||
furi_hal_crypto_enclave_unload_key(U2F_DATA_FILE_ENCRYPTION_KEY_SLOT_UNIQUE);
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* flipper_format = flipper_format_file_alloc(storage);
|
||||
|
||||
@@ -33,7 +33,7 @@ void crypto_cli_encrypt(Cli* cli, FuriString* args) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(!furi_hal_crypto_store_load_key(key_slot, iv)) {
|
||||
if(!furi_hal_crypto_enclave_load_key(key_slot, iv)) {
|
||||
printf("Unable to load key from slot %d", key_slot);
|
||||
break;
|
||||
}
|
||||
@@ -88,7 +88,7 @@ void crypto_cli_encrypt(Cli* cli, FuriString* args) {
|
||||
} while(0);
|
||||
|
||||
if(key_loaded) {
|
||||
furi_hal_crypto_store_unload_key(key_slot);
|
||||
furi_hal_crypto_enclave_unload_key(key_slot);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ void crypto_cli_decrypt(Cli* cli, FuriString* args) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(!furi_hal_crypto_store_load_key(key_slot, iv)) {
|
||||
if(!furi_hal_crypto_enclave_load_key(key_slot, iv)) {
|
||||
printf("Unable to load key from slot %d", key_slot);
|
||||
break;
|
||||
}
|
||||
@@ -160,7 +160,7 @@ void crypto_cli_decrypt(Cli* cli, FuriString* args) {
|
||||
} while(0);
|
||||
|
||||
if(key_loaded) {
|
||||
furi_hal_crypto_store_unload_key(key_slot);
|
||||
furi_hal_crypto_enclave_unload_key(key_slot);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,14 +175,14 @@ void crypto_cli_has_key(Cli* cli, FuriString* args) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(!furi_hal_crypto_store_load_key(key_slot, iv)) {
|
||||
if(!furi_hal_crypto_enclave_load_key(key_slot, iv)) {
|
||||
printf("Unable to load key from slot %d", key_slot);
|
||||
break;
|
||||
}
|
||||
|
||||
printf("Successfully loaded key from slot %d", key_slot);
|
||||
|
||||
furi_hal_crypto_store_unload_key(key_slot);
|
||||
furi_hal_crypto_enclave_unload_key(key_slot);
|
||||
} while(0);
|
||||
}
|
||||
|
||||
@@ -251,25 +251,25 @@ void crypto_cli_store_key(Cli* cli, FuriString* args) {
|
||||
if(key_slot > 0) {
|
||||
uint8_t iv[16] = {0};
|
||||
if(key_slot > 1) {
|
||||
if(!furi_hal_crypto_store_load_key(key_slot - 1, iv)) {
|
||||
if(!furi_hal_crypto_enclave_load_key(key_slot - 1, iv)) {
|
||||
printf(
|
||||
"Slot %d before %d is empty, which is not allowed",
|
||||
key_slot - 1,
|
||||
key_slot);
|
||||
break;
|
||||
}
|
||||
furi_hal_crypto_store_unload_key(key_slot - 1);
|
||||
furi_hal_crypto_enclave_unload_key(key_slot - 1);
|
||||
}
|
||||
|
||||
if(furi_hal_crypto_store_load_key(key_slot, iv)) {
|
||||
furi_hal_crypto_store_unload_key(key_slot);
|
||||
if(furi_hal_crypto_enclave_load_key(key_slot, iv)) {
|
||||
furi_hal_crypto_enclave_unload_key(key_slot);
|
||||
printf("Key slot %d is already used", key_slot);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t slot;
|
||||
if(furi_hal_crypto_store_add_key(&key, &slot)) {
|
||||
if(furi_hal_crypto_enclave_store_key(&key, &slot)) {
|
||||
printf("Success. Stored to slot: %d", slot);
|
||||
} else {
|
||||
printf("Failure");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <storage/storage.h>
|
||||
#include <assets_icons.h>
|
||||
#include <gui/gui.h>
|
||||
#include <gui/gui_i.h>
|
||||
#include <gui/view_stack.h>
|
||||
#include <notification/notification.h>
|
||||
#include <notification/notification_messages.h>
|
||||
@@ -38,103 +39,69 @@ static void desktop_loader_callback(const void* message, void* context) {
|
||||
view_dispatcher_send_custom_event(desktop->view_dispatcher, DesktopGlobalAfterAppFinished);
|
||||
}
|
||||
}
|
||||
|
||||
static void desktop_lock_icon_draw_callback(Canvas* canvas, void* context) {
|
||||
UNUSED(context);
|
||||
furi_assert(canvas);
|
||||
canvas_draw_icon(canvas, 0, 0, &I_Lock_7x8);
|
||||
}
|
||||
|
||||
static void desktop_clock_upd_time(Desktop* desktop, bool forced) {
|
||||
static void desktop_clock_update(Desktop* desktop) {
|
||||
furi_assert(desktop);
|
||||
|
||||
FuriHalRtcDateTime curr_dt;
|
||||
furi_hal_rtc_get_datetime(&curr_dt);
|
||||
bool time_format_12 = locale_get_time_format() == LocaleTimeFormat12h;
|
||||
|
||||
if(forced) {
|
||||
desktop->clock_type = (locale_get_time_format() == LocaleTimeFormat24h);
|
||||
}
|
||||
|
||||
if(forced || (desktop->minute != curr_dt.minute)) {
|
||||
if(desktop->clock_type) {
|
||||
desktop->hour = curr_dt.hour;
|
||||
} else {
|
||||
desktop->hour = (curr_dt.hour > 12) ? curr_dt.hour - 12 :
|
||||
((curr_dt.hour == 0) ? 12 : curr_dt.hour);
|
||||
}
|
||||
desktop->minute = curr_dt.minute;
|
||||
if(desktop->time_hour != curr_dt.hour || desktop->time_minute != curr_dt.minute ||
|
||||
desktop->time_format_12 != time_format_12) {
|
||||
desktop->time_format_12 = time_format_12;
|
||||
desktop->time_hour = curr_dt.hour;
|
||||
desktop->time_minute = curr_dt.minute;
|
||||
view_port_update(desktop->clock_viewport);
|
||||
}
|
||||
}
|
||||
|
||||
static void desktop_clock_toggle_view(Desktop* desktop, bool is_enabled) {
|
||||
static void desktop_clock_reconfigure(Desktop* desktop) {
|
||||
furi_assert(desktop);
|
||||
|
||||
desktop_clock_upd_time(desktop, true);
|
||||
desktop_clock_update(desktop);
|
||||
|
||||
if(is_enabled) { // && !furi_timer_is_running(desktop->update_clock_timer)) {
|
||||
if(XTREME_SETTINGS()->statusbar_clock) {
|
||||
furi_timer_start(desktop->update_clock_timer, furi_ms_to_ticks(1000));
|
||||
} else if(!is_enabled) { //&& furi_timer_is_running(desktop->update_clock_timer)) {
|
||||
} else {
|
||||
furi_timer_stop(desktop->update_clock_timer);
|
||||
}
|
||||
|
||||
view_port_enabled_set(desktop->clock_viewport, is_enabled);
|
||||
view_port_enabled_set(desktop->clock_viewport, XTREME_SETTINGS()->statusbar_clock);
|
||||
}
|
||||
|
||||
static uint8_t desktop_clock_get_num_w(uint8_t num) {
|
||||
if(num == 1) {
|
||||
return 3;
|
||||
} else if(num == 4) {
|
||||
return 6;
|
||||
} else {
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
static const char* digit[10] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
|
||||
|
||||
static void desktop_clock_draw_callback(Canvas* canvas, void* context) {
|
||||
furi_assert(context);
|
||||
furi_assert(canvas);
|
||||
|
||||
Desktop* desktop = context;
|
||||
|
||||
uint8_t d[4] = {
|
||||
desktop->minute % 10,
|
||||
desktop->minute / 10,
|
||||
desktop->hour % 10,
|
||||
desktop->hour / 10,
|
||||
};
|
||||
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
|
||||
uint8_t new_w = desktop_clock_get_num_w(d[0]) + //c1
|
||||
desktop_clock_get_num_w(d[1]) + //c2
|
||||
desktop_clock_get_num_w(d[2]) + //c3
|
||||
desktop_clock_get_num_w(d[3]) + //c4
|
||||
2 + 4; // ":" + 4 separators
|
||||
uint8_t hour = desktop->time_hour;
|
||||
if(desktop->time_format_12) {
|
||||
if(hour > 12) {
|
||||
hour -= 12;
|
||||
}
|
||||
if(hour == 0) {
|
||||
hour = 12;
|
||||
}
|
||||
}
|
||||
|
||||
// further away from the battery charge indicator, if the smallest minute is 1
|
||||
view_port_set_width(desktop->clock_viewport, new_w - !(d[0] == 1));
|
||||
char buffer[20];
|
||||
snprintf(buffer, sizeof(buffer), "%02u:%02u", hour, desktop->time_minute);
|
||||
|
||||
uint8_t x = new_w;
|
||||
// ToDo: never do that, may cause visual glitches
|
||||
view_port_set_width(
|
||||
desktop->clock_viewport,
|
||||
canvas_string_width(canvas, buffer) - 1 + (desktop->time_minute % 10 == 1));
|
||||
|
||||
uint8_t y = 8;
|
||||
uint8_t offset_r;
|
||||
|
||||
canvas_draw_str_aligned(canvas, x, y, AlignRight, AlignBottom, digit[d[0]]);
|
||||
offset_r = desktop_clock_get_num_w(d[0]);
|
||||
|
||||
canvas_draw_str_aligned(canvas, x -= (offset_r + 1), y, AlignRight, AlignBottom, digit[d[1]]);
|
||||
offset_r = desktop_clock_get_num_w(d[1]);
|
||||
|
||||
canvas_draw_str_aligned(canvas, x -= (offset_r + 1), y - 1, AlignRight, AlignBottom, ":");
|
||||
offset_r = 2;
|
||||
|
||||
canvas_draw_str_aligned(canvas, x -= (offset_r + 1), y, AlignRight, AlignBottom, digit[d[2]]);
|
||||
offset_r = desktop_clock_get_num_w(d[2]);
|
||||
|
||||
canvas_draw_str_aligned(canvas, x -= (offset_r + 1), y, AlignRight, AlignBottom, digit[d[3]]);
|
||||
canvas_draw_str_aligned(canvas, 0, 8, AlignLeft, AlignBottom, buffer);
|
||||
}
|
||||
|
||||
static void desktop_stealth_mode_icon_draw_callback(Canvas* canvas, void* context) {
|
||||
@@ -154,7 +121,7 @@ static bool desktop_custom_event_callback(void* context, uint32_t event) {
|
||||
return true;
|
||||
case DesktopGlobalAfterAppFinished:
|
||||
animation_manager_load_and_continue_animation(desktop->animation_manager);
|
||||
desktop_clock_toggle_view(desktop, XTREME_SETTINGS()->statusbar_clock);
|
||||
desktop_clock_reconfigure(desktop);
|
||||
desktop_auto_lock_arm(desktop);
|
||||
return true;
|
||||
case DesktopGlobalAutoLock:
|
||||
@@ -224,8 +191,8 @@ static void desktop_clock_timer_callback(void* context) {
|
||||
furi_assert(context);
|
||||
Desktop* desktop = context;
|
||||
|
||||
if(gui_get_count_of_enabled_view_port_in_layer(desktop->gui, GuiLayerStatusBarLeft) < 6) {
|
||||
desktop_clock_upd_time(desktop, false);
|
||||
if(gui_active_view_port_count(desktop->gui, GuiLayerStatusBarLeft) < 6) {
|
||||
desktop_clock_update(desktop);
|
||||
|
||||
view_port_enabled_set(desktop->clock_viewport, true);
|
||||
} else {
|
||||
@@ -420,11 +387,6 @@ Desktop* desktop_alloc() {
|
||||
desktop->update_clock_timer =
|
||||
furi_timer_alloc(desktop_clock_timer_callback, FuriTimerTypePeriodic, desktop);
|
||||
|
||||
FuriHalRtcDateTime curr_dt;
|
||||
furi_hal_rtc_get_datetime(&curr_dt);
|
||||
|
||||
desktop_clock_upd_time(desktop, true);
|
||||
|
||||
furi_record_create(RECORD_DESKTOP, desktop);
|
||||
|
||||
return desktop;
|
||||
@@ -524,7 +486,7 @@ int32_t desktop_srv(void* p) {
|
||||
|
||||
DESKTOP_KEYBINDS_LOAD(&desktop->keybinds, sizeof(desktop->keybinds));
|
||||
|
||||
desktop_clock_toggle_view(desktop, XTREME_SETTINGS()->statusbar_clock);
|
||||
desktop_clock_reconfigure(desktop);
|
||||
|
||||
scene_manager_next_scene(desktop->scene_manager, DesktopSceneMain);
|
||||
|
||||
|
||||
@@ -74,9 +74,10 @@ struct Desktop {
|
||||
FuriTimer* update_clock_timer;
|
||||
|
||||
FuriPubSub* status_pubsub;
|
||||
uint8_t hour;
|
||||
uint8_t minute;
|
||||
bool clock_type : 1; // true - 24h false - 12h
|
||||
|
||||
uint8_t time_hour;
|
||||
uint8_t time_minute;
|
||||
bool time_format_12 : 1; // 1 - 12 hour, 0 - 24H
|
||||
|
||||
bool in_transition : 1;
|
||||
};
|
||||
|
||||
@@ -20,11 +20,12 @@ ViewPort* gui_view_port_find_enabled(ViewPortArray_t array) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint8_t gui_get_count_of_enabled_view_port_in_layer(Gui* gui, GuiLayer layer) {
|
||||
size_t gui_active_view_port_count(Gui* gui, GuiLayer layer) {
|
||||
furi_assert(gui);
|
||||
furi_check(layer < GuiLayerMAX);
|
||||
uint8_t ret = 0;
|
||||
size_t ret = 0;
|
||||
|
||||
gui_lock(gui);
|
||||
ViewPortArray_it_t it;
|
||||
ViewPortArray_it_last(it, gui->layers[layer]);
|
||||
while(!ViewPortArray_end_p(it)) {
|
||||
@@ -34,6 +35,8 @@ uint8_t gui_get_count_of_enabled_view_port_in_layer(Gui* gui, GuiLayer layer) {
|
||||
}
|
||||
ViewPortArray_previous(it);
|
||||
}
|
||||
gui_unlock(gui);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -141,8 +141,6 @@ Canvas* gui_direct_draw_acquire(Gui* gui);
|
||||
*/
|
||||
void gui_direct_draw_release(Gui* gui);
|
||||
|
||||
uint8_t gui_get_count_of_enabled_view_port_in_layer(Gui* gui, GuiLayer layer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -76,6 +76,12 @@ struct Gui {
|
||||
ViewPort* ongoing_input_view_port;
|
||||
};
|
||||
|
||||
/** Find enabled ViewPort in ViewPortArray
|
||||
*
|
||||
* @param[in] array The ViewPortArray instance
|
||||
*
|
||||
* @return ViewPort instance or NULL
|
||||
*/
|
||||
ViewPort* gui_view_port_find_enabled(ViewPortArray_t array);
|
||||
|
||||
/** Update GUI, request redraw
|
||||
@@ -84,8 +90,30 @@ ViewPort* gui_view_port_find_enabled(ViewPortArray_t array);
|
||||
*/
|
||||
void gui_update(Gui* gui);
|
||||
|
||||
/** Input event callback
|
||||
*
|
||||
* Used to receive input from input service or to inject new input events
|
||||
*
|
||||
* @param[in] value The value pointer (InputEvent*)
|
||||
* @param ctx The context (Gui instance)
|
||||
*/
|
||||
void gui_input_events_callback(const void* value, void* ctx);
|
||||
|
||||
/** Get count of view ports in layer
|
||||
*
|
||||
* @param gui The Gui instance
|
||||
* @param[in] layer GuiLayer that we want to get count of view ports
|
||||
*/
|
||||
size_t gui_active_view_port_count(Gui* gui, GuiLayer layer);
|
||||
|
||||
/** Lock GUI
|
||||
*
|
||||
* @param gui The Gui instance
|
||||
*/
|
||||
void gui_lock(Gui* gui);
|
||||
|
||||
/** Unlock GUI
|
||||
*
|
||||
* @param gui The Gui instance
|
||||
*/
|
||||
void gui_unlock(Gui* gui);
|
||||
|
||||
Reference in New Issue
Block a user