ReactOS 0.4.15-dev-7924-g5949c20
sha2.h File Reference
#include <basetsd.h>
Include dependency graph for sha2.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _SHA256_CTX
 
struct  _SHA512_CTX
 

Macros

#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 UINT8 sha2_byte
 
typedef UINT32 sha2_word32
 
typedef UINT64 sha2_word64
 
typedef struct _SHA256_CTX SHA256_CTX
 
typedef struct _SHA512_CTX SHA512_CTX
 
typedef SHA512_CTX SHA384_CTX
 

Functions

void SHA256_Init (SHA256_CTX *)
 
void SHA256_Update (SHA256_CTX *, const sha2_byte *, size_t)
 
void SHA256_Final (sha2_byte[SHA256_DIGEST_LENGTH], SHA256_CTX *)
 
charSHA256_End (SHA256_CTX *, char[SHA256_DIGEST_STRING_LENGTH])
 
charSHA256_Data (const sha2_byte *, size_t, char[SHA256_DIGEST_STRING_LENGTH])
 
void SHA384_Init (SHA384_CTX *)
 
void SHA384_Update (SHA384_CTX *, const sha2_byte *, size_t)
 
void SHA384_Final (sha2_byte[SHA384_DIGEST_LENGTH], SHA384_CTX *)
 
charSHA384_End (SHA384_CTX *, char[SHA384_DIGEST_STRING_LENGTH])
 
charSHA384_Data (const sha2_byte *, size_t, char[SHA384_DIGEST_STRING_LENGTH])
 
void SHA512_Init (SHA512_CTX *)
 
void SHA512_Update (SHA512_CTX *, const sha2_byte *, size_t)
 
void SHA512_Final (sha2_byte[SHA512_DIGEST_LENGTH], SHA512_CTX *)
 
charSHA512_End (SHA512_CTX *, char[SHA512_DIGEST_STRING_LENGTH])
 
charSHA512_Data (const sha2_byte *, size_t, char[SHA512_DIGEST_STRING_LENGTH])
 

Macro Definition Documentation

◆ SHA256_BLOCK_LENGTH

#define SHA256_BLOCK_LENGTH   64

Definition at line 39 of file sha2.h.

◆ SHA256_DIGEST_LENGTH

#define SHA256_DIGEST_LENGTH   32

Definition at line 40 of file sha2.h.

◆ SHA256_DIGEST_STRING_LENGTH

#define SHA256_DIGEST_STRING_LENGTH   (SHA256_DIGEST_LENGTH * 2 + 1)

Definition at line 41 of file sha2.h.

◆ SHA384_BLOCK_LENGTH

#define SHA384_BLOCK_LENGTH   128

Definition at line 42 of file sha2.h.

◆ SHA384_DIGEST_LENGTH

#define SHA384_DIGEST_LENGTH   48

Definition at line 43 of file sha2.h.

◆ SHA384_DIGEST_STRING_LENGTH

#define SHA384_DIGEST_STRING_LENGTH   (SHA384_DIGEST_LENGTH * 2 + 1)

Definition at line 44 of file sha2.h.

◆ SHA512_BLOCK_LENGTH

#define SHA512_BLOCK_LENGTH   128

Definition at line 45 of file sha2.h.

◆ SHA512_DIGEST_LENGTH

#define SHA512_DIGEST_LENGTH   64

Definition at line 46 of file sha2.h.

◆ SHA512_DIGEST_STRING_LENGTH

#define SHA512_DIGEST_STRING_LENGTH   (SHA512_DIGEST_LENGTH * 2 + 1)

Definition at line 47 of file sha2.h.

Typedef Documentation

◆ SHA256_CTX

◆ sha2_byte

typedef UINT8 sha2_byte

Definition at line 51 of file sha2.h.

◆ sha2_word32

Definition at line 52 of file sha2.h.

◆ sha2_word64

Definition at line 53 of file sha2.h.

◆ SHA384_CTX

Definition at line 66 of file sha2.h.

◆ SHA512_CTX

Function Documentation

◆ SHA256_Data()

char * SHA256_Data ( const sha2_byte data,
size_t  len,
char  digest[SHA256_DIGEST_STRING_LENGTH] 
)

