Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BLAKE3 hash support #6358

Closed
wants to merge 9 commits into from
Closed

BLAKE3 hash support #6358

wants to merge 9 commits into from

Conversation

divinity76
Copy link
Contributor

@divinity76 divinity76 commented Oct 20, 2020

this is not ready for merging (but i hope it will become eventually)
this is a plea for help.

i want BLAKE3 hash support in php, some justifications can be found here https://bugs.php.net/bug.php?id=79492 (tl;dr: CS-secure hash, predecessor BLAKE was nearly crowned "SHA3" (SHA3 finalist), and it's very fast in software)

i have no idea how to add a hash to php, never done it before, just trying to guess / mimic the other hashes.

i have not implemented advanced-ish features of BLAKE3 (eg XOF or keyed hashing), and i have no plans to do that either. (at least not until php's generic hash api adds support)

the code works right now, eg

$ ./sapi/cli/php -v
PHP 8.1.0-dev (cli) (built: Oct 20 2020 17:33:50) ( NTS DEBUG )
Copyright (c) The PHP Group
Zend Engine v4.1.0-dev, Copyright (c) Zend Technologies

$ dd if=/dev/zero bs=10000 count=1 | ./sapi/cli/php -r 'echo hash("blake3",stream_get_contents(STDIN),false),"\n";'
1+0 records in
1+0 records out
10000 bytes (10 kB, 9,8 KiB) copied, 4,4446e-05 s, 225 MB/s
2c80729798539602ba83ee69feac7f9fb5b6b7507cb8f30d29fe2cf317f4e404

$ dd if=/dev/zero bs=10000 count=1 | b3sum
1+0 records in
1+0 records out
10000 bytes (10 kB, 9,8 KiB) copied, 4,473e-05 s, 224 MB/s
2c80729798539602ba83ee69feac7f9fb5b6b7507cb8f30d29fe2cf317f4e404  -

but does not generate optimally performant code, i'm just (barely) being able to compile it using a generic portable C-implementation, while blake3 has optimized versions for x86's SSE2/SSE4.1/AVX2/AVX512 instructions, and ARM's Neon instructions, - edit: SSE2/SSE4.1/AVX2/AVX512 has now been added for gcc+(windows|unix)+x86_64

so..


ext/hash/blake3/blake3_dispatch.c could probably be modified to use Zend/zend_cpuinfo.c instead of its own cpu detection scheme, is that important?


in ext/hash/config.m4 of this branch is

EXT_HASH_BLAKE3_SOURCES="hash_blake3.c blake3/blake3.c blake3/blake3_dispatch.c blake3/blake3_portable.c"
dnl todo: add optimized versions of blake3 for sse2/sse4.1/avx2/avx512/arm+neon 
dnl ...when applicable...
dnl EXT_HASH_BLAKE3_SOURCES="$EXT_HASH_BLAKE3_SOURCES blake3/blake3_sse2.c blake3/blake3_sse41.c blake3/blake3_avx2.c blake3/blake3_avx512.c"

PHP_HASH_CFLAGS="$PHP_HASH_CFLAGS -DBLAKE3_NO_SSE2 -DBLAKE3_NO_SSE41 -DBLAKE3_NO_AVX2 -DBLAKE3_NO_AVX512"

this is far from ideal, when it's x86, blake3_sse2.c should be compiled with -msse2, and blake3_sse41.c should be compiled with -msse4.1 and blake3_avx2.c should be compiled with -mavx2 and blake3_avx512.c should be compiled with -mavx512f -mavx512vl
, and none of them should be compiled with -DBLAKE3_NO_SSE2 -DBLAKE3_NO_SSE41 -DBLAKE3_NO_AVX2 -DBLAKE3_NO_AVX512
(alternatively, the S files can be used, eg blake3_sse2_x86-64_unix.S and blake3_sse2_x86-64_windows_gnu.S and blake3_sse2_x86-64_windows_msvc.asm etc, they generate even faster code, and compile faster, but deciding which of them to include is even more difficult, "x86 or x86_64? unix or windows? gcc or msvc?" )

but.. i have no idea how to tell that to m4. any help would be apricated

edit: fixed for the most part ( but not ARM+NEON..)


in ext/hash/php_hash_blake3.h is

// typedef struct blake3_hasher PHP_BLAKE3_CTX;
#define PHP_BLAKE3_CTX blake3_hasher
// help: what is V supposed to be?
#define PHP_BLAKE3_SPEC "l.I_HAVE_NO_IDEA_WHAT_THIS_IS_SUPPOSED_TO_BE"

.. that definitely isn't right, but i don't know what it should be.
edit: changed it to b8b8qb64bbbbb1760, i think that's right?

any help would be apricated

blake3 official  "C optimized implementation" version 0.3.7, obtained with "helper_script_blake3_version_fetcher.php"..
haven't figured out how to add the SSE2/SSE4.1/AVX2/AVX512/Arm+Neon optimized versions when applicable.. and other issues too, like PHP_BLAKE3_SPEC

going to ask for help upstream
@divinity76 divinity76 changed the title BLAKE3 hash support (help?) BLAKE3 hash support Oct 20, 2020
@divinity76 divinity76 changed the title (help?) BLAKE3 hash support BLAKE3 hash support Oct 20, 2020
@divinity76 divinity76 marked this pull request as ready for review October 20, 2020 16:58
@Girgias
Copy link
Member

Girgias commented Oct 20, 2020

Test failures are legit

@divinity76
Copy link
Contributor Author

divinity76 commented Oct 20, 2020

@Girgias thanks, i tried adding blake3 to the msvc config (portable c version like on m4), but i don't have a msvc system to test on so no idea if it was done correctly or not ( 9acf958 )

and i added blake3 to the

ext/hash/tests/hash-clone.phpt 
ext/hash/tests/hash_algos.phpt 
ext/hash/tests/hash_copy_001.phpt 
ext/hash/tests/hash_hmac_algos.phpt 

tests so they pass now ( 9e5e9ef ), that leaves

=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
Hash: serialize()/unserialize() [ext/hash/tests/hash_serialize_001.phpt]
Hash: serialize()/unserialize() with HASH_HMAC [ext/hash/tests/hash_serialize_002.phpt]
Test disk_free_space and its alias diskfreespace() functions : basic functionality [ext/standard/tests/file/disk_free_space_basic.phpt]
=====================================================================

... maybe the serialize issues has to do with the

#define PHP_BLAKE3_SPEC "l.I_HAVE_NO_IDEA_WHAT_THIS_IS_SUPPOSED_TO_BE"

thing? also when i try running the code i just get

hans@xDevAd:~/projects/php-src$ php test3.php
string(3) "md2"
PHP Fatal error:  Uncaught Exception: Serialization of 'HashContext' is not allowed in /home/hans/projects/php-src/test3.php:8
Stack trace:
#0 /home/hans/projects/php-src/test3.php(8): serialize()
#1 {main}
  thrown in /home/hans/projects/php-src/test3.php on line 8

did i mess up HashContext serialization / md2 somehow?

@divinity76
Copy link
Contributor Author

yup.. i somehow messed up

$ct = hash_init("md2");
var_dump(serialize($ct));

not sure how i did that tho, unless the problem is

#define PHP_BLAKE3_SPEC "l.I_HAVE_NO_IDEA_WHAT_THIS_IS_SUPPOSED_TO_BE"

?

@Girgias
Copy link
Member

Girgias commented Oct 20, 2020

I'm not familiar with the Hash Extension but have you looked at the implementation of php_hash_serialize() ? As this seems to be the function which handles the serialization

@divinity76
Copy link
Contributor Author

divinity76 commented Oct 20, 2020

hmm... thinking out loud here,
unpacking

typedef struct {
  uint32_t cv[8];
  uint64_t chunk_counter;
  uint8_t buf[BLAKE3_BLOCK_LEN];
  uint8_t buf_len;
  uint8_t blocks_compressed;
  uint8_t flags;
} blake3_chunk_state;

typedef struct {
  uint32_t key[8];
  blake3_chunk_state chunk;
  uint8_t cv_stack_len;
  // The stack size is MAX_DEPTH + 1 because we do lazy merging. For example,
  // with 7 chunks, we have 3 entries in the stack. Adding an 8th chunk
  // requires a 4th entry, rather than merging everything down to 1, because we
  // don't know whether more input is coming. This is different from how the
  // reference implementation does things.
  uint8_t cv_stack[(BLAKE3_MAX_DEPTH + 1) * BLAKE3_OUT_LEN];
} blake3_hasher;

i basically get

struct {
  uint32_t[8];
  uint32_t[8];
  uint64_t;
  uint8_t[64];
  uint8_t;
  uint8_t;
  uint8_t;
  uint8_t;
  uint8_t[1760];
}

.. i guess i need to figure out how to say that to

/* Serialize a hash context according to a `spec` string.
   Spec contents:
   b[COUNT] -- serialize COUNT bytes
   s[COUNT] -- serialize COUNT 16-bit integers
   l[COUNT] -- serialize COUNT 32-bit integers
   q[COUNT] -- serialize COUNT 64-bit integers
   i[COUNT] -- serialize COUNT `int`s
   B[COUNT] -- skip COUNT bytes
   S[COUNT], L[COUNT], etc. -- uppercase versions skip instead of read
   . (must be last character) -- assert that the hash context has exactly
       this size
   Example: "llllllb64l16." is the spec for an MD5 context: 6 32-bit
   integers, followed by 64 bytes, then 16 32-bit integers, and that's
   exactly the size of the context.

   The serialization result is an array. Each integer is serialized as a
   32-bit integer, except that a run of 2 or more bytes is encoded as a
   string, and each 64-bit integer is serialized as two 32-bit integers, least
   significant bits first. This allows 32-bit and 64-bit architectures to
   interchange serialized HashContexts. */

PHP_HASH_API int php_hash_serialize_spec(const php_hashcontext_object *hash, zval *zv, const char *spec) /* {{{ */
{

which i guess means the correct SPEC string would be...

#define PHP_BLAKE3_SPEC "l8l8qb64bbbbb1760."

.. i guess?

edit: realized im not supposed to use [], so "l8l8qb64bbbbb1760."

@divinity76
Copy link
Contributor Author

divinity76 commented Oct 20, 2020

hmm, with

#define PHP_BLAKE3_SPEC "l8l8qb64bbbbb1760."

i'm getting

hans@xDevAd:~/projects/php-src$ ./sapi/cli/php test3.php

Fatal error: Uncaught Exception: HashContext for algorithm "blake3" cannot be serialized in /home/hans/projects/php-src/test3.php:5
Stack trace:
#0 [internal function]: HashContext->__serialize()
#1 /home/hans/projects/php-src/test3.php(5): serialize(Object(HashContext))
#2 {main}
  thrown in /home/hans/projects/php-src/test3.php on line 5
[Tue Oct 20 23:22:23 2020]  Script:  '/home/hans/projects/php-src/test3.php'
/home/hans/projects/php-src/Zend/zend_hash.c(278) :  Freeing 0x00007ffff7a586c0 (56 bytes), script=/home/hans/projects/php-src/test3.php
[Tue Oct 20 23:22:23 2020]  Script:  '/home/hans/projects/php-src/test3.php'
/home/hans/projects/php-src/Zend/zend_string.h(141) :  Freeing 0x00007ffff7a70080 (96 bytes), script=/home/hans/projects/php-src/test3.php
Last leak repeated 1 time
[Tue Oct 20 23:22:23 2020]  Script:  '/home/hans/projects/php-src/test3.php'
/home/hans/projects/php-src/Zend/zend_hash.c(310) :  Freeing 0x00007ffff7a84000 (1032 bytes), script=/home/hans/projects/php-src/test3.php
=== Total 4 memory leaks detected ===

so.. idk, i'm stumped

  • edit: done some testing, and i'm pretty sure that PHP_BLAKE3_SPEC is the problem, the serialize error leak numbers change depending on what the spec is, so it's probably very related

edit:
the parse error happens here:

	if (*spec == '.' && align_to(pos, max_alignment) != hash->ops->context_size) {
		return FAILURE;
	}

and adding some debugging reveals

							zend_throw_error(NULL, "ggg2 %zu , %zu", align_to(pos, max_alignment) , hash->ops->context_size);

-> Fatal error: Uncaught Error: ggg2 1904 , 1912 in /home/hans/projects/php-src/test3.php:5

so.. seems that for some reason my PHP_BLAKE3_SPEC is 8 bytes off... also 8 bytes happens to be sizeof(uintptr_t) , not sure if that's related or not..

@divinity76
Copy link
Contributor Author

divinity76 commented Oct 20, 2020

got it! don't know how i came up with the original PHP_BLAKE3_SPEC, guess i read something wrong, anyhow changing it to
b8b8qb64bbbbb1760 made BLAKE3 serialization work :)
d2dd2a1 passes the existing hash testsuites it seems

edit: well something's still wrong on MSVC, guess there's something wrong with ext/hash/config.w32 .. i don't have a MSVC system to test on though, any suggestions?

i don't have a MSVC to test on, so i'm basically using the github bots to test for me..
@divinity76
Copy link
Contributor Author

divinity76 commented Oct 21, 2020

yay! fixed the MSVC compilation issue, and all built-in tests seem to pass, and the following test script outputs 100_000 dots, which is a good sign (both hash and context and clone(context) and unserialize(serialize(context)) generate the correct result for the first 100_000 zeroes )

<?php

declare(strict_types=1);
$zeroes = "";
for ($i = 0; $i < 100_000; ++$i) {
    $answer = shell_exec("head --bytes={$i} /dev/zero | b3sum --raw");
    $php_hash = hash("blake3", $zeroes, true);
    $php_hash_hc = hash_init("blake3");
    hash_update($php_hash_hc, $zeroes);
    $php_hash_hc_cloned = hash_final(clone ($php_hash_hc), true);
    $php_hash_hc_serialized = hash_final(unserialize(serialize($php_hash_hc)), true);
    $php_hash_hc = hash_final($php_hash_hc, true);
    if ($answer !== $php_hash) {
        var_dump("FAILED php_hash", $i, $answer, $php_hash);
        die();
    }
    if ($answer !== $php_hash_hc) {
        var_dump("FAILED php_hash_hc", $i, $answer, $php_hash_hc);
        die();
    }
    if ($answer !== $php_hash_hc_serialized) {
        var_dump("FAILED php_hash_hc_serialized", $i, $answer, $php_hash_hc_serialized);
        die();
    }
    if ($answer !== $php_hash_hc_cloned) {
        var_dump("FAILED php_hash_hc_cloned", $i, $answer, $php_hash_hc_cloned);
        die();
    }
    $zeroes .= "\x00";
    echo ".";
}

... that still leaves the question "how to detect if you're compiling for windows or linux" and "how to detect if you're compiling for x86_64 or something else" in m4 syntax, however.. (after figuring that out, the SSE2/SSE4.1/AVX2/AVX512 versions can be added for x86_64 builds)

edit: maybe the PR at #6361 contains some of the answers

when applicable, on gnuc (don't know how to do this on msvc though.. guess i'll ask if anyone on the windows php mailing list want to fix it)

there's also a *theoretical* situation that can be optimized, when we're targeting x86_64 but neither windows nor a unix-ish system.. at that point i opted to just disable the blake asm, i have nothing to test it on, but ideally we should use the ext/hash/blake3/blake3_avx512.c & co files in this situation (i cba looking into that)
@divinity76
Copy link
Contributor Author

divinity76 commented Oct 21, 2020

i think i figured it out, blake3 avx512/avx2/sse4.1/sse2 is now enabled for:
gcc+windows+x86_64
and
gcc+unix+x86_64

and as expected, blake3 is significantly faster than every other cryptographically-secure hash on the list (and even some non-crypto hashes! like the fnv family),
running ext/hash/bench.php on a CPU i7-8565U with AVX2 (but no AVX512) yields:

crc32b       0.001390
crc32c       0.001472
crc32        0.001626
adler32      0.013046
blake3       0.014249
fnv164       0.023157
fnv1a32      0.023443
fnv132       0.023665
md4          0.025338
fnv1a64      0.025490
joaat        0.030619
tiger128,3   0.033700
md5          0.033745
tiger192,3   0.034064
tiger160,3   0.034194
tiger128,4   0.043849
tiger160,4   0.044443
sha1         0.045933
tiger192,4   0.046402
sha3-224     0.061014
sha3-256     0.066776
ripemd128    0.069601
sha512/256   0.071233
sha512/224   0.072522
sha384       0.072561
haval160,3   0.073814
ripemd256    0.073880
haval256,3   0.074894
sha512       0.075017
haval224,3   0.075532
haval192,3   0.077055
haval128,3   0.077107
sha3-384     0.085347
ripemd320    0.098025
ripemd160    0.098233
haval224,4   0.104044
haval256,4   0.105642
haval192,4   0.106256
haval160,4   0.107436
haval128,4   0.109624
sha224       0.117680
sha256       0.117752
sha3-512     0.123096
haval256,5   0.129810
haval192,5   0.130261
haval160,5   0.132877
haval128,5   0.133029
haval224,5   0.134305
whirlpool    0.184143
gost         0.315982
gost-crypto  0.318833
snefru256    0.641408
snefru       0.647867
md2          2.333430
  • 2.3 times faster than tiger128,3 (CS-secure hash, technically unbroken, but near-collisions have been found, and if memory serves, endianness is ambiguous, not one i would recommend)

  • 4.2 times faster than sha3-224 (CS-secure hash, a good one)

  • presumably it would go even faster (perhaps beating the non-crypto adler32?) if the cpu had AVX512

edit: it broke 32bit builds, hmm, looking into that

edit: fixed the 32bit builds.

.. waiting for the github bots to tell me if i succeeded or not
@divinity76
Copy link
Contributor Author

divinity76 commented Oct 21, 2020

ok i think i fixed most of the initial problems now, but this question remains:

i think ext/hash/blake3/blake3_dispatch.c could be modified to use Zend/zend_cpuinfo.c instead of its own cpu feature detection scheme,

is it important to fix that before it could be considered for upstream merging, or is it ok-ish that it's using it's own detection scheme?

AVX512/AVX2/SSE4.1/SSE2 optimized blake3 implementations for MSVC.

... not that i know how to make MSVC use them, i'm going to ask the windows php mailing list for help about that (i don't even have a MSVC system to test on)

