PostgreSQL Source Code  git master
sha1_int.h File Reference
#include "common/sha1.h"
Include dependency graph for sha1_int.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  pg_sha1_ctx
 

Functions

void pg_sha1_init (pg_sha1_ctx *ctx)
 
void pg_sha1_update (pg_sha1_ctx *ctx, const uint8 *data, size_t len)
 
void pg_sha1_final (pg_sha1_ctx *ctx, uint8 *dest)
 

Function Documentation

◆ pg_sha1_final()

void pg_sha1_final ( pg_sha1_ctx ctx,
uint8 dest 
)

Definition at line 365 of file sha1.c.

References sha1_pad(), and sha1_result().

Referenced by pg_cryptohash_final().

366 {
367  sha1_pad(ctx);
368  sha1_result(dest, ctx);
369 }
static void sha1_result(uint8 *digest0, pg_sha1_ctx *ctx)
Definition: sha1.c:276
static void sha1_pad(pg_sha1_ctx *ctx)
Definition: sha1.c:233

◆ pg_sha1_init()

void pg_sha1_init ( pg_sha1_ctx ctx)

Definition at line 316 of file sha1.c.

References H.

Referenced by pg_cryptohash_init().

317 {
318  memset(ctx, 0, sizeof(pg_sha1_ctx));
319  H(0) = 0x67452301;
320  H(1) = 0xefcdab89;
321  H(2) = 0x98badcfe;
322  H(3) = 0x10325476;
323  H(4) = 0xc3d2e1f0;
324 }
#define H(n)
Definition: sha1.c:75

◆ pg_sha1_update()

void pg_sha1_update ( pg_sha1_ctx ctx,
const uint8 data,
size_t  len 
)

Definition at line 332 of file sha1.c.

References pg_sha1_ctx::b64, pg_sha1_ctx::b8, pg_sha1_ctx::c, COUNT, pg_sha1_ctx::m, and sha1_step().

Referenced by pg_cryptohash_update().

333 {
334  const uint8 *input;
335  size_t gaplen;
336  size_t gapstart;
337  size_t off;
338  size_t copysiz;
339 
340  input = (const uint8 *) data;
341  off = 0;
342 
343  while (off < len)
344  {
345  gapstart = COUNT % 64;
346  gaplen = 64 - gapstart;
347 
348  copysiz = (gaplen < len - off) ? gaplen : len - off;
349  memmove(&ctx->m.b8[gapstart], &input[off], copysiz);
350  COUNT += copysiz;
351  COUNT %= 64;
352  ctx->c.b64[0] += copysiz * 8;
353  if (COUNT % 64 == 0)
354  sha1_step(ctx);
355  off += copysiz;
356  }
357 }
#define COUNT
Definition: sha1.c:76
unsigned char uint8
Definition: c.h:439
union pg_sha1_ctx::@40 m
union pg_sha1_ctx::@39 c
uint8 b8[20]
Definition: sha1_int.h:60
static void sha1_step(pg_sha1_ctx *ctx)
Definition: sha1.c:90
uint64 b64[1]
Definition: sha1_int.h:66