Definition at line 593 of file sha2.c.

593 {
595
598 return SHA256_End(&context, digest);
599}
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLenum GLsizei len
Definition: glext.h:6722
void SHA256_Init(SHA256_CTX *context)
Definition: sha2.c:275
void SHA256_Update(SHA256_CTX *context, const sha2_byte *data, size_t len)
Definition: sha2.c:459
char * SHA256_End(SHA256_CTX *context, char buffer[])
Definition: sha2.c:570
Definition: http.c:7252

◆ SHA256_End()

char * SHA256_End ( SHA256_CTX ,
char  [SHA256_DIGEST_STRING_LENGTH] 
)

◆ SHA256_Final()

void SHA256_Final ( sha2_byte  [SHA256_DIGEST_LENGTH],
SHA256_CTX  
)

◆ SHA256_Init()

void SHA256_Init ( SHA256_CTX context)

Definition at line 275 of file sha2.c.

275 {
276 if (context == NULL) {
277 return;
278 }
281 context->bitcount = 0;
282}
#define NULL
Definition: types.h:112
static const sha2_word32 sha256_initial_hash_value[8]
Definition: sha2.c:188
#define MEMSET_BZERO(p, l)
Definition: sha2.c:115
#define MEMCPY_BCOPY(d, s, l)
Definition: sha2.c:116
#define SHA256_DIGEST_LENGTH
Definition: sha2.h:40
#define SHA256_BLOCK_LENGTH
Definition: sha2.h:39

Referenced by init_hash_impl(), and SHA256_Data().

◆ SHA256_Update()

void SHA256_Update ( SHA256_CTX context,
const sha2_byte data,
size_t  len 
)

Definition at line 459 of file sha2.c.

459 {
460 unsigned int freespace, usedspace;
461
462 if (len == 0) {
463 /* Calling with no data is valid - we do nothing */
464 return;
465 }
466
467 /* Sanity check: */
468 assert(context != NULL && data != NULL);
469
470 usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH;
471 if (usedspace > 0) {
472 /* Calculate how much free space is available in the buffer */
473 freespace = SHA256_BLOCK_LENGTH - usedspace;
474
475 if (len >= freespace) {
476 /* Fill the buffer completely and process it */
477 MEMCPY_BCOPY(&context->buffer[usedspace], data, freespace);
478 context->bitcount += freespace << 3;
479 len -= freespace;
480 data += freespace;
482 } else {
483 /* The buffer is not yet full */
484 MEMCPY_BCOPY(&context->buffer[usedspace], data, len);
485 context->bitcount += len << 3;
486 /* Clean up: */
487 usedspace = freespace = 0;
488 return;
489 }
490 }
491 while (len >= SHA256_BLOCK_LENGTH) {
492 /* Process as many complete blocks as we can */
494 context->bitcount += SHA256_BLOCK_LENGTH << 3;
497 }
498 if (len > 0) {
499 /* There's left-overs, so save 'em */
500 MEMCPY_BCOPY(context->buffer, data, len);
501 context->bitcount += len << 3;
502 }
503 /* Clean up: */
504 usedspace = freespace = 0;
505}
#define assert(x)
Definition: debug.h:53
void SHA256_Transform(SHA256_CTX *, const sha2_word32 *)
Definition: sha2.c:379
UINT32 sha2_word32
Definition: sha2.h:52

Referenced by SHA256_Data(), and update_hash_impl().

◆ SHA384_Data()

char * SHA384_Data ( const sha2_byte data,
size_t  len,
char  digest[SHA384_DIGEST_STRING_LENGTH] 
)

Definition at line 997 of file sha2.c.

997 {
999
1002 return SHA384_End(&context, digest);
1003}
char * SHA384_End(SHA384_CTX *context, char buffer[])
Definition: sha2.c:974
void SHA384_Init(SHA384_CTX *context)
Definition: sha2.c:932
void SHA384_Update(SHA384_CTX *context, const sha2_byte *data, size_t len)
Definition: sha2.c:941

◆ SHA384_End()

char * SHA384_End ( SHA384_CTX ,
char  [SHA384_DIGEST_STRING_LENGTH] 
)

