summaryrefslogtreecommitdiff
path: root/ext/standard/sha1.c
diff options
context:
space:
mode:
authorDerick Rethans <derick@php.net>2003-02-18 20:31:19 +0000
committerDerick Rethans <derick@php.net>2003-02-18 20:31:19 +0000
commitd95c41eddb2db3ebbbec863cd9ed29299575ac85 (patch)
treeeadf323e66fd4fa27c39123a4bb4babb1cdeed6d /ext/standard/sha1.c
parentdd0462c78f5ab6fdf4e7f543db08eb7833bc7d9a (diff)
downloadphp-git-d95c41eddb2db3ebbbec863cd9ed29299575ac85.tar.gz
- Added new parameter to sha1() and md5() which return the digest as
binary data. (Original patch by Michael Bretterklieber <mbretter@jawa.at>) - Added test cases for sha1() and md5() based on the testvectors in RFC 1321 and RFC 3174. @- Added new parameter to sha1() and md5() which return the digest as @ binary data. (Michael Bretterklieber <mbretter@jawa.at>, Derick)
Diffstat (limited to 'ext/standard/sha1.c')
-rw-r--r--ext/standard/sha1.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/ext/standard/sha1.c b/ext/standard/sha1.c
index 420c349414..765f9d46f2 100644
--- a/ext/standard/sha1.c
+++ b/ext/standard/sha1.c
@@ -37,26 +37,33 @@ PHPAPI void make_sha1_digest(char *sha1str, unsigned char *digest)
*sha1str = '\0';
}
-/* {{{ proto string sha1(string str)
+/* {{{ proto string sha1(string str [, bool raw_output])
Calculate the sha1 hash of a string */
PHP_FUNCTION(sha1)
{
- zval **arg;
+ char *arg;
+ int arg_len;
+ zend_bool raw_output = 0;
char sha1str[41];
PHP_SHA1_CTX context;
- unsigned char digest[20];
+ unsigned char digest[21];
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &arg, &arg_len, &raw_output) == FAILURE) {
+ return;
}
- convert_to_string_ex(arg);
sha1str[0] = '\0';
PHP_SHA1Init(&context);
- PHP_SHA1Update(&context, Z_STRVAL_PP(arg), Z_STRLEN_PP(arg));
+ PHP_SHA1Update(&context, arg, arg_len);
PHP_SHA1Final(digest, &context);
- make_sha1_digest(sha1str, digest);
- RETVAL_STRING(sha1str, 1);
+ if (raw_output) {
+ digest[20] = '\0';
+ RETURN_STRINGL(digest, 20, 1);
+ } else {
+ make_sha1_digest(sha1str, digest);
+ RETVAL_STRING(sha1str, 1);
+ }
+
}
/* }}} */