From 687ecb9f49962e001e306b2050a6b61f2ee8c458 Mon Sep 17 00:00:00 2001 From: Zhi Guan Date: Wed, 13 Dec 2023 20:16:05 +0800 Subject: [PATCH] Remove RC4 --- CMakeLists.txt | 4 +-- include/gmssl/rc4.h | 40 ---------------------- src/rc4.c | 83 --------------------------------------------- 3 files changed, 2 insertions(+), 125 deletions(-) delete mode 100644 include/gmssl/rc4.h delete mode 100644 src/rc4.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ecd2ebe..2f51be29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -249,8 +249,8 @@ endif() option(ENABLE_BROKEN_CRYPTO "Enable broken crypto algorithms" OFF) if (ENABLE_BROKEN_CRYPTO) message(STATUS "ENABLE_BROKEN_CRYPTO") - list(APPEND src src/des.c src/sha1.c src/rc4.c) - list(APPEND tests des sha1 rc4) + list(APPEND src src/des.c src/sha1.c) + list(APPEND tests des sha1) endif() diff --git a/include/gmssl/rc4.h b/include/gmssl/rc4.h deleted file mode 100644 index a6a523c3..00000000 --- a/include/gmssl/rc4.h +++ /dev/null @@ -1,40 +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 - */ - - - -#ifndef GMSSL_RC4_H -#define GMSSL_RC4_H - - -#include -#include - - -#ifdef __cplusplus -extern "C" { -#endif - - -#define RC4_MIN_KEY_BITS 40 -#define RC4_STATE_NUM_WORDS 256 - - -typedef struct { - uint8_t d[RC4_STATE_NUM_WORDS]; -} RC4_STATE; - -void rc4_init(RC4_STATE *state, const uint8_t *key, size_t keylen); -void rc4_generate_keystream(RC4_STATE *state, size_t outlen, uint8_t *out); - - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/rc4.c b/src/rc4.c deleted file mode 100644 index e3ae13e1..00000000 --- a/src/rc4.c +++ /dev/null @@ -1,83 +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 - -void rc4_init(RC4_STATE *state, const uint8_t *key, size_t keylen) -{ - int i, j; - uint8_t *s = state->d; - uint8_t k[256] = {0}; - uint8_t temp; - - if (keylen > sizeof(k)) { - keylen = sizeof(k); - } - - /* expand key */ - for (i = 0; i < (int)keylen; i++) { - k[i] = key[i]; - } - for (; i < 256; i++) { - k[i] = key[i % keylen]; - } - - /* init state */ - for (i = 0; i < 256; i++) { - s[i] = i; - } - - /* shuffle state with key */ - j = 0; - for (i = 0; i < 256; i++) { - j = (j + s[i] + k[i]) % 256; - - /* swap(s[i], s[j]) */ - temp = s[j]; - s[j] = s[i]; - s[i] = temp; - } - - /* clean expanded temp key */ - memset(k, 0, sizeof(k)); -} - -void rc4_generate_keystream(RC4_STATE *state, size_t outlen, uint8_t *out) -{ - int i = 0, j = 0; - uint8_t *s = state->d; - int oi; - int temp; - - while (outlen > 0) { - i = (i + 1) % 256; - j = (j + s[i]) % 256; - - /* swap(s[i], s[j]) */ - temp = s[j]; - s[j] = s[i]; - s[i] = temp; - - oi = (s[i] + s[j]) % 256; - *out++ = s[oi]; - - outlen--; - } -} - -uint8_t rc4_generate_keybyte(RC4_STATE *state) -{ - uint8_t out[1]; - rc4_generate_keystream(state, 1, out); - return out[0]; -}