Giter Site home page Giter Site logo

quarkslab / crypto-condor Goto Github PK

View Code? Open in Web Editor NEW
7.0 4.0 1.0 199.17 MB

crypto-condor is a Python library for compliance testing of implementations of cryptographic primitives

Home Page: https://quarkslab.github.io/crypto-condor/latest/index.html

License: Apache License 2.0

Makefile 0.24% Dockerfile 0.01% Python 19.18% C 57.56% Shell 0.10% M4 0.04% TeX 22.88%

crypto-condor's Introduction

crypto-condor

The logo of crypto-condor, depicting a condor holding a key.

crypto-condor is a tool for compliance testing of cryptographic primitives, in the form of a Python library and CLI. It is complemented by an extensive documentation, featuring guides on the primitives supported.

Q: What is a cryptographic primitive?

A: A low-level cryptographic algorithm, generally used to build a protocol. For example, AES is an encryption primitive that is used in the TLS protocol, which is the protocol your browser used to securely get this page.

Q: What is compliance testing?

A: Algorithms are described in specifications, such as FIPS publications or RFCs. When implementing these algorithms, we want to ensure that they comply with the specification, i.e. the implementation behaves as the algorithm described.

Q: How to test for compliance then?

A: We can use test vectors, which are sets of inputs and their corresponding outputs. For example, encrypting with AES is a deterministic operation: for a given key and message, AES will always return the same ciphertext. So we can choose some input values, run the algorithm, and record the value returned. All implementations of AES are then expected to return the same ciphertext for this given key and message. If it does not, then it is not compliant.

Q: And so, what does crypto-condor do?

A: crypto-condor provides both a nice Python API and a wrapper system to test implementations with sets of test vectors that come from sources such as the NIST CAVP.

The Python API exposes test functions that take an implementation as input, in the form of a Python function or class, passes the inputs defined by the test vectors to that implementation, and checks if the outputs are those defined by the vectors.

The wrappers are small programs that already define the function prototype. The user calls the implementation to test inside this function, and crypto-condor runs it with the test vectors as with the Python API.

And it comes with a documentation, wrapper examples, and guides on supported primitives.

Requirements

crypto-condor requires Python 3.11+. For information, it is developed using Python 3.12.2 on Fedora 39.

The implementations of AES, Kyber, Dilithium, and TestU01 are written in C and are compiled directly on the user's machine. As such, they require a C compiler and GNU Make. These primitives are only compiled when required, and not when installing the package:

  • AES: when testing the output of an implementation using classic modes of operation (not CCM or GCM).
  • Kyber: when testing the output of an implementation or when using test vectors on the encapsulate function.
  • Dilithium: when testing the output of an implementation.
  • TestU01: when used to test a file.

Installation

It is available on PyPI:

python -m pip install crypto-condor

An up-to-date list of the requirements can be found in the [tool.poetry.dependencies] section of the pyproject.toml file.

Usage

The documentation is available at https://quarkslab.github.io/crypto-condor/latest/index.html.

Once installed, the CLI is available as crypto-condor-cli. It is structured in commands, similar to Git. Run it without arguments or with --help to display the help message detailing the available subcommands. You can check the documentation for a quick rundown of all the commands.

As for the Python library, it is available as crypto_condor (note the underscore). Each primitive has its own module under primitives, e.g. crypto_condor.primitives.AES. It contains the functions used to test implementations.

Development

See CONTRIBUTING.

Changelog and versioning

A changelog is available. This projects adheres to CalVer. The format used is YYYY.MM.DD[.MICRO][-MODIFIER]:

  • YYYY: full year (2023).
  • 0M: zero-padded month (01, 02, ..., 12).
  • 0D: zero-padded day (01, 02, ..., 31).
  • MICRO: an increasing counter, used for patches published in the same day.
  • MODIFIER: usually rc<n> to indicate a release candidate.

Authors

  • Julio Loayza Meneses, Quarkslab.
  • Angèle Bossuat, Quarkslab.
  • Dahmun Goudarzi, Quarkslab.

Logo idea by Robin David, drawing by Irene Loayza.

crypto-condor's People

Contributors

julioloayzam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

gmh5225

crypto-condor's Issues

Reference implementation not found

$ python -m pip install crypto-condor
$ make build
[+] Installing with poetry
poetry install --with=dev,docs
The currently activated Python version 3.10.12 is not supported by the project (^3.11).
Trying to find and use a compatible version. 
Using python3.11 (3.11.0)
Installing dependencies from lock file

