PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
sha2.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  _SHA256_CTX
 
struct  _SHA512_CTX
 

Macros

#define SHA256_Init   pg_SHA256_Init
 
#define SHA256_Update   pg_SHA256_Update
 
#define SHA256_Final   pg_SHA256_Final
 
#define SHA384_Init   pg_SHA384_Init
 
#define SHA384_Update   pg_SHA384_Update
 
#define SHA384_Final   pg_SHA384_Final
 
#define SHA512_Init   pg_SHA512_Init
 
#define SHA512_Update   pg_SHA512_Update
 
#define SHA512_Final   pg_SHA512_Final
 
#define SHA224_BLOCK_LENGTH   64
 
#define SHA224_DIGEST_LENGTH   28
 
#define SHA224_DIGEST_STRING_LENGTH   (SHA224_DIGEST_LENGTH * 2 + 1)
 
#define SHA256_BLOCK_LENGTH   64
 
#define SHA256_DIGEST_LENGTH   32
 
#define SHA256_DIGEST_STRING_LENGTH   (SHA256_DIGEST_LENGTH * 2 + 1)
 
#define SHA384_BLOCK_LENGTH   128
 
#define SHA384_DIGEST_LENGTH   48
 
#define SHA384_DIGEST_STRING_LENGTH   (SHA384_DIGEST_LENGTH * 2 + 1)
 
#define SHA512_BLOCK_LENGTH   128
 
#define SHA512_DIGEST_LENGTH   64
 
#define SHA512_DIGEST_STRING_LENGTH   (SHA512_DIGEST_LENGTH * 2 + 1)
 

Typedefs

typedef struct _SHA256_CTX SHA256_CTX
 
typedef struct _SHA512_CTX SHA512_CTX
 
typedef SHA256_CTX SHA224_CTX
 
typedef SHA512_CTX SHA384_CTX
 

Functions

void SHA224_Init (SHA224_CTX *)
 
void SHA224_Update (SHA224_CTX *, const uint8 *, size_t)
 
void SHA224_Final (uint8[SHA224_DIGEST_LENGTH], SHA224_CTX *)
 
void SHA256_Init (SHA256_CTX *)
 
void SHA256_Update (SHA256_CTX *, const uint8 *, size_t)
 
void SHA256_Final (uint8[SHA256_DIGEST_LENGTH], SHA256_CTX *)
 
void SHA384_Init (SHA384_CTX *)
 
void SHA384_Update (SHA384_CTX *, const uint8 *, size_t)
 
void SHA384_Final (uint8[SHA384_DIGEST_LENGTH], SHA384_CTX *)
 
void SHA512_Init (SHA512_CTX *)
 
void SHA512_Update (SHA512_CTX *, const uint8 *, size_t)
 
void SHA512_Final (uint8[SHA512_DIGEST_LENGTH], SHA512_CTX *)
 

Macro Definition Documentation

#define SHA224_BLOCK_LENGTH   64

Definition at line 53 of file sha2.h.

Referenced by int_sha224_block_len().

#define SHA224_DIGEST_LENGTH   28

Definition at line 54 of file sha2.h.

Referenced by int_sha224_len(), and SHA224_Final().

#define SHA224_DIGEST_STRING_LENGTH   (SHA224_DIGEST_LENGTH * 2 + 1)

Definition at line 55 of file sha2.h.

#define SHA256_BLOCK_LENGTH   64

Definition at line 56 of file sha2.h.

Referenced by int_sha256_block_len(), SHA224_Init(), SHA256_Init(), SHA256_Last(), and SHA256_Update().

#define SHA256_DIGEST_LENGTH   32

Definition at line 57 of file sha2.h.

Referenced by int_sha256_len(), SHA224_Init(), SHA256_Final(), and SHA256_Init().

#define SHA256_DIGEST_STRING_LENGTH   (SHA256_DIGEST_LENGTH * 2 + 1)

Definition at line 58 of file sha2.h.

#define SHA256_Final   pg_SHA256_Final

Definition at line 44 of file sha2.h.

Referenced by int_sha256_finish().

#define SHA256_Init   pg_SHA256_Init

Definition at line 42 of file sha2.h.

Referenced by int_sha256_reset().

#define SHA256_Update   pg_SHA256_Update

Definition at line 43 of file sha2.h.

Referenced by int_sha256_update().

#define SHA384_BLOCK_LENGTH   128

Definition at line 59 of file sha2.h.

Referenced by int_sha384_block_len(), and SHA384_Init().

#define SHA384_DIGEST_LENGTH   48

Definition at line 60 of file sha2.h.

Referenced by int_sha384_len(), and SHA384_Final().

#define SHA384_DIGEST_STRING_LENGTH   (SHA384_DIGEST_LENGTH * 2 + 1)

Definition at line 61 of file sha2.h.

#define SHA384_Final   pg_SHA384_Final

Definition at line 47 of file sha2.h.

Referenced by int_sha384_finish().

#define SHA384_Init   pg_SHA384_Init

Definition at line 45 of file sha2.h.

Referenced by int_sha384_reset().

#define SHA384_Update   pg_SHA384_Update

