Giter VIP home page Giter VIP logo

Comments (8)

flashultra avatar flashultra commented on May 29, 2024

The problem is with bitwise shift left operation in PHP ( and Python) as it is mention here :
HaxeFoundation/haxe#7533

For example , this: 1634873650 << 25 will return C2E46264000000 in PHP, but 64000000 on other targets.
One possible solution could be to apply mask 0xFFFFFFFF for each bitwise left operation ( for PHP target)
About PR #12 , yes it's not released yet.

The last version is crypto 0.3.0 ( for some reason alpha is before the last one).

from crypto.

cedx avatar cedx commented on May 29, 2024

Fixed by version 0.4.0: thanks @flashultra!

from crypto.

flashultra avatar flashultra commented on May 29, 2024

Are you sure about the results using SHA-256 hash code without the crypto enabled ?
I did some tests and also compare the code and it returns wrong value for me -> c029836676a2e454cdafcd48507c211c8d52f0e06db9bd6d7a409fcf970f57c6 ( this is without crypto lib)

from crypto.

cedx avatar cedx commented on May 29, 2024

I confirm that the haxe.crypto.Sha256 class from the standard library returns the right value... at least with my setup (Haxe 4.2.4 / PHP 8.1.0 on Windows 10, also tested successfully on CentOS 8).

Minimal repro:

// File "Main.hx"
import haxe.crypto.Sha256;
import php.Global;

function main() {
	trace(Global.hash("sha256", "FooBar123"));
	trace(Sha256.encode("FooBar123"));
}

With this command:

haxe --main Main --php . --cmd "php index.php"

Output:

Main.hx:6: 77853caf12f9d2020f3715accd9c7b15738705daf03650906af17a7a655c2ee2
Main.hx:7: 77853caf12f9d2020f3715accd9c7b15738705daf03650906af17a7a655c2ee2

from crypto.

cedx avatar cedx commented on May 29, 2024

I made a quick diff between the 2 implementations, and there is some differences in Sha256.str2blks() method (crypto on left, stdlib on right):

image

from crypto.

flashultra avatar flashultra commented on May 29, 2024

Maybe I'm going crazy, but you can make one little test:

  1. Copy original Sha256.hx file in new subfolder /haxe/crypto/ where your Main.hx file is.
  2. Compile to php
  3. Run the test
    So your directory structure should be
 | -- Main.hx
 |---haxe/
    |-crypto/
         |----Sha256.hx

The idea is to use the local file ( which should be the same as Sha256.hx in Haxetoolkit

from crypto.

cedx avatar cedx commented on May 29, 2024

Whoa! Really weird... Effectively, if I make a local copy, the SHA-256 is wrong and results in:
c029836676a2e454cdafcd48507c211c8d52f0e06db9bd6d7a409fcf970f57c6

If I remove or rename the local copy, the result is:
77853caf12f9d2020f3715accd9c7b15738705daf03650906af17a7a655c2ee2

But there is of course an explanation...
After checking the generated files, I saw that, without a local copy, the compiler use this file in the final output:
https://github.com/HaxeFoundation/haxe/blob/development/std/php/_std/haxe/crypto/Sha256.hx

from crypto.

flashultra avatar flashultra commented on May 29, 2024

Yes, php target obviously uses a native function .
Well , the problem ( for int32) with the shift left operation still remains and could cause another function to fail , but we'll see.

from crypto.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.