Back to index

php5  5.3.10
Classes | Functions
php_hash_sha.h File Reference
#include "ext/standard/sha1.h"
#include "ext/standard/basic_functions.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  PHP_SHA224_CTX
struct  PHP_SHA256_CTX
struct  PHP_SHA384_CTX
struct  PHP_SHA512_CTX

Functions

PHP_HASH_API void PHP_SHA224Init (PHP_SHA224_CTX *)
PHP_HASH_API void PHP_SHA224Update (PHP_SHA224_CTX *, const unsigned char *, unsigned int)
PHP_HASH_API void PHP_SHA224Final (unsigned char[28], PHP_SHA224_CTX *)
PHP_HASH_API void PHP_SHA256Init (PHP_SHA256_CTX *)
PHP_HASH_API void PHP_SHA256Update (PHP_SHA256_CTX *, const unsigned char *, unsigned int)
PHP_HASH_API void PHP_SHA256Final (unsigned char[32], PHP_SHA256_CTX *)
PHP_HASH_API void PHP_SHA384Init (PHP_SHA384_CTX *)
PHP_HASH_API void PHP_SHA384Update (PHP_SHA384_CTX *, const unsigned char *, unsigned int)
PHP_HASH_API void PHP_SHA384Final (unsigned char[48], PHP_SHA384_CTX *)
PHP_HASH_API void PHP_SHA512Init (PHP_SHA512_CTX *)
PHP_HASH_API void PHP_SHA512Update (PHP_SHA512_CTX *, const unsigned char *, unsigned int)
PHP_HASH_API void PHP_SHA512Final (unsigned char[64], PHP_SHA512_CTX *)

Class Documentation

struct PHP_SHA224_CTX

Definition at line 54 of file php_hash_sha.h.

Class Members
unsigned char buffer
php_hash_uint32 count
php_hash_uint32 state
struct PHP_SHA256_CTX

Definition at line 65 of file php_hash_sha.h.

Class Members
unsigned char buffer
php_hash_uint32 count
php_hash_uint32 state
struct PHP_SHA384_CTX

Definition at line 76 of file php_hash_sha.h.

Class Members
unsigned char buffer
php_hash_uint64 count
php_hash_uint64 state
struct PHP_SHA512_CTX

Definition at line 87 of file php_hash_sha.h.

Class Members
unsigned char buffer
php_hash_uint64 count
php_hash_uint64 state

Function Documentation

PHP_HASH_API void PHP_SHA224Final ( unsigned  char[28],
PHP_SHA224_CTX  
)

Definition at line 581 of file hash_sha.c.

{
       unsigned char bits[8];
       unsigned int index, padLen;

       /* Save number of bits */
       bits[7] = (unsigned char) (context->count[0] & 0xFF);
       bits[6] = (unsigned char) ((context->count[0] >> 8) & 0xFF);
       bits[5] = (unsigned char) ((context->count[0] >> 16) & 0xFF);
       bits[4] = (unsigned char) ((context->count[0] >> 24) & 0xFF);
       bits[3] = (unsigned char) (context->count[1] & 0xFF);
       bits[2] = (unsigned char) ((context->count[1] >> 8) & 0xFF);
       bits[1] = (unsigned char) ((context->count[1] >> 16) & 0xFF);
       bits[0] = (unsigned char) ((context->count[1] >> 24) & 0xFF);

       /* Pad out to 56 mod 64.
        */
       index = (unsigned int) ((context->count[0] >> 3) & 0x3f);
       padLen = (index < 56) ? (56 - index) : (120 - index);
       PHP_SHA224Update(context, PADDING, padLen);

       /* Append length (before padding) */
       PHP_SHA224Update(context, bits, 8);

       /* Store state in digest */
       SHAEncode32(digest, context->state, 28);

       /* Zeroize sensitive information.
        */
       memset((unsigned char*) context, 0, sizeof(*context));
}

Here is the call graph for this function:

Definition at line 521 of file hash_sha.c.

{
       context->count[0] = context->count[1] = 0;
       /* Load magic initialization constants.
        */
       context->state[0] = 0xc1059ed8;
       context->state[1] = 0x367cd507;
       context->state[2] = 0x3070dd17;
       context->state[3] = 0xf70e5939;
       context->state[4] = 0xffc00b31;
       context->state[5] = 0x68581511;
       context->state[6] = 0x64f98fa7;
       context->state[7] = 0xbefa4fa4;
}
PHP_HASH_API void PHP_SHA224Update ( PHP_SHA224_CTX ,
const unsigned char *  ,
unsigned  int 
)

