summaryrefslogtreecommitdiffstats
path: root/cipher-chachapoly.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2020-04-03 04:27:03 +0000
committerDamien Miller <djm@mindrot.org>2020-04-03 15:36:57 +1100
commiteba523f0a130f1cce829e6aecdcefa841f526a1a (patch)
treeaf27de3afbd97d4fdcbc2515f0ee5a608bd32af2 /cipher-chachapoly.c
parentebd29e90129cf18fedfcfe1de86e324228669295 (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.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/cipher-chachapoly.c b/cipher-chachapoly.c
index 0899c5ad..42e8d40b 100644
--- a/cipher-chachapoly.c
+++ b/cipher-chachapoly.c
@@ -14,7 +14,7 @@
* 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"
@@ -28,15 +28,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));
}
/*