these files should have been imported in previous commit "blake3 C code import" / 75a7e5c , but was omitted by mistake
@cmb69
Copy link
Member

cmb69 commented Oct 21, 2020

Nice work, thanks! But from the repo's README:

This implementation is just C and assembly files. It doesn't include a public-facing build system. (The Makefile in this directory is only for testing.) Instead, the intention is that you can include these files in whatever build system you're already using. This section describes the commands your build system should execute, or which you can execute by hand. Note that these steps may change in future versions.

IMHO, that's an unfortunate way to ship code. If we bundle that Blake3 implementation, we have to maintain it somehow, and it seems that are currently ~30,000 lines of code – not few of those in assembly.

@divinity76
Copy link
Contributor Author

divinity76 commented Oct 21, 2020

@cmb69 yeah.. one possible option would be to just use the "portable C" version, which would leave us with roughly 5 files to maintain, instead of ~30+ files (at the cost of performance, obviously)

another possible option would be to only use the "c intrinsics" versions, which would allow us to delete all the assembly files (eg use blake3_sse2.c and delete these: blake3_sse2_x86-64_unix.S and blake3_sse2_x86-64_windows_gnu.S and blake3_sse2_x86-64_windows_msvc.asm), that would remove a majority of the files (it would still be a lot of code, but nowhere near ~30,000 lines) - this is actually what i tried first, but each of those files need to be individually compiled with different -march= options, i couldn't figure out how get m4 to do that, so i used the asm versions instead. (could also mention that the intrinsics-versions produce somewhat slower code than the pure assembly versions, and they compile slower, but i think the difference is small)

