From 577ce9cf685f5d8376276315575274b9e1b5f3fb Mon Sep 17 00:00:00 2001 From: claudio Date: Mon, 11 Oct 2021 16:06:36 +0000 Subject: [PATCH] base64_encode() should not add any newlines into the output. Because of this switch from EVP_EncodeUpdate() plus complexity to the much simpler use of calling EVP_EncodeBlock() directly. OK job@ --- usr.sbin/rpki-client/encoding.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/usr.sbin/rpki-client/encoding.c b/usr.sbin/rpki-client/encoding.c index b3dd38c208c..ff6d8731b70 100644 --- a/usr.sbin/rpki-client/encoding.c +++ b/usr.sbin/rpki-client/encoding.c @@ -1,4 +1,4 @@ -/* $OpenBSD: encoding.c,v 1.3 2021/09/01 08:09:41 claudio Exp $ */ +/* $OpenBSD: encoding.c,v 1.4 2021/10/11 16:06:36 claudio Exp $ */ /* * Copyright (c) 2020 Claudio Jeker * @@ -67,12 +67,8 @@ fail: int base64_encode(const unsigned char *in, size_t inlen, char **out) { - static EVP_ENCODE_CTX *ctx; unsigned char *to; - int tolen; - - if (ctx == NULL && (ctx = EVP_ENCODE_CTX_new()) == NULL) - err(1, "EVP_ENCODE_CTX_new"); + size_t tolen; *out = NULL; @@ -82,16 +78,9 @@ base64_encode(const unsigned char *in, size_t inlen, char **out) if ((to = malloc(tolen)) == NULL) return -1; - EVP_EncodeInit(ctx); - if (EVP_EncodeUpdate(ctx, to, &tolen, in, inlen) != 1) - goto fail; - EVP_EncodeFinal(ctx, to + tolen, &tolen); + EVP_EncodeBlock(to, in, inlen); *out = to; return 0; - -fail: - free(to); - return -1; } /* -- 2.20.1