diff --git a/CMakeLists.txt b/CMakeLists.txt index cf1e4143..88208563 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -645,7 +645,6 @@ if (ENABLE_SHA2) message(STATUS "ENABLE_SHA2 is ON") add_definitions(-DENABLE_SHA2) list(APPEND src src/sha256.c src/sha512.c) - list(APPEND src src/sha256_hmac.c) list(APPEND tests sha224 sha256 sha384 sha512 hmac) endif() @@ -1026,7 +1025,7 @@ endif() # set(CPACK_PACKAGE_NAME "GmSSL") set(CPACK_PACKAGE_VENDOR "GmSSL develop team") -set(CPACK_PACKAGE_VERSION "3.3.0-dev.1177") +set(CPACK_PACKAGE_VERSION "3.3.0-dev.1178") set(CPACK_PACKAGE_DESCRIPTION_FILE ${PROJECT_SOURCE_DIR}/README.md) set(CPACK_NSIS_MODIFY_PATH ON) include(CPack) diff --git a/include/gmssl/sha2.h b/include/gmssl/sha2.h index 0706413d..fd844f45 100644 --- a/include/gmssl/sha2.h +++ b/include/gmssl/sha2.h @@ -97,18 +97,6 @@ void sha512_224_init(SHA512_CTX *ctx); void sha512_224_finish(SHA512_CTX *ctx, uint8_t dgst[SHA224_DIGEST_SIZE]); -#define SHA256_HMAC_SIZE (SHA256_DIGEST_SIZE) - -typedef struct { - SHA256_CTX sha256_ctx; - uint8_t key[SHA256_BLOCK_SIZE]; -} SHA256_HMAC_CTX; - -void sha256_hmac_init(SHA256_HMAC_CTX *ctx, const uint8_t *key, size_t keylen); -void sha256_hmac_update(SHA256_HMAC_CTX *ctx, const uint8_t *data, size_t datalen); -void sha256_hmac_finish(SHA256_HMAC_CTX *ctx, uint8_t mac[SHA256_HMAC_SIZE]); - - #ifdef __cplusplus } #endif diff --git a/include/gmssl/version.h b/include/gmssl/version.h index e038b166..0d6a6e1d 100644 --- a/include/gmssl/version.h +++ b/include/gmssl/version.h @@ -18,7 +18,7 @@ extern "C" { #define GMSSL_VERSION_NUM 30300 -#define GMSSL_VERSION_STR "GmSSL 3.3.0-dev.1177" +#define GMSSL_VERSION_STR "GmSSL 3.3.0-dev.1178" int gmssl_version_num(void); const char *gmssl_version_str(void); diff --git a/src/sha256_hmac.c b/src/sha256_hmac.c deleted file mode 100644 index 85036292..00000000 --- a/src/sha256_hmac.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2014-2026 The GmSSL Project. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * - * http://www.apache.org/licenses/LICENSE-2.0 - */ - - -#include -#include -#include - -/** - * HMAC_k(m) = H((k ^ opad) || H((k ^ ipad) || m)) - * pseudo-code: - * function hmac(key, message) - * opad = [0x5c * blocksize] - * ipad = [0x36 * blocksize] - * if (length(key) > blocksize) then - * key = hash(key) - * end if - * for i from 0 to length(key) - 1 step 1 - * ipad[i] = ipad[i] XOR key[i] - * opad[i] = opad[i] XOR key[i] - * end for - * return hash(opad || hash(ipad || message)) - * end function - */ - - -#define IPAD 0x36 -#define OPAD 0x5C - -void sha256_hmac_init(SHA256_HMAC_CTX *ctx, const uint8_t *key, size_t key_len) -{ - int i; - - if (key_len <= SHA256_BLOCK_SIZE) { - memcpy(ctx->key, key, key_len); - memset(ctx->key + key_len, 0, SHA256_BLOCK_SIZE - key_len); - } else { - sha256_init(&ctx->sha256_ctx); - sha256_update(&ctx->sha256_ctx, key, key_len); - sha256_finish(&ctx->sha256_ctx, ctx->key); - memset(ctx->key + SHA256_DIGEST_SIZE, 0, - SHA256_BLOCK_SIZE - SHA256_DIGEST_SIZE); - } - for (i = 0; i < SHA256_BLOCK_SIZE; i++) { - ctx->key[i] ^= IPAD; - } - - sha256_init(&ctx->sha256_ctx); - sha256_update(&ctx->sha256_ctx, ctx->key, SHA256_BLOCK_SIZE); -} - -void sha256_hmac_update(SHA256_HMAC_CTX *ctx, const uint8_t *data, size_t data_len) -{ - sha256_update(&ctx->sha256_ctx, data, data_len); -} - -void sha256_hmac_finish(SHA256_HMAC_CTX *ctx, uint8_t mac[SHA256_HMAC_SIZE]) -{ - int i; - for (i = 0; i < SHA256_BLOCK_SIZE; i++) { - ctx->key[i] ^= (IPAD ^ OPAD); - } - sha256_finish(&ctx->sha256_ctx, mac); - sha256_init(&ctx->sha256_ctx); - sha256_update(&ctx->sha256_ctx, ctx->key, SHA256_BLOCK_SIZE); - sha256_update(&ctx->sha256_ctx, mac, SHA256_DIGEST_SIZE); - sha256_finish(&ctx->sha256_ctx, mac); -}