.. if some libblake3, existed, a third option might be to just ship the portable version (~5 files or so) and have an optional compile-time --with-libblake3=path/to/libblake3, but it appears that no such thing exists.. maybe i can ask the blake3 devs if there's any interest in making something like that

edit: thought of a possible 4th option: php can just ship the portable version (~5 files), and have an optional ./configure --with-blake3-source=path/to/BLAKE3 where people who want the optimized versions can compile it in at compile-time, and perhaps have a phpinfo() entry telling if the portable version, or the optimized version is compiled in, this way the blake3 will always be available, and for projects where the performance is important, interested parties can fairly easily add in the optimized versions themselves

divinity76 added a commit to divinity76/php-src that referenced this pull request Oct 29, 2020
this time i'm only importing the portable version..
this will result in decreased performance, obiously..

if i'm importing the assembly optimized versions, it will be some ~30,000 lines ( see php#6358 )
divinity76 added a commit to divinity76/php-src that referenced this pull request Oct 30, 2020
this is a significantly smaller alternative to the PR at php#6358 ,
now blake3 "portable c" version is bundled (specifically version 0.3.7 plus a few patches that will be part of the 0.3.8 release..), and ./configure supports a new optional --with-blake3-upstream-c-source-dir=DIR argument for specifying the location of the upstream BLAKE3 C implementation, if invoked, the SSE2/SSE4.1/AVX2/AVX512 optimized versions of BLAKE3 will be compiled in when applicable (this has not been added to MSVC, i don't know how to do it on MSVC, and i don't have a MSVC system to figure it out out on, if someone think getting those optimizations available on MSVC is important, take it up with the windows php mailing list.. just getting the portable version to compile on MSVC was good enough for me.)