No dependencies to install or update

Installing the current project: crypto-condor (2024.06.04)

[+] Importing NIST crypto_condor/vectors/_kyber test vectors
[+] Importing NIST crypto_condor/vectors/_HMAC test vectors
[+] Importing NIST crypto_condor/vectors/_ECDH test vectors
[+] Importing NIST crypto_condor/vectors/_dilithium test vectors
[+] Importing NIST crypto_condor/vectors/_sphincs test vectors
[+] Importing NIST crypto_condor/vectors/_ecdsa test vectors
[+] Importing NIST crypto_condor/vectors/_falcon test vectors
[+] Importing NIST crypto_condor/vectors/_aes test vectors
[+] Importing NIST crypto_condor/vectors/_rsa test vectors
[+] Importing NIST crypto_condor/vectors/_sha test vectors
[+] Compiling primitives
cd crypto_condor/primitives && make all -j4
make[1]: Entering directory '/home/test/Documents/crypto-condor/crypto_condor/primitives'
python AES.py
AES directory not found: crypto-condor uses its own C implementation of AES for the classic modes of operation, which has to be compiled and installed locally.
Installation will be done at /home/test/.local/share/crypto-condor/AES
python Dilithium.py
Dilithium directory not found: crypto-condor uses the reference implementation of Dilithium, which has to be compiled and installed locally
Installation will be done at /home/test/.local/share/crypto-condor/Dilithium
Traceback (most recent call last):
  File "/home/test/Documents/crypto-condor/crypto_condor/primitives/Dilithium.py", line 474, in <module>
    _get_lib_dir()
  File "/home/test/Documents/crypto-condor/crypto_condor/primitives/Dilithium.py", line 73, in _get_lib_dir
    shutil.copyfile(str(rsc / "README.md"), lib_dir / "README.md")
  File "/usr/lib/python3.11/shutil.py", line 256, in copyfile
    with open(src, 'rb') as fsrc:
         ^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/home/test/.local/lib/python3.11/site-packages/crypto_condor/primitives/_dilithium/README.md'
make[1]: *** [Makefile:7: libs] Error 1
make[1]: Leaving directory '/home/test/Documents/crypto-condor/crypto_condor/primitives'
make: *** [Makefile:32: compile-primitives] Error 2

However, I assume it's OK as long as we've installed crypto-condor from PyPI.

No such option: --language

Followed the instructions from https://quarkslab.github.io/crypto-condor/latest/cli/quickstart.html

$ crypto-condor-cli get-wrapper SHA --language Python --example 1
Copied sha_wrapper.py
Copied wrapper for SHA in Python to /home/test/Documents/crypto-condor. Fill it and then run it with crypto-condor-cli test wrapper SHA.
$ crypto-condor-cli test wrapper SHA --language Python --algorithm SHA-256
Usage: crypto-condor-cli test wrapper SHA [OPTIONS] LANGUAGE:{Python|C} ALGORITHM:{SHA-1|SHA-224|SHA-256|SHA-384|SHA-512|SHA-512/224|SHA-512/256|SHA3-224|SHA3-256|SHA3-384|SHA3-512}
                                          [ORIENTATION]:
Try 'crypto-condor-cli test wrapper SHA --help' for help.
╭─ Error ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ No such option: --language                                                                                                                                                                  │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

But this one works ;)

$ crypto-condor-cli test wrapper SHA Python SHA-256
[NIST] short message vectors ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━   
[NIST] long message vectors ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━   
[NIST] Monte-Carlo vectors ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00


╭────────────────────────────────────────────────────────────────────────────────────── Types of tests ───────────────────────────────────────────────────────────────────────────────────────╮
│ Valid tests     : valid inputs that the implementation should use correctly.                                                                                                                │
│ Invalid tests   : invalid inputs that the implementation should reject.                                                                                                                     │
│ Acceptable tests: inputs for legacy cases or weak parameters.                                                                                                                               │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭────────────────────────────────────────────────────────────────────────────────────── Results summary ──────────────────────────────────────────────────────────────────────────────────────╮
│ Primitives tested: SHA                                                                                                                                                                      │
│ Valid tests:                                                                                                                                                                                │
│   Passed: 130                                                                                                                                                                               │
│   Failed: 0                                                                                                                                                                                 │
╰─────────────────────────────────────────────────────────────────────────── crypto-condor 2024.06.04 by Quarkslab ───────────────────────────────────────────────────────────────────────────╯
Save the results to a file? [y/n] (n): 

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.