summaryrefslogtreecommitdiffstats
path: root/crypto/evp
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2018-04-09 16:06:50 +0200
committerMatt Caswell <matt@openssl.org>2018-04-13 10:37:38 +0200
commitc080461448815dab809661080ee5e21417478fb4 (patch)
tree8fb56ec9f510ecbf1581e53ae9fe0d4b5310936a /crypto/evp
parentDocs for OpenSSL_init_crypto: there is no way to specify another file (diff)
downloadopenssl-c080461448815dab809661080ee5e21417478fb4.tar.xz
openssl-c080461448815dab809661080ee5e21417478fb4.zip
Change SRP functions to use EVP_EncodeUpdate/EVP_DecodeUpdate functions
Previously they were using EVP_EncodeBlock/EVP_DecodeBlock. These are low level functions that do not handle padding characters. This was causing the SRP code to fail. One side effect of using EVP_EncodeUpdate is that it inserts newlines which is not what we need in SRP so we add a flag to avoid that. Reviewed-by: Andy Polyakov <appro@openssl.org> (Merged from https://github.com/openssl/openssl/pull/5925)
Diffstat (limited to 'crypto/evp')
-rw-r--r--crypto/evp/encode.c28
-rw-r--r--crypto/evp/evp_locl.h2
2 files changed, 22 insertions, 8 deletions
diff --git a/crypto/evp/encode.c b/crypto/evp/encode.c
index 17198ff6be..a43755ab17 100644
--- a/crypto/evp/encode.c
+++ b/crypto/evp/encode.c
@@ -12,6 +12,7 @@
#include "internal/cryptlib.h"
#include <openssl/evp.h>
#include "evp_locl.h"
+#include "internal/evp_int.h"
static unsigned char conv_ascii2bin(unsigned char a);
#ifndef CHARSET_EBCDIC
@@ -115,11 +116,17 @@ int EVP_ENCODE_CTX_num(EVP_ENCODE_CTX *ctx)
return ctx->num;
}
+void evp_encode_ctx_set_flags(EVP_ENCODE_CTX *ctx, unsigned int flags)
+{
+ ctx->flags = flags;
+}
+
void EVP_EncodeInit(EVP_ENCODE_CTX *ctx)
{
ctx->length = 48;
ctx->num = 0;
ctx->line_num = 0;
+ ctx->flags = 0;
}
int EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
@@ -145,18 +152,24 @@ int EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
j = EVP_EncodeBlock(out, ctx->enc_data, ctx->length);
ctx->num = 0;
out += j;
- *(out++) = '\n';
+ total = j;
+ if ((ctx->flags & EVP_ENCODE_CTX_NO_NEWLINES) == 0) {
+ *(out++) = '\n';
+ total++;
+ }
*out = '\0';
- total = j + 1;
}
while (inl >= ctx->length && total <= INT_MAX) {
j = EVP_EncodeBlock(out, in, ctx->length);
in += ctx->length;
inl -= ctx->length;
out += j;
- *(out++) = '\n';
+ total += j;
+ if ((ctx->flags & EVP_ENCODE_CTX_NO_NEWLINES) == 0) {
+ *(out++) = '\n';
+ total++;
+ }
*out = '\0';
- total += j + 1;
}
if (total > INT_MAX) {
/* Too much output data! */
@@ -177,7 +190,8 @@ void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl)
if (ctx->num != 0) {
ret = EVP_EncodeBlock(out, ctx->enc_data, ctx->num);
- out[ret++] = '\n';
+ if ((ctx->flags & EVP_ENCODE_CTX_NO_NEWLINES) == 0)
+ out[ret++] = '\n';
out[ret] = '\0';
ctx->num = 0;
}
@@ -217,11 +231,11 @@ int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int dlen)
void EVP_DecodeInit(EVP_ENCODE_CTX *ctx)
{
- /* Only ctx->num is used during decoding. */
+ /* Only ctx->num and ctx->flags are used during decoding. */
ctx->num = 0;
ctx->length = 0;
ctx->line_num = 0;
- ctx->expect_nl = 0;
+ ctx->flags = 0;
}
/*-
diff --git a/crypto/evp/evp_locl.h b/crypto/evp/evp_locl.h
index 209577b7c2..d5dbbeb0da 100644
--- a/crypto/evp/evp_locl.h
+++ b/crypto/evp/evp_locl.h
@@ -59,7 +59,7 @@ struct evp_Encode_Ctx_st {
unsigned char enc_data[80];
/* number read on current line */
int line_num;
- int expect_nl;
+ unsigned int flags;
};
typedef struct evp_pbe_st EVP_PBE_CTL;