PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
sha1.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  sha1_ctxt
 

Macros

#define SHA1Init(x)   sha1_init((x))
 
#define SHA1Update(x, y, z)   sha1_loop((x), (y), (z))
 
#define SHA1Final(x, y)   sha1_result((y), (x))
 
#define SHA1_RESULTLEN   (160/8)
 

Typedefs

typedef struct sha1_ctxt SHA1_CTX
 

Functions

void sha1_init (struct sha1_ctxt *)
 
void sha1_pad (struct sha1_ctxt *)
 
void sha1_loop (struct sha1_ctxt *, const uint8 *, size_t)
 
void sha1_result (struct sha1_ctxt *, uint8 *)
 

Macro Definition Documentation

#define SHA1_RESULTLEN   (160/8)

Definition at line 73 of file sha1.h.

Referenced by uuid_generate_internal().

#define SHA1Final (   x,
 
)    sha1_result((y), (x))

Definition at line 71 of file sha1.h.

Referenced by int_sha1_finish(), and uuid_generate_internal().

#define SHA1Init (   x)    sha1_init((x))

Definition at line 69 of file sha1.h.

Referenced by int_sha1_reset(), and uuid_generate_internal().

#define SHA1Update (   x,
  y,
 
)    sha1_loop((x), (y), (z))

Definition at line 70 of file sha1.h.

Referenced by int_sha1_update(), and uuid_generate_internal().

Typedef Documentation

Definition at line 67 of file sha1.h.

Function Documentation

void sha1_init ( struct sha1_ctxt )

Definition at line 229 of file sha1.c.

References H.

230 {
231  memset(ctxt, 0, sizeof(struct sha1_ctxt));
232  H(0) = 0x67452301;
233  H(1) = 0xefcdab89;
234  H(2) = 0x98badcfe;
235  H(3) = 0x10325476;
236  H(4) = 0xc3d2e1f0;
237 }
Definition: sha1.h:41
#define H(n)
Definition: sha1.c:57
void sha1_loop ( struct sha1_ctxt ,
const uint8 ,
size_t   
)

Definition at line 283 of file sha1.c.

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

284 {
285  const uint8 *input;
286  size_t gaplen;
287  size_t gapstart;
288  size_t off;
289  size_t copysiz;
290 
291  input = (const uint8 *) input0;
292  off = 0;
293 
294  while (off < len)
295  {
296  gapstart = COUNT % 64;
297  gaplen = 64 - gapstart;
298 
299  copysiz = (gaplen < len - off) ? gaplen : len - off;
300  memmove(&ctxt->m.b8[gapstart], &input[off], copysiz);
301  COUNT += copysiz;
302  COUNT %= 64;
303  ctxt->c.b64[0] += copysiz * 8;
304  if (COUNT % 64 == 0)
305  sha1_step(ctxt);
306  off += copysiz;
307  }
308 }
#define COUNT
Definition: sha1.c:58
unsigned char uint8
Definition: c.h:266
#define memmove(d, s, c)
Definition: c.h:1058
static void sha1_step(struct sha1_ctxt *)
Definition: sha1.c:84
void sha1_pad ( struct sha1_ctxt )

Definition at line 240 of file sha1.c.

References sha1_ctxt::b8, sha1_ctxt::c, COUNT, sha1_ctxt::m, PUTPAD, and sha1_step().

Referenced by sha1_result().

241 {
242  size_t padlen; /* pad length in bytes */
243  size_t padstart;
244 
245  PUTPAD(0x80);
246 
247  padstart = COUNT % 64;
248  padlen = 64 - padstart;
249  if (padlen < 8)
250  {
251  memset(&ctxt->m.b8[padstart], 0, padlen);
252  COUNT += padlen;
253  COUNT %= 64;
254  sha1_step(ctxt);
255  padstart = COUNT % 64; /* should be 0 */
256  padlen = 64 - padstart; /* should be 64 */
257  }
258  memset(&ctxt->m.b8[padstart], 0, padlen - 8);
259  COUNT += (padlen - 8);
260  COUNT %= 64;
261 #ifdef WORDS_BIGENDIAN
262  PUTPAD(ctxt->c.b8[0]);
263  PUTPAD(ctxt->c.b8[1]);
264  PUTPAD(ctxt->c.b8[2]);
265  PUTPAD(ctxt->c.b8[3]);
266  PUTPAD(ctxt->c.b8[4]);
267  PUTPAD(ctxt->c.b8[5]);
268  PUTPAD(ctxt->c.b8[6]);
269  PUTPAD(ctxt->c.b8[7]);
270 #else
271  PUTPAD(ctxt->c.b8[7]);
272  PUTPAD(ctxt->c.b8[6]);
273  PUTPAD(ctxt->c.b8[5]);
274  PUTPAD(ctxt->c.b8[4]);
275  PUTPAD(ctxt->c.b8[3]);
276  PUTPAD(ctxt->c.b8[2]);
277  PUTPAD(ctxt->c.b8[1]);
278  PUTPAD(ctxt->c.b8[0]);
279 #endif
280 }
#define COUNT
Definition: sha1.c:58
#define PUTPAD(x)
Definition: sha1.c:72
static void sha1_step(struct sha1_ctxt *)
Definition: sha1.c:84
void sha1_result ( struct sha1_ctxt ,
uint8  
)

Definition at line 311 of file sha1.c.

References sha1_ctxt::b8, sha1_ctxt::h, memmove, and sha1_pad().

312 {
313  uint8 *digest;
314 
315  digest = (uint8 *) digest0;
316  sha1_pad(ctxt);
317 #ifdef WORDS_BIGENDIAN
318  memmove(digest, &ctxt->h.b8[0], 20);
319 #else
320  digest[0] = ctxt->h.b8[3];
321  digest[1] = ctxt->h.b8[2];
322  digest[2] = ctxt->h.b8[1];
323  digest[3] = ctxt->h.b8[0];
324  digest[4] = ctxt->h.b8[7];
325  digest[5] = ctxt->h.b8[6];
326  digest[6] = ctxt->h.b8[5];
327  digest[7] = ctxt->h.b8[4];
328  digest[8] = ctxt->h.b8[11];
329  digest[9] = ctxt->h.b8[10];
330  digest[10] = ctxt->h.b8[9];
331  digest[11] = ctxt->h.b8[8];
332  digest[12] = ctxt->h.b8[15];
333  digest[13] = ctxt->h.b8[14];
334  digest[14] = ctxt->h.b8[13];
335  digest[15] = ctxt->h.b8[12];
336  digest[16] = ctxt->h.b8[19];
337  digest[17] = ctxt->h.b8[18];
338  digest[18] = ctxt->h.b8[17];
339  digest[19] = ctxt->h.b8[16];
340 #endif
341 }
unsigned char uint8
Definition: c.h:266
#define memmove(d, s, c)
Definition: c.h:1058
void sha1_pad(struct sha1_ctxt *ctxt)
Definition: sha1.c:240