-/* $OpenBSD: sha3.c,v 1.13 2023/04/15 19:30:31 jsing Exp $ */
+/* $OpenBSD: sha3.c,v 1.14 2023/04/15 20:00:24 jsing Exp $ */
/*
* The MIT License (MIT)
*
memset(c, 0, sizeof(*c));
c->mdlen = mdlen;
- c->rsiz = 200 - 2 * mdlen;
+ c->rsize = 200 - 2 * mdlen;
return 1;
}
int
sha3_update(sha3_ctx *c, const void *data, size_t len)
{
- size_t i;
- int j;
+ size_t i, j;
j = c->pt;
for (i = 0; i < len; i++) {
c->state.b[j++] ^= ((const uint8_t *) data)[i];
- if (j >= c->rsiz) {
+ if (j >= c->rsize) {
sha3_keccakf(c->state.q);
j = 0;
}
int i;
c->state.b[c->pt] ^= 0x06;
- c->state.b[c->rsiz - 1] ^= 0x80;
+ c->state.b[c->rsize - 1] ^= 0x80;
sha3_keccakf(c->state.q);
for (i = 0; i < c->mdlen; i++) {
shake_xof(sha3_ctx *c)
{
c->state.b[c->pt] ^= 0x1F;
- c->state.b[c->rsiz - 1] ^= 0x80;
+ c->state.b[c->rsize - 1] ^= 0x80;
sha3_keccakf(c->state.q);
c->pt = 0;
}
void
shake_out(sha3_ctx *c, void *out, size_t len)
{
- size_t i;
- int j;
+ size_t i, j;
j = c->pt;
for (i = 0; i < len; i++) {
- if (j >= c->rsiz) {
+ if (j >= c->rsize) {
sha3_keccakf(c->state.q);
j = 0;
}
-/* $OpenBSD: sha3_internal.h,v 1.12 2023/04/15 19:44:36 jsing Exp $ */
+/* $OpenBSD: sha3_internal.h,v 1.13 2023/04/15 20:00:24 jsing Exp $ */
/*
* The MIT License (MIT)
*
#define SHA3_512_BLOCK_SIZE (SHA3_512_CAPACITY / 8)
#define SHA3_512_DIGEST_LENGTH (SHA3_512_BIT_LENGTH / 8)
-typedef struct {
+typedef struct sha3_ctx_st {
union {
uint8_t b[200]; /* State as 8 bit bytes. */
uint64_t q[25]; /* State as 64 bit words. */
} state;
- int pt, rsiz, mdlen;
+ size_t pt;
+ size_t rsize;
+ size_t mdlen;
} sha3_ctx;
int sha3_init(sha3_ctx *c, int mdlen);