From 9a2ac1eeb5b08396ac397b9c124dab4167b17d98 Mon Sep 17 00:00:00 2001 From: RogueMaster Date: Wed, 12 Oct 2022 00:51:55 -0400 Subject: [PATCH] totp fix --- .../plugins/totp/services/hmac/hmac_common.h | 64 ------------------- .../plugins/totp/services/hmac/hmac_sha1.c | 24 ------- .../plugins/totp/services/hmac/hmac_sha1.h | 11 ---- .../plugins/totp/services/hmac/hmac_sha256.c | 23 ------- .../plugins/totp/services/hmac/hmac_sha256.h | 11 ---- .../plugins/totp/services/hmac/hmac_sha512.c | 24 ------- .../plugins/totp/services/hmac/hmac_sha512.h | 11 ---- 7 files changed, 168 deletions(-) delete mode 100644 applications/plugins/totp/services/hmac/hmac_common.h delete mode 100644 applications/plugins/totp/services/hmac/hmac_sha1.c delete mode 100644 applications/plugins/totp/services/hmac/hmac_sha1.h delete mode 100644 applications/plugins/totp/services/hmac/hmac_sha256.c delete mode 100644 applications/plugins/totp/services/hmac/hmac_sha256.h delete mode 100644 applications/plugins/totp/services/hmac/hmac_sha512.c delete mode 100644 applications/plugins/totp/services/hmac/hmac_sha512.h diff --git a/applications/plugins/totp/services/hmac/hmac_common.h b/applications/plugins/totp/services/hmac/hmac_common.h deleted file mode 100644 index 9c5b5828f..000000000 --- a/applications/plugins/totp/services/hmac/hmac_common.h +++ /dev/null @@ -1,64 +0,0 @@ -#include -#include "sha256.h" -#include "memxor.h" - -#define IPAD 0x36 -#define OPAD 0x5c - -/* Concatenate two preprocessor tokens. */ -#define _GLHMAC_CONCAT_(prefix, suffix) prefix##suffix -#define _GLHMAC_CONCAT(prefix, suffix) _GLHMAC_CONCAT_(prefix, suffix) - -#if GL_HMAC_NAME == 5 -#define HMAC_ALG md5 -#else -#define HMAC_ALG _GLHMAC_CONCAT(sha, GL_HMAC_NAME) -#endif - -#define GL_HMAC_CTX _GLHMAC_CONCAT(HMAC_ALG, _ctx) -#define GL_HMAC_FN _GLHMAC_CONCAT(hmac_, HMAC_ALG) -#define GL_HMAC_FN_INIT _GLHMAC_CONCAT(HMAC_ALG, _init_ctx) -#define GL_HMAC_FN_BLOC _GLHMAC_CONCAT(HMAC_ALG, _process_block) -#define GL_HMAC_FN_PROC _GLHMAC_CONCAT(HMAC_ALG, _process_bytes) -#define GL_HMAC_FN_FINI _GLHMAC_CONCAT(HMAC_ALG, _finish_ctx) - -static void - hmac_hash(const void* key, size_t keylen, const void* in, size_t inlen, int pad, void* resbuf) { - struct GL_HMAC_CTX hmac_ctx; - char block[GL_HMAC_BLOCKSIZE]; - - memset(block, pad, sizeof block); - memxor(block, key, keylen); - - GL_HMAC_FN_INIT(&hmac_ctx); - GL_HMAC_FN_BLOC(block, sizeof block, &hmac_ctx); - GL_HMAC_FN_PROC(in, inlen, &hmac_ctx); - GL_HMAC_FN_FINI(&hmac_ctx, resbuf); -} - -int GL_HMAC_FN(const void* key, size_t keylen, const void* in, size_t inlen, void* resbuf) { - char optkeybuf[GL_HMAC_HASHSIZE]; - char innerhash[GL_HMAC_HASHSIZE]; - - /* Ensure key size is <= block size. */ - if(keylen > GL_HMAC_BLOCKSIZE) { - struct GL_HMAC_CTX keyhash; - - GL_HMAC_FN_INIT(&keyhash); - GL_HMAC_FN_PROC(key, keylen, &keyhash); - GL_HMAC_FN_FINI(&keyhash, optkeybuf); - - key = optkeybuf; - /* zero padding of the key to the block size - is implicit in the memxor. */ - keylen = sizeof optkeybuf; - } - - /* Compute INNERHASH from KEY and IN. */ - hmac_hash(key, keylen, in, inlen, IPAD, innerhash); - - /* Compute result from KEY and INNERHASH. */ - hmac_hash(key, keylen, innerhash, sizeof innerhash, OPAD, resbuf); - - return 0; -} diff --git a/applications/plugins/totp/services/hmac/hmac_sha1.c b/applications/plugins/totp/services/hmac/hmac_sha1.c deleted file mode 100644 index a597ecb3a..000000000 --- a/applications/plugins/totp/services/hmac/hmac_sha1.c +++ /dev/null @@ -1,24 +0,0 @@ -/* hmac_sha1.c -- hashed message authentication codes - Copyright (C) 2018-2022 Free Software Foundation, Inc. - - This file is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of the - License, or (at your option) any later version. - - This file is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . */ - -#include "hmac_sha1.h" - -#include "sha1.h" - -#define GL_HMAC_NAME 1 -#define GL_HMAC_BLOCKSIZE 64 -#define GL_HMAC_HASHSIZE 20 -#include "hmac_common.h" diff --git a/applications/plugins/totp/services/hmac/hmac_sha1.h b/applications/plugins/totp/services/hmac/hmac_sha1.h deleted file mode 100644 index 25ff2f648..000000000 --- a/applications/plugins/totp/services/hmac/hmac_sha1.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include - -#define HMAC_SHA1_RESULT_SIZE 20 - -/* Compute Hashed Message Authentication Code with SHA-1, over BUFFER - data of BUFLEN bytes using the KEY of KEYLEN bytes, writing the - output to pre-allocated 20 byte minimum RESBUF buffer. Return 0 on - success. */ -int hmac_sha1(const void* key, size_t keylen, const void* in, size_t inlen, void* restrict resbuf); diff --git a/applications/plugins/totp/services/hmac/hmac_sha256.c b/applications/plugins/totp/services/hmac/hmac_sha256.c deleted file mode 100644 index dbf027101..000000000 --- a/applications/plugins/totp/services/hmac/hmac_sha256.c +++ /dev/null @@ -1,23 +0,0 @@ -/* hmac_sha256.c -- hashed message authentication codes - Copyright (C) 2018-2022 Free Software Foundation, Inc. - - This file is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of the - License, or (at your option) any later version. - - This file is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . */ - -#include "hmac_sha256.h" - -#define GL_HMAC_NAME 256 -#define GL_HMAC_BLOCKSIZE 64 -#define GL_HMAC_HASHSIZE 32 - -#include "hmac_common.h" diff --git a/applications/plugins/totp/services/hmac/hmac_sha256.h b/applications/plugins/totp/services/hmac/hmac_sha256.h deleted file mode 100644 index 9aeaf10d6..000000000 --- a/applications/plugins/totp/services/hmac/hmac_sha256.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include - -#define HMAC_SHA256_RESULT_SIZE 32 - -/* Compute Hashed Message Authentication Code with SHA-256, over BUFFER - data of BUFLEN bytes using the KEY of KEYLEN bytes, writing the - output to pre-allocated 32 byte minimum RESBUF buffer. Return 0 on - success. */ -int hmac_sha256(const void* key, size_t keylen, const void* in, size_t inlen, void* restrict resbuf); diff --git a/applications/plugins/totp/services/hmac/hmac_sha512.c b/applications/plugins/totp/services/hmac/hmac_sha512.c deleted file mode 100644 index eafe80fd2..000000000 --- a/applications/plugins/totp/services/hmac/hmac_sha512.c +++ /dev/null @@ -1,24 +0,0 @@ -/* hmac_sha512.c -- hashed message authentication codes - Copyright (C) 2018-2022 Free Software Foundation, Inc. - - This file is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of the - License, or (at your option) any later version. - - This file is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . */ - -#include "hmac_sha512.h" - -#include "sha512.h" - -#define GL_HMAC_NAME 512 -#define GL_HMAC_BLOCKSIZE 128 -#define GL_HMAC_HASHSIZE 64 -#include "hmac_common.h" diff --git a/applications/plugins/totp/services/hmac/hmac_sha512.h b/applications/plugins/totp/services/hmac/hmac_sha512.h deleted file mode 100644 index 712b7f4a0..000000000 --- a/applications/plugins/totp/services/hmac/hmac_sha512.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include - -#define HMAC_SHA512_RESULT_SIZE 64 - -/* Compute Hashed Message Authentication Code with SHA-512, over BUFFER - data of BUFLEN bytes using the KEY of KEYLEN bytes, writing the - output to pre-allocated 64 byte minimum RESBUF buffer. Return 0 on - success. */ -int hmac_sha512(const void* key, size_t keylen, const void* in, size_t inlen, void* restrict resbuf);