diff --git a/scenes/add_new_token/totp_scene_add_new_token.c b/scenes/add_new_token/totp_scene_add_new_token.c index 2c9973789ef..090cfa808f6 100644 --- a/scenes/add_new_token/totp_scene_add_new_token.c +++ b/scenes/add_new_token/totp_scene_add_new_token.c @@ -282,6 +282,7 @@ bool totp_scene_add_new_token_handle_event(PluginEvent* const event, PluginState } break; } + default: break; } break; case InputKeyBack: @@ -294,6 +295,7 @@ bool totp_scene_add_new_token_handle_event(PluginEvent* const event, PluginState totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL); } break; + default: break; } return true; diff --git a/scenes/app_settings/totp_app_settings.c b/scenes/app_settings/totp_app_settings.c index 980688e7377..1e74a351cea 100644 --- a/scenes/app_settings/totp_app_settings.c +++ b/scenes/app_settings/totp_app_settings.c @@ -163,6 +163,7 @@ bool totp_scene_app_settings_handle_event( } break; } + default: break; } return true; diff --git a/scenes/authenticate/totp_scene_authenticate.c b/scenes/authenticate/totp_scene_authenticate.c index a6458b3edd2..4ceacd033ca 100644 --- a/scenes/authenticate/totp_scene_authenticate.c +++ b/scenes/authenticate/totp_scene_authenticate.c @@ -67,7 +67,7 @@ void totp_scene_authenticate_render(Canvas* const canvas, PluginState* plugin_st 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; + 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++) { canvas_draw_disc( canvas, @@ -152,6 +152,7 @@ bool totp_scene_authenticate_handle_event( scene_state->code_length--; } break; + default: break; } return true; diff --git a/scenes/generate_token/totp_scene_generate_token.c b/scenes/generate_token/totp_scene_generate_token.c index 7d52f9f5921..7582a166ea2 100644 --- a/scenes/generate_token/totp_scene_generate_token.c +++ b/scenes/generate_token/totp_scene_generate_token.c @@ -73,6 +73,7 @@ TOTP_ALGO get_totp_algo_impl(TokenHashAlgo algo) { return TOTP_ALGO_SHA256; case SHA512: return TOTP_ALGO_SHA512; + default: break; } return NULL; @@ -299,6 +300,7 @@ bool totp_scene_generate_token_handle_event( break; case InputKeyBack: break; + default: break; } return true; diff --git a/scenes/scene_director.c b/scenes/scene_director.c index 5265123f594..88e9cd96a4f 100644 --- a/scenes/scene_director.c +++ b/scenes/scene_director.c @@ -30,6 +30,7 @@ void totp_scene_director_activate_scene( break; case TotpSceneNone: break; + default: break; } plugin_state->current_scene = scene; @@ -55,6 +56,7 @@ void totp_scene_director_deactivate_active_scene(PluginState* const plugin_state break; case TotpSceneNone: break; + default: break; } } @@ -85,6 +87,7 @@ void totp_scene_director_render(Canvas* const canvas, PluginState* const plugin_ break; case TotpSceneNone: break; + default: break; } } @@ -116,6 +119,7 @@ bool totp_scene_director_handle_event(PluginEvent* const event, PluginState* con break; case TotpSceneNone: break; + default: break; } return processing; diff --git a/scenes/token_menu/totp_scene_token_menu.c b/scenes/token_menu/totp_scene_token_menu.c index 1445c7b65ed..58657006d4f 100644 --- a/scenes/token_menu/totp_scene_token_menu.c +++ b/scenes/token_menu/totp_scene_token_menu.c @@ -171,6 +171,7 @@ bool totp_scene_token_menu_handle_event(const PluginEvent* const event, PluginSt } break; } + default: break; } break; case InputKeyBack: { @@ -184,6 +185,7 @@ bool totp_scene_token_menu_handle_event(const PluginEvent* const event, PluginSt } break; } + default: break; } return true; diff --git a/services/cli/commands/add/add.c b/services/cli/commands/add/add.c index fa29a912990..86ec667cf56 100644 --- a/services/cli/commands/add/add.c +++ b/services/cli/commands/add/add.c @@ -22,6 +22,7 @@ static bool token_info_set_digits_from_str(TokenInfo* token_info, const FuriStri case '8': token_info->digits = TOTP_8_DIGITS; return true; + default: break; } return false; diff --git a/services/cli/commands/list/list.c b/services/cli/commands/list/list.c index 61791084d96..7f85b568abc 100644 --- a/services/cli/commands/list/list.c +++ b/services/cli/commands/list/list.c @@ -13,6 +13,7 @@ static char* get_algo_as_cstr(TokenHashAlgo algo) { return TOTP_CONFIG_TOKEN_ALGO_SHA256_NAME; case SHA512: return TOTP_CONFIG_TOKEN_ALGO_SHA512_NAME; + default: break; } return "UNKNOWN"; @@ -24,6 +25,7 @@ static uint8_t get_digits_as_int(TokenDigitsCount digits) { return 6; case TOTP_8_DIGITS: return 8; + default: break; } return 6; diff --git a/services/config/config.c b/services/config/config.c index d458d682f27..fa2fb9d5934 100644 --- a/services/config/config.c +++ b/services/config/config.c @@ -16,6 +16,7 @@ static uint8_t token_info_get_digits_as_int(const TokenInfo* token_info) { return 6; case TOTP_8_DIGITS: return 8; + default: break; } return 6; @@ -29,6 +30,7 @@ static void token_info_set_digits_from_int(TokenInfo* token_info, uint8_t digits case 8: token_info->digits = TOTP_8_DIGITS; break; + default: break; } } @@ -40,6 +42,7 @@ static char* token_info_get_algo_as_cstr(const TokenInfo* token_info) { return TOTP_CONFIG_TOKEN_ALGO_SHA256_NAME; case SHA512: return TOTP_CONFIG_TOKEN_ALGO_SHA512_NAME; + default: break; } return NULL; diff --git a/services/hmac/sha1.c b/services/hmac/sha1.c index 578fb826bb3..51bfec38afe 100644 --- a/services/hmac/sha1.c +++ b/services/hmac/sha1.c @@ -22,9 +22,6 @@ */ /* Specification. */ -#if HAVE_OPENSSL_SHA1 -#define GL_OPENSSL_INLINE _GL_EXTERN_INLINE -#endif #include "sha1.h" #include @@ -37,8 +34,6 @@ #define SWAP(n) swap_uint32(n) #endif -#if !HAVE_OPENSSL_SHA1 - /* This array contains the bytes used to pad the buffer to the next 64-byte boundary. (RFC 1321, 3.1: Step 1) */ static const unsigned char fillbuf[64] = {0x80, 0 /* , 0, 0, ... */}; @@ -266,8 +261,6 @@ void sha1_process_block(const void* buffer, size_t len, struct sha1_ctx* ctx) { } } -#endif - /* * Hey Emacs! * Local Variables: diff --git a/services/hmac/sha1.h b/services/hmac/sha1.h index d602d26fd6a..e9eb7712a72 100644 --- a/services/hmac/sha1.h +++ b/services/hmac/sha1.h @@ -21,23 +21,12 @@ #include #include -#if HAVE_OPENSSL_SHA1 -#ifndef OPENSSL_API_COMPAT -#define OPENSSL_API_COMPAT 0x10101000L /* FIXME: Use OpenSSL 1.1+ API. */ -#endif -#include -#endif - #ifdef __cplusplus extern "C" { #endif #define SHA1_DIGEST_SIZE 20 -#if HAVE_OPENSSL_SHA1 -#define GL_OPENSSL_NAME 1 -#include "gl_openssl.h" -#else /* Structure to save state of computation between the single steps. */ struct sha1_ctx { uint32_t A; @@ -83,16 +72,6 @@ extern void* sha1_read_ctx(const struct sha1_ctx* ctx, void* restrict resbuf); digest. */ extern void* sha1_buffer(const char* buffer, size_t len, void* restrict resblock); -#endif - -/* Compute SHA1 message digest for bytes read from STREAM. - STREAM is an open file stream. Regular files are handled more efficiently. - The contents of STREAM from its current position to its end will be read. - The case that the last operation on STREAM was an 'ungetc' is not supported. - The resulting message digest number will be written into the 20 bytes - beginning at RESBLOCK. */ -extern int sha1_stream(FILE* stream, void* resblock); - #ifdef __cplusplus } #endif diff --git a/services/hmac/sha256.c b/services/hmac/sha256.c index 02409f0d4ad..bf24e01e86d 100644 --- a/services/hmac/sha256.c +++ b/services/hmac/sha256.c @@ -1,4 +1,4 @@ -/* sha256.c - Functions to compute SHA256 and SHA224 message digest of files or +/* sha256.c - Functions to compute SHA256 message digest of files or memory blocks according to the NIST specification FIPS-180-2. Copyright (C) 2005-2006, 2008-2022 Free Software Foundation, Inc. @@ -21,9 +21,6 @@ */ /* Specification. */ -#if HAVE_OPENSSL_SHA256 -#define GL_OPENSSL_INLINE _GL_EXTERN_INLINE -#endif #include "sha256.h" #include @@ -36,8 +33,6 @@ #define SWAP(n) swap_uint32(n) #endif -#if !HAVE_OPENSSL_SHA256 - /* This array contains the bytes used to pad the buffer to the next 64-byte boundary. */ static const unsigned char fillbuf[64] = {0x80, 0 /* , 0, 0, ... */}; @@ -61,20 +56,6 @@ void sha256_init_ctx(struct sha256_ctx* ctx) { ctx->buflen = 0; } -void sha224_init_ctx(struct sha256_ctx* ctx) { - ctx->state[0] = 0xc1059ed8UL; - ctx->state[1] = 0x367cd507UL; - ctx->state[2] = 0x3070dd17UL; - ctx->state[3] = 0xf70e5939UL; - ctx->state[4] = 0xffc00b31UL; - ctx->state[5] = 0x68581511UL; - ctx->state[6] = 0x64f98fa7UL; - ctx->state[7] = 0xbefa4fa4UL; - - ctx->total[0] = ctx->total[1] = 0; - ctx->buflen = 0; -} - /* Copy the value from v into the memory location pointed to by *CP, If your architecture allows unaligned access, this is equivalent to * (__typeof__ (v) *) cp = v */ @@ -93,15 +74,6 @@ void* sha256_read_ctx(const struct sha256_ctx* ctx, void* resbuf) { return resbuf; } -void* sha224_read_ctx(const struct sha256_ctx* ctx, void* resbuf) { - int i; - char* r = resbuf; - - for(i = 0; i < 7; i++) set_uint32(r + i * sizeof ctx->state[0], SWAP(ctx->state[i])); - - return resbuf; -} - /* Process the remaining bytes in the internal buffer and the usual prolog according to the standard and write the result to RESBUF. */ static void sha256_conclude_ctx(struct sha256_ctx* ctx) { @@ -130,11 +102,6 @@ void* sha256_finish_ctx(struct sha256_ctx* ctx, void* resbuf) { return sha256_read_ctx(ctx, resbuf); } -void* sha224_finish_ctx(struct sha256_ctx* ctx, void* resbuf) { - sha256_conclude_ctx(ctx); - return sha224_read_ctx(ctx, resbuf); -} - /* Compute SHA256 message digest for LEN bytes beginning at BUFFER. The result is always in little endian byte order, so that a byte-wise output yields to the wanted ASCII representation of the message @@ -152,19 +119,6 @@ void* sha256_buffer(const char* buffer, size_t len, void* resblock) { return sha256_finish_ctx(&ctx, resblock); } -void* sha224_buffer(const char* buffer, size_t len, void* resblock) { - struct sha256_ctx ctx; - - /* Initialize the computation context. */ - sha224_init_ctx(&ctx); - - /* Process whole buffer but last len % 64 bytes. */ - sha256_process_bytes(buffer, len, &ctx); - - /* Put result in desired memory area. */ - return sha224_finish_ctx(&ctx, resblock); -} - void sha256_process_bytes(const void* buffer, size_t len, struct sha256_ctx* ctx) { /* When we already have some bits in our internal buffer concatenate both inputs first. */ @@ -324,8 +278,6 @@ void sha256_process_block(const void* buffer, size_t len, struct sha256_ctx* ctx } } -#endif - /* * Hey Emacs! * Local Variables: diff --git a/services/hmac/sha256.h b/services/hmac/sha256.h index 2f99d142865..964f2eb9788 100644 --- a/services/hmac/sha256.h +++ b/services/hmac/sha256.h @@ -1,4 +1,4 @@ -/* Declarations of functions and data types used for SHA256 and SHA224 sum +/* Declarations of functions and data types used for SHA256 sum library functions. Copyright (C) 2005-2006, 2008-2022 Free Software Foundation, Inc. @@ -20,26 +20,12 @@ #include #include -#if HAVE_OPENSSL_SHA256 -#ifndef OPENSSL_API_COMPAT -#define OPENSSL_API_COMPAT 0x10101000L /* FIXME: Use OpenSSL 1.1+ API. */ -#endif -#include -#endif - #ifdef __cplusplus extern "C" { #endif -enum { SHA224_DIGEST_SIZE = 224 / 8 }; enum { SHA256_DIGEST_SIZE = 256 / 8 }; -#if HAVE_OPENSSL_SHA256 -#define GL_OPENSSL_NAME 224 -#include "gl_openssl.h" -#define GL_OPENSSL_NAME 256 -#include "gl_openssl.h" -#else /* Structure to save state of computation between the single steps. */ struct sha256_ctx { uint32_t state[8]; @@ -51,7 +37,6 @@ struct sha256_ctx { /* Initialize structure containing state of computation. */ extern void sha256_init_ctx(struct sha256_ctx* ctx); -extern void sha224_init_ctx(struct sha256_ctx* ctx); /* Starting with the result of former calls of this function (or the initialization function update the context for the next LEN bytes @@ -70,31 +55,17 @@ extern void sha256_process_bytes(const void* buffer, size_t len, struct sha256_c endian byte order, so that a byte-wise output yields to the wanted ASCII representation of the message digest. */ extern void* sha256_finish_ctx(struct sha256_ctx* ctx, void* restrict resbuf); -extern void* sha224_finish_ctx(struct sha256_ctx* ctx, void* restrict resbuf); /* Put result from CTX in first 32 (28) bytes following RESBUF. The result is always in little endian byte order, so that a byte-wise output yields to the wanted ASCII representation of the message digest. */ extern void* sha256_read_ctx(const struct sha256_ctx* ctx, void* restrict resbuf); -extern void* sha224_read_ctx(const struct sha256_ctx* ctx, void* restrict resbuf); -/* Compute SHA256 (SHA224) message digest for LEN bytes beginning at BUFFER. +/* Compute SHA256 message digest for LEN bytes beginning at BUFFER. The result is always in little endian byte order, so that a byte-wise output yields to the wanted ASCII representation of the message digest. */ extern void* sha256_buffer(const char* buffer, size_t len, void* restrict resblock); -extern void* sha224_buffer(const char* buffer, size_t len, void* restrict resblock); - -#endif - -/* Compute SHA256 (SHA224) message digest for bytes read from STREAM. - STREAM is an open file stream. Regular files are handled more efficiently. - The contents of STREAM from its current position to its end will be read. - The case that the last operation on STREAM was an 'ungetc' is not supported. - The resulting message digest number will be written into the 32 (28) bytes - beginning at RESBLOCK. */ -extern int sha256_stream(FILE* stream, void* resblock); -extern int sha224_stream(FILE* stream, void* resblock); #ifdef __cplusplus } diff --git a/services/hmac/sha512.c b/services/hmac/sha512.c index 8b17d271774..6daa9ea8968 100644 --- a/services/hmac/sha512.c +++ b/services/hmac/sha512.c @@ -1,4 +1,4 @@ -/* sha512.c - Functions to compute SHA512 and SHA384 message digest of files or +/* sha512.c - Functions to compute SHA512 message digest of files or memory blocks according to the NIST specification FIPS-180-2. Copyright (C) 2005-2006, 2008-2022 Free Software Foundation, Inc. @@ -21,9 +21,6 @@ */ /* Specification. */ -#if HAVE_OPENSSL_SHA512 -#define GL_OPENSSL_INLINE _GL_EXTERN_INLINE -#endif #include "sha512.h" #include @@ -36,8 +33,6 @@ #define SWAP(n) swap_uint64(n) #endif -#if !HAVE_OPENSSL_SHA512 - /* This array contains the bytes used to pad the buffer to the next 128-byte boundary. */ static const unsigned char fillbuf[128] = {0x80, 0 /* , 0, 0, ... */}; @@ -61,20 +56,6 @@ void sha512_init_ctx(struct sha512_ctx* ctx) { ctx->buflen = 0; } -void sha384_init_ctx(struct sha512_ctx* ctx) { - ctx->state[0] = u64hilo(0xcbbb9d5d, 0xc1059ed8); - ctx->state[1] = u64hilo(0x629a292a, 0x367cd507); - ctx->state[2] = u64hilo(0x9159015a, 0x3070dd17); - ctx->state[3] = u64hilo(0x152fecd8, 0xf70e5939); - ctx->state[4] = u64hilo(0x67332667, 0xffc00b31); - ctx->state[5] = u64hilo(0x8eb44a87, 0x68581511); - ctx->state[6] = u64hilo(0xdb0c2e0d, 0x64f98fa7); - ctx->state[7] = u64hilo(0x47b5481d, 0xbefa4fa4); - - ctx->total[0] = ctx->total[1] = u64lo(0); - ctx->buflen = 0; -} - /* Copy the value from V into the memory location pointed to by *CP, If your architecture allows unaligned access, this is equivalent to * (__typeof__ (v) *) cp = v */ @@ -93,15 +74,6 @@ void* sha512_read_ctx(const struct sha512_ctx* ctx, void* resbuf) { return resbuf; } -void* sha384_read_ctx(const struct sha512_ctx* ctx, void* resbuf) { - int i; - char* r = resbuf; - - for(i = 0; i < 6; i++) set_uint64(r + i * sizeof ctx->state[0], SWAP(ctx->state[i])); - - return resbuf; -} - /* Process the remaining bytes in the internal buffer and the usual prolog according to the standard and write the result to RESBUF. */ static void sha512_conclude_ctx(struct sha512_ctx* ctx) { @@ -132,11 +104,6 @@ void* sha512_finish_ctx(struct sha512_ctx* ctx, void* resbuf) { return sha512_read_ctx(ctx, resbuf); } -void* sha384_finish_ctx(struct sha512_ctx* ctx, void* resbuf) { - sha512_conclude_ctx(ctx); - return sha384_read_ctx(ctx, resbuf); -} - /* Compute SHA512 message digest for LEN bytes beginning at BUFFER. The result is always in little endian byte order, so that a byte-wise output yields to the wanted ASCII representation of the message @@ -154,19 +121,6 @@ void* sha512_buffer(const char* buffer, size_t len, void* resblock) { return sha512_finish_ctx(&ctx, resblock); } -void* sha384_buffer(const char* buffer, size_t len, void* resblock) { - struct sha512_ctx ctx; - - /* Initialize the computation context. */ - sha384_init_ctx(&ctx); - - /* Process whole buffer but last len % 128 bytes. */ - sha512_process_bytes(buffer, len, &ctx); - - /* Put result in desired memory area. */ - return sha384_finish_ctx(&ctx, resblock); -} - void sha512_process_bytes(const void* buffer, size_t len, struct sha512_ctx* ctx) { /* When we already have some bits in our internal buffer concatenate both inputs first. */ @@ -353,8 +307,6 @@ void sha512_process_block(const void* buffer, size_t len, struct sha512_ctx* ctx } } -#endif - /* * Hey Emacs! * Local Variables: diff --git a/services/hmac/sha512.h b/services/hmac/sha512.h index 6489fc3cbe5..38590829e8e 100644 --- a/services/hmac/sha512.h +++ b/services/hmac/sha512.h @@ -20,26 +20,12 @@ #include #include "u64.h" -#if HAVE_OPENSSL_SHA512 -#ifndef OPENSSL_API_COMPAT -#define OPENSSL_API_COMPAT 0x10101000L /* FIXME: Use OpenSSL 1.1+ API. */ -#endif -#include -#endif - #ifdef __cplusplus extern "C" { #endif -enum { SHA384_DIGEST_SIZE = 384 / 8 }; enum { SHA512_DIGEST_SIZE = 512 / 8 }; -#if HAVE_OPENSSL_SHA512 -#define GL_OPENSSL_NAME 384 -#include "gl_openssl.h" -#define GL_OPENSSL_NAME 512 -#include "gl_openssl.h" -#else /* Structure to save state of computation between the single steps. */ struct sha512_ctx { u64 state[8]; @@ -51,7 +37,6 @@ struct sha512_ctx { /* Initialize structure containing state of computation. */ extern void sha512_init_ctx(struct sha512_ctx* ctx); -extern void sha384_init_ctx(struct sha512_ctx* ctx); /* Starting with the result of former calls of this function (or the initialization function update the context for the next LEN bytes @@ -70,7 +55,6 @@ extern void sha512_process_bytes(const void* buffer, size_t len, struct sha512_c endian byte order, so that a byte-wise output yields to the wanted ASCII representation of the message digest. */ extern void* sha512_finish_ctx(struct sha512_ctx* ctx, void* restrict resbuf); -extern void* sha384_finish_ctx(struct sha512_ctx* ctx, void* restrict resbuf); /* Put result from CTX in first 64 (48) bytes following RESBUF. The result is always in little endian byte order, so that a byte-wise output yields @@ -79,25 +63,12 @@ extern void* sha384_finish_ctx(struct sha512_ctx* ctx, void* restrict resbuf); IMPORTANT: On some systems it is required that RESBUF is correctly aligned for a 32 bits value. */ extern void* sha512_read_ctx(const struct sha512_ctx* ctx, void* restrict resbuf); -extern void* sha384_read_ctx(const struct sha512_ctx* ctx, void* restrict resbuf); -/* Compute SHA512 (SHA384) message digest for LEN bytes beginning at BUFFER. +/* Compute SHA512 message digest for LEN bytes beginning at BUFFER. The result is always in little endian byte order, so that a byte-wise output yields to the wanted ASCII representation of the message digest. */ extern void* sha512_buffer(const char* buffer, size_t len, void* restrict resblock); -extern void* sha384_buffer(const char* buffer, size_t len, void* restrict resblock); - -#endif - -/* Compute SHA512 (SHA384) message digest for bytes read from STREAM. - STREAM is an open file stream. Regular files are handled more efficiently. - The contents of STREAM from its current position to its end will be read. - The case that the last operation on STREAM was an 'ungetc' is not supported. - The resulting message digest number will be written into the 64 (48) bytes - beginning at RESBLOCK. */ -extern int sha512_stream(FILE* stream, void* resblock); -extern int sha384_stream(FILE* stream, void* resblock); #ifdef __cplusplus } diff --git a/services/hmac/u64.h b/services/hmac/u64.h index af0bb067bf3..91e42e6c991 100644 --- a/services/hmac/u64.h +++ b/services/hmac/u64.h @@ -26,7 +26,7 @@ #endif /* Return X rotated left by N bits, where 0 < N < 64. */ -#define u64rol(x, n) u64or(u64shl(x, n), u64shr(x, 64 - n)) +#define u64rol(x, n) u64or(u64shl(x, n), u64shr(x, 64 - (n))) /* Native implementations are trivial. See below for comments on what these operations do. */ diff --git a/types/token_info.c b/types/token_info.c index 6c672ab00a8..dabd5e13e97 100644 --- a/types/token_info.c +++ b/types/token_info.c @@ -51,6 +51,7 @@ uint8_t token_info_get_digits_count(const TokenInfo* token_info) { return 6; case TOTP_8_DIGITS: return 8; + default: break; } return 6;