Welcome to little lamb

Code » limb » release » tree

[release] / src / liblimb / ccpl.h / ccpl_init.c

/* This file is part of limb                           https://lila.oss/limb
 * Copyright (C) 2023 Olivier Brunel                          jjk@jjacky.com */
/* SPDX-License-Identifier: GPL-2.0-only */
#include <limb/ccpl.h>
#include <limb/u32.h>

void
ccpl_init(void *key, void *nonce, void *ctx_)
{
    ccpl_ctx *ctx = ctx_;

    char k[32] = { 0 };
    chacha20_init(key, nonce, &ctx->cc);
    chacha20_crypt(k, k, sizeof(k), &ctx->cc);
    poly1305_init(k, &ctx->pl);

    chacha20_init(key, nonce, &ctx->cc);
    ctx->cc.in[12] = 1;
    u32p_le(&ctx->cc.in[12]);

    ctx->alen = ctx->dlen = 0;
    ctx->w = 0;
}