Definition at line 46 of file sha2.h.

Referenced by int_sha384_update().

#define SHA512_BLOCK_LENGTH   128

Definition at line 62 of file sha2.h.

Referenced by int_sha512_block_len(), SHA512_Init(), SHA512_Last(), and SHA512_Update().

#define SHA512_DIGEST_LENGTH   64

Definition at line 63 of file sha2.h.

Referenced by int_sha512_len(), SHA384_Init(), SHA512_Final(), and SHA512_Init().

#define SHA512_DIGEST_STRING_LENGTH   (SHA512_DIGEST_LENGTH * 2 + 1)

Definition at line 64 of file sha2.h.

#define SHA512_Final   pg_SHA512_Final

Definition at line 50 of file sha2.h.

Referenced by int_sha512_finish().

#define SHA512_Init   pg_SHA512_Init

Definition at line 48 of file sha2.h.

Referenced by int_sha512_reset().

#define SHA512_Update   pg_SHA512_Update

Definition at line 49 of file sha2.h.

Referenced by int_sha512_update().

Typedef Documentation

Definition at line 81 of file sha2.h.

Definition at line 82 of file sha2.h.

Function Documentation

void SHA224_Final ( uint8  [SHA224_DIGEST_LENGTH],
SHA224_CTX  
)
void SHA224_Init ( SHA224_CTX )

Definition at line 953 of file sha2.c.

References _SHA256_CTX::bitcount, _SHA256_CTX::buffer, NULL, sha224_initial_hash_value, SHA256_BLOCK_LENGTH, SHA256_DIGEST_LENGTH, and _SHA256_CTX::state.

Referenced by int_sha224_reset().

954 {
955  if (context == NULL)
956  return;
957  memcpy(context->state, sha224_initial_hash_value, SHA256_DIGEST_LENGTH);
958  memset(context->buffer, 0, SHA256_BLOCK_LENGTH);
959  context->bitcount = 0;
960 }
#define SHA256_BLOCK_LENGTH
Definition: sha2.h:56
#define NULL
Definition: c.h:226
#define SHA256_DIGEST_LENGTH
Definition: sha2.h:57
static const uint32 sha224_initial_hash_value[8]
Definition: sha2.c:160
void SHA224_Update ( SHA224_CTX ,
const uint8 ,
size_t   
)

Definition at line 963 of file sha2.c.

References SHA256_Update().

Referenced by int_sha224_update().

964 {
965  SHA256_Update((SHA256_CTX *) context, data, len);
966 }
void SHA256_Update(SHA256_CTX *context, const uint8 *data, size_t len)
Definition: sha2.c:451
void SHA256_Final ( uint8  [SHA256_DIGEST_LENGTH],
SHA256_CTX  
)
void SHA256_Init ( SHA256_CTX )

Definition at line 254 of file sha2.c.

References _SHA256_CTX::bitcount, _SHA256_CTX::buffer, NULL, SHA256_BLOCK_LENGTH, SHA256_DIGEST_LENGTH, sha256_initial_hash_value, and _SHA256_CTX::state.

255 {
256  if (context == NULL)
257  return;
258  memcpy(context->state, sha256_initial_hash_value, SHA256_DIGEST_LENGTH);
259  memset(context->buffer, 0, SHA256_BLOCK_LENGTH);
260  context->bitcount = 0;
261 }
#define SHA256_BLOCK_LENGTH
Definition: sha2.h:56
static const uint32 sha256_initial_hash_value[8]
Definition: sha2.c:172
#define NULL
Definition: c.h:226
#define SHA256_DIGEST_LENGTH
Definition: sha2.h:57
void SHA256_Update ( SHA256_CTX ,
const uint8 ,
size_t   
)

Definition at line 451 of file sha2.c.

References _SHA256_CTX::bitcount, _SHA256_CTX::buffer, SHA256_BLOCK_LENGTH, and SHA256_Transform().

Referenced by SHA224_Update().

452 {
453  size_t freespace,
454  usedspace;
455 
456  /* Calling with no data is valid (we do nothing) */
457  if (len == 0)
458  return;
459 
460  usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH;
461  if (usedspace > 0)
462  {
463  /* Calculate how much free space is available in the buffer */
464  freespace = SHA256_BLOCK_LENGTH - usedspace;
465 
466  if (len >= freespace)
467  {
468  /* Fill the buffer completely and process it */
469  memcpy(&context->buffer[usedspace], data, freespace);
470  context->bitcount += freespace << 3;
471  len -= freespace;
472  data += freespace;
473  SHA256_Transform(context, context->buffer);
474  }
475  else
476  {
477  /* The buffer is not yet full */
478  memcpy(&context->buffer[usedspace], data, len);
479  context->bitcount += len << 3;
480  /* Clean up: */
481  usedspace = freespace = 0;
482  return;
483  }
484  }
485  while (len >= SHA256_BLOCK_LENGTH)
486  {
487  /* Process as many complete blocks as we can */
488  SHA256_Transform(context, data);
489  context->bitcount += SHA256_BLOCK_LENGTH << 3;
490  len -= SHA256_BLOCK_LENGTH;
491  data += SHA256_BLOCK_LENGTH;
492  }
493  if (len > 0)
494  {
495  /* There's left-overs, so save 'em */
496  memcpy(context->buffer, data, len);
497  context->bitcount += len << 3;
498  }
499  /* Clean up: */
500  usedspace = freespace = 0;
501 }
#define SHA256_BLOCK_LENGTH
Definition: sha2.h:56
static void SHA256_Transform(SHA256_CTX *, const uint8 *)
Definition: sha2.c:361
void SHA384_Final ( uint8  [SHA384_DIGEST_LENGTH],
SHA384_CTX  
)
void SHA384_Init ( SHA384_CTX )

