-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhashit.c
66 lines (57 loc) · 1.84 KB
/
hashit.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdbool.h>
#include <gcrypt.h>
#include <errno.h>
#include <time.h>
#include "login.h"
int main(int argc, char** argv)
{
time_t thetime = time(NULL);
printf("hashit v0.1 - %s", ctime(&thetime));
clock_t start, end;
start = clock();
int algo;
char buffer[1<<12];
char final[1<<12];
gcrypt_init();
printf("These are the available algorithms: \n\
GCRY_MD_MD5 = 1,\n\
GCRY_MD_SHA1 = 2,\n\
GCRY_MD_RMD160 = 3,\n\
GCRY_MD_TIGER = 6, /* TIGER/192 as used by gpg <= 1.3.2. */\n\
GCRY_MD_SHA256 = 8,\n\
GCRY_MD_SHA384 = 9,\n\
GCRY_MD_SHA512 = 10,\n\
GCRY_MD_SHA224 = 11,\n\
GCRY_MD_MD4 = 301,\n\
GCRY_MD_CRC32 = 302,\n\
GCRY_MD_CRC32_RFC1510 = 303,\n\
GCRY_MD_CRC24_RFC2440 = 304,\n\
GCRY_MD_WHIRLPOOL = 305,\n\
GCRY_MD_TIGER1 = 306, /* TIGER fixed. */\n\
GCRY_MD_TIGER2 = 307 /* TIGER2 variant. */\n");
printf("Please enter the number of the desired algorithm: ");
scanf("%i", &algo);
bool rangeOk = false;
if ((algo > 0 && algo < 12 && (algo != 4 && algo != 5 && algo != 7)) || (algo > 300 && algo < 308))
rangeOk = true;
if (!rangeOk) {
printf("Select a valid algorithm please\n");
abort();
}
char* ptr = buffer;
getchar(); // fall thru without this call
printf("What value do you want to hash? ");
fgets(ptr, sizeof buffer, stdin);
ptr[strlen(ptr)-1] = '\0'; // remove '\n' of fgets
char* hash = final;
hash_func(ptr, hash, algo, GCRY_MD_FLAG_SECURE);
printf("\"%s\" hashed is:\n%s\n", ptr, hash);
end = clock();
double execution_time = (double) ((end - start) / CLOCKS_PER_SEC);
printf("Execution of the program took %.12lf secs\n",execution_time); //(double) ((end - start) / CLOCKS_PER_SEC) );
return 0;
}