ldaphotos/sources/main/main.c
Sandy Mossgrave da6f0568b6 Initial commit. Works.
Takes a line of input from stdin, then outputs its SHA256 hash.
Verbosity cannot be changed.
2023-05-21 21:02:25 +00:00

48 lines
998 B
C

#include <stdio.h>
#include <string.h>
#include "hasher.h"
#include "log.h"
#define BUFLEN 2048
int main(void){
log("hi\n");
if(init_hasher()){
log("Error encountered while initializing hasher");
}
unsigned char * in = (unsigned char*)malloc(sizeof(unsigned char) * BUFLEN);
size_t inlen = 0;
char * signin = (char*)malloc(sizeof(char) * BUFLEN);
ssize_t bytesread = getline(&signin, &inlen, stdin);
memcpy(in, signin, bytesread);
printf("Input:\n\t");
for(int i = 0; i < bytesread; i++){
printf("%02x ", in[i]);
}
printf("\n\t");
for(int i = 0; i < bytesread; i++){
printf(" %c ", in[i]);
}
printf("\n");
unsigned int len;
unsigned char * a = digest(in, bytesread, &len);
char * aa = (char*)malloc(sizeof(char) * 2 * len);
printf("Output:\n\t");
for(int i = 0; i < len; i++){
sprintf(aa + (2 * i), "%02x", a[i]);
}
printf("%s\n", aa);
OPENSSL_free(a);
free(aa);
if(deinit_hasher()){
log("Error encountered while deinitializing hasher");
}
return 0;
}