Definition at line 909 of file sha2.c.

References _SHA512_CTX::bitcount, _SHA512_CTX::buffer, NULL, SHA384_BLOCK_LENGTH, sha384_initial_hash_value, SHA512_DIGEST_LENGTH, and _SHA512_CTX::state.

910 {
911  if (context == NULL)
912  return;
913  memcpy(context->state, sha384_initial_hash_value, SHA512_DIGEST_LENGTH);
914  memset(context->buffer, 0, SHA384_BLOCK_LENGTH);
915  context->bitcount[0] = context->bitcount[1] = 0;
916 }
#define SHA384_BLOCK_LENGTH
Definition: sha2.h:59
static const uint64 sha384_initial_hash_value[8]
Definition: sha2.c:228
#define NULL
Definition: c.h:226
#define SHA512_DIGEST_LENGTH
Definition: sha2.h:63
void SHA384_Update ( SHA384_CTX ,
const uint8 ,
size_t   
)

Definition at line 919 of file sha2.c.

References SHA512_Update().

920 {
921  SHA512_Update((SHA512_CTX *) context, data, len);
922 }
void SHA512_Update(SHA512_CTX *context, const uint8 *data, size_t len)
Definition: sha2.c:777
void SHA512_Final ( uint8  [SHA512_DIGEST_LENGTH],
SHA512_CTX  
)
void SHA512_Init ( SHA512_CTX )

Definition at line 580 of file sha2.c.

References _SHA512_CTX::bitcount, _SHA512_CTX::buffer, NULL, SHA512_BLOCK_LENGTH, SHA512_DIGEST_LENGTH, sha512_initial_hash_value, and _SHA512_CTX::state.

581 {
582  if (context == NULL)
583  return;
584  memcpy(context->state, sha512_initial_hash_value, SHA512_DIGEST_LENGTH);
585  memset(context->buffer, 0, SHA512_BLOCK_LENGTH);
586  context->bitcount[0] = context->bitcount[1] = 0;
587 }
static const uint64 sha512_initial_hash_value[8]
Definition: sha2.c:240
#define NULL
Definition: c.h:226
#define SHA512_DIGEST_LENGTH
Definition: sha2.h:63
#define SHA512_BLOCK_LENGTH
Definition: sha2.h:62
void SHA512_Update ( SHA512_CTX ,
const uint8 ,
size_t   
)

Definition at line 777 of file sha2.c.

References ADDINC128, _SHA512_CTX::bitcount, _SHA512_CTX::buffer, SHA512_BLOCK_LENGTH, and SHA512_Transform().

Referenced by SHA384_Update().

778 {
779  size_t freespace,
780  usedspace;
781 
782  /* Calling with no data is valid (we do nothing) */
783  if (len == 0)
784  return;
785 
786  usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH;
787  if (usedspace > 0)
788  {
789  /* Calculate how much free space is available in the buffer */
790  freespace = SHA512_BLOCK_LENGTH - usedspace;
791 
792  if (len >= freespace)
793  {
794  /* Fill the buffer completely and process it */
795  memcpy(&context->buffer[usedspace], data, freespace);
796  ADDINC128(context->bitcount, freespace << 3);
797  len -= freespace;
798  data += freespace;
799  SHA512_Transform(context, context->buffer);
800  }
801  else
802  {
803  /* The buffer is not yet full */
804  memcpy(&context->buffer[usedspace], data, len);
805  ADDINC128(context->bitcount, len << 3);
806  /* Clean up: */
807  usedspace = freespace = 0;
808  return;
809  }
810  }
811  while (len >= SHA512_BLOCK_LENGTH)
812  {
813  /* Process as many complete blocks as we can */
814  SHA512_Transform(context, data);
815  ADDINC128(context->bitcount, SHA512_BLOCK_LENGTH << 3);
816  len -= SHA512_BLOCK_LENGTH;
817  data += SHA512_BLOCK_LENGTH;
818  }
819  if (len > 0)
820  {
821  /* There's left-overs, so save 'em */
822  memcpy(context->buffer, data, len);
823  ADDINC128(context->bitcount, len << 3);
824  }
825  /* Clean up: */
826  usedspace = freespace = 0;
827 }
#define ADDINC128(w, n)
Definition: sha2.c:89
static void SHA512_Transform(SHA512_CTX *, const uint8 *)
Definition: sha2.c:687
#define SHA512_BLOCK_LENGTH
Definition: sha2.h:62