Back to index

glibc  2.9
Classes | Functions
sha512.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  sha512_ctx

Functions

void __sha512_init_ctx (struct sha512_ctx *ctx) __THROW
void __sha512_process_bytes (const void *buffer, size_t len, struct sha512_ctx *ctx) __THROW
void * __sha512_finish_ctx (struct sha512_ctx *ctx, void *resbuf) __THROW

Function Documentation

void* __sha512_finish_ctx ( struct sha512_ctx ctx,
void *  resbuf 
)

Definition at line 231 of file sha512.c.

{
  /* Take yet unprocessed bytes into account.  */
  uint64_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 >= 112 ? 128 + 112 - bytes : 112 - bytes;
  memcpy (&ctx->buffer[bytes], fillbuf, pad);

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

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

  /* Put result from CTX in first 64 bytes following RESBUF.  */
  for (unsigned int i = 0; i < 8; ++i)
    ((uint64_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 __sha512_init_ctx ( struct sha512_ctx ctx)

Definition at line 208 of file sha512.c.

{
  ctx->H[0] = UINT64_C (0x6a09e667f3bcc908);
  ctx->H[1] = UINT64_C (0xbb67ae8584caa73b);
  ctx->H[2] = UINT64_C (0x3c6ef372fe94f82b);
  ctx->H[3] = UINT64_C (0xa54ff53a5f1d36f1);
  ctx->H[4] = UINT64_C (0x510e527fade682d1);
  ctx->H[5] = UINT64_C (0x9b05688c2b3e6c1f);
  ctx->H[6] = UINT64_C (0x1f83d9abfb41bd6b);
  ctx->H[7] = UINT64_C (0x5be0cd19137e2179);

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

Here is the caller graph for this function:

void __sha512_process_bytes ( const void *  buffer,
size_t  len,
struct sha512_ctx ctx 
)