diff options
Diffstat (limited to 'cipher-chachapoly.c')
-rw-r--r-- | cipher-chachapoly.c | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/cipher-chachapoly.c b/cipher-chachapoly.c index 0899c5ad5..716f8d426 100644 --- a/cipher-chachapoly.c +++ b/cipher-chachapoly.c | |||
@@ -14,9 +14,14 @@ | |||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | /* $OpenBSD: cipher-chachapoly.c,v 1.8 2016/08/03 05:41:57 djm Exp $ */ | 17 | /* $OpenBSD: cipher-chachapoly.c,v 1.9 2020/04/03 04:27:03 djm Exp $ */ |
18 | 18 | ||
19 | #include "includes.h" | 19 | #include "includes.h" |
20 | #ifdef WITH_OPENSSL | ||
21 | #include "openbsd-compat/openssl-compat.h" | ||
22 | #endif | ||
23 | |||
24 | #if !defined(HAVE_EVP_CHACHA20) || defined(HAVE_BROKEN_CHACHA20) | ||
20 | 25 | ||
21 | #include <sys/types.h> | 26 | #include <sys/types.h> |
22 | #include <stdarg.h> /* needed for log.h */ | 27 | #include <stdarg.h> /* needed for log.h */ |
@@ -28,15 +33,28 @@ | |||
28 | #include "ssherr.h" | 33 | #include "ssherr.h" |
29 | #include "cipher-chachapoly.h" | 34 | #include "cipher-chachapoly.h" |
30 | 35 | ||
31 | int | 36 | struct chachapoly_ctx { |
32 | chachapoly_init(struct chachapoly_ctx *ctx, | 37 | struct chacha_ctx main_ctx, header_ctx; |
33 | const u_char *key, u_int keylen) | 38 | }; |
39 | |||
40 | struct chachapoly_ctx * | ||
41 | chachapoly_new(const u_char *key, u_int keylen) | ||
34 | { | 42 | { |
43 | struct chachapoly_ctx *ctx; | ||
44 | |||
35 | if (keylen != (32 + 32)) /* 2 x 256 bit keys */ | 45 | if (keylen != (32 + 32)) /* 2 x 256 bit keys */ |
36 | return SSH_ERR_INVALID_ARGUMENT; | 46 | return NULL; |
47 | if ((ctx = calloc(1, sizeof(*ctx))) == NULL) | ||
48 | return NULL; | ||
37 | chacha_keysetup(&ctx->main_ctx, key, 256); | 49 | chacha_keysetup(&ctx->main_ctx, key, 256); |
38 | chacha_keysetup(&ctx->header_ctx, key + 32, 256); | 50 | chacha_keysetup(&ctx->header_ctx, key + 32, 256); |
39 | return 0; | 51 | return ctx; |
52 | } | ||
53 | |||
54 | void | ||
55 | chachapoly_free(struct chachapoly_ctx *cpctx) | ||
56 | { | ||
57 | freezero(cpctx, sizeof(*cpctx)); | ||
40 | } | 58 | } |
41 | 59 | ||
42 | /* | 60 | /* |
@@ -117,3 +135,5 @@ chachapoly_get_length(struct chachapoly_ctx *ctx, | |||
117 | *plenp = PEEK_U32(buf); | 135 | *plenp = PEEK_U32(buf); |
118 | return 0; | 136 | return 0; |
119 | } | 137 | } |
138 | |||
139 | #endif /* !defined(HAVE_EVP_CHACHA20) || defined(HAVE_BROKEN_CHACHA20) */ | ||