Back to index

php5  5.3.10
Classes | Functions
sha1.h File Reference
#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_SHA1_CTX

Functions

PHPAPI void PHP_SHA1Init (PHP_SHA1_CTX *)
PHPAPI void PHP_SHA1Update (PHP_SHA1_CTX *, const unsigned char *, unsigned int)
PHPAPI void PHP_SHA1Final (unsigned char[20], PHP_SHA1_CTX *)
PHPAPI void make_sha1_digest (char *sha1str, unsigned char *digest)
 PHP_FUNCTION (sha1)
 PHP_FUNCTION (sha1_file)

Class Documentation

struct PHP_SHA1_CTX

Definition at line 27 of file sha1.h.

Class Members
unsigned char buffer
php_uint32 count
php_uint32 state

Function Documentation

PHPAPI void make_sha1_digest ( char *  sha1str,
unsigned char *  digest 
)

Definition at line 28 of file sha1.c.

{
       make_digest_ex(sha1str, digest, 20);
}

Here is the call graph for this function:

PHP_FUNCTION ( sha1  )

Definition at line 35 of file sha1.c.

{
       char *arg;
       int arg_len;
       zend_bool raw_output = 0;
       char sha1str[41];
       PHP_SHA1_CTX context;
       unsigned char digest[20];
       
       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &arg, &arg_len, &raw_output) == FAILURE) {
              return;
       }

       sha1str[0] = '\0';
       PHP_SHA1Init(&context);
       PHP_SHA1Update(&context, arg, arg_len);
       PHP_SHA1Final(digest, &context);
       if (raw_output) {
              RETURN_STRINGL(digest, 20, 1);
       } else {
              make_digest_ex(sha1str, digest, 20);
              RETVAL_STRING(sha1str, 1);
       }

}

Here is the call graph for this function:

PHP_FUNCTION ( sha1_file  )

Definition at line 66 of file sha1.c.

{
       char          *arg;
       int           arg_len;
       zend_bool raw_output = 0;
       char          sha1str[41];
       unsigned char buf[1024];
       unsigned char digest[20];
       PHP_SHA1_CTX   context;
       int           n;
       php_stream    *stream;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &arg, &arg_len, &raw_output) == FAILURE) {
              return;
       }
       
       stream = php_stream_open_wrapper(arg, "rb", REPORT_ERRORS | ENFORCE_SAFE_MODE, NULL);
       if (!stream) {
              RETURN_FALSE;
       }

       PHP_SHA1Init(&context);

       while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) {
              PHP_SHA1Update(&context, buf, n);
       }

       PHP_SHA1Final(digest, &context);

       php_stream_close(stream);

       if (n<0) {
              RETURN_FALSE;
       }

       if (raw_output) {
              RETURN_STRINGL(digest, 20, 1);
       } else {
              make_digest_ex(sha1str, digest, 20);
              RETVAL_STRING(sha1str, 1);
       }
}

Here is the call graph for this function:

PHPAPI void PHP_SHA1Final ( unsigned  char[20],
PHP_SHA1_CTX  
)

Definition at line 224 of file sha1.c.

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

       /* Save number of bits */
       bits[7] = context->count[0] & 0xFF;
       bits[6] = (context->count[0] >> 8) & 0xFF;
       bits[5] = (context->count[0] >> 16) & 0xFF;
       bits[4] = (context->count[0] >> 24) & 0xFF;
       bits[3] = context->count[1] & 0xFF;
       bits[2] = (context->count[1] >> 8) & 0xFF;
       bits[1] = (context->count[1] >> 16) & 0xFF;
       bits[0] = (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_SHA1Update(context, PADDING, padLen);

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

       /* Store state in digest */
       SHA1Encode(digest, context->state, 20);

       /* 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 165 of file sha1.c.

{
       context->count[0] = context->count[1] = 0;
       /* Load magic initialization constants.
        */
       context->state[0] = 0x67452301;
       context->state[1] = 0xefcdab89;
       context->state[2] = 0x98badcfe;
       context->state[3] = 0x10325476;
       context->state[4] = 0xc3d2e1f0;
}

Here is the caller graph for this function:

PHPAPI void PHP_SHA1Update ( PHP_SHA1_CTX ,
const unsigned char *  ,
unsigned  int 
)

Definition at line 183 of file sha1.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_uint32) inputLen << 3))
              < ((php_uint32) inputLen << 3))
              context->count[1]++;
       context->count[1] += ((php_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);
              SHA1Transform(context->state, context->buffer);

              for (i = partLen; i + 63 < inputLen; i += 64)
                     SHA1Transform(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: