Alexander Kopachov 3 anni fa
parent
commit
44879ecc1d

+ 2 - 0
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;
             break;
         }
         }
+        default: break;
         }
         }
         break;
         break;
     case InputKeyBack:
     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);
             totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
         }
         }
         break;
         break;
+    default: break;
     }
     }
 
 
     return true;
     return true;

+ 1 - 0
scenes/app_settings/totp_app_settings.c

@@ -163,6 +163,7 @@ bool totp_scene_app_settings_handle_event(
         }
         }
         break;
         break;
     }
     }
+    default: break;
     }
     }
 
 
     return true;
     return true;

+ 2 - 1
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_RADIUS = 3;
     const uint8_t PIN_ASTERISK_STEP = (PIN_ASTERISK_RADIUS << 1) + 2;
     const uint8_t PIN_ASTERISK_STEP = (PIN_ASTERISK_RADIUS << 1) + 2;
     if(scene_state->code_length > 0) {
     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++) {
         for(uint8_t i = 0; i < scene_state->code_length; i++) {
             canvas_draw_disc(
             canvas_draw_disc(
                 canvas,
                 canvas,
@@ -152,6 +152,7 @@ bool totp_scene_authenticate_handle_event(
             scene_state->code_length--;
             scene_state->code_length--;
         }
         }
         break;
         break;
+    default: break;
     }
     }
 
 
     return true;
     return true;

+ 2 - 0
scenes/generate_token/totp_scene_generate_token.c

@@ -73,6 +73,7 @@ TOTP_ALGO get_totp_algo_impl(TokenHashAlgo algo) {
         return TOTP_ALGO_SHA256;
         return TOTP_ALGO_SHA256;
     case SHA512:
     case SHA512:
         return TOTP_ALGO_SHA512;
         return TOTP_ALGO_SHA512;
+    default: break;
     }
     }
 
 
     return NULL;
     return NULL;
@@ -299,6 +300,7 @@ bool totp_scene_generate_token_handle_event(
         break;
         break;
     case InputKeyBack:
     case InputKeyBack:
         break;
         break;
+    default: break;
     }
     }
 
 
     return true;
     return true;

+ 4 - 0
scenes/scene_director.c

@@ -30,6 +30,7 @@ void totp_scene_director_activate_scene(
         break;
         break;
     case TotpSceneNone:
     case TotpSceneNone:
         break;
         break;
+    default: break;
     }
     }
 
 
     plugin_state->current_scene = scene;
     plugin_state->current_scene = scene;
@@ -55,6 +56,7 @@ void totp_scene_director_deactivate_active_scene(PluginState* const plugin_state
         break;
         break;
     case TotpSceneNone:
     case TotpSceneNone:
         break;
         break;
+    default: break;
     }
     }
 }
 }
 
 
@@ -85,6 +87,7 @@ void totp_scene_director_render(Canvas* const canvas, PluginState* const plugin_
         break;
         break;
     case TotpSceneNone:
     case TotpSceneNone:
         break;
         break;
+    default: break;
     }
     }
 }
 }
 
 
@@ -116,6 +119,7 @@ bool totp_scene_director_handle_event(PluginEvent* const event, PluginState* con
         break;
         break;
     case TotpSceneNone:
     case TotpSceneNone:
         break;
         break;
+    default: break;
     }
     }
 
 
     return processing;
     return processing;

+ 2 - 0
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;
             break;
         }
         }
+        default: break;
         }
         }
         break;
         break;
     case InputKeyBack: {
     case InputKeyBack: {
@@ -184,6 +185,7 @@ bool totp_scene_token_menu_handle_event(const PluginEvent* const event, PluginSt
         }
         }
         break;
         break;
     }
     }
+    default: break;
     }
     }
 
 
     return true;
     return true;

+ 1 - 0
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':
     case '8':
         token_info->digits = TOTP_8_DIGITS;
         token_info->digits = TOTP_8_DIGITS;
         return true;
         return true;
+    default: break;
     }
     }
 
 
     return false;
     return false;

+ 2 - 0
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;
         return TOTP_CONFIG_TOKEN_ALGO_SHA256_NAME;
     case SHA512:
     case SHA512:
         return TOTP_CONFIG_TOKEN_ALGO_SHA512_NAME;
         return TOTP_CONFIG_TOKEN_ALGO_SHA512_NAME;
+    default: break;
     }
     }
 
 
     return "UNKNOWN";
     return "UNKNOWN";
@@ -24,6 +25,7 @@ static uint8_t get_digits_as_int(TokenDigitsCount digits) {
         return 6;
         return 6;
     case TOTP_8_DIGITS:
     case TOTP_8_DIGITS:
         return 8;
         return 8;
+    default: break;
     }
     }
 
 
     return 6;
     return 6;

