Welcome to little lamb

Code » limb » release » tree

[release] / src / liblimb / sha3.h / sha3_init.c

/* This file is part of limb                           https://lila.oss/limb
 * Copyright (C) 2023 Olivier Brunel                          jjk@jjacky.com */
/* Based on RHash: http://rhash.sourceforge.net/
 * Based on The Keccak SHA-3 submission. Submission to NIST (Round 3), 2011
 * by Guido Bertoni, Joan Daemen, Michaƫl Peeters and Gilles Van Assche
 * Copyright (c) 2013 Aleksey Kravchenko */
/* SPDX-License-Identifier: 0BSD */

#include <string.h>
#include "sha3/sha3.h"

/**
 * Initializing a sha3 context for given number of output bits
 *
 * @param bits number of output bits
 * @param ctx  context to initialize
 */
void
sha3_init(unsigned bits, sha3_ctx *ctx)
{
    /* NB: The Keccak capacity parameter = bits * 2 */
    unsigned rate = 1600 - bits * 2;

    memset(ctx, 0, sizeof(*ctx));
    ctx->block_size = rate / 8;
}