diff options
Diffstat (limited to 'cmd/cmd_sha1.c')
-rw-r--r-- | cmd/cmd_sha1.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/cmd/cmd_sha1.c b/cmd/cmd_sha1.c new file mode 100644 index 0000000..4472ed1 --- /dev/null +++ b/cmd/cmd_sha1.c @@ -0,0 +1,41 @@ +#include "cmd_sha1.h" + +void *cmd_sha1(void *data) +{ + char *param = (char *)data; + char *ret = NULL; + int fret=-1; + + + int i; + char hash_result[21]; + char hex_result[41]; + + const int buf_size = 128; + char buf[buf_size+1]; + + printf("SHA1\n"); + + + if (param == NULL) + { + ret = alloc_new_str("No params mate\n"); + return ret; + } + + SHA1(hash_result, param, strlen(param)); + + //cool way how to convert array to string + for (i=0;i<20;i++) + { + sprintf(hex_result+(2*i), "%02x", hash_result[i]&0xff); + } + hex_result[40]=0x0; + + + snprintf(buf, buf_size, "sha1 %s\n",hex_result); + ret = alloc_new_str(buf); + + + return ret; +}
\ No newline at end of file |