CryptoByLeo/Src/MGF1/Main.mqh

75 lines
2.6 KiB
MQL5
Raw Permalink Normal View History

2026-08-10 17:35:30 -05:00
//+------------------------------------------------------------------+
//| Main.mqh |
//| Copyright 2026, Niquel Mendoza |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2026, Niquel Mendoza"
#property link "https://www.mql5.com"
#property strict
2026-08-13 18:48:30 -05:00
#ifndef CRYPTOBYLEO_SRC_MGF1_MAIN_MQH
#define CRYPTOBYLEO_SRC_MGF1_MAIN_MQH
2026-08-13 19:43:39 -05:00
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#include "Def.mqh"
2026-08-13 18:48:30 -05:00
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
2026-08-13 17:24:10 -05:00
namespace TSN
{
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
2026-08-13 19:43:39 -05:00
void MGF1(const uchar& seed[], int seeds, int outl, uchar& outm[], CCryptoHashMeta::ENUM_TSN_CRYPTO_HASH f)
2026-08-13 18:48:30 -05:00
{
2026-08-13 19:43:39 -05:00
//----
const int hlen = TSN::CCryptoHashMeta::g_crytpo_hash_meta[f].outl; // tamaño de salida
const CCryptoHashMeta::TsnCryptoByLeoHashFuncFixed fhash = TSN::CCryptoHashMeta::g_crypto_fhash_fixed[f];
//--- buffer base
uchar buf[];
const int bufs = ArrayResize(buf, seeds + 4);
for(int i = 0; i < seeds; i++)
buf[i] = seed[i]; // copiamos
//--- buffer del reuslto del hasher
uchar buf_hash_ou[];
ArrayResize(buf_hash_ou, hlen);
//---
uint32_t counter = 0;
int w = 0; // incide de escrituira
//--- numero de bloques a procesar
const uint nblocks = uint((outl + (hlen - 1)) / hlen); // ceil..
//--
for(uint32_t counter = 0; counter < nblocks; counter++)
{
// añadimos el contador
buf[seeds] = uchar(counter >> 24);
buf[seeds + 1] = uchar(counter >> 16);
buf[seeds + 2] = uchar(counter >> 8);
buf[seeds + 3] = uchar(counter);
// aplicamos hasher
fhash(buf, bufs, buf_hash_ou);
// truncamos si hace falta (en caso sobrepase solo tomaoms lo necsario)
const int chunk = (w + hlen > outl) ? (outl - w) : hlen;
2026-08-13 18:48:30 -05:00
2026-08-13 19:43:39 -05:00
// copiamos datos
for(int i = 0; i < chunk; i++)
outm[w + i] = buf_hash_ou[i];
2026-08-13 18:48:30 -05:00
2026-08-13 19:43:39 -05:00
// aumentamos
w += chunk;
}
2026-08-13 18:48:30 -05:00
}
}
2026-08-13 17:24:10 -05:00
//+------------------------------------------------------------------+
2026-08-13 19:43:39 -05:00
#endif // CRYPTOBYLEO_SRC_MGF1_MAIN_MQH