◆ SHA384_Final()

void SHA384_Final ( sha2_byte  [SHA384_DIGEST_LENGTH],
SHA384_CTX  
)

◆ SHA384_Init()

void SHA384_Init ( SHA384_CTX context)

Definition at line 932 of file sha2.c.

932 {
933 if (context == NULL) {
934 return;
935 }
938 context->bitcount[0] = context->bitcount[1] = 0;
939}
static const sha2_word64 sha384_initial_hash_value[8]
Definition: sha2.c:244
#define SHA512_DIGEST_LENGTH
Definition: sha2.h:46
#define SHA384_BLOCK_LENGTH
Definition: sha2.h:42

Referenced by init_hash_impl(), and SHA384_Data().

◆ SHA384_Update()

void SHA384_Update ( SHA384_CTX context,
const sha2_byte data,
size_t  len 
)

Definition at line 941 of file sha2.c.

941 {
943}
void SHA512_Update(SHA512_CTX *context, const sha2_byte *data, size_t len)
Definition: sha2.c:781

Referenced by SHA384_Data(), and update_hash_impl().

◆ SHA512_Data()

char * SHA512_Data ( const sha2_byte data,
size_t  len,
char  digest[SHA512_DIGEST_STRING_LENGTH] 
)

Definition at line 922 of file sha2.c.

922 {
924
927 return SHA512_End(&context, digest);
928}
char * SHA512_End(SHA512_CTX *context, char buffer[])
Definition: sha2.c:899
void SHA512_Init(SHA512_CTX *context)
Definition: sha2.c:603

◆ SHA512_End()

char * SHA512_End ( SHA512_CTX ,
char  [SHA512_DIGEST_STRING_LENGTH] 
)

◆ SHA512_Final()

void SHA512_Final ( sha2_byte  [SHA512_DIGEST_LENGTH],
SHA512_CTX  
)

◆ SHA512_Init()

void SHA512_Init ( SHA512_CTX context)

Definition at line 603 of file sha2.c.

603 {
604 if (context == NULL) {
605 return;
606 }
609 context->bitcount[0] = context->bitcount[1] = 0;
610}
static const sha2_word64 sha512_initial_hash_value[8]
Definition: sha2.c:256
#define SHA512_BLOCK_LENGTH
Definition: sha2.h:45

Referenced by init_hash_impl(), and SHA512_Data().

◆ SHA512_Update()

void SHA512_Update ( SHA512_CTX context,
const sha2_byte data,
size_t  len 
)

Definition at line 781 of file sha2.c.

781 {
782 unsigned int freespace, usedspace;
783
784 if (len == 0) {
785 /* Calling with no data is valid - we do nothing */
786 return;
787 }
788
789 /* Sanity check: */
790 assert(context != NULL && data != NULL);
791
792 usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH;
793 if (usedspace > 0) {
794 /* Calculate how much free space is available in the buffer */
795 freespace = SHA512_BLOCK_LENGTH - usedspace;
796
797 if (len >= freespace) {
798 /* Fill the buffer completely and process it */
799 MEMCPY_BCOPY(&context->buffer[usedspace], data, freespace);
800 ADDINC128(context->bitcount, freespace << 3);
801 len -= freespace;
802 data += freespace;
804 } else {
805 /* The buffer is not yet full */
806 MEMCPY_BCOPY(&context->buffer[usedspace], data, len);
807 ADDINC128(context->bitcount, len << 3);
808 /* Clean up: */
809 usedspace = freespace = 0;
810 return;
811 }
812 }
813 while (len >= SHA512_BLOCK_LENGTH) {
814 /* Process as many complete blocks as we can */
816 ADDINC128(context->bitcount, SHA512_BLOCK_LENGTH << 3);
819 }
820 if (len > 0) {
821 /* There's left-overs, so save 'em */
822 MEMCPY_BCOPY(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
void SHA512_Transform(SHA512_CTX *, const sha2_word64 *)
Definition: sha2.c:703
UINT64 sha2_word64
Definition: sha2.h:53

Referenced by SHA384_Update(), SHA512_Data(), and update_hash_impl().