"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "libjte/checksum.c" between
xorriso-1.5.2.tar.gz and xorriso-1.5.4.tar.gz

About: GNU xorriso creates, loads, manipulates and writes ISO 9660 filesystem images with Rock Ridge extensions. It is suitable for incremental data backup and for production of bootable ISO 9660 images. GNU xorriso is a statical compilation of the libraries libburn, libisofs, libisoburn, and libjte.

checksum.c  (xorriso-1.5.2):checksum.c  (xorriso-1.5.4)
/* /*
* checksum.c * checksum.c
* *
* Copyright (c) 2008- Steve McIntyre <steve@einval.com> * Copyright (c) 2008-2019 Steve McIntyre <steve@einval.com>
* *
* Implementation of a generic checksum interface, used in JTE. * Implementation of a generic checksum interface, used in JTE.
* *
* GNU GPL v2+ * GNU GPL v2+
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "../config.h" #include "../config.h"
#endif #endif
#include <sys/types.h> #include <sys/types.h>
#include <regex.h> #include <regex.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <sys/stat.h>
#ifdef HAVE_STDINT_H #ifdef HAVE_STDINT_H
#include <stdint.h> #include <stdint.h>
#else #else
#ifdef HAVE_INTTYPES_H #ifdef HAVE_INTTYPES_H
#include <inttypes.h> #include <inttypes.h>
#endif #endif
#endif #endif
#include "md5.h" #include "md5.h"
#include "sha1.h" #include "sha1.h"
#include "sha256.h" #include "sha256.h"
#include "sha512.h" #include "sha512.h"
#include "checksum.h" #include "checksum.h"
#ifdef THREADED_CHECKSUMS #ifdef THREADED_CHECKSUMS
#include <pthread.h> #include <pthread.h>
#endif #endif
/* O_BINARY is needed for Cygwin but undefined elsewhere */
#ifndef O_BINARY
#define O_BINARY 0
#endif
static void md5_init(void *context) static void md5_init(void *context)
{ {
mk_MD5Init(context); mk_MD5Init(context);
} }
static void md5_update(void *context, unsigned char const *buf, unsigned int len ) static void md5_update(void *context, unsigned char const *buf, unsigned int len )
{ {
mk_MD5Update(context, buf, len); mk_MD5Update(context, buf, len);
} }
static void md5_final(unsigned char *digest, void *context) static void md5_final(unsigned char *digest, void *context)
{ {
skipping to change at line 236 skipping to change at line 232
/* and tell the main thread that we're done with that /* and tell the main thread that we're done with that
* buffer */ * buffer */
pthread_mutex_lock(&c->done_mutex); pthread_mutex_lock(&c->done_mutex);
c->threads_running--; c->threads_running--;
if (c->threads_running == 0) if (c->threads_running == 0)
pthread_cond_signal(&c->done_cv); pthread_cond_signal(&c->done_cv);
pthread_mutex_unlock(&c->done_mutex); pthread_mutex_unlock(&c->done_mutex);
} }
pthread_exit(0); pthread_exit(NULL);
} }
#endif #endif
checksum_context_t *checksum_init_context(int checksums, const char *owner) checksum_context_t *checksum_init_context(int checksums, const char *owner)
{ {
int i = 0; int i = 0;
#ifdef THREADED_CHECKSUMS #ifdef THREADED_CHECKSUMS
int ret = 0; int ret = 0;
#endif #endif
skipping to change at line 418 skipping to change at line 414
struct _checksum_context *c = context; struct _checksum_context *c = context;
#ifdef THREADED_CHECKSUMS #ifdef THREADED_CHECKSUMS
/* Clean up the threads */ /* Clean up the threads */
c->threads_running = c->threads_desired; c->threads_running = c->threads_desired;
for (i = 0; i < NUM_CHECKSUMS; i++) for (i = 0; i < NUM_CHECKSUMS; i++)
{ {
if (c->algo[i].enabled) if (c->algo[i].enabled)
{ {
void *ret = 0; void *ret = NULL;
struct algo_context *a = &c->algo[i]; struct algo_context *a = &c->algo[i];
pthread_mutex_lock(&a->start_mutex); pthread_mutex_lock(&a->start_mutex);
a->len = 0; a->len = 0;
a->buf = (unsigned char *)-1; a->buf = (unsigned char *)-1;
pthread_cond_signal(&a->start_cv); pthread_cond_signal(&a->start_cv);
pthread_mutex_unlock(&a->start_mutex); pthread_mutex_unlock(&a->start_mutex);
pthread_join(a->thread, &ret); pthread_join(a->thread, &ret);
a->thread = 0; a->thread = 0;
} }
skipping to change at line 526 skipping to change at line 522
if (start_ptr[len] == 0) if (start_ptr[len] == 0)
break; break;
start_ptr += len + 1; start_ptr += len + 1;
} }
return 0; return 0;
} }
/* Helper function: Simply calculate the checksum of the first "size"
* bytes of a file using the specified algorithm. If size == -1,
* calculate the checksum for the whole of the file. The caller is
* responsible for passing in a large enough buffer as "digest", based
* on their choice of algorithm. */
int checksum_calculate(char *filename,
int64_t size,
unsigned char *out,
enum checksum_types which)
{
char buffer[32768];
FILE *infile = NULL;
int64_t remain = 0;
int use;
struct checksum_context_t *context;
context = checksum_init_context(1 << which, "misc");
if (!context)
{
errno = ENOMEM;
return -1;
}
infile = fopen(filename, "rb");
if (!infile)
return -1;
if (-1 == size)
{
struct stat st;
stat(filename, &st);
size = st.st_size;
}
remain = size;
while (remain > 0)
{
use = (remain > (int) sizeof(buffer) ? (int) sizeof(buffer)
: remain);
if (fread(buffer, 1, use, infile) == 0)
return -1;
/* Update the checksum */
checksum_update(context, (unsigned char *)buffer, use);
remain -= use;
}
fclose(infile);
checksum_final(context);
checksum_copy(context, which, out);
checksum_free_context(context);
return 0;
}
/* Read in a hex-dumped checksum and parse it */
int checksum_parse_hex(char *in, unsigned char *out, int size)
{
int i = 0;
if (size % 2) /* odd number */
return EINVAL;
for (i = 0; i < size / 2; i++)
{
if (in[2*i] >= '0' && in[2*i] <= '9')
in[2*i] -= '0';
else if (in[2*i] >= 'A' && in[2*i] <= 'F')
in[2*i] += 10 - 'A';
else if (in[2*i] >= 'a' && in[2*i] <= 'f')
in[2*i] += 10 - 'a';
else
return 1;
if (in[1+(2*i)] >= '0' && in[1+(2*i)] <= '9')
in[1+(2*i)] -= '0';
else if (in[1+(2*i)] >= 'A' && in[1+(2*i)] <= 'F')
in[1+(2*i)] += 10 - 'A';
else if (in[1+(2*i)] >= 'a' && in[1+(2*i)] <= 'f')
in[1+(2*i)] += 10 - 'a';
else
return 1;
out[i] = in[2*i] << 4 | in[1+(2*i)];
}
return 0;
}
#ifdef CHECKSUM_SELF_TEST #ifdef CHECKSUM_SELF_TEST
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
skipping to change at line 550 skipping to change at line 629
static checksum_context_t *test_context = NULL; static checksum_context_t *test_context = NULL;
int i = 0; int i = 0;
if (argc != 2) if (argc != 2)
{ {
fprintf(stderr, "Need a filename to act on!\n"); fprintf(stderr, "Need a filename to act on!\n");
return 1; return 1;
} }
filename = argv[1]; filename = argv[1];
fd = open(filename, O_RDONLY | O_BINARY); fd = open(filename, O_RDONLY);
if (fd < 0) if (fd < 0)
{ {
fprintf(stderr, "Unable to open file %s, errno %d\n", filename, errno); fprintf(stderr, "Unable to open file %s, errno %d\n", filename, errno);
return 1; return 1;
} }
test_context = checksum_init_context(CHECK_ALL_USED, "test"); test_context = checksum_init_context(CHECK_ALL_USED, "test");
if (!test_context) if (!test_context)
{ {
fprintf(stderr, "Unable to initialise checksum context\n"); fprintf(stderr, "Unable to initialise checksum context\n");
 End of changes. 7 change blocks. 
9 lines changed or deleted 88 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)