summaryrefslogtreecommitdiff
path: root/src/libstdcrypto/blake2s_update.c
blob: bf0639bfe5dae26515d2aff0d563d5550cd19b00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 /* ISC license. */

#include <string.h>

#include <skalibs/blake2s.h>
#include "blake2s-internal.h"

void blake2s_update (blake2s_ctx *ctx, char const *s, size_t len)
{
  size_t w = 64 - ctx->buflen ;
  if (!len) return ;
  if (len > w)
  {
    memcpy(ctx->buf + ctx->buflen, s, w) ;
    blake2s_transform(ctx, ctx->buf, 1, 64) ;
    ctx->buflen = 0 ;
    s += w ; len -= w ;
  }
  if (len > 64)
  {
    size_t n = (len+63)/64 - 1 ;
    blake2s_transform(ctx, s, n, 64) ;
    n <<= 6 ; s += n ; len -= n ;
  }
  memcpy(ctx->buf + ctx->buflen, s, len) ;
  ctx->buflen += len ;
}