Coder Social home page Coder Social logo

Fuzzing about constantine HOT 4 CLOSED

mratsim avatar mratsim commented on July 24, 2024
Fuzzing

from constantine.

Comments (4)

guidovranken avatar guidovranken commented on July 24, 2024 1

Thanks for pinging me @paulmillr !

@mratsim My project supports a wide range of operations including pairing cryptography and bignum operations and it has found hundreds of bugs in major libraries. Let me know if you'd like to integrate a module for constantine..

from constantine.

mratsim avatar mratsim commented on July 24, 2024 1

Some progress towards fuzzing.

There is a new bindings generator, which can be called with nimble bindings which will generate a DLL for BLS12_381 and the Pasta curves and the accompanying headers.

For now serialization is restricted to only field elements Fp and Fr and the dll wasn't tested at all.

Before running the actual code the "NimMain" function like ctt_bls12381_NimMain should be called, it populates CPU runtime detection (for now that's the only runtime stuff). On that note, I might add a pure C compilation target for fuzzing that as well.

Example bindings: https://github.com/mratsim/constantine/blob/37354e9/bindings/generated/constantine_bls12_381.h

Some example C code to load that and property-based test the code or differential fuzz vs GMP in the CI will be added in the future as an example.

from constantine.

mratsim avatar mratsim commented on July 24, 2024

Easy initial fuzzing targets:

  • Multiplication against Squaring
  • pow(prime-2) against Euclid inversion
  • pow((p-1)/2) should always be 0, 1 or p-1 (Euler's Criterion, Legendre Symbol, Quadratic Residuosity test)
  • squaring against sqrt
  • isSquare against sqrt_if_square
  • multiplication against inversion
  • EC add against EC double

Note: Coverage-guided fuzzers like libFuzzer try to trigger all codepaths based on branches in the code.
Constantine doesn't have branch which makes fuzzing harder.
Have to find the article/paper that mentioned that, apparently for fuzzing they reintroduced branches (how?) to help the fuzzer.

https://blog.fuzzing-project.org/31-Fuzzing-Math-miscalculations-in-OpenSSLs-BN_mod_exp-CVE-2015-3193.html

Fuzzing versus branch-free code

After reporting the bug I was asked by the OpenSSL developers if I could do a similar test on their HMAC implementation. I did that and the result is interesting. At first I was confused: A while after the fuzzing started american fuzzy lop was only reporting two code paths. Usually it finds dozends of code paths within seconds.

This happens because cryptographic code is often implemented in a branch-free way. That means that there are no if-blocks that will execute different parts of the code depending on the input. The reason this is done is to protect against all sorts of sidechannel attacks. This conflicts with the way modern fuzzers like american fuzzy lop or libfuzzer work. They use the detection of new code paths as a way to be smart about their inputs.

Pascal Cuoq on Friday, December 4. 2015:
You can re-introduce, for the purpose of fuzzing, the if-then-elses that, for the purpose of avoiding timing attacks, have been made into constant-time selections with a patch similar to the one shown here for an old version of OpenSSL:

http://pastebin.com/rdLyQRVU

from constantine.

paulmillr avatar paulmillr commented on July 24, 2024

cc @guidovranken who is a world-class fuzzer - he may find this library and fuzzing ideas interesting

from constantine.

Related Issues (20)

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.