+ 3 - 0
services/config/config.c

@@ -16,6 +16,7 @@ static uint8_t token_info_get_digits_as_int(const TokenInfo* token_info) {
         return 6;
         return 6;
     case TOTP_8_DIGITS:
     case TOTP_8_DIGITS:
         return 8;
         return 8;
+    default: break;
     }
     }
 
 
     return 6;
     return 6;
@@ -29,6 +30,7 @@ static void token_info_set_digits_from_int(TokenInfo* token_info, uint8_t digits
     case 8:
     case 8:
         token_info->digits = TOTP_8_DIGITS;
         token_info->digits = TOTP_8_DIGITS;
         break;
         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;
         return TOTP_CONFIG_TOKEN_ALGO_SHA256_NAME;
     case SHA512:
     case SHA512:
         return TOTP_CONFIG_TOKEN_ALGO_SHA512_NAME;
         return TOTP_CONFIG_TOKEN_ALGO_SHA512_NAME;
+    default: break;
     }
     }
 
 
     return NULL;
     return NULL;

+ 0 - 7
services/hmac/sha1.c

@@ -22,9 +22,6 @@
 */
 */
 
 
 /* Specification.  */
 /* Specification.  */
-#if HAVE_OPENSSL_SHA1
-#define GL_OPENSSL_INLINE _GL_EXTERN_INLINE
-#endif
 #include "sha1.h"
 #include "sha1.h"
 
 
 #include <stdint.h>
 #include <stdint.h>
@@ -37,8 +34,6 @@
 #define SWAP(n) swap_uint32(n)
 #define SWAP(n) swap_uint32(n)
 #endif
 #endif
 
 
-#if !HAVE_OPENSSL_SHA1
-
 /* This array contains the bytes used to pad the buffer to the next
 /* This array contains the bytes used to pad the buffer to the next
    64-byte boundary.  (RFC 1321, 3.1: Step 1)  */
    64-byte boundary.  (RFC 1321, 3.1: Step 1)  */
 static const unsigned char fillbuf[64] = {0x80, 0 /* , 0, 0, ...  */};
 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!
  * Hey Emacs!
  * Local Variables:
  * Local Variables:

+ 0 - 21
services/hmac/sha1.h

@@ -21,23 +21,12 @@
 #include <stdio.h>
 #include <stdio.h>
 #include <stdint.h>
 #include <stdint.h>
 
 
-#if HAVE_OPENSSL_SHA1
-#ifndef OPENSSL_API_COMPAT
-#define OPENSSL_API_COMPAT 0x10101000L /* FIXME: Use OpenSSL 1.1+ API.  */
-#endif
-#include <openssl/sha.h>
-#endif
-
 #ifdef __cplusplus
 #ifdef __cplusplus
 extern "C" {
 extern "C" {
 #endif
 #endif
 
 
 #define SHA1_DIGEST_SIZE 20
 #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.  */
 /* Structure to save state of computation between the single steps.  */
 struct sha1_ctx {
 struct sha1_ctx {
     uint32_t A;
     uint32_t A;
@@ -83,16 +72,6 @@ extern void* sha1_read_ctx(const struct sha1_ctx* ctx, void* restrict resbuf);
    digest.  */
    digest.  */
 extern void* sha1_buffer(const char* buffer, size_t len, void* restrict resblock);
 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
 #ifdef __cplusplus
 }
 }
 #endif
 #endif

+ 1 - 49
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.
    memory blocks according to the NIST specification FIPS-180-2.
 
 
    Copyright (C) 2005-2006, 2008-2022 Free Software Foundation, Inc.
    Copyright (C) 2005-2006, 2008-2022 Free Software Foundation, Inc.
@@ -21,9 +21,6 @@
 */
 */
 
 
 /* Specification.  */
 /* Specification.  */
-#if HAVE_OPENSSL_SHA256
-#define GL_OPENSSL_INLINE _GL_EXTERN_INLINE
-#endif
 #include "sha256.h"
 #include "sha256.h"
 
 
 #include <stdint.h>
 #include <stdint.h>
@@ -36,8 +33,6 @@
 #define SWAP(n) swap_uint32(n)
 #define SWAP(n) swap_uint32(n)
 #endif
 #endif
 
 
-#if !HAVE_OPENSSL_SHA256
-
 /* This array contains the bytes used to pad the buffer to the next
 /* This array contains the bytes used to pad the buffer to the next
    64-byte boundary.  */
    64-byte boundary.  */
 static const unsigned char fillbuf[64] = {0x80, 0 /* , 0, 0, ...  */};
 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;
     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,
 /* Copy the value from v into the memory location pointed to by *CP,
    If your architecture allows unaligned access, this is equivalent to
    If your architecture allows unaligned access, this is equivalent to
    * (__typeof__ (v) *) cp = v  */
    * (__typeof__ (v) *) cp = v  */
@@ -93,15 +74,6 @@ void* sha256_read_ctx(const struct sha256_ctx* ctx, void* resbuf) {
     return 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
 /* Process the remaining bytes in the internal buffer and the usual
    prolog according to the standard and write the result to RESBUF.  */
    prolog according to the standard and write the result to RESBUF.  */
 static void sha256_conclude_ctx(struct sha256_ctx* ctx) {
 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);
     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
 /* Compute SHA256 message digest for LEN bytes beginning at BUFFER.  The
    result is always in little endian byte order, so that a byte-wise
    result is always in little endian byte order, so that a byte-wise
    output yields to the wanted ASCII representation of the message
    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);
     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) {
 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
     /* When we already have some bits in our internal buffer concatenate
      both inputs first.  */
      both inputs first.  */
@@ -324,8 +278,6 @@ void sha256_process_block(const void* buffer, size_t len, struct sha256_ctx* ctx
     }
     }
 }
 }
 
 
