New API for MD5 production: iso_md5_start(), iso_md5_compute(),
iso_md5_clone(), iso_md5_end()
This commit is contained in:
@ -269,7 +269,28 @@ static int md5_final(libisofs_md5_ctx *ctx, char result[16], int flag)
|
||||
return(1);
|
||||
}
|
||||
|
||||
/** Compute a MD5 checksum from one or more calls of this function.
|
||||
The first call has to be made with flag bit0 == 1. It may already submit
|
||||
processing payload in data and datalen.
|
||||
The last call has to be made with bit15 set. Normally bit1 will be set
|
||||
too in order to receive the checksum before it gets disposed.
|
||||
bit1 may only be set in the last call or together with bit2.
|
||||
The combination of bit1 and bit2 may be used to get an intermediate
|
||||
result without hampering an ongoing checksum computation.
|
||||
|
||||
@param ctx the checksum context which stores the state between calls.
|
||||
It gets created with flag bit0 and disposed with bit15.
|
||||
With flag bit0, *ctx has to be NULL or point to freeable
|
||||
memory.
|
||||
@param data the bytes to be checksummed
|
||||
@param datalen the number of bytes in data
|
||||
@param result returns the 16 bytes of checksum if called with bit1 set
|
||||
@param flag bit0= allocate and init *ctx
|
||||
bit1= transfer ctx to result
|
||||
bit2= with bit 0 : clone new *ctx from data
|
||||
bit15= free *ctx
|
||||
*/
|
||||
static
|
||||
int libisofs_md5(void **ctx_in, char *data, int datalen,
|
||||
char result[16], int flag)
|
||||
/* *ctx has to be NULL or point to freeable memory */
|
||||
@ -310,6 +331,60 @@ int libisofs_md5(void **ctx_in, char *data, int datalen,
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
/* Public MD5 computing facility */
|
||||
|
||||
/* API */
|
||||
int iso_md5_start(void **md5_context)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = libisofs_md5(md5_context, NULL, 0, NULL, 1);
|
||||
if (ret <= 0)
|
||||
return ISO_OUT_OF_MEM;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* API */
|
||||
int iso_md5_compute(void *md5_context, char *data, int datalen)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = libisofs_md5(&md5_context, data, datalen, NULL, 0);
|
||||
if (ret <= 0)
|
||||
return ISO_NULL_POINTER;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* API */
|
||||
int iso_md5_clone(void *old_md5_context, void **new_md5_context)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = libisofs_md5(new_md5_context, old_md5_context, 0, NULL, 4);
|
||||
if (ret < 0)
|
||||
return ISO_OUT_OF_MEM;
|
||||
if (ret == 0)
|
||||
return ISO_NULL_POINTER;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* API */
|
||||
int iso_md5_end(void **md5_context, char result[16])
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = libisofs_md5(md5_context, NULL, 0, result, 2 | (1 << 15));
|
||||
if (ret <= 0)
|
||||
return ISO_NULL_POINTER;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
|
||||
@ -324,6 +399,10 @@ int checksum_xinfo_func(void *data, int flag)
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
/* MD5 checksum image writer */
|
||||
|
||||
#ifdef Libisofs_with_checksumS
|
||||
|
||||
/*
|
||||
@ -459,10 +538,9 @@ int checksum_writer_write_data(IsoImageWriter *writer)
|
||||
/* Write image checksum to index 0 */
|
||||
if (t->checksum_ctx != NULL) {
|
||||
|
||||
/* >>> rather fork a result than killing t->checksum_ctx */;
|
||||
/* >>> rather clone a result than killing t->checksum_ctx */;
|
||||
|
||||
res = libisofs_md5(&(t->checksum_ctx), NULL, 0, t->image_md5,
|
||||
2 | (1 << 15));
|
||||
res = iso_md5_end(&(t->checksum_ctx), t->image_md5);
|
||||
if (res > 0)
|
||||
memcpy(t->checksum_buffer + 0, t->image_md5, 16);
|
||||
}
|
||||
|
Reference in New Issue
Block a user