php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #75266 hash_algos doesnt work properly for listing HMAC algos
Submitted: 2017-09-27 09:41 UTC Modified: 2017-09-27 15:21 UTC
From: phpdoc at mail dot my1 dot info Assigned: cmb (profile)
Status: Closed Package: *Encryption and hash functions
PHP Version: 7.2.0RC2 OS: Win8.1 x64
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: phpdoc at mail dot my1 dot info
New email:
PHP Version: OS:

 

 [2017-09-27 09:41 UTC] phpdoc at mail dot my1 dot info
Description:
------------
---
From manual page: http://www.php.net/function.hash-hmac
---

This is a mix of a doc problem and a feature request.

Simply said the doc says, that one should refer to the hash_algos funtion to see what can be used for HMACs but that's not entirely true, as it contains algorithms that cant be used for HMAC.

while I know that it's totally stupid to use things like CRC32 or Adler32 for HMACs, but this doesnt change that there isnt a proper list fuunction for HMACs.



Test script:
---------------
<?php
$garray=[];
$barray=[];

foreach (hash_algos() as $hashx) {
  $h=hash_hmac($hashx,"hello","hello");
  if($h) {$garray[$hashx]=$h;} else {$barray[$hashx]=$h;}
}
var_dump($garray,$barray);
if(count($barray)>0) {
  echo "hashes that dont work for HMAC are: ".implode(", ",array_keys($barray));
}
else {
  echo "all hashes are compatible with HMAC"
}
?>

Expected result:
----------------
a list of algos and their HMACs, an empty array for the hashes that dont work as well as the output "all hashes are compatible with HMAC"

Actual result:
--------------
2 Lists of algos one which has working hmacs and another which has false as the value, as well as the output:

"hashes that dont work for HMAC are: adler32, crc32, crc32b, fnv132, fnv1a32, fnv164, fnv1a64, joaat"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-09-27 10:04 UTC] requinix@php.net
-Type: Feature/Change Request +Type: Documentation Problem
 [2017-09-27 10:04 UTC] requinix@php.net
PHP 7.2 will introduce a function specifically for this:

  array hash_hmac_algos ( void )
  Return a list of registered hashing algorithms suitable for hash_hmac

I don't think documentation has been written for it yet.

There's also a minor issue where hash_hmac_algos() isn't listed in the New Functions section of UPGRADING.
 [2017-09-27 15:13 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=343152
Log: Fix bug #75266: hash_algos doesnt work properly for listing HMAC algos
 [2017-09-27 15:21 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2017-09-27 15:21 UTC] cmb@php.net
> here's also a minor issue where hash_hmac_algos() isn't listed in the New
> Functions section of UPGRADING.

Fixed with <http://git.php.net/?p=php-src.git;a=commit;h=b0d6d27>.

This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2020-02-07 06:06 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=38fb328862c0e14c63c33f295398e28b66d301d5
Log: Fix bug #75266: hash_algos doesnt work properly for listing HMAC algos
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 14:01:31 2024 UTC