add sha256sum support code
This commit is contained in:
parent
6a58b4a5fc
commit
48045bdf6a
74
src/common/checksum.c
Normal file
74
src/common/checksum.c
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
/* this is a cleaned-up version of
|
||||||
|
* http://adamlamers.com/?p=5
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include "checksum.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
sha256_hash_string (unsigned char hash[SHA256_DIGEST_LENGTH], char outputBuffer[65])
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
for (i = 0; i < SHA256_DIGEST_LENGTH; i++)
|
||||||
|
{
|
||||||
|
sprintf(outputBuffer + (i * 2), "%02x", hash[i]);
|
||||||
|
}
|
||||||
|
outputBuffer[64] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sha256 (char *string, char outputBuffer[65])
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
unsigned char hash[SHA256_DIGEST_LENGTH];
|
||||||
|
SHA256_CTX sha256;
|
||||||
|
|
||||||
|
SHA256_Init (&sha256);
|
||||||
|
SHA256_Update (&sha256, string, strlen(string));
|
||||||
|
SHA256_Final (hash, &sha256);
|
||||||
|
|
||||||
|
for (i = 0; i < SHA256_DIGEST_LENGTH; i++)
|
||||||
|
{
|
||||||
|
sprintf (outputBuffer + (i * 2), "%02x", hash[i]);
|
||||||
|
}
|
||||||
|
outputBuffer[64] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
sha256_file (char *path, char outputBuffer[65])
|
||||||
|
{
|
||||||
|
int bytesRead;
|
||||||
|
unsigned char *buffer;
|
||||||
|
unsigned char hash[SHA256_DIGEST_LENGTH];
|
||||||
|
SHA256_CTX sha256;
|
||||||
|
|
||||||
|
FILE *file = fopen (path, "rb");
|
||||||
|
if (!file)
|
||||||
|
{
|
||||||
|
return -534;
|
||||||
|
}
|
||||||
|
|
||||||
|
SHA256_Init (&sha256);
|
||||||
|
buffer = malloc (BUFSIZE);
|
||||||
|
bytesRead = 0;
|
||||||
|
|
||||||
|
if (!buffer)
|
||||||
|
{
|
||||||
|
return ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((bytesRead = fread (buffer, 1, BUFSIZE, file)))
|
||||||
|
{
|
||||||
|
SHA256_Update (&sha256, buffer, bytesRead);
|
||||||
|
}
|
||||||
|
|
||||||
|
SHA256_Final (hash, &sha256);
|
||||||
|
sha256_hash_string (hash, outputBuffer);
|
||||||
|
|
||||||
|
fclose (file);
|
||||||
|
free (buffer);
|
||||||
|
return 0;
|
||||||
|
}
|
6
src/common/checksum.h
Normal file
6
src/common/checksum.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include <openssl/sha.h>
|
||||||
|
#define BUFSIZE 32768
|
||||||
|
|
||||||
|
void sha256_hash_string (unsigned char hash[SHA256_DIGEST_LENGTH], char outputBuffer[65]);
|
||||||
|
void sha256 (char *string, char outputBuffer[65]);
|
||||||
|
int sha256_file (char *path, char outputBuffer[65]);
|
@ -968,7 +968,7 @@ diff -ruN --strip-trailing-cr xchat-wdk.orig/src/fe-gtk/fe-gtk.c xchat-wdk/src/f
|
|||||||
sess = find_dialog (serv_list->data, "(warnings)");
|
sess = find_dialog (serv_list->data, "(warnings)");
|
||||||
diff -ruN --strip-trailing-cr xchat-wdk.orig/src/fe-gtk/fe-gtk.h xchat-wdk/src/fe-gtk/fe-gtk.h
|
diff -ruN --strip-trailing-cr xchat-wdk.orig/src/fe-gtk/fe-gtk.h xchat-wdk/src/fe-gtk/fe-gtk.h
|
||||||
--- xchat-wdk.orig/src/fe-gtk/fe-gtk.h 2010-05-30 08:31:29 +0200
|
--- xchat-wdk.orig/src/fe-gtk/fe-gtk.h 2010-05-30 08:31:29 +0200
|
||||||
+++ xchat-wdk/src/fe-gtk/fe-gtk.h 2010-10-09 12:53:27 +0200
|
+++ xchat-wdk/src/fe-gtk/fe-gtk.h 2010-10-17 00:26:18 +0200
|
||||||
@@ -4,7 +4,7 @@
|
@@ -4,7 +4,7 @@
|
||||||
/* If you're compiling this for Windows, your release is un-official
|
/* If you're compiling this for Windows, your release is un-official
|
||||||
* and not condoned. Please don't use the XChat name. Make up your
|
* and not condoned. Please don't use the XChat name. Make up your
|
||||||
|
Loading…
Reference in New Issue
Block a user