From 3a3f632b46bcfc1cd51ded31ef7e409e792f81fa Mon Sep 17 00:00:00 2001 From: Zhi Guan Date: Mon, 22 Jun 2026 19:13:05 +0800 Subject: [PATCH] Remove ChaCha20 --- CMakeLists.txt | 9 +---- README.md | 2 +- include/gmssl/chacha20.h | 57 --------------------------- include/gmssl/version.h | 2 +- src/chacha20.c | 85 ---------------------------------------- tests/chacha20test.c | 58 --------------------------- 6 files changed, 3 insertions(+), 210 deletions(-) delete mode 100644 include/gmssl/chacha20.h delete mode 100644 src/chacha20.c delete mode 100644 tests/chacha20test.c diff --git a/CMakeLists.txt b/CMakeLists.txt index d3747a15..cd7be918 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -138,7 +138,6 @@ option(ENABLE_SHA1 "Enable SHA1" ON) option(ENABLE_SHA2 "Enable SHA2" ON) option(ENABLE_AES "Enable AES" ON) option(ENABLE_AES_CCM "Enable AES CCM mode" ON) -option(ENABLE_CHACHA20 "Enable Chacha20" ON) option(ENABLE_ZUC "Enable ZUC" ON) option(ENABLE_GHASH "Enable standalone GHASH command and test" ON) @@ -601,12 +600,6 @@ if (ENABLE_AES_CCM) endif() -if (ENABLE_CHACHA20) - message(STATUS "ENABLE_CHACHA20 is ON") - list(APPEND src src/chacha20.c) - list(APPEND tests chacha20) -endif() - if (ENABLE_ZUC) message(STATUS "ENABLE_ZUC is ON") add_definitions(-DENABLE_ZUC) @@ -939,7 +932,7 @@ endif() # set(CPACK_PACKAGE_NAME "GmSSL") set(CPACK_PACKAGE_VENDOR "GmSSL develop team") -set(CPACK_PACKAGE_VERSION "3.3.0-dev.1153") +set(CPACK_PACKAGE_VERSION "3.3.0-dev.1154") set(CPACK_PACKAGE_DESCRIPTION_FILE ${PROJECT_SOURCE_DIR}/README.md) set(CPACK_NSIS_MODIFY_PATH ON) include(CPack) diff --git a/README.md b/README.md index 9dceb843..1cf824ef 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ nmake ### 密码算法 * 分组密码:SM4 (CBC/CTR/GCM/ECB/CFB/OFB/CCM/XTS), AES (CBC/CTR/GCM) -* 序列密码:ZUC/ZUC-256, ChaCha20 +* 序列密码:ZUC/ZUC-256 * 哈希函数: SM3, SHA-1, SHA-224/256/384/512 * 公钥密码:SM2加密/签名, SM9加密/签名 * 后量子密码:LMS/HSS签名 diff --git a/include/gmssl/chacha20.h b/include/gmssl/chacha20.h deleted file mode 100644 index 6021575a..00000000 --- a/include/gmssl/chacha20.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2014-2022 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 - */ - - -/* RFC 8439 "ChaCha20 and Poly1305 for IETF Protocols" */ - -#ifndef GMSSL_CHACHA20_H -#define GMSSL_CHACHA20_H - -#define CHACHA20_IS_BIG_ENDIAN 0 - -#include -#include - -#include - -#define CHACHA20_KEY_BITS 256 -#define CHACHA20_NONCE_BITS 96 -#define CHACHA20_COUNTER_BITS 32 - -#define CHACHA20_KEY_SIZE (CHACHA20_KEY_BITS/8) -#define CHACHA20_NONCE_SIZE (CHACHA20_NONCE_BITS/8) -#define CHACHA20_COUNTER_SIZE (CHACHA20_COUNTER_BITS/8) - -#define CHACHA20_KEY_WORDS (CHACHA20_KEY_SIZE/sizeof(uint32_t)) -#define CHACHA20_NONCE_WORDS (CHACHA20_NONCE_SIZE/sizeof(uint32_t)) -#define CHACHA20_COUNTER_WORDS (CHACHA20_COUNTER_SIZE/sizeof(uint32_t)) - - -#ifdef __cplusplus -extern "C" { -#endif - - -typedef struct { - uint32_t d[16]; -} CHACHA20_STATE; - - -void chacha20_init(CHACHA20_STATE *state, - const uint8_t key[CHACHA20_KEY_SIZE], - const uint8_t nonce[CHACHA20_NONCE_SIZE], uint32_t counter); - -void chacha20_generate_keystream(CHACHA20_STATE *state, - size_t counts, uint8_t *out); - - -#ifdef __cplusplus -} -#endif -#endif diff --git a/include/gmssl/version.h b/include/gmssl/version.h index 650ce021..fe187caa 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.1153" +#define GMSSL_VERSION_STR "GmSSL 3.3.0-dev.1154" int gmssl_version_num(void); const char *gmssl_version_str(void); diff --git a/src/chacha20.c b/src/chacha20.c deleted file mode 100644 index 424e61e6..00000000 --- a/src/chacha20.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2014-2022 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 -#include -#include - - -void chacha20_init(CHACHA20_STATE *state, - const uint8_t key[CHACHA20_KEY_SIZE], - const uint8_t nonce[CHACHA20_NONCE_SIZE], - uint32_t counter) -{ - state->d[ 0] = 0x61707865; - state->d[ 1] = 0x3320646e; - state->d[ 2] = 0x79622d32; - state->d[ 3] = 0x6b206574; - state->d[ 4] = GETU32_LE(key ); - state->d[ 5] = GETU32_LE(key + 4); - state->d[ 6] = GETU32_LE(key + 8); - state->d[ 7] = GETU32_LE(key + 12); - state->d[ 8] = GETU32_LE(key + 16); - state->d[ 9] = GETU32_LE(key + 20); - state->d[10] = GETU32_LE(key + 24); - state->d[11] = GETU32_LE(key + 28); - state->d[12] = counter; - state->d[13] = GETU32_LE(nonce); - state->d[14] = GETU32_LE(nonce + 4); - state->d[15] = GETU32_LE(nonce + 8); -} - -/* quarter round */ -#define QR(A, B, C, D) \ - A += B; D ^= A; D = ROL32(D, 16); \ - C += D; B ^= C; B = ROL32(B, 12); \ - A += B; D ^= A; D = ROL32(D, 8); \ - C += D; B ^= C; B = ROL32(B, 7) - -/* double round on state 4x4 matrix: - * four column rounds and and four diagonal rounds - * - * 0 1 2 3 - * 4 5 6 7 - * 8 9 10 11 - * 12 13 14 15 - * - */ -#define DR(S) \ - QR(S[0], S[4], S[ 8], S[12]); \ - QR(S[1], S[5], S[ 9], S[13]); \ - QR(S[2], S[6], S[10], S[14]); \ - QR(S[3], S[7], S[11], S[15]); \ - QR(S[0], S[5], S[10], S[15]); \ - QR(S[1], S[6], S[11], S[12]); \ - QR(S[2], S[7], S[ 8], S[13]); \ - QR(S[3], S[4], S[ 9], S[14]) - -void chacha20_generate_keystream(CHACHA20_STATE *state, size_t counts, uint8_t *out) -{ - uint32_t working_state[16]; - int i; - - while (counts-- > 0) { - memcpy(working_state, state->d, sizeof(working_state)); - for (i = 0; i < 10; i++) { - DR(working_state); - } - for (i = 0; i < 16; i++) { - working_state[i] += state->d[i]; - PUTU32_LE(out, working_state[i]); - out += sizeof(uint32_t); - } - state->d[12]++; - } -} diff --git a/tests/chacha20test.c b/tests/chacha20test.c deleted file mode 100644 index e88eebb0..00000000 --- a/tests/chacha20test.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2014-2022 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 -#include - - -int main(void) -{ - int err = 0; - const unsigned char key[] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, - }; - const unsigned char nonce[] = { - 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x4a, - 0x00, 0x00, 0x00, 0x00, - }; - uint32_t counter = 1; - const unsigned char testdata[] = { - 0x10, 0xf1, 0xe7, 0xe4, 0xd1, 0x3b, 0x59, 0x15, - 0x50, 0x0f, 0xdd, 0x1f, 0xa3, 0x20, 0x71, 0xc4, - 0xc7, 0xd1, 0xf4, 0xc7, 0x33, 0xc0, 0x68, 0x03, - 0x04, 0x22, 0xaa, 0x9a, 0xc3, 0xd4, 0x6c, 0x4e, - 0xd2, 0x82, 0x64, 0x46, 0x07, 0x9f, 0xaa, 0x09, - 0x14, 0xc2, 0xd7, 0x05, 0xd9, 0x8b, 0x02, 0xa2, - 0xb5, 0x12, 0x9c, 0xd1, 0xde, 0x16, 0x4e, 0xb9, - 0xcb, 0xd0, 0x83, 0xe8, 0xa2, 0x50, 0x3c, 0x4e, - }; - unsigned char buf[64]; - - CHACHA20_STATE state; - chacha20_init(&state, key, nonce, counter); - chacha20_generate_keystream(&state, 1, buf); - - printf("chacha20 test "); - if (memcmp(buf, testdata, sizeof(testdata)) != 0) { - printf("failed\n"); - err++; - } else { - printf("ok\n"); - } - - return err; -} -