also userland scripts can detect at runtime if the portable version or the upstream version, of BLAKE was compiled by consulting phpinfo(), it will either say "blake3 implementation: portable 0.3.7" or "blake3 implementation: upstream X.X.X"
@mvorisek
Copy link
Contributor

I think we can bundle if needed, but have this clearly documented with:

  • the exact command(s) how it was copied from the blake3 repo
  • verify in CI, that these files are never changed manually (like calc. hash of that bundled directory and emit an error if it is different)

@divinity76
Copy link
Contributor Author

btw have an alternative PR for BLAKE3 support here #6393
(with the biggest difference being 31K sloc => 1.7K sloc and slower performance (less than half on some cpus!)), but neither PR is withdrawn currently, i want to see which PR (if any) gets more support than the other, first.

@mvorisek

the exact command(s) how it was copied from the blake3 repo

well i wrote a little script to fetch the code, https://github.com/php/php-src/blob/b79adc48dc42df22296f2e77b4de1c215771bdac/ext/hash/blake3/helper_script_blake3_version_fetcher.php
, it's the 0.3.7 release, but with 1 patch ( BLAKE3-team/BLAKE3#128 ) to blake3_dispatch.c that was accepted upstream and will be part of the 0.3.8 release..

@mvorisek
Copy link
Contributor

