Fast cryptographic library for MQL5 (Hashes [SHA3, SHA2, BLAK2]) (HMAC) (Simetric Cipher - AES - CHACHA20) (Asymetric Chiper (RSA - Sign - Enc- Dec - Key generation, etc..) ) (Padding (OAEP, PSS PKCS1v15)) (MaskFunction (MGF1)) (RSP Full Fast parser (.rsp test files for hashes)) (Fernet)
  • MQL5 87.5%
  • MQL4 12.1%
  • C++ 0.2%
  • CMake 0.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Nique_372 f7bc69165f
2026-09-04 09:28:53 -05:00
Src 2026-09-04 09:06:25 -05:00
Wf listo ya corregi todologre pasar todos los test de los vectores del nisst 2026-09-02 08:26:08 -05:00
CryptoByLeo.mqproj Generated by MQL5 Wizard 2026-08-10 15:56:21 -05:00
dependencies.json 2026-09-01 12:22:18 -05:00
LICENSE Añadir LICENSE 2026-08-10 21:10:19 +00:00
README.md 2026-09-04 09:28:53 -05:00

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 .rsp NIST test vector files, used to validate hash implementations
  • URandom: pluggable random sources for the rest of the library — Windows bcrypt.dll entropy (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:


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


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