-#endif
-
 /*
 /*
  * Hey Emacs!
  * Hey Emacs!
  * Local Variables:
  * Local Variables:

+ 2 - 31
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.
    library functions.
    Copyright (C) 2005-2006, 2008-2022 Free Software Foundation, Inc.
    Copyright (C) 2005-2006, 2008-2022 Free Software Foundation, Inc.
 
 
@@ -20,26 +20,12 @@
 #include <stdio.h>
 #include <stdio.h>
 #include <stdint.h>
 #include <stdint.h>
 
 
-#if HAVE_OPENSSL_SHA256
-#ifndef OPENSSL_API_COMPAT
-#define OPENSSL_API_COMPAT 0x10101000L /* FIXME: Use OpenSSL 1.1+ API.  */
-#endif
-#include <openssl/sha.h>
-#endif
-
 #ifdef __cplusplus
 #ifdef __cplusplus
 extern "C" {
 extern "C" {
 #endif
 #endif
 
 
-enum { SHA224_DIGEST_SIZE = 224 / 8 };
 enum { SHA256_DIGEST_SIZE = 256 / 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.  */
 /* Structure to save state of computation between the single steps.  */
 struct sha256_ctx {
 struct sha256_ctx {
     uint32_t state[8];
     uint32_t state[8];
@@ -51,7 +37,6 @@ struct sha256_ctx {
 
 
 /* Initialize structure containing state of computation. */
 /* Initialize structure containing state of computation. */
 extern void sha256_init_ctx(struct sha256_ctx* ctx);
 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
 /* Starting with the result of former calls of this function (or the
    initialization function update the context for the next LEN bytes
    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
    endian byte order, so that a byte-wise output yields to the wanted
    ASCII representation of the message digest.  */
    ASCII representation of the message digest.  */
 extern void* sha256_finish_ctx(struct sha256_ctx* ctx, void* restrict resbuf);
 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
 /* 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
    always in little endian byte order, so that a byte-wise output yields
    to the wanted ASCII representation of the message digest.  */
    to the wanted ASCII representation of the message digest.  */
 extern void* sha256_read_ctx(const struct sha256_ctx* ctx, void* restrict resbuf);
 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
    The result is always in little endian byte order, so that a byte-wise
    output yields to the wanted ASCII representation of the message
    output yields to the wanted ASCII representation of the message
    digest.  */
    digest.  */
 extern void* sha256_buffer(const char* buffer, size_t len, void* restrict resblock);
 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
 #ifdef __cplusplus
 }
 }

+ 1 - 49
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.
    memory blocks according to the NIST specification FIPS-180-2.
 
 
    Copyright (C) 2005-2006, 2008-2022 Free Software Foundation, Inc.
    Copyright (C) 2005-2006, 2008-2022 Free Software Foundation, Inc.
@@ -21,9 +21,6 @@
 */
 */
 
 
 /* Specification.  */
 /* Specification.  */
-#if HAVE_OPENSSL_SHA512
-#define GL_OPENSSL_INLINE _GL_EXTERN_INLINE
-#endif
 #include "sha512.h"
 #include "sha512.h"
 
 
 #include <stdint.h>
 #include <stdint.h>
@@ -36,8 +33,6 @@
 #define SWAP(n) swap_uint64(n)
 #define SWAP(n) swap_uint64(n)
 #endif
 #endif
 
 
-#if !HAVE_OPENSSL_SHA512
-
 /* This array contains the bytes used to pad the buffer to the next
 /* This array contains the bytes used to pad the buffer to the next
    128-byte boundary.  */
    128-byte boundary.  */
 static const unsigned char fillbuf[128] = {0x80, 0 /* , 0, 0, ...  */};
 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;
     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,
 /* Copy the value from V into the memory location pointed to by *CP,
    If your architecture allows unaligned access, this is equivalent to
    If your architecture allows unaligned access, this is equivalent to
    * (__typeof__ (v) *) cp = v  */
    * (__typeof__ (v) *) cp = v  */
@@ -93,15 +74,6 @@ void* sha512_read_ctx(const struct sha512_ctx* ctx, void* resbuf) {
     return 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
 /* Process the remaining bytes in the internal buffer and the usual
    prolog according to the standard and write the result to RESBUF.  */
    prolog according to the standard and write the result to RESBUF.  */
 static void sha512_conclude_ctx(struct sha512_ctx* ctx) {
 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);
     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
 /* Compute SHA512 message digest for LEN bytes beginning at BUFFER.  The
    result is always in little endian byte order, so that a byte-wise
    result is always in little endian byte order, so that a byte-wise
    output yields to the wanted ASCII representation of the message
    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);
     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) {
 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
     /* When we already have some bits in our internal buffer concatenate
      both inputs first.  */
      both inputs first.  */
@@ -353,8 +307,6 @@ void sha512_process_block(const void* buffer, size_t len, struct sha512_ctx* ctx
     }
     }
 }
 }
 
 
-#endif
-
 /*
 /*
  * Hey Emacs!
  * Hey Emacs!
  * Local Variables:
  * Local Variables:

+ 1 - 30
services/hmac/sha512.h

@@ -20,26 +20,12 @@
 #include <stdio.h>
 #include <stdio.h>
 #include "u64.h"
 #include "u64.h"
 
 
-#if HAVE_OPENSSL_SHA512
-#ifndef OPENSSL_API_COMPAT
-#define OPENSSL_API_COMPAT 0x10101000L /* FIXME: Use OpenSSL 1.1+ API.  */
-#endif
-#include <openssl/sha.h>
-#endif
-
 #ifdef __cplusplus
 #ifdef __cplusplus
 extern "C" {
 extern "C" {
 #endif
 #endif
 
 
-enum { SHA384_DIGEST_SIZE = 384 / 8 };
 enum { SHA512_DIGEST_SIZE = 512 / 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.  */
 /* Structure to save state of computation between the single steps.  */
 struct sha512_ctx {
 struct sha512_ctx {
     u64 state[8];
     u64 state[8];
@@ -51,7 +37,6 @@ struct sha512_ctx {
 
 
 /* Initialize structure containing state of computation. */
 /* Initialize structure containing state of computation. */
 extern void sha512_init_ctx(struct sha512_ctx* ctx);
 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
 /* Starting with the result of former calls of this function (or the
    initialization function update the context for the next LEN bytes
    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
    endian byte order, so that a byte-wise output yields to the wanted
    ASCII representation of the message digest.  */
    ASCII representation of the message digest.  */
 extern void* sha512_finish_ctx(struct sha512_ctx* ctx, void* restrict resbuf);
 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
 /* 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
    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
    IMPORTANT: On some systems it is required that RESBUF is correctly
    aligned for a 32 bits value.  */
    aligned for a 32 bits value.  */
 extern void* sha512_read_ctx(const struct sha512_ctx* ctx, void* restrict resbuf);
 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
    The result is always in little endian byte order, so that a byte-wise
    output yields to the wanted ASCII representation of the message
    output yields to the wanted ASCII representation of the message
    digest.  */
    digest.  */
 extern void* sha512_buffer(const char* buffer, size_t len, void* restrict resblock);
 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
 #ifdef __cplusplus
 }
 }

+ 1 - 1
services/hmac/u64.h

@@ -26,7 +26,7 @@
 #endif
 #endif
 
 
 /* Return X rotated left by N bits, where 0 < N < 64.  */
 /* 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
 /* Native implementations are trivial.  See below for comments on what
    these operations do.  */
    these operations do.  */

+ 1 - 0
types/token_info.c

@@ -51,6 +51,7 @@ uint8_t token_info_get_digits_count(const TokenInfo* token_info) {
         return 6;
         return 6;
     case TOTP_8_DIGITS:
     case TOTP_8_DIGITS:
         return 8;
         return 8;
+    default: break;
     }
     }
 
 
     return 6;
     return 6;