CryptoByLeo/Src/Hash/Base.mqh

89 lignes
3 Kio
MQL5
Brut Lien permanent Vue normale Historique

2026-08-10 17:35:30 -05:00
//+------------------------------------------------------------------+
//| Base.mqh |
//| Copyright 2026, Niquel Mendoza |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2026, Niquel Mendoza"
#property link "https://www.mql5.com"
#property strict
#ifndef CRYPTOBYLEO_SRC_HASH_BASE_MQH
#define CRYPTOBYLEO_SRC_HASH_BASE_MQH
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
namespace TSN
{
class CCryptoHash
{
2026-08-11 17:33:10 -05:00
private:
2026-08-13 17:24:10 -05:00
//--- internas
2026-08-11 17:33:10 -05:00
static void SHA3_KECCAK_F(ulong &s[]);
2026-08-10 17:35:30 -05:00
public:
2026-08-11 18:00:24 -05:00
CCryptoHash(void) {}
~CCryptoHash(void) {}
2026-08-10 17:35:30 -05:00
//---
2026-08-11 18:00:24 -05:00
// SHA3 Famiy
2026-08-11 17:33:10 -05:00
static void SHA3_HASH(const uchar &in[], int ins, uchar &out[], int outl, int chunk_t, uchar delim);
2026-08-11 18:00:24 -05:00
// especifico
static __forceinline void SHA3_256(const uchar &in[], int ins, uchar &out[]);
static __forceinline void SHA3_512(const uchar &in[], int ins, uchar &out[]);
static __forceinline void SHAKE128(const uchar &in[], int ins, uchar &out[], int outl);
static __forceinline void SHAKE256(const uchar &in[], int ins, uchar &out[], int outl);
//--- SHA2
static void SHA256(const uchar &inp[], int ins, uchar& out[]);
2026-08-11 18:00:24 -05:00
2026-08-13 17:24:10 -05:00
// sha2 high family
2026-08-13 18:48:30 -05:00
static void SHA2_HIGH(ulong& h[], const uchar &inp[], int ins); // funcion base de bajo nivel
2026-08-13 14:01:20 -05:00
static void SHA512(const uchar &inp[], int ins, uchar& out[]);
2026-08-13 17:24:10 -05:00
static void SHA384(const uchar &inp[], int ins, uchar& out[]);
2026-08-13 14:01:20 -05:00
2026-08-11 18:00:24 -05:00
//--- BLAKE
2026-08-11 10:06:33 -05:00
static void BLAKE2B(const uchar &in[], int ins, uchar &out[], int outl = 64);
2026-08-11 18:00:24 -05:00
//--- Extra internal
2026-08-10 22:07:32 -05:00
static void Expand8To32(uint32_t &in[], uint8_t& out[]);
2026-08-13 14:01:20 -05:00
static void Expand8To32(uint64_t &in[], uint8_t& out[]);
2026-08-10 17:35:30 -05:00
};
2026-08-11 18:00:24 -05:00
2026-08-10 22:07:32 -05:00
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
// Esto en BE no es LE
2026-08-10 22:07:32 -05:00
static void CCryptoHash::Expand8To32(uint &in[], uchar &out[])
{
//--- BE
#define CRYPTOHASHBYLEO_HASH_ASSING(INDEX) \
out[INDEX] = uint8_t(t >> 24); \
out[INDEX+1] = uint8_t(t >> 16); \
out[INDEX+2] = uint8_t(t >> 8); \
out[INDEX+3] = uint8_t(t);
//---
uint32_t t = in[0];
CRYPTOHASHBYLEO_HASH_ASSING(0)
t = in[1];
CRYPTOHASHBYLEO_HASH_ASSING(4)
t = in[2];
CRYPTOHASHBYLEO_HASH_ASSING(8)
t = in[3];
CRYPTOHASHBYLEO_HASH_ASSING(12)
t = in[4];
CRYPTOHASHBYLEO_HASH_ASSING(16)
t = in[5];
CRYPTOHASHBYLEO_HASH_ASSING(20)
t = in[6];
CRYPTOHASHBYLEO_HASH_ASSING(24)
t = in[7];
CRYPTOHASHBYLEO_HASH_ASSING(28)
//---
#undef CRYPTOHASHBYLEO_HASH_ASSING
}
2026-08-10 17:35:30 -05:00
}
#endif // CRYPTOBYLEO_SRC_HASH_BASE_MQH
//+------------------------------------------------------------------+