Definition at line 542 of file hash_sha.c.

{
       unsigned int i, index, partLen;

       /* Compute number of bytes mod 64 */
       index = (unsigned int) ((context->count[0] >> 3) & 0x3F);

       /* Update number of bits */
       if ((context->count[0] += ((php_hash_uint32) inputLen << 3)) < ((php_hash_uint32) inputLen << 3)) {
              context->count[1]++;
       }
       context->count[1] += ((php_hash_uint32) inputLen >> 29);

       partLen = 64 - index;

       /* Transform as many times as possible.
        */
       if (inputLen >= partLen) {
              memcpy((unsigned char*) & context->buffer[index], (unsigned char*) input, partLen);
              SHA256Transform(context->state, context->buffer);

              for (i = partLen; i + 63 < inputLen; i += 64) {
                     SHA256Transform(context->state, &input[i]);
              }

              index = 0;
       } else {
              i = 0;
       }

       /* Buffer remaining input */
       memcpy((unsigned char*) & context->buffer[index], (unsigned char*) & input[i], inputLen - i);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHP_HASH_API void PHP_SHA256Final ( unsigned  char[32],
PHP_SHA256_CTX  
)

Definition at line 658 of file hash_sha.c.

{
       unsigned char bits[8];
       unsigned int index, padLen;

       /* Save number of bits */
       bits[7] = (unsigned char) (context->count[0] & 0xFF);
       bits[6] = (unsigned char) ((context->count[0] >> 8) & 0xFF);
       bits[5] = (unsigned char) ((context->count[0] >> 16) & 0xFF);
       bits[4] = (unsigned char) ((context->count[0] >> 24) & 0xFF);
       bits[3] = (unsigned char) (context->count[1] & 0xFF);
       bits[2] = (unsigned char) ((context->count[1] >> 8) & 0xFF);
       bits[1] = (unsigned char) ((context->count[1] >> 16) & 0xFF);
       bits[0] = (unsigned char) ((context->count[1] >> 24) & 0xFF);
       
       /* Pad out to 56 mod 64.
        */
       index = (unsigned int) ((context->count[0] >> 3) & 0x3f);
       padLen = (index < 56) ? (56 - index) : (120 - index);
       PHP_SHA256Update(context, PADDING, padLen);

       /* Append length (before padding) */
       PHP_SHA256Update(context, bits, 8);

       /* Store state in digest */
       SHAEncode32(digest, context->state, 32);

       /* Zeroize sensitive information.
        */
       memset((unsigned char*) context, 0, sizeof(*context));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 461 of file hash_sha.c.

{
       context->count[0] = context->count[1] = 0;
       /* Load magic initialization constants.
        */
       context->state[0] = 0x6a09e667;
       context->state[1] = 0xbb67ae85;
       context->state[2] = 0x3c6ef372;
       context->state[3] = 0xa54ff53a;
       context->state[4] = 0x510e527f;
       context->state[5] = 0x9b05688c;
       context->state[6] = 0x1f83d9ab;
       context->state[7] = 0x5be0cd19;
}

Here is the caller graph for this function:

PHP_HASH_API void PHP_SHA256Update ( PHP_SHA256_CTX ,
const unsigned char *  ,
unsigned  int 
)

Definition at line 619 of file hash_sha.c.

{
       unsigned int i, index, partLen;

       /* Compute number of bytes mod 64 */
       index = (unsigned int) ((context->count[0] >> 3) & 0x3F);

       /* Update number of bits */
       if ((context->count[0] += ((php_hash_uint32) inputLen << 3)) < ((php_hash_uint32) inputLen << 3)) {
              context->count[1]++;
       }
       context->count[1] += ((php_hash_uint32) inputLen >> 29);

       partLen = 64 - index;

       /* Transform as many times as possible.
        */
       if (inputLen >= partLen) {
              memcpy((unsigned char*) & context->buffer[index], (unsigned char*) input, partLen);
              SHA256Transform(context->state, context->buffer);

              for (i = partLen; i + 63 < inputLen; i += 64) {
                     SHA256Transform(context->state, &input[i]);
              }

              index = 0;
       } else {
              i = 0;
       }

       /* Buffer remaining input */
       memcpy((unsigned char*) & context->buffer[index], (unsigned char*) & input[i], inputLen - i);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHP_HASH_API void PHP_SHA384Final ( unsigned  char[48],
PHP_SHA384_CTX  
)

Definition at line 872 of file hash_sha.c.

{
       unsigned char bits[16];
       unsigned int index, padLen;

       /* Save number of bits */
       bits[15] = (unsigned char) (context->count[0] & 0xFF);
       bits[14] = (unsigned char) ((context->count[0] >> 8) & 0xFF);
       bits[13] = (unsigned char) ((context->count[0] >> 16) & 0xFF);
       bits[12] = (unsigned char) ((context->count[0] >> 24) & 0xFF);
       bits[11] = (unsigned char) ((context->count[0] >> 32) & 0xFF);
       bits[10] = (unsigned char) ((context->count[0] >> 40) & 0xFF);
       bits[9]  = (unsigned char) ((context->count[0] >> 48) & 0xFF);
       bits[8]  = (unsigned char) ((context->count[0] >> 56) & 0xFF);
       bits[7]  = (unsigned char) (context->count[1] & 0xFF);
       bits[6]  = (unsigned char) ((context->count[1] >> 8) & 0xFF);
       bits[5]  = (unsigned char) ((context->count[1] >> 16) & 0xFF);
       bits[4]  = (unsigned char) ((context->count[1] >> 24) & 0xFF);
       bits[3]  = (unsigned char) ((context->count[1] >> 32) & 0xFF);
       bits[2]  = (unsigned char) ((context->count[1] >> 40) & 0xFF);
       bits[1]  = (unsigned char) ((context->count[1] >> 48) & 0xFF);
       bits[0]  = (unsigned char) ((context->count[1] >> 56) & 0xFF);
       
       /* Pad out to 112 mod 128.
        */
       index = (unsigned int) ((context->count[0] >> 3) & 0x7f);
       padLen = (index < 112) ? (112 - index) : (240 - index);
       PHP_SHA384Update(context, PADDING, padLen);

       /* Append length (before padding) */
       PHP_SHA384Update(context, bits, 16);

       /* Store state in digest */
       SHAEncode64(digest, context->state, 48);

       /* Zeroize sensitive information.
        */
       memset((unsigned char*) context, 0, sizeof(*context));
}

Here is the call graph for this function:

Definition at line 770 of file hash_sha.c.

{
       context->count[0] = context->count[1] = 0;
       /* Load magic initialization constants.
        */
       context->state[0] = L64(0xcbbb9d5dc1059ed8);
       context->state[1] = L64(0x629a292a367cd507);
       context->state[2] = L64(0x9159015a3070dd17);
       context->state[3] = L64(0x152fecd8f70e5939);
       context->state[4] = L64(0x67332667ffc00b31);
       context->state[5] = L64(0x8eb44a8768581511);
       context->state[6] = L64(0xdb0c2e0d64f98fa7);
       context->state[7] = L64(0x47b5481dbefa4fa4);
}
PHP_HASH_API void PHP_SHA384Update ( PHP_SHA384_CTX ,
const unsigned char *  ,
unsigned  int 
)

Definition at line 833 of file hash_sha.c.

{
       unsigned int i, index, partLen;

       /* Compute number of bytes mod 128 */
       index = (unsigned int) ((context->count[0] >> 3) & 0x7F);

       /* Update number of bits */
       if ((context->count[0] += ((php_hash_uint64) inputLen << 3)) < ((php_hash_uint64) inputLen << 3)) {
              context->count[1]++;
       }
       context->count[1] += ((php_hash_uint64) inputLen >> 61);

       partLen = 128 - index;

       /* Transform as many times as possible.
        */
       if (inputLen >= partLen) {
              memcpy((unsigned char*) & context->buffer[index], (unsigned char*) input, partLen);
              SHA512Transform(context->state, context->buffer);

              for (i = partLen; i + 127 < inputLen; i += 128) {
                     SHA512Transform(context->state, &input[i]);
              }

              index = 0;
       } else {
              i = 0;
       }

       /* Buffer remaining input */
       memcpy((unsigned char*) & context->buffer[index], (unsigned char*) & input[i], inputLen - i);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHP_HASH_API void PHP_SHA512Final ( unsigned  char[64],
PHP_SHA512_CTX  
)

Definition at line 986 of file hash_sha.c.

{
       unsigned char bits[16];
       unsigned int index, padLen;

       /* Save number of bits */
       bits[15] = (unsigned char) (context->count[0] & 0xFF);
       bits[14] = (unsigned char) ((context->count[0] >> 8) & 0xFF);
       bits[13] = (unsigned char) ((context->count[0] >> 16) & 0xFF);
       bits[12] = (unsigned char) ((context->count[0] >> 24) & 0xFF);
       bits[11] = (unsigned char) ((context->count[0] >> 32) & 0xFF);
       bits[10] = (unsigned char) ((context->count[0] >> 40) & 0xFF);
       bits[9]  = (unsigned char) ((context->count[0] >> 48) & 0xFF);
       bits[8]  = (unsigned char) ((context->count[0] >> 56) & 0xFF);
       bits[7]  = (unsigned char) (context->count[1] & 0xFF);
       bits[6]  = (unsigned char) ((context->count[1] >> 8) & 0xFF);
       bits[5]  = (unsigned char) ((context->count[1] >> 16) & 0xFF);
       bits[4]  = (unsigned char) ((context->count[1] >> 24) & 0xFF);
       bits[3]  = (unsigned char) ((context->count[1] >> 32) & 0xFF);
       bits[2]  = (unsigned char) ((context->count[1] >> 40) & 0xFF);
       bits[1]  = (unsigned char) ((context->count[1] >> 48) & 0xFF);
       bits[0]  = (unsigned char) ((context->count[1] >> 56) & 0xFF);

       /* Pad out to 112 mod 128.
        */
       index = (unsigned int) ((context->count[0] >> 3) & 0x7f);
       padLen = (index < 112) ? (112 - index) : (240 - index);
       PHP_SHA512Update(context, PADDING, padLen);

       /* Append length (before padding) */
       PHP_SHA512Update(context, bits, 16);

       /* Store state in digest */
       SHAEncode64(digest, context->state, 64);

       /* Zeroize sensitive information.
        */
       memset((unsigned char*) context, 0, sizeof(*context));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 926 of file hash_sha.c.

{
       context->count[0] = context->count[1] = 0;
       /* Load magic initialization constants.
        */
       context->state[0] = L64(0x6a09e667f3bcc908);
       context->state[1] = L64(0xbb67ae8584caa73b);
       context->state[2] = L64(0x3c6ef372fe94f82b);
       context->state[3] = L64(0xa54ff53a5f1d36f1);
       context->state[4] = L64(0x510e527fade682d1);
       context->state[5] = L64(0x9b05688c2b3e6c1f);
       context->state[6] = L64(0x1f83d9abfb41bd6b);
       context->state[7] = L64(0x5be0cd19137e2179);
}

Here is the caller graph for this function:

PHP_HASH_API void PHP_SHA512Update ( PHP_SHA512_CTX ,
const unsigned char *  ,
unsigned  int 
)

Definition at line 947 of file hash_sha.c.

{
       unsigned int i, index, partLen;

       /* Compute number of bytes mod 128 */
       index = (unsigned int) ((context->count[0] >> 3) & 0x7F);

       /* Update number of bits */
       if ((context->count[0] += ((php_hash_uint64) inputLen << 3)) < ((php_hash_uint64) inputLen << 3)) {
              context->count[1]++;
       }
       context->count[1] += ((php_hash_uint64) inputLen >> 61);

       partLen = 128 - index;

       /* Transform as many times as possible.
        */
       if (inputLen >= partLen) {
              memcpy((unsigned char*) & context->buffer[index], (unsigned char*) input, partLen);
              SHA512Transform(context->state, context->buffer);

              for (i = partLen; i + 127 < inputLen; i += 128) {
                     SHA512Transform(context->state, &input[i]);
              }

              index = 0;
       } else {
              i = 0;
       }

       /* Buffer remaining input */
       memcpy((unsigned char*) & context->buffer[index], (unsigned char*) & input[i], inputLen - i);
}

Here is the call graph for this function:

Here is the caller graph for this function: