diff options
author | djm@openbsd.org <djm@openbsd.org> | 2020-04-03 04:27:03 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2020-04-03 15:36:57 +1100 |
commit | eba523f0a130f1cce829e6aecdcefa841f526a1a (patch) | |
tree | af27de3afbd97d4fdcbc2515f0ee5a608bd32af2 /cipher-chachapoly.c | |
parent | ebd29e90129cf18fedfcfe1de86e324228669295 (diff) |
upstream: make Chacha20-POLY1305 context struct opaque; ok tb@ as
part of a larger diff at a2k20
OpenBSD-Commit-ID: a4609b7263284f95c9417ef60ed7cdbb7bf52cfd
Diffstat (limited to 'cipher-chachapoly.c')
-rw-r--r-- | cipher-chachapoly.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/cipher-chachapoly.c b/cipher-chachapoly.c index 0899c5ad5..42e8d40b7 100644 --- a/cipher-chachapoly.c +++ b/cipher-chachapoly.c | |||
@@ -14,7 +14,7 @@ | |||
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 | 20 | ||
@@ -28,15 +28,28 @@ | |||
28 | #include "ssherr.h" | 28 | #include "ssherr.h" |
29 | #include "cipher-chachapoly.h" | 29 | #include "cipher-chachapoly.h" |
30 | 30 | ||
31 | int | 31 | struct chachapoly_ctx { |
32 | chachapoly_init(struct chachapoly_ctx *ctx, | 32 | struct chacha_ctx main_ctx, header_ctx; |
33 | const u_char *key, u_int keylen) | 33 | }; |
34 | |||
35 | struct chachapoly_ctx * | ||
36 | chachapoly_new(const u_char *key, u_int keylen) | ||
34 | { | 37 | { |
38 | struct chachapoly_ctx *ctx; | ||
39 | |||
35 | if (keylen != (32 + 32)) /* 2 x 256 bit keys */ | 40 | if (keylen != (32 + 32)) /* 2 x 256 bit keys */ |
36 | return SSH_ERR_INVALID_ARGUMENT; | 41 | return NULL; |
42 | if ((ctx = calloc(1, sizeof(*ctx))) == NULL) | ||
43 | return NULL; | ||
37 | chacha_keysetup(&ctx->main_ctx, key, 256); | 44 | chacha_keysetup(&ctx->main_ctx, key, 256); |
38 | chacha_keysetup(&ctx->header_ctx, key + 32, 256); | 45 | chacha_keysetup(&ctx->header_ctx, key + 32, 256); |
39 | return 0; | 46 | return ctx; |
47 | } | ||
48 | |||
49 | void | ||
50 | chachapoly_free(struct chachapoly_ctx *cpctx) | ||
51 | { | ||
52 | freezero(cpctx, sizeof(*cpctx)); | ||
40 | } | 53 | } |
41 | 54 | ||
42 | /* | 55 | /* |