mvorisek commented Oct 31, 2020

the exact command(s) how it was copied from the blake3 repo

well i wrote a little script to fetch the code, https://github.com/php/php-src/blob/b79adc48dc42df22296f2e77b4de1c215771bdac/ext/hash/blake3/helper_script_blake3_version_fetcher.php
, it's the 0.3.7 release, but with 1 patch ( BLAKE3-team/BLAKE3#128 ) to blake3_dispatch.c that was accepted upstream and will be part of the 0.3.8 release..

👍 , then just add a CI test - diff if files are 1:1 with specific release version, eg. were not updated manually by a mistake - and higher SLOC should be no issue

@KalleZ
Copy link
Member

KalleZ commented Oct 31, 2020

the exact command(s) how it was copied from the blake3 repo

well i wrote a little script to fetch the code, https://github.com/php/php-src/blob/b79adc48dc42df22296f2e77b4de1c215771bdac/ext/hash/blake3/helper_script_blake3_version_fetcher.php
, it's the 0.3.7 release, but with 1 patch ( BLAKE3-team/BLAKE3#128 ) to blake3_dispatch.c that was accepted upstream and will be part of the 0.3.8 release..

👍 , then just add a CI test - diff if files are 1:1 with specific release version, eg. were not updated manually by a mistake - and higher SLOC should be no issue

