Back to index

openldap  2.4.31
Classes | Defines | Typedefs | Functions
sha2.h File Reference
#include <sys/types.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

Defines

#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 SHA512_CTX SHA384_CTX

Functions

void SHA256_Init (SHA256_CTX *)
void SHA256_Update (SHA256_CTX *, const u_int8_t *, size_t)
void SHA256_Final (u_int8_t[SHA256_DIGEST_LENGTH], SHA256_CTX *)
char * SHA256_End (SHA256_CTX *, char[SHA256_DIGEST_STRING_LENGTH])
char * SHA256_Data (const u_int8_t *, size_t, char[SHA256_DIGEST_STRING_LENGTH])
void SHA384_Init (SHA384_CTX *)
void SHA384_Update (SHA384_CTX *, const u_int8_t *, size_t)
void SHA384_Final (u_int8_t[SHA384_DIGEST_LENGTH], SHA384_CTX *)
char * SHA384_End (SHA384_CTX *, char[SHA384_DIGEST_STRING_LENGTH])
char * SHA384_Data (const u_int8_t *, size_t, char[SHA384_DIGEST_STRING_LENGTH])
void SHA512_Init (SHA512_CTX *)
void SHA512_Update (SHA512_CTX *, const u_int8_t *, size_t)
void SHA512_Final (u_int8_t[SHA512_DIGEST_LENGTH], SHA512_CTX *)
char * SHA512_End (SHA512_CTX *, char[SHA512_DIGEST_STRING_LENGTH])
char * SHA512_Data (const u_int8_t *, size_t, char[SHA512_DIGEST_STRING_LENGTH])

Class Documentation

struct _SHA256_CTX

Definition at line 111 of file sha2.h.

Class Members
u_int64_t bitcount
u_int8_t buffer
u_int32_t state
struct _SHA512_CTX

Definition at line 116 of file sha2.h.

Class Members
u_int64_t bitcount
u_int8_t buffer
u_int64_t state

Define Documentation

#define SHA256_BLOCK_LENGTH   64

Definition at line 59 of file sha2.h.

#define SHA256_DIGEST_LENGTH   32

Definition at line 60 of file sha2.h.

Definition at line 61 of file sha2.h.

#define SHA384_BLOCK_LENGTH   128

Definition at line 62 of file sha2.h.

#define SHA384_DIGEST_LENGTH   48

Definition at line 63 of file sha2.h.

Definition at line 64 of file sha2.h.

#define SHA512_BLOCK_LENGTH   128

Definition at line 65 of file sha2.h.

#define SHA512_DIGEST_LENGTH   64

Definition at line 66 of file sha2.h.

Definition at line 67 of file sha2.h.


Typedef Documentation

typedef struct _SHA256_CTX SHA256_CTX

Definition at line 124 of file sha2.h.

typedef struct _SHA512_CTX SHA512_CTX

Function Documentation

char* SHA256_Data ( const u_int8_t *  ,
size_t  ,
char  [SHA256_DIGEST_STRING_LENGTH] 
)

Definition at line 655 of file sha2.c.

                                                                                               {
       SHA256_CTX    context;

       SHA256_Init(&context);
       SHA256_Update(&context, data, len);
       return SHA256_End(&context, digest);
}

Here is the call graph for this function:

char* SHA256_End ( SHA256_CTX ,
char  [SHA256_DIGEST_STRING_LENGTH] 
)
void SHA256_Final ( u_int8_t  [SHA256_DIGEST_LENGTH],
SHA256_CTX  
)

Definition at line 337 of file sha2.c.

                                      {
       if (context == (SHA256_CTX*)0) {
              return;
       }
       MEMCPY_BCOPY(context->state, sha256_initial_hash_value, SHA256_DIGEST_LENGTH);
       MEMSET_BZERO(context->buffer, SHA256_BLOCK_LENGTH);
       context->bitcount = 0;
}

Here is the caller graph for this function:

void SHA256_Update ( SHA256_CTX ,
const u_int8_t *  ,
size_t   
)

Definition at line 521 of file sha2.c.

                                                                           {
       unsigned int  freespace, usedspace;

       if (len == 0) {
              /* Calling with no data is valid - we do nothing */
              return;
       }

       /* Sanity check: */
       assert(context != (SHA256_CTX*)0 && data != (sha2_byte*)0);

       usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH;
       if (usedspace > 0) {
              /* Calculate how much free space is available in the buffer */
              freespace = SHA256_BLOCK_LENGTH - usedspace;

              if (len >= freespace) {
                     /* Fill the buffer completely and process it */
                     MEMCPY_BCOPY(&context->buffer[usedspace], data, freespace);
                     context->bitcount += freespace << 3;
                     len -= freespace;
                     data += freespace;
                     SHA256_Transform(context, (sha2_word32*)context->buffer);
              } else {
                     /* The buffer is not yet full */
                     MEMCPY_BCOPY(&context->buffer[usedspace], data, len);
                     context->bitcount += len << 3;
                     /* Clean up: */
                     usedspace = freespace = 0;
                     return;
              }
       }
       while (len >= SHA256_BLOCK_LENGTH) {
              /* Process as many complete blocks as we can */
              SHA256_Transform(context, (sha2_word32*)data);
              context->bitcount += SHA256_BLOCK_LENGTH << 3;
              len -= SHA256_BLOCK_LENGTH;
              data += SHA256_BLOCK_LENGTH;
       }
       if (len > 0) {
              /* There's left-overs, so save 'em */
              MEMCPY_BCOPY(context->buffer, data, len);
              context->bitcount += len << 3;
       }
       /* Clean up: */
       usedspace = freespace = 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* SHA384_Data ( const u_int8_t *  ,
size_t  ,
char  [SHA384_DIGEST_STRING_LENGTH] 
)

Definition at line 1059 of file sha2.c.

                                                                                               {
       SHA384_CTX    context;

       SHA384_Init(&context);
       SHA384_Update(&context, data, len);
       return SHA384_End(&context, digest);
}

Here is the call graph for this function:

char* SHA384_End ( SHA384_CTX ,
char  [SHA384_DIGEST_STRING_LENGTH] 
)
void SHA384_Final ( u_int8_t  [SHA384_DIGEST_LENGTH],
SHA384_CTX  
)

Definition at line 994 of file sha2.c.

                                      {
       if (context == (SHA384_CTX*)0) {
              return;
       }
       MEMCPY_BCOPY(context->state, sha384_initial_hash_value, SHA512_DIGEST_LENGTH);
       MEMSET_BZERO(context->buffer, SHA384_BLOCK_LENGTH);
       context->bitcount[0] = context->bitcount[1] = 0;
}

Here is the caller graph for this function:

void SHA384_Update ( SHA384_CTX ,
const u_int8_t *  ,
size_t   
)

Definition at line 1003 of file sha2.c.

                                                                           {
       SHA512_Update((SHA512_CTX*)context, data, len);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* SHA512_Data ( const u_int8_t *  ,
size_t  ,
char  [SHA512_DIGEST_STRING_LENGTH] 
)

Definition at line 984 of file sha2.c.

                                                                                               {
       SHA512_CTX    context;

       SHA512_Init(&context);
       SHA512_Update(&context, data, len);
       return SHA512_End(&context, digest);
}

Here is the call graph for this function:

char* SHA512_End ( SHA512_CTX ,
char  [SHA512_DIGEST_STRING_LENGTH] 
)
void SHA512_Final ( u_int8_t  [SHA512_DIGEST_LENGTH],
SHA512_CTX  
)

Definition at line 665 of file sha2.c.

                                      {
       if (context == (SHA512_CTX*)0) {
              return;
       }
       MEMCPY_BCOPY(context->state, sha512_initial_hash_value, SHA512_DIGEST_LENGTH);
       MEMSET_BZERO(context->buffer, SHA512_BLOCK_LENGTH);
       context->bitcount[0] = context->bitcount[1] =  0;
}

Here is the caller graph for this function:

void SHA512_Update ( SHA512_CTX ,
const u_int8_t *  ,
size_t   
)

Definition at line 843 of file sha2.c.

                                                                           {
       unsigned int  freespace, usedspace;

       if (len == 0) {
              /* Calling with no data is valid - we do nothing */
              return;
       }

       /* Sanity check: */
       assert(context != (SHA512_CTX*)0 && data != (sha2_byte*)0);

       usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH;
       if (usedspace > 0) {
              /* Calculate how much free space is available in the buffer */
              freespace = SHA512_BLOCK_LENGTH - usedspace;

              if (len >= freespace) {
                     /* Fill the buffer completely and process it */
                     MEMCPY_BCOPY(&context->buffer[usedspace], data, freespace);
                     ADDINC128(context->bitcount, freespace << 3);
                     len -= freespace;
                     data += freespace;
                     SHA512_Transform(context, (sha2_word64*)context->buffer);
              } else {
                     /* The buffer is not yet full */
                     MEMCPY_BCOPY(&context->buffer[usedspace], data, len);
                     ADDINC128(context->bitcount, len << 3);
                     /* Clean up: */
                     usedspace = freespace = 0;
                     return;
              }
       }
       while (len >= SHA512_BLOCK_LENGTH) {
              /* Process as many complete blocks as we can */
              SHA512_Transform(context, (sha2_word64*)data);
              ADDINC128(context->bitcount, SHA512_BLOCK_LENGTH << 3);
              len -= SHA512_BLOCK_LENGTH;
              data += SHA512_BLOCK_LENGTH;
       }
       if (len > 0) {
              /* There's left-overs, so save 'em */
              MEMCPY_BCOPY(context->buffer, data, len);
              ADDINC128(context->bitcount, len << 3);
       }
       /* Clean up: */
       usedspace = freespace = 0;
}

Here is the call graph for this function:

Here is the caller graph for this function: