From 8cd6cd175df0fcbe16ddf75e0ae4d1b6679ab6aa Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Fri, 20 Oct 2023 13:20:11 +0200 Subject: [PATCH] EVP_EncodeBlock should not append a newline --- tests/api.c | 9 +++------ wolfcrypt/src/evp.c | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/api.c b/tests/api.c index a3759296c..dae838e59 100644 --- a/tests/api.c +++ b/tests/api.c @@ -4886,6 +4886,7 @@ static int test_wolfSSL_EVP_EncodeUpdate(void) const unsigned char plain1[] = {"This is a base64 encodeing test."}; const unsigned char plain2[] = {"This is additional data."}; + const unsigned char encBlock0[] = {"VGg="}; const unsigned char enc0[] = {"VGg=\n"}; /* expected encoded result for the first output 64 chars plus trailing LF*/ const unsigned char enc1[] = {"VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVpbmcgdGVzdC5UaGlzIGlzIGFkZGl0aW9u\n"}; @@ -4987,12 +4988,8 @@ static int test_wolfSSL_EVP_EncodeUpdate(void) XMEMSET( encOutBuff,0, sizeof(encOutBuff)); ExpectIntEQ(EVP_EncodeBlock(encOutBuff, plain0, sizeof(plain0)-1), - sizeof(enc0)-1); - ExpectIntEQ( - XSTRNCMP( - (const char*)encOutBuff, - (const char*)enc0,sizeof(enc0) ), - 0); + sizeof(encBlock0)-1); + ExpectStrEQ(encOutBuff, encBlock0); /* pass small size( < 48bytes ) input, then make sure they are not * encoded and just stored in ctx diff --git a/wolfcrypt/src/evp.c b/wolfcrypt/src/evp.c index 7087c88ac..2b3f058c3 100644 --- a/wolfcrypt/src/evp.c +++ b/wolfcrypt/src/evp.c @@ -12028,7 +12028,7 @@ int wolfSSL_EVP_EncodeBlock(unsigned char *out, const unsigned char *in, if (out == NULL || in == NULL) return WOLFSSL_FATAL_ERROR; - if (Base64_Encode(in, (word32)inLen, out, &ret) == 0) + if (Base64_Encode_NoNl(in, (word32)inLen, out, &ret) == 0) return (int)ret; else return WOLFSSL_FATAL_ERROR;