cobreaktws 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.vscode/settings.json +10 -0
- data/Gemfile +18 -0
- data/README.md +72 -0
- data/bin/cbrdb +95 -0
- data/bin/cobreak +11 -0
- data/cobreak.gemspec +28 -0
- data/ext/cobreak/cobreak.c +17 -0
- data/ext/cobreak/cobreak_cipher.c +341 -0
- data/ext/cobreak/cobreak_cipher.h +10 -0
- data/ext/cobreak/cobreak_gcrypt.c +556 -0
- data/ext/cobreak/cobreak_gcrypt.h +14 -0
- data/ext/cobreak/cobreak_openmp.c +9 -0
- data/ext/cobreak/cobreak_openmp.h +14 -0
- data/ext/cobreak/cobreak_openssl.c +438 -0
- data/ext/cobreak/cobreak_openssl.h +21 -0
- data/ext/cobreak/cobreak_ruby.h +24 -0
- data/ext/cobreak/extconf.rb +27 -0
- data/lib/cobreak/binary.rb +10 -0
- data/lib/cobreak/cesar.rb +30 -0
- data/lib/cobreak/cifrado.rb +30 -0
- data/lib/cobreak/cobreak_opt.rb +77 -0
- data/lib/cobreak/config/database.db +0 -0
- data/lib/cobreak/decifrado.rb +30 -0
- data/lib/cobreak/decrypt.rb +98 -0
- data/lib/cobreak/details.rb +19 -0
- data/lib/cobreak/encrypt.rb +114 -0
- data/lib/cobreak/force.rb +226 -0
- data/lib/cobreak/force_brute.rb +62 -0
- data/lib/cobreak/force_chars.rb +54 -0
- data/lib/cobreak/function_db.rb +26 -0
- data/lib/cobreak/function_hash.rb +28 -0
- data/lib/cobreak/hash/hash.db +1 -0
- data/lib/cobreak/info_author.rb +20 -0
- data/lib/cobreak/list_all.rb +41 -0
- data/lib/cobreak/optionpr.rb +148 -0
- data/lib/cobreak/run.rb +9 -0
- data/lib/cobreak/version.rb +5 -0
- data/lib/cobreak.rb +4 -0
- metadata +185 -0
@@ -0,0 +1,556 @@
|
|
1
|
+
#include<cobreak_gcrypt.h>
|
2
|
+
|
3
|
+
VALUE mCoBreakGCrypt;
|
4
|
+
VALUE cCoBreakGCrypttiger160;
|
5
|
+
VALUE cCoBreakGCryptdoublesha1;
|
6
|
+
VALUE cCoBreakGCryptblake2s_128;
|
7
|
+
VALUE cCoBreakGCryptblake2s_160;
|
8
|
+
VALUE cCoBreakGCryptblake2b_160;
|
9
|
+
VALUE cCoBreakGCryptblake2s_224;
|
10
|
+
VALUE cCoBreakGCryptblake2s_256;
|
11
|
+
VALUE cCoBreakGCryptblake2b_256;
|
12
|
+
VALUE cCoBreakGCryptblake2b_384;
|
13
|
+
VALUE cCoBreakGCryptblake2b_512;
|
14
|
+
VALUE cCoBreakGCrypthaval_160;
|
15
|
+
VALUE cCoBreakGCryptwhirlpool;
|
16
|
+
VALUE cCoBreakGCryptgost_streebog_256;
|
17
|
+
VALUE cCoBreakGCryptgost_streebog_512;
|
18
|
+
|
19
|
+
|
20
|
+
VALUE tiger160_hexdigest(VALUE self, VALUE full) {
|
21
|
+
char *str = RSTRING_PTR(full);
|
22
|
+
int length = RSTRING_LEN(full); // Obtener la longitud de la cadena
|
23
|
+
gcry_md_hd_t handle;
|
24
|
+
unsigned char digest[20]; // Tiger-160 produce un hash de 20 bytes
|
25
|
+
char out[41]; // 20 bytes * 2 para hexadecimal + 1 para el terminador
|
26
|
+
|
27
|
+
// Inicializar la biblioteca libgcrypt
|
28
|
+
if (!gcry_check_version(GCRYPT_VERSION)) {
|
29
|
+
rb_raise(rb_eRuntimeError, "Versión de libgcrypt no compatible.");
|
30
|
+
}
|
31
|
+
|
32
|
+
// Abrir el contexto de hash para Tiger-160
|
33
|
+
gcry_md_open(&handle, GCRY_MD_TIGER, 0);
|
34
|
+
|
35
|
+
// Actualizar el hash con la cadena de entrada
|
36
|
+
gcry_md_write(handle, str, length);
|
37
|
+
|
38
|
+
// Finalizar el hash y obtener el resultado
|
39
|
+
memcpy(digest, gcry_md_read(handle, GCRY_MD_TIGER), 20);
|
40
|
+
gcry_md_close(handle);
|
41
|
+
|
42
|
+
// Convertir el hash a una cadena hexadecimal
|
43
|
+
for (int n = 0; n < 20; ++n) {
|
44
|
+
sprintf(&(out[n * 2]), "%02x", (unsigned int)digest[n]);
|
45
|
+
}
|
46
|
+
out[40] = '\0'; // Terminar la cadena
|
47
|
+
|
48
|
+
VALUE result = rb_str_new2(out); // Crear una nueva cadena Ruby
|
49
|
+
return result;
|
50
|
+
}
|
51
|
+
|
52
|
+
VALUE double_sha1_hexdigest(VALUE self, VALUE full) {
|
53
|
+
char *str = RSTRING_PTR(full);
|
54
|
+
int length = RSTRING_LEN(full); // Obtener la longitud de la cadena
|
55
|
+
gcry_md_hd_t handle;
|
56
|
+
unsigned char digest[20]; // SHA-1 produce un hash de 20 bytes
|
57
|
+
unsigned char intermediate_digest[20]; // Para almacenar el primer hash
|
58
|
+
char out[41]; // 20 bytes * 2 para hexadecimal + 1 para el terminador
|
59
|
+
|
60
|
+
// Inicializar la biblioteca libgcrypt
|
61
|
+
if (!gcry_check_version(GCRYPT_VERSION)) {
|
62
|
+
rb_raise(rb_eRuntimeError, "Versión de libgcrypt no compatible.");
|
63
|
+
}
|
64
|
+
|
65
|
+
// Abrir el contexto de hash para SHA-1
|
66
|
+
gcry_md_open(&handle, GCRY_MD_SHA1, 0);
|
67
|
+
|
68
|
+
// Actualizar el hash con la cadena de entrada
|
69
|
+
gcry_md_write(handle, str, length);
|
70
|
+
|
71
|
+
// Finalizar el hash y obtener el primer resultado
|
72
|
+
memcpy(intermediate_digest, gcry_md_read(handle, GCRY_MD_SHA1), 20);
|
73
|
+
gcry_md_close(handle);
|
74
|
+
|
75
|
+
// Abrir un nuevo contexto de hash para el segundo SHA-1
|
76
|
+
gcry_md_open(&handle, GCRY_MD_SHA1, 0);
|
77
|
+
|
78
|
+
// Actualizar el hash con el resultado del primer hash
|
79
|
+
gcry_md_write(handle, intermediate_digest, 20);
|
80
|
+
|
81
|
+
// Finalizar el hash y obtener el resultado final
|
82
|
+
memcpy(digest, gcry_md_read(handle, GCRY_MD_SHA1), 20);
|
83
|
+
gcry_md_close(handle);
|
84
|
+
|
85
|
+
// Convertir el hash a una cadena hexadecimal
|
86
|
+
for (int n = 0; n < 20; ++n) {
|
87
|
+
sprintf(&(out[n * 2]), "%02x", (unsigned int)digest[n]);
|
88
|
+
}
|
89
|
+
out[40] = '\0'; // Terminar la cadena
|
90
|
+
|
91
|
+
VALUE result = rb_str_new2(out); // Crear una nueva cadena Ruby
|
92
|
+
return result;
|
93
|
+
}
|
94
|
+
|
95
|
+
VALUE blake2s_128_hexdigest(VALUE self, VALUE input) {
|
96
|
+
// Convertir el valor Ruby a una cadena C
|
97
|
+
char *str = RSTRING_PTR(input);
|
98
|
+
int length = RSTRING_LEN(input); // Obtener la longitud de la cadena
|
99
|
+
unsigned char digest[16]; // BLAKE2s-128 produce un hash de 16 bytes
|
100
|
+
char out[33]; // 16 bytes * 2 para hexadecimal + 1 para el terminador
|
101
|
+
|
102
|
+
// Inicializar la biblioteca libgcrypt
|
103
|
+
if (!gcry_check_version(GCRYPT_VERSION)) {
|
104
|
+
rb_raise(rb_eRuntimeError, "Versión de libgcrypt no compatible.");
|
105
|
+
}
|
106
|
+
|
107
|
+
// Abrir el contexto de hash para BLAKE2s-128
|
108
|
+
gcry_md_hd_t handle;
|
109
|
+
gcry_md_open(&handle, GCRY_MD_BLAKE2S_128, 0);
|
110
|
+
|
111
|
+
// Actualizar el hash con la cadena de entrada
|
112
|
+
gcry_md_write(handle, str, length);
|
113
|
+
|
114
|
+
// Finalizar el hash y obtener el resultado
|
115
|
+
memcpy(digest, gcry_md_read(handle, GCRY_MD_BLAKE2S_128), 16);
|
116
|
+
gcry_md_close(handle);
|
117
|
+
|
118
|
+
// Convertir el hash a una cadena hexadecimal
|
119
|
+
for (int n = 0; n < 16; ++n) {
|
120
|
+
sprintf(&(out[n * 2]), "%02x", (unsigned int)digest[n]);
|
121
|
+
}
|
122
|
+
out[32] = '\0'; // Terminar la cadena
|
123
|
+
|
124
|
+
VALUE result = rb_str_new2(out); // Crear una nueva cadena Ruby
|
125
|
+
return result;
|
126
|
+
}
|
127
|
+
|
128
|
+
VALUE blake2s_160_hexdigest(VALUE self, VALUE input) {
|
129
|
+
// Convertir el valor Ruby a una cadena C
|
130
|
+
char *str = RSTRING_PTR(input);
|
131
|
+
int length = RSTRING_LEN(input); // Obtener la longitud de la cadena
|
132
|
+
unsigned char digest[20]; // BLAKE2s-160 produce un hash de 20 bytes
|
133
|
+
char out[41]; // 20 bytes * 2 para hexadecimal + 1 para el terminador
|
134
|
+
|
135
|
+
// Inicializar la biblioteca libgcrypt
|
136
|
+
if (!gcry_check_version(GCRYPT_VERSION)) {
|
137
|
+
rb_raise(rb_eRuntimeError, "Versión de libgcrypt no compatible.");
|
138
|
+
}
|
139
|
+
|
140
|
+
// Abrir el contexto de hash para BLAKE2s-160
|
141
|
+
gcry_md_hd_t handle;
|
142
|
+
gcry_md_open(&handle, GCRY_MD_BLAKE2S_160, 0);
|
143
|
+
|
144
|
+
// Actualizar el hash con la cadena de entrada
|
145
|
+
gcry_md_write(handle, str, length);
|
146
|
+
|
147
|
+
// Finalizar el hash y obtener el resultado
|
148
|
+
memcpy(digest, gcry_md_read(handle, GCRY_MD_BLAKE2S_160), 20);
|
149
|
+
gcry_md_close(handle);
|
150
|
+
|
151
|
+
// Convertir el hash a una cadena hexadecimal
|
152
|
+
for (int n = 0; n < 20; ++n) {
|
153
|
+
sprintf(&(out[n * 2]), "%02x", (unsigned int)digest[n]);
|
154
|
+
}
|
155
|
+
out[40] = '\0'; // Terminar la cadena
|
156
|
+
|
157
|
+
VALUE result = rb_str_new2(out); // Crear una nueva cadena Ruby
|
158
|
+
return result;
|
159
|
+
}
|
160
|
+
|
161
|
+
VALUE blake2b_160_hexdigest(VALUE self, VALUE input) {
|
162
|
+
char *str = RSTRING_PTR(input);
|
163
|
+
int length = RSTRING_LEN(input); // Obtener la longitud de la cadena
|
164
|
+
unsigned char digest[20]; // BLAKE2b-160 produce un hash de 20 bytes (160 bits)
|
165
|
+
char out[41]; // 20 bytes * 2 para hexadecimal + 1 para el terminador
|
166
|
+
|
167
|
+
// Inicializar la biblioteca libgcrypt
|
168
|
+
if (!gcry_check_version(GCRYPT_VERSION)) {
|
169
|
+
rb_raise(rb_eRuntimeError, "Versión de libgcrypt no compatible.");
|
170
|
+
}
|
171
|
+
|
172
|
+
// Abrir el contexto de hash para BLAKE2b-160
|
173
|
+
gcry_md_hd_t handle;
|
174
|
+
gcry_md_open(&handle, GCRY_MD_BLAKE2B_160, 0);
|
175
|
+
|
176
|
+
// Actualizar el hash con la cadena de entrada
|
177
|
+
gcry_md_write(handle, str, length);
|
178
|
+
|
179
|
+
// Finalizar el hash y obtener el resultado
|
180
|
+
memcpy(digest, gcry_md_read(handle, GCRY_MD_BLAKE2B_160), 20);
|
181
|
+
gcry_md_close(handle);
|
182
|
+
|
183
|
+
// Convertir el hash a una cadena hexadecimal
|
184
|
+
for (int n = 0; n < 20; ++n) {
|
185
|
+
sprintf(&(out[n * 2]), "%02x", (unsigned int)digest[n]);
|
186
|
+
}
|
187
|
+
out[40] = '\0'; // Terminar la cadena
|
188
|
+
|
189
|
+
VALUE result = rb_str_new2(out); // Crear una nueva cadena Ruby
|
190
|
+
return result;
|
191
|
+
}
|
192
|
+
|
193
|
+
VALUE blake2s_224_hexdigest(VALUE self, VALUE input) {
|
194
|
+
// Convertir el valor Ruby a una cadena C
|
195
|
+
char *str = RSTRING_PTR(input);
|
196
|
+
int length = RSTRING_LEN(input); // Obtener la longitud de la cadena
|
197
|
+
unsigned char digest[28]; // BLAKE2s-224 produce un hash de 28 bytes
|
198
|
+
char out[57]; // 28 bytes * 2 para hexadecimal + 1 para el terminador
|
199
|
+
|
200
|
+
// Inicializar la biblioteca libgcrypt
|
201
|
+
if (!gcry_check_version(GCRYPT_VERSION)) {
|
202
|
+
rb_raise(rb_eRuntimeError, "Versión de libgcrypt no compatible.");
|
203
|
+
}
|
204
|
+
|
205
|
+
// Abrir el contexto de hash para BLAKE2s-224
|
206
|
+
gcry_md_hd_t handle;
|
207
|
+
gcry_md_open(&handle, GCRY_MD_BLAKE2S_224, 0);
|
208
|
+
|
209
|
+
// Actualizar el hash con la cadena de entrada
|
210
|
+
gcry_md_write(handle, str, length);
|
211
|
+
|
212
|
+
// Finalizar el hash y obtener el resultado
|
213
|
+
memcpy(digest, gcry_md_read(handle, GCRY_MD_BLAKE2S_224), 28);
|
214
|
+
gcry_md_close(handle);
|
215
|
+
|
216
|
+
// Convertir el hash a una cadena hexadecimal
|
217
|
+
for (int n = 0; n < 28; ++n) {
|
218
|
+
sprintf(&(out[n * 2]), "%02x", (unsigned int)digest[n]);
|
219
|
+
}
|
220
|
+
out[56] = '\0'; // Terminar la cadena
|
221
|
+
|
222
|
+
VALUE result = rb_str_new2(out); // Crear una nueva cadena Ruby
|
223
|
+
return result;
|
224
|
+
}
|
225
|
+
|
226
|
+
VALUE blake2s_256_hexdigest(VALUE self, VALUE input) {
|
227
|
+
// Convertir el valor Ruby a una cadena C
|
228
|
+
char *str = RSTRING_PTR(input);
|
229
|
+
int length = RSTRING_LEN(input); // Obtener la longitud de la cadena
|
230
|
+
unsigned char digest[32]; // BLAKE2s-256 produce un hash de 32 bytes
|
231
|
+
char out[65]; // 32 bytes * 2 para hexadecimal + 1 para el terminador
|
232
|
+
|
233
|
+
// Inicializar la biblioteca libgcrypt
|
234
|
+
if (!gcry_check_version(GCRYPT_VERSION)) {
|
235
|
+
rb_raise(rb_eRuntimeError, "Versión de libgcrypt no compatible.");
|
236
|
+
}
|
237
|
+
|
238
|
+
// Abrir el contexto de hash para BLAKE2s-256
|
239
|
+
gcry_md_hd_t handle;
|
240
|
+
gcry_md_open(&handle, GCRY_MD_BLAKE2S_256, 0);
|
241
|
+
|
242
|
+
// Actualizar el hash con la cadena de entrada
|
243
|
+
gcry_md_write(handle, str, length);
|
244
|
+
|
245
|
+
// Finalizar el hash y obtener el resultado
|
246
|
+
memcpy(digest, gcry_md_read(handle, GCRY_MD_BLAKE2S_256), 32);
|
247
|
+
gcry_md_close(handle);
|
248
|
+
|
249
|
+
// Convertir el hash a una cadena hexadecimal
|
250
|
+
for (int n = 0; n < 32; ++n) {
|
251
|
+
sprintf(&(out[n * 2]), "%02x", (unsigned int)digest[n]);
|
252
|
+
}
|
253
|
+
out[64] = '\0'; // Terminar la cadena
|
254
|
+
|
255
|
+
VALUE result = rb_str_new2(out); // Crear una nueva cadena Ruby
|
256
|
+
return result;
|
257
|
+
}
|
258
|
+
|
259
|
+
VALUE blake2b_256_hexdigest(VALUE self, VALUE input) {
|
260
|
+
char *str = RSTRING_PTR(input);
|
261
|
+
int length = RSTRING_LEN(input); // Obtener la longitud de la cadena
|
262
|
+
unsigned char digest[32]; // BLAKE2b-256 produce un hash de 32 bytes (256 bits)
|
263
|
+
char out[65]; // 32 bytes * 2 para hexadecimal + 1 para el terminador
|
264
|
+
|
265
|
+
// Inicializar la biblioteca libgcrypt
|
266
|
+
if (!gcry_check_version(GCRYPT_VERSION)) {
|
267
|
+
rb_raise(rb_eRuntimeError, "Versión de libgcrypt no compatible.");
|
268
|
+
}
|
269
|
+
|
270
|
+
// Abrir el contexto de hash para BLAKE2b-256
|
271
|
+
gcry_md_hd_t handle;
|
272
|
+
gcry_md_open(&handle, GCRY_MD_BLAKE2B_256, 0);
|
273
|
+
|
274
|
+
// Actualizar el hash con la cadena de entrada
|
275
|
+
gcry_md_write(handle, str, length);
|
276
|
+
|
277
|
+
// Finalizar el hash y obtener el resultado
|
278
|
+
memcpy(digest, gcry_md_read(handle, GCRY_MD_BLAKE2B_256), 32);
|
279
|
+
gcry_md_close(handle);
|
280
|
+
|
281
|
+
// Convertir el hash a una cadena hexadecimal
|
282
|
+
for (int n = 0; n < 32; ++n) {
|
283
|
+
sprintf(&(out[n * 2]), "%02x", (unsigned int)digest[n]);
|
284
|
+
}
|
285
|
+
out[64] = '\0'; // Terminar la cadena
|
286
|
+
|
287
|
+
VALUE result = rb_str_new2(out); // Crear una nueva cadena Ruby
|
288
|
+
return result;
|
289
|
+
}
|
290
|
+
|
291
|
+
VALUE blake2b_384_hexdigest(VALUE self, VALUE input) {
|
292
|
+
char *str = RSTRING_PTR(input);
|
293
|
+
int length = RSTRING_LEN(input); // Obtener la longitud de la cadena
|
294
|
+
unsigned char digest[48]; // BLAKE2b-384 produce un hash de 48 bytes (384 bits)
|
295
|
+
char out[97]; // 48 bytes * 2 para hexadecimal + 1 para el terminador
|
296
|
+
|
297
|
+
// Inicializar la biblioteca libgcrypt
|
298
|
+
if (!gcry_check_version(GCRYPT_VERSION)) {
|
299
|
+
rb_raise(rb_eRuntimeError, "Versión de libgcrypt no compatible.");
|
300
|
+
}
|
301
|
+
|
302
|
+
// Abrir el contexto de hash para BLAKE2b-384
|
303
|
+
gcry_md_hd_t handle;
|
304
|
+
gcry_md_open(&handle, GCRY_MD_BLAKE2B_384, 0);
|
305
|
+
|
306
|
+
// Actualizar el hash con la cadena de entrada
|
307
|
+
gcry_md_write(handle, str, length);
|
308
|
+
|
309
|
+
// Finalizar el hash y obtener el resultado
|
310
|
+
memcpy(digest, gcry_md_read(handle, GCRY_MD_BLAKE2B_384), 48);
|
311
|
+
gcry_md_close(handle);
|
312
|
+
|
313
|
+
// Convertir el hash a una cadena hexadecimal
|
314
|
+
for (int n = 0; n < 48; ++n) {
|
315
|
+
sprintf(&(out[n * 2]), "%02x", (unsigned int)digest[n]);
|
316
|
+
}
|
317
|
+
out[96] = '\0'; // Terminar la cadena
|
318
|
+
|
319
|
+
VALUE result = rb_str_new2(out); // Crear una nueva cadena Ruby
|
320
|
+
return result;
|
321
|
+
}
|
322
|
+
|
323
|
+
VALUE blake2b_512_hexdigest(VALUE self, VALUE input) {
|
324
|
+
char *str = RSTRING_PTR(input);
|
325
|
+
int length = RSTRING_LEN(input); // Obtener la longitud de la cadena
|
326
|
+
unsigned char digest[64]; // BLAKE2b-512 produce un hash de 64 bytes (512 bits)
|
327
|
+
char out[129]; // 64 bytes * 2 para hexadecimal + 1 para el terminador
|
328
|
+
|
329
|
+
// Inicializar la biblioteca libgcrypt
|
330
|
+
if (!gcry_check_version(GCRYPT_VERSION)) {
|
331
|
+
rb_raise(rb_eRuntimeError, "Versión de libgcrypt no compatible.");
|
332
|
+
}
|
333
|
+
|
334
|
+
// Abrir el contexto de hash para BLAKE2b-512
|
335
|
+
gcry_md_hd_t handle;
|
336
|
+
gcry_md_open(&handle, GCRY_MD_BLAKE2B_512, 0);
|
337
|
+
|
338
|
+
// Actualizar el hash con la cadena de entrada
|
339
|
+
gcry_md_write(handle, str, length);
|
340
|
+
|
341
|
+
// Finalizar el hash y obtener el resultado
|
342
|
+
memcpy(digest, gcry_md_read(handle, GCRY_MD_BLAKE2B_512), 64);
|
343
|
+
gcry_md_close(handle);
|
344
|
+
|
345
|
+
// Convertir el hash a una cadena hexadecimal
|
346
|
+
for (int n = 0; n < 64; ++n) {
|
347
|
+
sprintf(&(out[n * 2]), "%02x", (unsigned int)digest[n]);
|
348
|
+
}
|
349
|
+
out[128] = '\0'; // Terminar la cadena
|
350
|
+
|
351
|
+
VALUE result = rb_str_new2(out); // Crear una nueva cadena Ruby
|
352
|
+
return result;
|
353
|
+
}
|
354
|
+
|
355
|
+
VALUE whirlpool_hexdigest(VALUE self, VALUE input) {
|
356
|
+
// Convertir el valor Ruby a una cadena C
|
357
|
+
char *str = RSTRING_PTR(input);
|
358
|
+
int length = RSTRING_LEN(input); // Obtener la longitud de la cadena
|
359
|
+
unsigned char digest[64]; // Whirlpool produce un hash de 64 bytes
|
360
|
+
char out[129]; // 64 bytes * 2 para hexadecimal + 1 para el terminador
|
361
|
+
|
362
|
+
// Inicializar la biblioteca de Libgcrypt
|
363
|
+
if (!gcry_check_version(GCRYPT_VERSION)) {
|
364
|
+
rb_raise(rb_eRuntimeError, "No se pudo inicializar la biblioteca Libgcrypt");
|
365
|
+
}
|
366
|
+
|
367
|
+
// Inicializar el contexto de hashing
|
368
|
+
gcry_md_hd_t handle;
|
369
|
+
if (gcry_md_open(&handle, GCRY_MD_WHIRLPOOL, 0) != 0) {
|
370
|
+
rb_raise(rb_eRuntimeError, "No se pudo abrir el contexto de hashing");
|
371
|
+
}
|
372
|
+
|
373
|
+
// Calcular el hash Whirlpool
|
374
|
+
gcry_md_write(handle, str, length);
|
375
|
+
memcpy(digest, gcry_md_read(handle, 0), 64); // Leer el hash
|
376
|
+
|
377
|
+
// Cerrar el contexto
|
378
|
+
gcry_md_close(handle);
|
379
|
+
|
380
|
+
// Convertir el hash a una cadena hexadecimal
|
381
|
+
for (int n = 0; n < 64; ++n) {
|
382
|
+
sprintf(&(out[n * 2]), "%02x", (unsigned int)digest[n]);
|
383
|
+
}
|
384
|
+
out[128] = '\0'; // Terminar la cadena
|
385
|
+
|
386
|
+
VALUE result = rb_str_new2(out); // Crear una nueva cadena Ruby
|
387
|
+
return result;
|
388
|
+
}
|
389
|
+
|
390
|
+
VALUE streebog_256_hexdigest(VALUE self, VALUE input) {
|
391
|
+
|
392
|
+
// Inicializar la biblioteca
|
393
|
+
|
394
|
+
gcry_check_version(GCRYPT_VERSION);
|
395
|
+
|
396
|
+
|
397
|
+
// Convertir el valor Ruby a cadena C
|
398
|
+
|
399
|
+
const char* str_input = StringValueCStr(input);
|
400
|
+
|
401
|
+
size_t input_len = strlen(str_input);
|
402
|
+
|
403
|
+
|
404
|
+
// Crear un contexto para el hash
|
405
|
+
|
406
|
+
gcry_md_hd_t handle;
|
407
|
+
|
408
|
+
gcry_error_t err = gcry_md_open(&handle, GCRY_MD_STRIBOG256, GCRY_MD_FLAG_SECURE); // Cambiado aquí
|
409
|
+
|
410
|
+
if (err) {
|
411
|
+
|
412
|
+
rb_raise(rb_eRuntimeError, "Error al abrir el contexto: %s", gcry_strerror(err));
|
413
|
+
|
414
|
+
}
|
415
|
+
|
416
|
+
|
417
|
+
// Añadir el mensaje al hash
|
418
|
+
|
419
|
+
gcry_md_write(handle, str_input, input_len);
|
420
|
+
|
421
|
+
|
422
|
+
// Obtener el hash
|
423
|
+
|
424
|
+
unsigned char* hash = gcry_md_read(handle, GCRY_MD_STRIBOG256); // Cambiado aquí
|
425
|
+
|
426
|
+
|
427
|
+
|
428
|
+
// Crear un string Ruby para el resultado
|
429
|
+
|
430
|
+
VALUE result = rb_str_new(NULL, gcry_md_get_algo_dlen(GCRY_MD_STRIBOG256) * 2); // Espacio para hex
|
431
|
+
|
432
|
+
char *result_ptr = RSTRING_PTR(result);
|
433
|
+
|
434
|
+
|
435
|
+
|
436
|
+
for (size_t i = 0; i < gcry_md_get_algo_dlen(GCRY_MD_STRIBOG256); i++) {
|
437
|
+
|
438
|
+
snprintf(result_ptr + i * 2, 3, "%02x", hash[i]); // 3 para incluir el null terminator
|
439
|
+
|
440
|
+
}
|
441
|
+
|
442
|
+
|
443
|
+
// Cerrar el contexto
|
444
|
+
|
445
|
+
gcry_md_close(handle);
|
446
|
+
|
447
|
+
|
448
|
+
return result;
|
449
|
+
|
450
|
+
}
|
451
|
+
|
452
|
+
VALUE streebog_512_hexdigest(VALUE self, VALUE input) {
|
453
|
+
|
454
|
+
// Inicializar la biblioteca
|
455
|
+
|
456
|
+
gcry_check_version(GCRYPT_VERSION);
|
457
|
+
|
458
|
+
|
459
|
+
// Convertir el valor Ruby a cadena C
|
460
|
+
|
461
|
+
const char* str_input = StringValueCStr(input);
|
462
|
+
|
463
|
+
size_t input_len = strlen(str_input);
|
464
|
+
|
465
|
+
|
466
|
+
// Crear un contexto para el hash
|
467
|
+
|
468
|
+
gcry_md_hd_t handle;
|
469
|
+
|
470
|
+
gcry_error_t err = gcry_md_open(&handle, GCRY_MD_STRIBOG512, GCRY_MD_FLAG_SECURE);
|
471
|
+
|
472
|
+
if (err) {
|
473
|
+
|
474
|
+
rb_raise(rb_eRuntimeError, "Error al abrir el contexto: %s", gcry_strerror(err));
|
475
|
+
|
476
|
+
}
|
477
|
+
|
478
|
+
|
479
|
+
// Añadir el mensaje al hash
|
480
|
+
|
481
|
+
gcry_md_write(handle, str_input, input_len);
|
482
|
+
|
483
|
+
|
484
|
+
// Obtener el hash
|
485
|
+
|
486
|
+
unsigned char* hash = gcry_md_read(handle, GCRY_MD_STRIBOG512);
|
487
|
+
|
488
|
+
|
489
|
+
|
490
|
+
// Crear un string Ruby para el resultado
|
491
|
+
|
492
|
+
VALUE result = rb_str_new(NULL, gcry_md_get_algo_dlen(GCRY_MD_STRIBOG512) * 2); // Espacio para hex
|
493
|
+
|
494
|
+
char *result_ptr = RSTRING_PTR(result);
|
495
|
+
|
496
|
+
|
497
|
+
|
498
|
+
for (size_t i = 0; i < gcry_md_get_algo_dlen(GCRY_MD_STRIBOG512); i++) {
|
499
|
+
|
500
|
+
snprintf(result_ptr + i * 2, 3, "%02x", hash[i]); // 3 para incluir el null terminator
|
501
|
+
|
502
|
+
}
|
503
|
+
|
504
|
+
|
505
|
+
// Cerrar el contexto
|
506
|
+
|
507
|
+
gcry_md_close(handle);
|
508
|
+
|
509
|
+
|
510
|
+
return result;
|
511
|
+
|
512
|
+
}
|
513
|
+
|
514
|
+
void init_cobreak_gcrypt(){
|
515
|
+
//Define module GCrypt in mCoBreak
|
516
|
+
mCoBreakGCrypt = rb_define_module_under(mCoBreak, "GCrypt");
|
517
|
+
//Define Class TIGER-160 encrypt mode
|
518
|
+
cCoBreakGCrypttiger160 = rb_define_class_under(mCoBreakGCrypt, "TIGER_160", rb_cObject);
|
519
|
+
rb_define_singleton_method(cCoBreakGCrypttiger160, "hexdigest", tiger160_hexdigest, 1);
|
520
|
+
//Define Class DOUBLE SHA-1 encrypt mode
|
521
|
+
cCoBreakGCryptdoublesha1 = rb_define_class_under(mCoBreakGCrypt, "DOUBLE_SHA1", rb_cObject);
|
522
|
+
rb_define_singleton_method(cCoBreakGCryptdoublesha1, "hexdigest", double_sha1_hexdigest, 1);
|
523
|
+
//Define Class BLAKE2S-128 encrypt mode
|
524
|
+
cCoBreakGCryptblake2s_128 = rb_define_class_under(mCoBreakGCrypt, "BLAKE2S_128", rb_cObject);
|
525
|
+
rb_define_singleton_method(cCoBreakGCryptblake2s_128, "hexdigest", blake2s_128_hexdigest, 1);
|
526
|
+
//Define Class BLAKE2S-160 encrypt mode
|
527
|
+
cCoBreakGCryptblake2s_160 = rb_define_class_under(mCoBreakGCrypt, "BLAKE2S_160", rb_cObject);
|
528
|
+
rb_define_singleton_method(cCoBreakGCryptblake2s_160, "hexdigest", blake2s_160_hexdigest, 1);
|
529
|
+
//Define Class BLAKE2B-160 encrypt mode
|
530
|
+
cCoBreakGCryptblake2b_160 = rb_define_class_under(mCoBreakGCrypt, "BLAKE2B_160", rb_cObject);
|
531
|
+
rb_define_singleton_method(cCoBreakGCryptblake2b_160, "hexdigest", blake2b_160_hexdigest, 1);
|
532
|
+
//Define Class BLAKE2S-224 encrypt mode
|
533
|
+
cCoBreakGCryptblake2s_224 = rb_define_class_under(mCoBreakGCrypt, "BLAKE2S_224", rb_cObject);
|
534
|
+
rb_define_singleton_method(cCoBreakGCryptblake2s_224, "hexdigest", blake2s_224_hexdigest, 1);
|
535
|
+
//Define Class BLAKE2S-256 encrypt mode
|
536
|
+
cCoBreakGCryptblake2s_256 = rb_define_class_under(mCoBreakGCrypt, "BLAKE2S_256", rb_cObject);
|
537
|
+
rb_define_singleton_method(cCoBreakGCryptblake2s_256, "hexdigest", blake2s_256_hexdigest, 1);
|
538
|
+
//Define Class BLAKE2B-256 encrypt mode
|
539
|
+
cCoBreakGCryptblake2b_256 = rb_define_class_under(mCoBreakGCrypt, "BLAKE2B_256", rb_cObject);
|
540
|
+
rb_define_singleton_method(cCoBreakGCryptblake2b_256, "hexdigest", blake2b_256_hexdigest, 1);
|
541
|
+
//Define Class BLAKE2B-384 encrypt mode
|
542
|
+
cCoBreakGCryptblake2b_384 = rb_define_class_under(mCoBreakGCrypt, "BLAKE2B_384", rb_cObject);
|
543
|
+
rb_define_singleton_method(cCoBreakGCryptblake2b_384, "hexdigest", blake2b_384_hexdigest, 1);
|
544
|
+
//Define Class BLAKE2B-512 encrypt mode
|
545
|
+
cCoBreakGCryptblake2b_512 = rb_define_class_under(mCoBreakGCrypt, "BLAKE2B_512", rb_cObject);
|
546
|
+
rb_define_singleton_method(cCoBreakGCryptblake2b_512, "hexdigest", blake2b_512_hexdigest, 1);
|
547
|
+
//Define Class WHIRLPOOL encrypt mode
|
548
|
+
cCoBreakGCryptwhirlpool = rb_define_class_under(mCoBreakGCrypt, "WHIRLPOOL", rb_cObject);
|
549
|
+
rb_define_singleton_method(cCoBreakGCryptwhirlpool, "hexdigest", whirlpool_hexdigest, 1);
|
550
|
+
//Define Class GOST_STREEBOG_256 encrypt mode
|
551
|
+
cCoBreakGCryptgost_streebog_256 = rb_define_class_under(mCoBreakGCrypt, "GOST_STREEBOG_256", rb_cObject);
|
552
|
+
rb_define_singleton_method(cCoBreakGCryptgost_streebog_256, "hexdigest", streebog_256_hexdigest, 1);
|
553
|
+
//Define Class GOST_STREEBOG_512 encrypt mode
|
554
|
+
cCoBreakGCryptgost_streebog_512 = rb_define_class_under(mCoBreakGCrypt, "GOST_STREEBOG_512", rb_cObject);
|
555
|
+
rb_define_singleton_method(cCoBreakGCryptgost_streebog_512, "hexdigest", streebog_512_hexdigest, 1);
|
556
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#ifndef COBREAK_GCRYPT_RUBY
|
2
|
+
#define COBREAK_GCRYPT_RUBY
|
3
|
+
|
4
|
+
//include library <cobreak_ruby.h> for project
|
5
|
+
#include<cobreak_ruby.h>
|
6
|
+
|
7
|
+
//definition body for file <header>
|
8
|
+
#include<gcrypt.h>
|
9
|
+
|
10
|
+
|
11
|
+
//initialize function
|
12
|
+
void init_cobreak_gcrypt();
|
13
|
+
|
14
|
+
#endif
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#ifndef COBREAK_OPENMP_RUBY
|
2
|
+
#define COBREAK_OPENMP_RUBY
|
3
|
+
|
4
|
+
//include library <cobreak_ruby.h> for project
|
5
|
+
#include<cobreak_ruby.h>
|
6
|
+
|
7
|
+
//include library OpenMP Parallel Program
|
8
|
+
#include<omp.h>
|
9
|
+
|
10
|
+
|
11
|
+
//initialize function
|
12
|
+
void init_cobreak_openmp();
|
13
|
+
|
14
|
+
#endif
|