KhaosT / nhcalc

Compute NeuralHash for the given image
Apache License 2.0
128 stars 10 forks source link

An implementation without the need of iOS or macOS environment #2

Open AsuharietYgvar opened 2 years ago

AsuharietYgvar commented 2 years ago

First of all, thanks for sharing your findings of this private api!

I have created AppleNeuralHash2ONNX, which can convert Apple's model to ONNX, by doing reverse-engineering on this API. It can be used to calculate neural hash with onnxruntime, even on Linux.

One suggestion: The API returns 96-bit binary data encoded in base64. You can decode it to raw binary and encode again with hex. This will result in 24 hex characters instead of 32 produced here, making it easier to do bitwise comparisons.

KhaosT commented 2 years ago

That's really cool 🙏 Hopefully these tools will help researcher to better measure NeuralHash's collision rates.

AsuharietYgvar commented 2 years ago

Indeed. In theory you can train a GAN using the exported ONNX model as the discriminator. Then you can use the generator to generate a random image for any input hash. This can be used to spam Apple with endless false positives if we can also export the CSAM database on device.

nicolas17 commented 2 years ago

if we can also export the CSAM database on device

No you can't.

image