Class: CoBreak::OpenSSL::SHA3_384

Inherits:
Object
  • Object
show all
Defined in:
ext/cobreak/cobreak_openssl.c

Class Method Summary collapse

Class Method Details

.hexdigest(input) ⇒ Object



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# File 'ext/cobreak/cobreak_openssl.c', line 303

VALUE sha3_384_hexdigest(VALUE self, VALUE input) {

    // Asegúrate de que el input es una cadena

    Check_Type(input, T_STRING);


    // Crear un contexto para el hash

    EVP_MD_CTX *ctx = EVP_MD_CTX_new();

    const EVP_MD *md = EVP_sha3_384();

    

    // Inicializar el contexto y calcular el hash

    EVP_DigestInit_ex(ctx, md, NULL);

    EVP_DigestUpdate(ctx, (unsigned char *)StringValueCStr(input), RSTRING_LEN(input));

    

    unsigned char output[EVP_MAX_MD_SIZE];

    unsigned int output_len;


    EVP_DigestFinal_ex(ctx, output, &output_len);

    EVP_MD_CTX_free(ctx);


    // Convertir el hash a una cadena hexadecimal

    VALUE hex_string = rb_str_new("", 0);

    for (unsigned int i = 0; i < output_len; i++) {

        rb_str_catf(hex_string, "%02x", output[i]);

    }
    return hex_string;
}