Back to index

glibc  2.9
Classes | Functions
sha256.h File Reference
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  sha256_ctx

Functions

void __sha256_init_ctx (struct sha256_ctx *ctx) __THROW
void __sha256_process_bytes (const void *buffer, size_t len, struct sha256_ctx *ctx) __THROW
void * __sha256_finish_ctx (struct sha256_ctx *ctx, void *resbuf) __THROW

Function Documentation

void* __sha256_finish_ctx ( struct sha256_ctx ctx,
void *  resbuf 
)

Definition at line 200 of file sha256.c.

{
  /* Take yet unprocessed bytes into account.  */
  uint32_t bytes = ctx->buflen;
  size_t pad;

  /* Now count remaining bytes.  */
  ctx->total[0] += bytes;
  if (ctx->total[0] < bytes)
    ++ctx->total[1];

  pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes;
  memcpy (&ctx->buffer[bytes], fillbuf, pad);

  /* Put the 64-bit file length in *bits* at the end of the buffer.  */
  *(uint32_t *) &ctx->buffer[bytes + pad + 4] = SWAP (ctx->total[0] << 3);
  *(uint32_t *) &ctx->buffer[bytes + pad] = SWAP ((ctx->total[1] << 3) |
                                            (ctx->total[0] >> 29));

  /* Process last bytes.  */
  sha256_process_block (ctx->buffer, bytes + pad + 8, ctx);

  /* Put result from CTX in first 32 bytes following RESBUF.  */
  for (unsigned int i = 0; i < 8; ++i)
    ((uint32_t *) resbuf)[i] = SWAP (ctx->H[i]);

  return resbuf;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void __sha256_init_ctx ( struct sha256_ctx ctx)

Definition at line 177 of file sha256.c.

{
  ctx->H[0] = 0x6a09e667;
  ctx->H[1] = 0xbb67ae85;
  ctx->H[2] = 0x3c6ef372;
  ctx->H[3] = 0xa54ff53a;
  ctx->H[4] = 0x510e527f;
  ctx->H[5] = 0x9b05688c;
  ctx->H[6] = 0x1f83d9ab;
  ctx->H[7] = 0x5be0cd19;

  ctx->total[0] = ctx->total[1] = 0;
  ctx->buflen = 0;
}

Here is the caller graph for this function:

void __sha256_process_bytes ( const void *  buffer,
size_t  len,
struct sha256_ctx ctx 
)