skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

blake2s_update.c (579B)


      1  /* ISC license. */
      2 
      3 #include <string.h>
      4 
      5 #include <skalibs/blake2s.h>
      6 #include "blake2s-internal.h"
      7 
      8 void blake2s_update (blake2s_ctx *ctx, char const *s, size_t len)
      9 {
     10   size_t w = 64 - ctx->buflen ;
     11   if (!len) return ;
     12   if (len > w)
     13   {
     14     memcpy(ctx->buf + ctx->buflen, s, w) ;
     15     blake2s_transform(ctx, ctx->buf, 1, 64) ;
     16     ctx->buflen = 0 ;
     17     s += w ; len -= w ;
     18   }
     19   if (len > 64)
     20   {
     21     size_t n = (len+63)/64 - 1 ;
     22     blake2s_transform(ctx, s, n, 64) ;
     23     n <<= 6 ; s += n ; len -= n ;
     24   }
     25   memcpy(ctx->buf + ctx->buflen, s, len) ;
     26   ctx->buflen += len ;
     27 }