CryptoByLeo/Src/Hash/Base.mqh

84 lines
2.7 KiB
MQL5
Raw Permalink Normal View History

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
{
public:
2026-08-11 18:00:24 -05:00
CCryptoHash(void) {}
~CCryptoHash(void) {}
2026-08-20 17:10:56 -05:00
//---
2026-08-11 18:00:24 -05:00
//--- SHA2
2026-08-20 17:10:56 -05:00
static void SHA256(const uchar &inp[], int ins, uchar& out[], int o_s);
2026-08-11 18:00:24 -05:00
2026-08-13 17:24:10 -05:00
// sha2 high family
2026-08-20 17:10:56 -05:00
static void SHA2_HIGH(ulong& h[], const uchar &inp[], int ins); // funcion base de bajo nivel
2026-08-25 20:10:08 -05:00
// 512
static void SHA512_224(const uchar &inp[], int ins, uchar& out[], const int o_s);
static void SHA512_256(const uchar &inp[], int ins, uchar& out[], const int o_s);
2026-08-20 17:10:56 -05:00
static void SHA512(const uchar &inp[], const int inpr, uchar& out[], int o_s);
2026-08-25 20:10:08 -05:00
// 384
2026-08-20 17:10:56 -05:00
static void SHA384(const uchar &inp[], const int inpr, uchar& out[], int o_s);
2026-08-13 14:01:20 -05:00
2026-08-25 20:10:08 -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
//+------------------------------------------------------------------+