--- ../../../php4-200007210645/ext/standard/basic_functions.c Sat Jul 8 20:45:37 2000 +++ basic_functions.c Fri Jul 21 17:22:38 2000 @@ -112,6 +112,7 @@ PHP_NAMED_FE(md5, php_if_md5, NULL) PHP_NAMED_FE(crc32, php_if_crc32, NULL) + PHP_NAMED_FE(hmac_md5, php_if_hmac_md5, NULL) PHP_FE(iptcparse, NULL) PHP_FE(iptcembed, NULL) --- ../../../php4-200007210645/ext/standard/md5.h Mon Jul 3 00:45:10 2000 +++ md5.h Fri Jul 21 17:03:25 2000 @@ -67,5 +67,5 @@ void PHP_MD5Final PROTO_LIST((unsigned char[16], PHP_MD5_CTX *)); PHP_NAMED_FUNCTION(php_if_md5); - +PHP_NAMED_FUNCTION(php_if_hmac_md5); #endif --- ../../../php4-200007210645/ext/standard/md5.c Mon Jun 5 20:45:12 2000 +++ md5.c Fri Jul 21 17:21:57 2000 @@ -53,6 +53,64 @@ } /* }}} */ +/* {{{ proto string hmac_md5(string str, string key) + Calculate the hmac md5 hash of a string using authentication key (rfc2104) */ +PHP_NAMED_FUNCTION(php_if_hmac_md5) +{ + pval **arg, **key; + + PHP_MD5_CTX context; + unsigned char digest[16]; + unsigned char k_ipad[64]; + unsigned char k_opad[64]; + unsigned char mk[16]; + int i; + char *r; + char md5str[33]; + + if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg, &key) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_string_ex(arg); + convert_to_string_ex(key); + + if((*key)->value.str.len>64) { + PHP_MD5Init(&context); + PHP_MD5Update(&context, (*key)->value.str.val, (*key)->value.str.len); + PHP_MD5Final(mk, &context); + pval_destructor(*key); + (*key)->value.str.len = strlen(mk); + (*key)->value.str.val = estrndup(mk, (*key)->value.str.len); + (*key)->type = IS_STRING; + } + for (i = 0; i < (*key)->value.str.len; i++) { + k_ipad[i] = (*key)->value.str.val[i] ^ 0x36; + k_opad[i] = (*key)->value.str.val[i] ^ 0x5c; + } + while(i<64) { + k_ipad[i] = 0x36; + k_opad[i] = 0x5c; + i++; + } + PHP_MD5Init(&context); + PHP_MD5Update(&context, k_ipad, 64); + PHP_MD5Update(&context, (*arg)->value.str.val, (*arg)->value.str.len); + PHP_MD5Final(digest, &context); + + PHP_MD5Init(&context); + PHP_MD5Update(&context, k_opad, 64); + PHP_MD5Update(&context, digest, 16); + PHP_MD5Final(digest, &context); + + md5str[0] = '\0'; + for (i = 0, r = md5str; i < 16; i++, r += 2) { + sprintf(r, "%02x", digest[i]); + } + *r = '\0'; + RETVAL_STRING(md5str,1); +} +/* }}} */ + /* * The remaining code is the reference MD5 code (md5c.c) from rfc1321 */