We do not do this for any other bundled library so I do not see that as a hindrance for potentially including BLAKE3 support with PHP.

Or at least have that as a separate thing to do later if you want to ensure that is the case for other extensions, like PCRE2, SQLite3, ...

@Gauss23
Copy link

Gauss23 commented Nov 27, 2020

I like the idea of having Blake3 hashing implemented. Maybe think about file hashing, too. md5_file() and sha1_file() are really outdated. Better than the need to call b3sum on the command line:
https://github.com/BLAKE3-team/BLAKE3

@divinity76
Copy link
Contributor Author

@Gauss23 this PR adds blake3 to the php hash-extension, which means blake3 is also available in the hash_file function,

php -r 'echo hash_file("blake3","/dev/null");'

@cypherbits
Copy link

I'm looking forward to have this on PHP 8.1 Blake3 is an awesome substitute for the mainstream "file hash when downloading files".

Actually, I tried to make a Blake3 PHP extension here (https://github.com/cypherbits/php-blake3) and the hash is working but the hmac password is not... It's my first time making an extension and writing C.

@cypherbits
Copy link

Should be possible to have this for PHP 8.1?? @divinity76 Could you make an extension so people can use this easily right now? (I started making one but I don't know if it is good and fails with hmac)

@divinity76
Copy link
Contributor Author

Should be possible to have this for PHP 8.1?? @divinity76 Could you make an extension so people can use this easily right now? (I started making one but I don't know if it is good and fails with hmac)

right now this PR is just rotting/slowly-collecting-merge-conflicts, not sure what's needed to really get this merged upstream/8.next =/ maybe try asking the php internals mailing list?

Could you make an extension so people can use this easily right now?

no, but your extension looks like a good start, wonder how much extra it would take to hook into the hash('blake3',...) api on your extension

@cmb69
Copy link
Member

cmb69 commented Feb 23, 2021

maybe try asking the php internals mailing list?

Yes, that's the way forward. If there is no response, consider to pursue the RFC process.

@ramsey
Copy link
Member

ramsey commented Jun 9, 2021

maybe try asking the php internals mailing list?

Yes, that's the way forward. If there is no response, consider to pursue the RFC process.

Have you asked on the internals list and started the RFC process yet? If you'd like to get this or #6393 accepted for 8.1, now is the time to get the RFC into the discussion phase. I recommend presenting both options in the same RFC.

@divinity76
Copy link
Contributor Author

Have you asked on the internals list and started the RFC process yet? If you'd like to get this or #6393 accepted for 8.1, now is the time to get the RFC into the discussion phase. I recommend presenting both options in the same RFC.

no, i'm having a hard time and have no energy for non-essentials. the only way it's going into 8.1 is if someone else pushes for it.

that said, i expect to be jobless early August, then I'll have a lot of time.

@github-actions
Copy link

github-actions bot commented Feb 6, 2022

There has not been any recent activity in this PR. It will automatically be closed in 7 days if no further action is taken.

@github-actions github-actions bot added the Stale label Feb 6, 2022
@github-actions github-actions bot closed this Feb 14, 2022
@mvorisek
Copy link
Contributor

I belive this PR is valuable and should be not closed.

@divinity76
Copy link
Contributor Author

@mvorisek it needed some maintenance and someone to actively push the issue, i'm not up for it currently. also there's been a version 1.x release of the upstream blake library that should be used instead of this one (this was based on a 0.x-something of blake c lib iirc)

@cypherbits
Copy link

I really want this upstream... Meanwhile I have my extension...

@divinity76
Copy link
Contributor Author

new attempt for 8.4: #13194

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants