Remove ChaCha20

This commit is contained in:
Zhi Guan
2026-06-22 19:13:05 +08:00
parent d5de748e45
commit 3a3f632b46
6 changed files with 3 additions and 210 deletions

View File

@@ -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)

View File

@@ -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签名

View File

@@ -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 <stdint.h>
#include <stdlib.h>
#include <string.h>
#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

View File

@@ -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);

View File

@@ -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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <gmssl/chacha20.h>
#include <gmssl/endian.h>
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]++;
}
}

View File

@@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gmssl/chacha20.h>
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;
}