From 44df62c9d1b9f2baf8e85d8df850e378e9bb9efb Mon Sep 17 00:00:00 2001 From: Alexander Kopachov Date: Thu, 16 Feb 2023 11:12:00 +0100 Subject: [PATCH] * Updated firmware submodules (#76) (#78) * Updated firmware submodules (#76) * Added more colors to cli * Fixed bug #77 --- cli/cli.c | 2 +- cli/cli_helpers.h | 29 +++++++++++++- cli/commands/add/add.c | 22 +++++----- cli/commands/delete/delete.c | 11 ++--- cli/commands/move/move.c | 11 ++--- cli/commands/notification/notification.c | 19 ++++----- cli/commands/pin/pin.c | 6 +-- cli/commands/reset/reset.c | 14 +++---- cli/commands/timezone/timezone.c | 11 ++--- services/hmac/sha1.c | 40 ++++++------------- types/token_info.c | 1 + .../authenticate/totp_scene_authenticate.c | 5 ++- .../totp_scene_generate_token.c | 17 +++++--- 13 files changed, 105 insertions(+), 83 deletions(-) diff --git a/cli/cli.c b/cli/cli.c index 8f4708f4dbf..28d17376626 100644 --- a/cli/cli.c +++ b/cli/cli.c @@ -14,7 +14,7 @@ #include "commands/reset/reset.h" static void totp_cli_print_unknown_command(const FuriString* unknown_command) { - TOTP_CLI_PRINTF( + TOTP_CLI_PRINTF_ERROR( "Command \"%s\" is unknown. Use \"" TOTP_CLI_COMMAND_HELP "\" command to get list of available commands.", furi_string_get_cstr(unknown_command)); diff --git a/cli/cli_helpers.h b/cli/cli_helpers.h index 5027d7027f1..a35a2e59993 100644 --- a/cli/cli_helpers.h +++ b/cli/cli_helpers.h @@ -22,6 +22,31 @@ _Pragma(STRINGIFY(GCC diagnostic pop)) \ } while(false) +#define TOTP_CLI_PRINTF_COLORFUL(color, format, ...) \ + do { \ + _Pragma(STRINGIFY(GCC diagnostic push)) \ + _Pragma(STRINGIFY(GCC diagnostic ignored "-Wdouble-promotion")) \ + printf("\e[%s", color); \ + printf(format, ##__VA_ARGS__); \ + printf("\e[0m"); \ + fflush(stdout); \ + _Pragma(STRINGIFY(GCC diagnostic pop)) \ + } while(false) + +#define TOTP_CLI_COLOR_ERROR "91m" +#define TOTP_CLI_COLOR_WARNING "93m" +#define TOTP_CLI_COLOR_SUCCESS "92m" +#define TOTP_CLI_COLOR_INFO "96m" + +#define TOTP_CLI_PRINTF_ERROR(format, ...) \ + TOTP_CLI_PRINTF_COLORFUL(TOTP_CLI_COLOR_ERROR, format, ##__VA_ARGS__) +#define TOTP_CLI_PRINTF_WARNING(format, ...) \ + TOTP_CLI_PRINTF_COLORFUL(TOTP_CLI_COLOR_WARNING, format, ##__VA_ARGS__) +#define TOTP_CLI_PRINTF_SUCCESS(format, ...) \ + TOTP_CLI_PRINTF_COLORFUL(TOTP_CLI_COLOR_SUCCESS, format, ##__VA_ARGS__) +#define TOTP_CLI_PRINTF_INFO(format, ...) \ + TOTP_CLI_PRINTF_COLORFUL(TOTP_CLI_COLOR_INFO, format, ##__VA_ARGS__) + #define TOTP_CLI_DELETE_LAST_LINE() \ TOTP_CLI_PRINTF("\033[A\33[2K\r"); \ fflush(stdout) @@ -35,11 +60,11 @@ fflush(stdout) #define TOTP_CLI_PRINT_INVALID_ARGUMENTS() \ - TOTP_CLI_PRINTF( \ + TOTP_CLI_PRINTF_ERROR( \ "Invalid command arguments. use \"help\" command to get list of available commands") #define TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE() \ - TOTP_CLI_PRINTF("An error has occurred during updating config file\r\n") + TOTP_CLI_PRINTF_ERROR("An error has occurred during updating config file\r\n") /** * @brief Checks whether user is authenticated and entered correct PIN. diff --git a/cli/commands/add/add.c b/cli/commands/add/add.c index 2183d527770..fbcd58530c2 100644 --- a/cli/commands/add/add.c +++ b/cli/commands/add/add.c @@ -115,10 +115,10 @@ void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cl bool parsed = false; if(furi_string_cmpi_str(temp_str, TOTP_CLI_COMMAND_ADD_ARG_ALGO_PREFIX) == 0) { if(!args_read_string_and_trim(args, temp_str)) { - TOTP_CLI_PRINTF("Missed value for argument \"" TOTP_CLI_COMMAND_ADD_ARG_ALGO_PREFIX - "\"\r\n"); + TOTP_CLI_PRINTF_ERROR( + "Missed value for argument \"" TOTP_CLI_COMMAND_ADD_ARG_ALGO_PREFIX "\"\r\n"); } else if(!token_info_set_algo_from_str(token_info, temp_str)) { - TOTP_CLI_PRINTF( + TOTP_CLI_PRINTF_ERROR( "\"%s\" is incorrect value for argument \"" TOTP_CLI_COMMAND_ADD_ARG_ALGO_PREFIX "\"\r\n", furi_string_get_cstr(temp_str)); @@ -128,11 +128,11 @@ void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cl } else if(furi_string_cmpi_str(temp_str, TOTP_CLI_COMMAND_ADD_ARG_DIGITS_PREFIX) == 0) { uint8_t digit_value; if(!args_read_uint8_and_trim(args, &digit_value)) { - TOTP_CLI_PRINTF( + TOTP_CLI_PRINTF_ERROR( "Missed or incorrect value for argument \"" TOTP_CLI_COMMAND_ADD_ARG_DIGITS_PREFIX "\"\r\n"); } else if(!token_info_set_digits_from_int(token_info, digit_value)) { - TOTP_CLI_PRINTF( + TOTP_CLI_PRINTF_ERROR( "\"%" PRIu8 "\" is incorrect value for argument \"" TOTP_CLI_COMMAND_ADD_ARG_DIGITS_PREFIX "\"\r\n", @@ -143,11 +143,11 @@ void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cl } else if(furi_string_cmpi_str(temp_str, TOTP_CLI_COMMAND_ADD_ARG_DURATION_PREFIX) == 0) { uint8_t duration_value; if(!args_read_uint8_and_trim(args, &duration_value)) { - TOTP_CLI_PRINTF( + TOTP_CLI_PRINTF_ERROR( "Missed or incorrect value for argument \"" TOTP_CLI_COMMAND_ADD_ARG_DURATION_PREFIX "\"\r\n"); } else if(!token_info_set_duration_from_int(token_info, duration_value)) { - TOTP_CLI_PRINTF( + TOTP_CLI_PRINTF_ERROR( "\"%" PRIu8 "\" is incorrect value for argument \"" TOTP_CLI_COMMAND_ADD_ARG_DURATION_PREFIX "\"\r\n", @@ -159,7 +159,7 @@ void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cl mask_user_input = false; parsed = true; } else { - TOTP_CLI_PRINTF("Unknown argument \"%s\"\r\n", furi_string_get_cstr(temp_str)); + TOTP_CLI_PRINTF_ERROR("Unknown argument \"%s\"\r\n", furi_string_get_cstr(temp_str)); } if(!parsed) { @@ -176,7 +176,7 @@ void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cl if(!totp_cli_read_line(cli, temp_str, mask_user_input) || !totp_cli_ensure_authenticated(plugin_state, cli)) { TOTP_CLI_DELETE_LAST_LINE(); - TOTP_CLI_PRINTF("Cancelled by user\r\n"); + TOTP_CLI_PRINTF_INFO("Cancelled by user\r\n"); furi_string_secure_free(temp_str); token_info_free(token_info); return; @@ -189,7 +189,7 @@ void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cl furi_string_get_cstr(temp_str), furi_string_size(temp_str), plugin_state->iv)) { - TOTP_CLI_PRINTF("Token secret seems to be invalid and can not be parsed\r\n"); + TOTP_CLI_PRINTF_ERROR("Token secret seems to be invalid and can not be parsed\r\n"); furi_string_secure_free(temp_str); token_info_free(token_info); return; @@ -206,7 +206,7 @@ void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cl TOTP_LIST_INIT_OR_ADD(plugin_state->tokens_list, token_info, furi_check); plugin_state->tokens_count++; if(totp_config_file_save_new_token(token_info) == TotpConfigFileUpdateSuccess) { - TOTP_CLI_PRINTF("Token \"%s\" has been successfully added\r\n", token_info->name); + TOTP_CLI_PRINTF_SUCCESS("Token \"%s\" has been successfully added\r\n", token_info->name); } else { TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE(); } diff --git a/cli/commands/delete/delete.c b/cli/commands/delete/delete.c index 0463416931c..8fe72e22097 100644 --- a/cli/commands/delete/delete.c +++ b/cli/commands/delete/delete.c @@ -64,11 +64,11 @@ void totp_cli_command_delete_handle(PluginState* plugin_state, FuriString* args, bool confirmed = !confirm_needed; if(confirm_needed) { - TOTP_CLI_PRINTF("WARNING!\r\n"); - TOTP_CLI_PRINTF( + TOTP_CLI_PRINTF_WARNING("WARNING!\r\n"); + TOTP_CLI_PRINTF_WARNING( "TOKEN \"%s\" WILL BE PERMANENTLY DELETED WITHOUT ABILITY TO RECOVER IT.\r\n", token_info->name); - TOTP_CLI_PRINTF("Confirm? [y/n]\r\n"); + TOTP_CLI_PRINTF_WARNING("Confirm? [y/n]\r\n"); fflush(stdout); char user_pick; do { @@ -94,7 +94,8 @@ void totp_cli_command_delete_handle(PluginState* plugin_state, FuriString* args, plugin_state->tokens_count--; if(totp_full_save_config_file(plugin_state) == TotpConfigFileUpdateSuccess) { - TOTP_CLI_PRINTF("Token \"%s\" has been successfully deleted\r\n", token_info->name); + TOTP_CLI_PRINTF_SUCCESS( + "Token \"%s\" has been successfully deleted\r\n", token_info->name); } else { TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE(); } @@ -105,6 +106,6 @@ void totp_cli_command_delete_handle(PluginState* plugin_state, FuriString* args, totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL); } } else { - TOTP_CLI_PRINTF("User not confirmed\r\n"); + TOTP_CLI_PRINTF_INFO("User has not confirmed\r\n"); } } \ No newline at end of file diff --git a/cli/commands/move/move.c b/cli/commands/move/move.c index e2929f1532e..1d5a23bbfeb 100644 --- a/cli/commands/move/move.c +++ b/cli/commands/move/move.c @@ -65,7 +65,7 @@ void totp_cli_command_move_handle(PluginState* plugin_state, FuriString* args, C bool parsed = false; if(furi_string_cmpi_str(temp_str, TOTP_CLI_COMMAND_MOVE_ARG_NEW_NAME_PREFIX) == 0) { if(!args_read_string_and_trim(args, temp_str)) { - TOTP_CLI_PRINTF( + TOTP_CLI_PRINTF_ERROR( "Missed value for argument \"" TOTP_CLI_COMMAND_MOVE_ARG_NEW_NAME_PREFIX "\"\r\n"); } else { @@ -87,11 +87,11 @@ void totp_cli_command_move_handle(PluginState* plugin_state, FuriString* args, C } } else if(furi_string_cmpi_str(temp_str, TOTP_CLI_COMMAND_MOVE_ARG_NEW_INDEX_PREFIX) == 0) { if(!args_read_int_and_trim(args, &new_token_index)) { - TOTP_CLI_PRINTF( + TOTP_CLI_PRINTF_ERROR( "Missed value for argument \"" TOTP_CLI_COMMAND_MOVE_ARG_NEW_INDEX_PREFIX "\"\r\n"); } else if(new_token_index < 1 || new_token_index > plugin_state->tokens_count) { - TOTP_CLI_PRINTF( + TOTP_CLI_PRINTF_ERROR( "\"%" PRId16 "\" is incorrect value for argument \"" TOTP_CLI_COMMAND_MOVE_ARG_NEW_INDEX_PREFIX "\"\r\n", @@ -100,7 +100,7 @@ void totp_cli_command_move_handle(PluginState* plugin_state, FuriString* args, C parsed = true; } } else { - TOTP_CLI_PRINTF("Unknown argument \"%s\"\r\n", furi_string_get_cstr(temp_str)); + TOTP_CLI_PRINTF_ERROR("Unknown argument \"%s\"\r\n", furi_string_get_cstr(temp_str)); } if(!parsed) { @@ -148,7 +148,8 @@ void totp_cli_command_move_handle(PluginState* plugin_state, FuriString* args, C if(token_updated) { if(totp_full_save_config_file(plugin_state) == TotpConfigFileUpdateSuccess) { - TOTP_CLI_PRINTF("Token \"%s\" has been successfully updated\r\n", token_info->name); + TOTP_CLI_PRINTF_SUCCESS( + "Token \"%s\" has been successfully updated\r\n", token_info->name); } else { TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE(); } diff --git a/cli/commands/notification/notification.c b/cli/commands/notification/notification.c index 5b98a857b08..bbbd52703bb 100644 --- a/cli/commands/notification/notification.c +++ b/cli/commands/notification/notification.c @@ -28,21 +28,21 @@ void totp_cli_command_notification_docopt_arguments() { ", " TOTP_CLI_COMMAND_NOTIFICATION_METHOD_VIBRO "]\r\n"); } -static void totp_cli_command_notification_print_method(NotificationMethod method) { +static void totp_cli_command_notification_print_method(NotificationMethod method, char* color) { bool has_previous_method = false; if(method & NotificationMethodSound) { - TOTP_CLI_PRINTF("\"" TOTP_CLI_COMMAND_NOTIFICATION_METHOD_SOUND "\""); + TOTP_CLI_PRINTF_COLORFUL(color, "\"" TOTP_CLI_COMMAND_NOTIFICATION_METHOD_SOUND "\""); has_previous_method = true; } if(method & NotificationMethodVibro) { if(has_previous_method) { - TOTP_CLI_PRINTF(" and "); + TOTP_CLI_PRINTF_COLORFUL(color, " and "); } - TOTP_CLI_PRINTF("\"" TOTP_CLI_COMMAND_NOTIFICATION_METHOD_VIBRO "\""); + TOTP_CLI_PRINTF_COLORFUL(color, "\"" TOTP_CLI_COMMAND_NOTIFICATION_METHOD_VIBRO "\""); } if(method == NotificationMethodNone) { - TOTP_CLI_PRINTF("\"" TOTP_CLI_COMMAND_NOTIFICATION_METHOD_NONE "\""); + TOTP_CLI_PRINTF_COLORFUL(color, "\"" TOTP_CLI_COMMAND_NOTIFICATION_METHOD_NONE "\""); } } @@ -88,8 +88,8 @@ void totp_cli_command_notification_handle(PluginState* plugin_state, FuriString* plugin_state->notification_method = new_method; if(totp_config_file_update_notification_method(new_method) == TotpConfigFileUpdateSuccess) { - TOTP_CLI_PRINTF("Notification method is set to "); - totp_cli_command_notification_print_method(new_method); + TOTP_CLI_PRINTF_SUCCESS("Notification method is set to "); + totp_cli_command_notification_print_method(new_method, TOTP_CLI_COLOR_SUCCESS); cli_nl(); } else { TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE(); @@ -99,8 +99,9 @@ void totp_cli_command_notification_handle(PluginState* plugin_state, FuriString* totp_scene_director_activate_scene(plugin_state, previous_scene, NULL); } } else { - TOTP_CLI_PRINTF("Current notification method is "); - totp_cli_command_notification_print_method(plugin_state->notification_method); + TOTP_CLI_PRINTF_INFO("Current notification method is "); + totp_cli_command_notification_print_method( + plugin_state->notification_method, TOTP_CLI_COLOR_INFO); cli_nl(); } } while(false); diff --git a/cli/commands/pin/pin.c b/cli/commands/pin/pin.c index 198324e2734..b5b4943d6b4 100644 --- a/cli/commands/pin/pin.c +++ b/cli/commands/pin/pin.c @@ -65,7 +65,7 @@ static bool totp_cli_read_pin(Cli* cli, uint8_t* pin, uint8_t* pin_length) { } } else if(c == CliSymbolAsciiETX) { TOTP_CLI_DELETE_CURRENT_LINE(); - TOTP_CLI_PRINTF("Cancelled by user\r\n"); + TOTP_CLI_PRINTF_INFO("Cancelled by user\r\n"); return false; } else if(c == CliSymbolAsciiBackspace || c == CliSymbolAsciiDel) { if(*pin_length > 0) { @@ -162,9 +162,9 @@ void totp_cli_command_pin_handle(PluginState* plugin_state, FuriString* args, Cl if(totp_full_save_config_file(plugin_state) == TotpConfigFileUpdateSuccess) { if(do_change) { - TOTP_CLI_PRINTF("PIN has been successfully changed\r\n"); + TOTP_CLI_PRINTF_SUCCESS("PIN has been successfully changed\r\n"); } else if(do_remove) { - TOTP_CLI_PRINTF("PIN has been successfully removed\r\n"); + TOTP_CLI_PRINTF_SUCCESS("PIN has been successfully removed\r\n"); } } else { TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE(); diff --git a/cli/commands/reset/reset.c b/cli/commands/reset/reset.c index 3f20dc8adf1..c7928db3115 100644 --- a/cli/commands/reset/reset.c +++ b/cli/commands/reset/reset.c @@ -17,21 +17,21 @@ void totp_cli_command_reset_docopt_usage() { } void totp_cli_command_reset_handle(Cli* cli, FuriMessageQueue* event_queue) { - TOTP_CLI_PRINTF( + TOTP_CLI_PRINTF_WARNING( "As a result of reset all the settings and tokens will be permanently lost.\r\n"); - TOTP_CLI_PRINTF("Do you really want to reset application?\r\n"); - TOTP_CLI_PRINTF("Type \"" TOTP_CLI_RESET_CONFIRMATION_KEYWORD - "\" and hit to confirm:\r\n"); + TOTP_CLI_PRINTF_WARNING("Do you really want to reset application?\r\n"); + TOTP_CLI_PRINTF_WARNING("Type \"" TOTP_CLI_RESET_CONFIRMATION_KEYWORD + "\" and hit to confirm:\r\n"); FuriString* temp_str = furi_string_alloc(); bool is_confirmed = totp_cli_read_line(cli, temp_str, false) && furi_string_cmpi_str(temp_str, TOTP_CLI_RESET_CONFIRMATION_KEYWORD) == 0; furi_string_free(temp_str); if(is_confirmed) { totp_config_file_reset(); - TOTP_CLI_PRINTF("Application has been successfully reset to default.\r\n"); - TOTP_CLI_PRINTF("Now application will be closed to apply all the changes.\r\n"); + TOTP_CLI_PRINTF_SUCCESS("Application has been successfully reset to default.\r\n"); + TOTP_CLI_PRINTF_SUCCESS("Now application will be closed to apply all the changes.\r\n"); totp_cli_force_close_app(event_queue); } else { - TOTP_CLI_PRINTF("Action was not confirmed by user\r\n"); + TOTP_CLI_PRINTF_INFO("Action was not confirmed by user\r\n"); } } \ No newline at end of file diff --git a/cli/commands/timezone/timezone.c b/cli/commands/timezone/timezone.c index 4a737f6efe3..9eb0cb5f646 100644 --- a/cli/commands/timezone/timezone.c +++ b/cli/commands/timezone/timezone.c @@ -30,11 +30,12 @@ void totp_cli_command_timezone_handle(PluginState* plugin_state, FuriString* arg FuriString* temp_str = furi_string_alloc(); if(args_read_string_and_trim(args, temp_str)) { - float tz = strtof(furi_string_get_cstr(temp_str), NULL); - if(tz >= -12.75f && tz <= 12.75f) { + char* strtof_endptr; + float tz = strtof(furi_string_get_cstr(temp_str), &strtof_endptr); + if(*strtof_endptr == 0 && tz >= -12.75f && tz <= 12.75f) { plugin_state->timezone_offset = tz; if(totp_config_file_update_timezone_offset(tz) == TotpConfigFileUpdateSuccess) { - TOTP_CLI_PRINTF("Timezone is set to %f\r\n", tz); + TOTP_CLI_PRINTF_SUCCESS("Timezone is set to %f\r\n", tz); } else { TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE(); } @@ -46,10 +47,10 @@ void totp_cli_command_timezone_handle(PluginState* plugin_state, FuriString* arg totp_scene_director_activate_scene(plugin_state, TotpSceneAppSettings, NULL); } } else { - TOTP_CLI_PRINTF("Invalid timezone offset\r\n"); + TOTP_CLI_PRINTF_ERROR("Invalid timezone offset\r\n"); } } else { - TOTP_CLI_PRINTF("Current timezone offset is %f\r\n", plugin_state->timezone_offset); + TOTP_CLI_PRINTF_INFO("Current timezone offset is %f\r\n", plugin_state->timezone_offset); } furi_string_free(temp_str); } \ No newline at end of file diff --git a/services/hmac/sha1.c b/services/hmac/sha1.c index 243a6dde82a..ecf22fc972f 100644 --- a/services/hmac/sha1.c +++ b/services/hmac/sha1.c @@ -174,16 +174,13 @@ void sha1_process_bytes(const void* buffer, size_t len, struct sha1_ctx* ctx) { /* --- Code below is the primary difference between md5.c and sha1.c --- */ /* SHA1 round constants */ -#define K1 0x5a827999 -#define K2 0x6ed9eba1 -#define K3 0x8f1bbcdc -#define K4 0xca62c1d6 +static const int sha1_round_constants[4] = {0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6}; /* Round functions. Note that F2 is the same as F4. */ #define F1(B, C, D) (D ^ (B & (C ^ D))) -#define F2(B, C, D) (B ^ C ^ D) +#define F2_4(B, C, D) (B ^ C ^ D) #define F3(B, C, D) ((B & C) | (D & (B | C))) -#define F4(B, C, D) (B ^ C ^ D) +#define FN(I, B, C, D) (I == 0 ? F1(B, C, D) : (I == 2 ? F3(B, C, D) : F2_4(B, C, D))) /* Process LEN bytes of BUFFER, accumulating context into CTX. It is assumed that LEN % 64 == 0. @@ -213,10 +210,10 @@ void sha1_process_block(const void* buffer, size_t len, struct sha1_ctx* ctx) { (tm = x[I & 0x0f] ^ x[(I - 14) & 0x0f] ^ x[(I - 8) & 0x0f] ^ x[(I - 3) & 0x0f], \ (x[I & 0x0f] = rol(tm, 1))) -#define R(A, B, C, D, E, F, K, M) \ - do { \ - E += rol(A, 5) + F(B, C, D) + K + M; \ - B = rol(B, 30); \ +#define R(A, B, C, D, E, F, K, M, KI) \ + do { \ + E += rol(A, 5) + F(KI, B, C, D) + K + M; \ + B = rol(B, 30); \ } while(0) while(words < endp) { @@ -227,24 +224,11 @@ void sha1_process_block(const void* buffer, size_t len, struct sha1_ctx* ctx) { words++; } - for(int i = 0; i < 80; i++) { - uint32_t xx = i < 16 ? x[i] : M(i); - uint32_t ki = i / 20; - switch(ki) { - case 0: - R(a, b, c, d, e, F1, K1, xx); - break; - case 1: - R(a, b, c, d, e, F2, K2, xx); - break; - case 2: - R(a, b, c, d, e, F3, K3, xx); - break; - default: - R(a, b, c, d, e, F4, K4, xx); - break; - } - + for(uint8_t i = 0; i < 80; i++) { + uint32_t m = i < 16 ? x[i] : M(i); + uint8_t ki = i / 20; + int k_const = sha1_round_constants[ki]; + R(a, b, c, d, e, FN, k_const, m, ki); uint32_t tt = a; a = e; e = d; diff --git a/types/token_info.c b/types/token_info.c index 60d04245f9d..b69979cc71f 100644 --- a/types/token_info.c +++ b/types/token_info.c @@ -12,6 +12,7 @@ TokenInfo* token_info_alloc() { furi_check(tokenInfo != NULL); tokenInfo->algo = SHA1; tokenInfo->digits = TOTP_6_DIGITS; + tokenInfo->duration = TOTP_TOKEN_DURATION_DEFAULT; return tokenInfo; } diff --git a/ui/scenes/authenticate/totp_scene_authenticate.c b/ui/scenes/authenticate/totp_scene_authenticate.c index c595b5bd0b4..17beb64c6a3 100644 --- a/ui/scenes/authenticate/totp_scene_authenticate.c +++ b/ui/scenes/authenticate/totp_scene_authenticate.c @@ -10,6 +10,8 @@ #include "../../../types/user_pin_codes.h" #define MAX_CODE_LENGTH TOTP_IV_SIZE +static const uint8_t PIN_ASTERISK_RADIUS = 3; +static const uint8_t PIN_ASTERISK_STEP = (PIN_ASTERISK_RADIUS << 1) + 2; typedef struct { TotpUserPinCode code_input[MAX_CODE_LENGTH]; @@ -61,8 +63,7 @@ void totp_scene_authenticate_render(Canvas* const canvas, PluginState* plugin_st AlignCenter, "Use arrow keys to enter PIN"); } - const uint8_t PIN_ASTERISK_RADIUS = 3; - const uint8_t PIN_ASTERISK_STEP = (PIN_ASTERISK_RADIUS << 1) + 2; + if(scene_state->code_length > 0) { uint8_t left_start_x = ((scene_state->code_length - 1) * PIN_ASTERISK_STEP) >> 1; for(uint8_t i = 0; i < scene_state->code_length; i++) { diff --git a/ui/scenes/generate_token/totp_scene_generate_token.c b/ui/scenes/generate_token/totp_scene_generate_token.c index 51c2e770215..a882ae78ca1 100644 --- a/ui/scenes/generate_token/totp_scene_generate_token.c +++ b/ui/scenes/generate_token/totp_scene_generate_token.c @@ -16,6 +16,9 @@ #include "../token_menu/totp_scene_token_menu.h" #include "../../../workers/type_code/type_code.h" +static const uint8_t PROGRESS_BAR_MARGIN = 3; +static const uint8_t PROGRESS_BAR_HEIGHT = 4; + typedef struct { uint16_t current_token_index; char last_code[TOTP_TOKEN_DIGITS_MAX_COUNT + 1]; @@ -306,14 +309,18 @@ void totp_scene_generate_token_render(Canvas* const canvas, PluginState* plugin_ AlignCenter, scene_state->last_code); - const uint8_t BAR_MARGIN = 3; - const uint8_t BAR_HEIGHT = 4; const uint8_t TOKEN_LIFETIME = scene_state->current_token->duration; float percentDone = (float)(TOKEN_LIFETIME - curr_ts % TOKEN_LIFETIME) / (float)TOKEN_LIFETIME; - uint8_t barWidth = (uint8_t)((float)(SCREEN_WIDTH - (BAR_MARGIN << 1)) * percentDone); - uint8_t barX = ((SCREEN_WIDTH - (BAR_MARGIN << 1) - barWidth) >> 1) + BAR_MARGIN; + uint8_t barWidth = (uint8_t)((float)(SCREEN_WIDTH - (PROGRESS_BAR_MARGIN << 1)) * percentDone); + uint8_t barX = + ((SCREEN_WIDTH - (PROGRESS_BAR_MARGIN << 1) - barWidth) >> 1) + PROGRESS_BAR_MARGIN; - canvas_draw_box(canvas, barX, SCREEN_HEIGHT - BAR_MARGIN - BAR_HEIGHT, barWidth, BAR_HEIGHT); + canvas_draw_box( + canvas, + barX, + SCREEN_HEIGHT - PROGRESS_BAR_MARGIN - PROGRESS_BAR_HEIGHT, + barWidth, + PROGRESS_BAR_HEIGHT); if(plugin_state->tokens_count > 1) { canvas_draw_icon(canvas, 0, SCREEN_HEIGHT_CENTER - 24, &I_totp_arrow_left_8x9);