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-19 16:55:01 -05:00 | | | // seed: semilla
|
| | | // r: indic de lectura
|
| | | // seeds: tamaño de la semilla
|
| | | // outl: tamaño del out en bytes
|
| | | // out: array de salida
|
| | | // w: indice de escritura final para out
|
| | | // f: funcion de hashing
|
| | |
|
| | | //---
|
| | | void MGF1(const uchar& seed[], int r, int seeds, uchar& outm[], int w, int outl,
|
| | | 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);
|
2026-08-19 16:55:01 -05:00 | | | const int rl = r;
|
2026-08-19 21:20:19 -05:00 | | | const int fin = seeds + r;
|
2026-08-19 16:55:01 -05:00 | | |
|
| | | //--- empiza a leer desde r en seed y copia desde r-rl (i)
|
2026-08-19 21:20:19 -05:00 | | | for(; r < fin; r++)
|
2026-08-19 16:55:01 -05:00 | | | buf[r - rl] = seed[r]; // copiamos
|
2026-08-13 19:43:39 -05:00 | | |
|
| | | //--- buffer del reuslto del hasher
|
2026-08-20 17:10:56 -05:00 | | | // uchar buf_hash_ou[CRYPTOBYLEO_HASHFUNC_FIXED_MAX_OL]; // tamaño=maximo
|
2026-08-19 21:20:19 -05:00 | | | //ArrayResize(buf_hash_ou, hlen);
|
2026-08-13 19:43:39 -05:00 | | |
|
| | | //--- numero de bloques a procesar
|
| | | const uint nblocks = uint((outl + (hlen - 1)) / hlen); // ceil..
|
| | |
|
2026-08-20 17:10:56 -05:00 | | | //--- necesitmoas seguridad para hlen (evitar escrituras fuera de rango)
|
| | | const int sob = outl & (CRYPTOBYLEO_HASHFUNC_FIXED_MAX_OL - 1); // % 64
|
| | | if(sob > 0)
|
| | | {
|
| | | // En caso haya sobrante para llegar a ser multiplo del max
|
| | | // w=donde se empzia a escribir
|
| | | // outl=numero de datos
|
| | | // sob=sobrante que neceismtoas para qeu sea multiplo
|
| | | const int sum = w + outl + sob;
|
| | | if(sum > ArraySize(outm))
|
| | | {
|
| | | // Agrandamos el buffer a lo uqe falta para ser multiplo del hash maximo
|
| | | ArrayResize(outm, sum);
|
| | | }
|
| | | }
|
| | |
|
2026-08-19 21:20:19 -05:00 | | | //--- aumentamos
|
| | | outl += w;
|
| | |
|
2026-08-13 19:43:39 -05:00 | | | //--
|
| | | 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
|
2026-08-20 17:10:56 -05:00 | | | fhash(buf, bufs, outm, w);
|
| | | // la salida se escribe en outm apartir de w
|
2026-08-13 18:48:30 -05:00 | | |
|
2026-08-20 17:10:56 -05:00 | | | // aumentamos w en hlen bytes que escribimos
|
| | | w += hlen;
|
2026-08-13 19:43:39 -05:00 | | | }
|
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
|