From: Vitaly Chikunov Date: Sat, 4 Dec 2021 06:13:14 +0000 (+0300) Subject: MSVC: Replace variable-length automatic arrays with alloca X-Git-Tag: v3.0.1~27 X-Git-Url: http://www.wagner.pp.ru/gitweb/?p=openssl-gost%2Fengine.git;a=commitdiff_plain;h=66c4ce5fb9fe3c3598a5707bde7ac6929ec0b83c MSVC: Replace variable-length automatic arrays with alloca MSVC is not C99 compatible[1]. Errors: test_ciphers.c(312,25): error C2057: expected constant expression test_ciphers.c(312,25): error C2466: cannot allocate an array of constant size 0 test_ciphers.c(312,26): error C2133: 'c': unknown size Link: https://docs.microsoft.com/en-us/cpp/c-language/ansi-conformance Signed-off-by: Vitaly Chikunov --- diff --git a/test_ciphers.c b/test_ciphers.c index 8497652..ddf572d 100644 --- a/test_ciphers.c +++ b/test_ciphers.c @@ -13,6 +13,14 @@ #include #include +#if defined _MSC_VER +# include +# define alloca _alloca +#elif defined __linux__ +# include +#endif +#include + #define T(e) ({ \ if (!(e)) {\ ERR_print_errors_fp(stderr);\ @@ -306,12 +314,12 @@ static void hexdump(const void *ptr, size_t len) static int test_block(const EVP_CIPHER *type, const char *name, int block_size, const unsigned char *pt, const unsigned char *key, const unsigned char *exp, - size_t size, const unsigned char *iv, size_t iv_size, int acpkm, + const size_t size, const unsigned char *iv, size_t iv_size, int acpkm, int inplace) { EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); const char *standard = acpkm? "R 23565.1.017-2018" : "GOST R 34.13-2015"; - unsigned char c[size]; + unsigned char *c = alloca(size); int outlen, tmplen; int ret = 0, test; @@ -334,7 +342,7 @@ static int test_block(const EVP_CIPHER *type, const char *name, int block_size, if (inplace) memcpy(c, pt, size); else - memset(c, 0, sizeof(c)); + memset(c, 0, size); if (acpkm) { if (EVP_CIPHER_get0_provider(type) != NULL) { OSSL_PARAM params[] = { OSSL_PARAM_END, OSSL_PARAM_END }; @@ -368,7 +376,7 @@ static int test_block(const EVP_CIPHER *type, const char *name, int block_size, if (inplace) memcpy(c, pt, size); else - memset(c, 0, sizeof(c)); + memset(c, 0, size); if (acpkm) { if (EVP_CIPHER_get0_provider(type) != NULL) { OSSL_PARAM params[] = { OSSL_PARAM_END, OSSL_PARAM_END }; @@ -406,7 +414,7 @@ static int test_block(const EVP_CIPHER *type, const char *name, int block_size, if (inplace) memcpy(c, exp, size); else - memset(c, 0, sizeof(c)); + memset(c, 0, size); if (acpkm) { if (EVP_CIPHER_get0_provider(type) != NULL) { OSSL_PARAM params[] = { OSSL_PARAM_END, OSSL_PARAM_END }; @@ -435,10 +443,11 @@ static int test_block(const EVP_CIPHER *type, const char *name, int block_size, static int test_stream(const EVP_CIPHER *type, const char *name, const unsigned char *pt, const unsigned char *key, const unsigned char *exp, - size_t size, const unsigned char *iv, size_t iv_size, int acpkm) + const size_t size, const unsigned char *iv, size_t iv_size, int acpkm) { EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); const char *standard = acpkm? "R 23565.1.017-2018" : "GOST R 34.13-2015"; + unsigned char *c = alloca(size); int ret = 0, test; int z; @@ -450,7 +459,6 @@ static int test_stream(const EVP_CIPHER *type, const char *name, T(EVP_CIPHER_block_size(type) == 1); for (z = 1; z <= size; z++) { - unsigned char c[size]; int outlen, tmplen; int sz = 0; int i; @@ -458,7 +466,7 @@ static int test_stream(const EVP_CIPHER *type, const char *name, EVP_CIPHER_CTX_init(ctx); T(EVP_CipherInit_ex(ctx, type, NULL, key, iv, 1)); T(EVP_CIPHER_CTX_set_padding(ctx, 0)); - memset(c, 0xff, sizeof(c)); + memset(c, 0xff, size); if (acpkm) { if (EVP_CIPHER_get0_provider(type) != NULL) { OSSL_PARAM params[] = { OSSL_PARAM_END, OSSL_PARAM_END };