- MQL5 87.5%
- MQL4 12.1%
- C++ 0.2%
- CMake 0.2%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| Src | ||
| Wf | ||
| CryptoByLeo.mqproj | ||
| dependencies.json | ||
| LICENSE | ||
| README.md | ||
Fast cryptographic library for MQL5: hashes, HMAC, symmetric and asymmetric ciphers, padding and RSP test vector parsing.
Pure MQL5, no DLLs required for the crypto primitives themselves.
Main Features
- Hashes: SHA-2 (SHA256/384/512), SHA-3 (incl. SHAKE128/256), BLAKE2b
- HMAC: generic HMAC construction over any supported hash function
- Symmetric ciphers: AES (128/256) and ChaCha20
- Asymmetric cipher (RSA): key generation, encryption/decryption and signing — ~90% complete
- Fernet: authenticated symmetric encryption (AES + HMAC)
- Padding schemes: OAEP, PSS and PKCS#1 v1.5
- Mask generation function: MGF1
- RSP parser: fast parser for
.rspNIST test vector files, used to validate hash implementations - URandom: pluggable random sources for the rest of the library — Windows
bcrypt.dllentropy (CURandom) or a pure-MQL5 PRNG backend with no DLLs required (CURandomPRNG<TBackend>), both interchangeable via templates
Usage examples
Hashing (SHA-3-256):
#include "Src\\Hash\\SHA3.mqh"
uchar data[] = { /* ... */ };
uchar out[32];
TSN::CCryptoHashSHA3::SHA3_256(data, ArraySize(data), 0, out);
PSS padding encode (for RSA signing):
#include "Src\\Padding\\PSS\\Main.mqh"
uchar msg[], salt[], out[];
// ...
int len = TSN::CPSS::Encode(msg, msg_hash_len, salt, em_bits,
TSN::CCryptoHashMeta::TSN_CRYPTO_HASH_TYPE_SHA256, out);
Random bytes (no DLL required):
#include "Src\\URandom\\PRNG.mqh"
uchar raw[16];
TSN::CURandomPRNG<Xoshiro256>::RandomCryptoBytes(raw, 16);
Random bytes (via Windows bcrypt.dll):
#include "Src\\URandom\\BCrypt.mqh"
uchar raw[16];
TSN::CURandom::RandomCryptoBytes(raw, 16);
ALL Test Passed with NIST Oficial vectors (SHA3, SHA2, AES) and Github Official vectors for BLAKE2b:
(For now, only tests that do not involve Monte Carlo for SHA/AES testing were considered.) Also, mention that these tests currently only cover testing with official NIST vectors or GitHub repositories (in the case of implementations like GitHub). Certainly, there are more types of tests than "KATs," but we will integrate those in the future.
2026.09.02 08:25:37.177 EA (EURUSD,H1) [INFO] TSN::CiTestUtil::RunAllTestAndSend | [PASSED] | Test [SHA2-256 Test NIST Vectors]
2026.09.02 08:25:37.190 EA (EURUSD,H1) [INFO] TSN::CiTestUtil::RunAllTestAndSend | [PASSED] | Test [SHA2-384 Test NIST Vectors]
2026.09.02 08:25:37.203 EA (EURUSD,H1) [INFO] TSN::CiTestUtil::RunAllTestAndSend | [PASSED] | Test [SHA2-512 Test NIST Vectors]
2026.09.02 08:25:37.215 EA (EURUSD,H1) [INFO] TSN::CiTestUtil::RunAllTestAndSend | [PASSED] | Test [SHA2-512/224 Test NIST Vectors]
2026.09.02 08:25:37.228 EA (EURUSD,H1) [INFO] TSN::CiTestUtil::RunAllTestAndSend | [PASSED] | Test [SHA2-512/256 Test NIST Vectors]
2026.09.02 08:25:37.240 EA (EURUSD,H1) [INFO] TSN::CiTestUtil::RunAllTestAndSend | [PASSED] | Test [SHA3-256 Test NIST Vectors]
2026.09.02 08:25:37.250 EA (EURUSD,H1) [INFO] TSN::CiTestUtil::RunAllTestAndSend | [PASSED] | Test [SHA3-384 Test NIST Vectors]
2026.09.02 08:25:37.257 EA (EURUSD,H1) [INFO] TSN::CiTestUtil::RunAllTestAndSend | [PASSED] | Test [SHA3-512 Test NIST Vectors]
2026.09.02 08:25:37.259 EA (EURUSD,H1) [INFO] TSN::CiTestUtil::RunAllTestAndSend | [PASSED] | Test [BLAKE2 Official vector test]
2026.09.02 08:25:37.260 EA (EURUSD,H1) [INFO] TSN::CiTestUtil::RunAllTestAndSend | [PASSED] | Test [AES-128 ECB Test NIST Vectors]
2026.09.02 08:25:37.263 EA (EURUSD,H1) [INFO] TSN::CiTestUtil::RunAllTestAndSend | [PASSED] | Test [AES-256 ECB Test NIST Vectors]
2026.09.02 08:25:37.284 EA (EURUSD,H1) [INFO] TSN::CiTestUtil::RunAllTestAndSend | [PASSED] | Test [AES-128 CBC Test NIST Vectors]
2026.09.02 08:25:37.321 EA (EURUSD,H1) [INFO] TSN::CiTestUtil::RunAllTestAndSend | [PASSED] | Test [AES-256 CBC Test NIST Vectors]
References:
- https://csrc.nist.gov/projects/cryptographic-algorithm-validation-program/secure-hashing
- https://github.com/BLAKE2/BLAKE2/blob/master/testvectors/blake2-kat.json
- https://csrc.nist.gov/projects/cryptographic-algorithm-validation-program/block-ciphers#AES
Repository Structure
CryptoByLeo/
├── Src/
│ ├── Hash/ # SHA-2, SHA-3, BLAKE2b
│ ├── MAC/ # HMAC
│ ├── MGF1/ # Mask generation function
│ ├── Padding/ # OAEP, PKCS1v15, PSS
│ ├── URandom/ # Pluggable random sources (bcrypt.dll or pure-MQL5 PRNG)
│ ├── RSA/ # Key generation, sign/enc/dec
│ ├── Fernet/ # Authenticated symmetric encryption
│ ├── RSPParser/ # .rsp NIST test vector parser
│ ├── Simetric/ # AES, ChaCha20
│ └── Imports/ # External DLL imports (bcrypt.dll)
└── Wf/ # Workflow / integration test EA
Requirements
See dependencies.json for the full list.
Installation
cd "C:\Users\YOUR_USER\AppData\Roaming\MetaQuotes\Terminal\YOUR_ID\MQL5\Shared Projects"
tsndep install "https://forge.mql5.io/nique_372/CryptoByLeo.git"
Requires the tsndep package, available on PyPI. It automatically downloads and installs all declared dependencies.
Quick Start
1. Include the module you need:
#include "..\\CryptoByLeo\\Src\\Hash\\All.mqh"
2. Use it:
uchar out[32];
TSN::CCryptoHashSHA3::SHA3_256(data, ArraySize(data), 0, out);
License
Read Full License By downloading or using this repository, you accept the license terms.
Contact
- Platform: MQL5 Community
- Profile: https://www.mql5.com/es/users/nique_372
- Articles: https://www.mql5.com/es/users/nique_372/publications
Roadmap
- Hashes (SHA-2, SHA-3, BLAKE2b), HMAC, AES, ChaCha20, Padding (OAEP/PSS/PKCS1v15), MGF1, RSP parser, URandom [Complete]
- RSA (key generation, sign/enc/dec) [~90%, in progress]
- Fernet (authenticated symmetric encryption) [100%]
- Test suite coverage [~70%, in progress]
Copyright © 2026 Niquel & Leo — TSN Ecosystem