diff options
Diffstat (limited to 'crypto/openssh/cipher-chachapoly.c')
-rw-r--r-- | crypto/openssh/cipher-chachapoly.c | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/crypto/openssh/cipher-chachapoly.c b/crypto/openssh/cipher-chachapoly.c index 0899c5ad5b79..716f8d426a06 100644 --- a/crypto/openssh/cipher-chachapoly.c +++ b/crypto/openssh/cipher-chachapoly.c @@ -14,9 +14,14 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $OpenBSD: cipher-chachapoly.c,v 1.8 2016/08/03 05:41:57 djm Exp $ */ +/* $OpenBSD: cipher-chachapoly.c,v 1.9 2020/04/03 04:27:03 djm Exp $ */ #include "includes.h" +#ifdef WITH_OPENSSL +#include "openbsd-compat/openssl-compat.h" +#endif + +#if !defined(HAVE_EVP_CHACHA20) || defined(HAVE_BROKEN_CHACHA20) #include <sys/types.h> #include <stdarg.h> /* needed for log.h */ @@ -28,15 +33,28 @@ #include "ssherr.h" #include "cipher-chachapoly.h" -int -chachapoly_init(struct chachapoly_ctx *ctx, - const u_char *key, u_int keylen) +struct chachapoly_ctx { + struct chacha_ctx main_ctx, header_ctx; +}; + +struct chachapoly_ctx * +chachapoly_new(const u_char *key, u_int keylen) { + struct chachapoly_ctx *ctx; + if (keylen != (32 + 32)) /* 2 x 256 bit keys */ - return SSH_ERR_INVALID_ARGUMENT; + return NULL; + if ((ctx = calloc(1, sizeof(*ctx))) == NULL) + return NULL; chacha_keysetup(&ctx->main_ctx, key, 256); chacha_keysetup(&ctx->header_ctx, key + 32, 256); - return 0; + return ctx; +} + +void +chachapoly_free(struct chachapoly_ctx *cpctx) +{ + freezero(cpctx, sizeof(*cpctx)); } /* @@ -117,3 +135,5 @@ chachapoly_get_length(struct chachapoly_ctx *ctx, *plenp = PEEK_U32(buf); return 0; } + +#endif /* !defined(HAVE_EVP_CHACHA20) || defined(HAVE_BROKEN_CHACHA20) */ |