Skip to content
Snippets Groups Projects
Commit 48599eac authored by Julian Rother's avatar Julian Rother
Browse files

Revert "hashfile: replaced md5 with sha256"

This reverts commit 1a06687a.
parent 68eb93cc
No related branches found
No related tags found
No related merge requests found
...@@ -2,34 +2,34 @@ ...@@ -2,34 +2,34 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <libavutil/sha.h> #include <libavutil/md5.h>
#include "../util.h" #include "../util.h"
char *hashfile(char *path) char *hashfile(char *path)
{ {
struct AVSHA *ctx; struct AVMD5 *ctx;
int i, fd; int i, fd;
char *ptr, *buf; char *ptr, *buf;
size_t len, size; size_t len, size;
FILE *stream; FILE *stream;
if ((fd = open(path, O_RDONLY)) < 0) if ((fd = open(path, O_RDONLY)) < 0)
job_failed("Could not open file for hashing: %s", strerror(errno)); job_failed("Could not open file for hashing: %s", strerror(errno));
if (!(ctx = av_sha_alloc())) if (!(ctx = av_md5_alloc()))
exit(99); exit(99);
av_sha_init(ctx, 256); av_md5_init(ctx);
buf = xmalloc(4096); buf = xmalloc(4096);
while ((len = read(fd, buf, 4096)) > 0) while ((len = read(fd, buf, 4096)) > 0)
av_sha_update(ctx, buf, len); av_md5_update(ctx, buf, len);
if (len < 0) if (len < 0)
job_failed("Could not read file for hashing: %s", strerror(errno)); job_failed("Could not read file for hashing: %s", strerror(errno));
close(fd); close(fd);
av_sha_final(ctx, buf); av_md5_final(ctx, buf);
av_free(ctx); av_free(ctx);
if (!(stream = open_memstream(&ptr, &size))) if (!(stream = open_memstream(&ptr, &size)))
exit(99); exit(99);
fprintf(stream, "sha256:"); fprintf(stream, "md5:");
for (i = 0; i < 32; i ++) for (i = 0; i < 16; i ++)
fprintf(stream, "%02hhx", buf[i]); fprintf(stream, "%02hhx", buf[i]);
free(buf); free(buf);
fclose(stream); fclose(stream);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment