Comments (8)
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.
Fixed by version 0.4.0: thanks @flashultra!
from crypto.
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.
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.
I made a quick diff between the 2 implementations, and there is some differences in Sha256.str2blks()
method (crypto
on left, stdlib on right):
from crypto.
Maybe I'm going crazy, but you can make one little test:
- Copy original Sha256.hx file in new subfolder /haxe/crypto/ where your Main.hx file is.
- Compile to php
- 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.
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.
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)
- Travis : Type not found : haxe.crypto.Aes HOT 3
- Does it support Aes-256 bit HOT 2
- Incorrect result for AES CTR 128 Bit HOT 7
- Error "haxe.io.Bytes should be String" HOT 3
- Haxelib says latest version is 1.0.2-alpha, but 0.4.0 was published more recently? HOT 2
- Need PKCS5 Padding HOT 6
- Haxe-crypto HOT 9
- [Neko specific issue] Uncaught exception - load.c(398) : Invalid module : main.n HOT 4
- PHP test failures HOT 2
- Sha256 Unicode test failed HOT 7
- BCrypt is too slow HOT 10
- [eval] Ripemd-160 test failed on Appveyor HOT 2
- Compatibility for Haxe 3 HOT 5
- [feature request] rsa support HOT 4
- Publish on haxelib HOT 2
- Use Vector instead of Array HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crypto.