示例#1
0
void sha256_update(sha256_ctx *ctx, const unsigned char *message,
                   unsigned int len)
{
    uint32 block_nb;
    uint32 new_len, rem_len, tmp_len;
    const unsigned char *shifted_message;

    tmp_len = SHA256_BLOCK_SIZE - ctx->len;
    rem_len = len < tmp_len ? len : tmp_len;

    memcpy(&ctx->block[ctx->len], message, rem_len);

    if (ctx->len + len < SHA256_BLOCK_SIZE) {
        ctx->len += len;
        return;
    }

    new_len = len - rem_len;
    block_nb = new_len / SHA256_BLOCK_SIZE;

    shifted_message = message + rem_len;

    sha256_transf(ctx, ctx->block, 1);
    sha256_transf(ctx, shifted_message, block_nb);

    rem_len = new_len % SHA256_BLOCK_SIZE;

    memcpy(ctx->block, &shifted_message[block_nb << 6],
           rem_len);

    ctx->len = rem_len;
    ctx->tot_len += (block_nb + 1) << 6;
}
示例#2
0
文件: sha2.c 项目: xharbour/core
void hb_sha224_update( sha224_ctx * ctx, const void * messagev,
                       unsigned int len )
{
   const unsigned char *   message = ( const unsigned char * ) messagev;
   unsigned int            block_nb;
   unsigned int            new_len, rem_len, tmp_len;
   const unsigned char *   shifted_message;

   tmp_len  = SHA224_BLOCK_SIZE - ctx->len;
   rem_len  = len < tmp_len ? len : tmp_len;

   HB_MEMCPY( &ctx->block[ ctx->len ], message, rem_len );

   if( ctx->len + len < SHA224_BLOCK_SIZE )
   {
      ctx->len += len;
      return;
   }

   new_len           = len - rem_len;
   block_nb          = new_len / SHA224_BLOCK_SIZE;

   shifted_message   = message + rem_len;

   sha256_transf( ctx, ctx->block, 1 );
   sha256_transf( ctx, shifted_message, block_nb );

   rem_len = new_len % SHA224_BLOCK_SIZE;

   HB_MEMCPY( ctx->block, &shifted_message[ block_nb << 6 ],
              rem_len );

   ctx->len       = rem_len;
   ctx->tot_len   += ( block_nb + 1 ) << 6;
}
示例#3
0
文件: sha2.c 项目: emazv72/core
void hb_sha224_update(hb_sha224_ctx *ctx, const void *messagev,
                      HB_SIZE len)
{
    const unsigned char * message = ( const unsigned char * ) messagev;
    HB_SIZE block_nb;
    HB_SIZE new_len, rem_len, tmp_len;
    const unsigned char *shifted_message;

    tmp_len = HB_SHA224_BLOCK_SIZE - ctx->len;
    rem_len = len < tmp_len ? len : tmp_len;

    memcpy(&ctx->block[ctx->len], message, rem_len);

    if (ctx->len + len < HB_SHA224_BLOCK_SIZE) {
        ctx->len += len;
        return;
    }

    new_len = len - rem_len;
    block_nb = new_len / HB_SHA224_BLOCK_SIZE;

    shifted_message = message + rem_len;

    sha256_transf(ctx, ctx->block, 1);
    sha256_transf(ctx, shifted_message, block_nb);

    rem_len = new_len % HB_SHA224_BLOCK_SIZE;

    memcpy(ctx->block, &shifted_message[block_nb << 6],
           rem_len);

    ctx->len = rem_len;
    ctx->tot_len += (block_nb + 1) << 6;
}
示例#4
0
void sha256_final(sha256_ctx *ctx, unsigned char *digest)
{
    uint32 block_nb;
    uint32 pm_len;
    uint32 len_b;

    int i;

    block_nb = (1 + ((SHA256_BLOCK_SIZE - 9)
                     < (ctx->len % SHA256_BLOCK_SIZE)));

    len_b = (ctx->tot_len + ctx->len) << 3;
    pm_len = block_nb << 6;

    memset(ctx->block + ctx->len, 0, pm_len - ctx->len);
    ctx->block[ctx->len] = 0x80;
    UNPACK32(len_b, ctx->block + pm_len - 4);

    sha256_transf(ctx, ctx->block, block_nb);

    for (i = 0 ; i < 8; i++) {
        UNPACK32(ctx->h[i], &digest[i << 2]);
    }

}
示例#5
0
void sha256_final(sha256_ctx *ctx, unsigned char *digest) {
    unsigned int block_nb;
    unsigned int pm_len;
    unsigned int len_b;
#ifndef UNROLL_LOOPS
    int i;
#endif
    block_nb = (1 + ((SHA256_BLOCK_SIZE - 9) < (ctx->len % SHA256_BLOCK_SIZE)));
    len_b = (ctx->tot_len + ctx->len) << 3;
    pm_len = block_nb << 6;
    memset(ctx->block + ctx->len, 0, pm_len - ctx->len);
    ctx->block[ctx->len] = 0x80;
    UNPACK32(len_b, ctx->block + pm_len - 4);
    sha256_transf(ctx, ctx->block, block_nb);
#ifndef UNROLL_LOOPS
    for (i = 0; i < 8; i++) {
        UNPACK32(ctx->h[i], &digest[i << 2]);
    }
#else
    UNPACK32(ctx->h[0], &digest[ 0]);
    UNPACK32(ctx->h[1], &digest[ 4]);
    UNPACK32(ctx->h[2], &digest[ 8]);
    UNPACK32(ctx->h[3], &digest[12]);
    UNPACK32(ctx->h[4], &digest[16]);
    UNPACK32(ctx->h[5], &digest[20]);
    UNPACK32(ctx->h[6], &digest[24]);
    UNPACK32(ctx->h[7], &digest[28]);
#endif
}
示例#6
0
文件: sha2.c 项目: emazv72/core
void hb_sha224_final(hb_sha224_ctx *ctx, unsigned char *digest)
{
    HB_SIZE block_nb;
    HB_SIZE pm_len;
    HB_SIZE len_b;

#ifndef UNROLL_LOOPS
    int i;
#endif

    block_nb = (1 + ((HB_SHA224_BLOCK_SIZE - 9)
                     < (ctx->len % HB_SHA224_BLOCK_SIZE)));

    len_b = (ctx->tot_len + ctx->len) << 3;
    pm_len = block_nb << 6;

    memset(ctx->block + ctx->len, 0, pm_len - ctx->len);
    ctx->block[ctx->len] = 0x80;
    UNPACK32(len_b, ctx->block + pm_len - 4);

    sha256_transf(ctx, ctx->block, block_nb);

#ifndef UNROLL_LOOPS
    for (i = 0 ; i < 7; i++) {
        UNPACK32(ctx->h[i], &digest[i << 2]);
    }
#else
   UNPACK32(ctx->h[0], &digest[ 0]);
   UNPACK32(ctx->h[1], &digest[ 4]);
   UNPACK32(ctx->h[2], &digest[ 8]);
   UNPACK32(ctx->h[3], &digest[12]);
   UNPACK32(ctx->h[4], &digest[16]);
   UNPACK32(ctx->h[5], &digest[20]);
   UNPACK32(ctx->h[6], &digest[24]);
#endif /* !UNROLL_LOOPS */
}