Several fixes for issue #21.

This commit is contained in:
Moinak Ghosh 2014-08-28 22:48:36 +05:30
parent d5ceda559e
commit 376a56622b
3 changed files with 61 additions and 1 deletions

View file

@ -150,6 +150,8 @@ genShortMsg(int hashbitlen)
}
else {
printf("genShortMsg: Couldn't read Principal Submitter\n");
fclose(fp_in);
fclose(fp_out);
return KAT_HEADER_ERROR;
}
@ -165,6 +167,8 @@ genShortMsg(int hashbitlen)
if ( !ReadHex(fp_in, Msg, msgbytelen, "Msg = ") ) {
printf("ERROR: unable to read 'Msg' from <ShortMsgKAT.txt>\n");
fclose(fp_in);
fclose(fp_out);
return KAT_DATA_ERROR;
}
Keccak_Hash(hashbitlen, Msg, msglen, MD);
@ -219,6 +223,8 @@ genShortMsgSponge(unsigned int rate, unsigned int capacity, int outputLength, co
}
if ( FindMarker(fp_in, "# Principal Submitter:") ) {
rv = fscanf(fp_in, "%[^\n]\n", line);
fclose(fp_in);
fclose(fp_out);
fprintf(fp_out, "# Principal Submitter:%s\n", line);
}
else {
@ -238,6 +244,8 @@ genShortMsgSponge(unsigned int rate, unsigned int capacity, int outputLength, co
if ( !ReadHex(fp_in, Msg, msgbytelen, "Msg = ") ) {
printf("ERROR: unable to read 'Msg' from <ShortMsgKAT.txt>\n");
fclose(fp_in);
fclose(fp_out);
return KAT_DATA_ERROR;
}
fprintf(fp_out, "\nLen = %d\n", msglen);
@ -299,6 +307,8 @@ genLongMsg(int hashbitlen)
}
else {
printf("genLongMsg: Couldn't read Principal Submitter\n");
fclose(fp_in);
fclose(fp_out);
return KAT_HEADER_ERROR;
}
@ -312,6 +322,8 @@ genLongMsg(int hashbitlen)
if ( !ReadHex(fp_in, Msg, msgbytelen, "Msg = ") ) {
printf("ERROR: unable to read 'Msg' from <LongMsgKAT.txt>\n");
fclose(fp_in);
fclose(fp_out);
return KAT_DATA_ERROR;
}
#ifdef AllowExtendedFunctions
@ -386,6 +398,8 @@ genExtremelyLongMsg(int hashbitlen)
}
else {
printf("genExtremelyLongMsg: Couldn't read Principal Submitter\n");
fclose(fp_in);
fclose(fp_out);
return KAT_HEADER_ERROR;
}
@ -393,6 +407,8 @@ genExtremelyLongMsg(int hashbitlen)
rv = fscanf(fp_in, "%d", &repeat);
else {
printf("ERROR: unable to read 'Repeat' from <ExtremelyLongMsgKAT.txt>\n");
fclose(fp_in);
fclose(fp_out);
return KAT_DATA_ERROR;
}
@ -400,6 +416,8 @@ genExtremelyLongMsg(int hashbitlen)
rv = fscanf(fp_in, "%s", Text);
else {
printf("ERROR: unable to read 'Text' from <ExtremelyLongMsgKAT.txt>\n");
fclose(fp_in);
fclose(fp_out);
return KAT_DATA_ERROR;
}
@ -407,15 +425,21 @@ genExtremelyLongMsg(int hashbitlen)
if ( (retval = Keccak_Init(&state, hashbitlen)) != KAT_SUCCESS ) {
printf("Keccak_Init returned <%d> in genExtremelyLongMsg\n", retval);
fclose(fp_in);
fclose(fp_out);
return KAT_HASH_ERROR;
}
for ( i=0; i<repeat; i++ )
if ( (retval = Keccak_Update(&state, Text, 512)) != KAT_SUCCESS ) {
printf("Keccak_Update returned <%d> in genExtremelyLongMsg\n", retval);
fclose(fp_in);
fclose(fp_out);
return KAT_HASH_ERROR;
}
if ( (retval = Keccak_Final(&state, MD)) != KAT_SUCCESS ) {
printf("Keccak_Final returned <%d> in genExtremelyLongMsg\n", retval);
fclose(fp_in);
fclose(fp_out);
return KAT_HASH_ERROR;
}
#ifdef AllowExtendedFunctions
@ -476,11 +500,15 @@ genMonteCarlo(int hashbitlen)
}
else {
printf("genMonteCarlo: Couldn't read Principal Submitter\n");
fclose(fp_in);
fclose(fp_out);
return KAT_HEADER_ERROR;
}
if ( !ReadHex(fp_in, Seed, 128, "Seed = ") ) {
printf("ERROR: unable to read 'Seed' from <MonteCarlo.txt>\n");
fclose(fp_in);
fclose(fp_out);
return KAT_DATA_ERROR;
}
@ -544,11 +572,15 @@ genMonteCarloSqueezing(int hashbitlen)
}
else {
printf("genMonteCarlo: Couldn't read Principal Submitter\n");
fclose(fp_in);
fclose(fp_out);
return KAT_HEADER_ERROR;
}
if ( !ReadHex(fp_in, Seed, 128, "Seed = ") ) {
printf("ERROR: unable to read 'Seed' from <MonteCarlo.txt>\n");
fclose(fp_in);
fclose(fp_out);
return KAT_DATA_ERROR;
}
@ -556,14 +588,20 @@ genMonteCarloSqueezing(int hashbitlen)
if ( (retval = Keccak_Init(&state, hashbitlen)) != KAT_SUCCESS ) {
printf("Keccak_Init returned <%d> in genMonteCarloSqueezing\n", retval);
fclose(fp_in);
fclose(fp_out);
return KAT_HASH_ERROR;
}
if ( (retval = Keccak_Update(&state, Seed, 128*8)) != KAT_SUCCESS ) {
printf("Keccak_Update returned <%d> in genMonteCarloSqueezing\n", retval);
fclose(fp_in);
fclose(fp_out);
return KAT_HASH_ERROR;
}
if ( (retval = Keccak_Final(&state, 0)) != KAT_SUCCESS ) {
printf("Keccak_Final returned <%d> in genMonteCarloSqueezing\n", retval);
fclose(fp_in);
fclose(fp_out);
return KAT_HASH_ERROR;
}
bytelen = 64;
@ -571,6 +609,8 @@ genMonteCarloSqueezing(int hashbitlen)
for ( i=0; i<1000; i++ ) {
if ( (retval = (HashReturn)Squeeze(&state, MD, bytelen*8)) != KAT_SUCCESS ) {
printf("Squeeze returned <%d> in genMonteCarloSqueezing\n", retval);
fclose(fp_in);
fclose(fp_out);
return KAT_HASH_ERROR;
}
}

View file

@ -1902,6 +1902,8 @@ INTERN bool compare_output( void )
if ( ( buff_ori == NULL ) || ( buff_cmp == NULL ) ) {
sprintf( errormessage, MEM_ERRMSG );
errorlevel = 2;
free(buff_ori);
free(buff_cmp);
return false;
}
@ -1916,6 +1918,8 @@ INTERN bool compare_output( void )
sprintf( errormessage, "error in input stream" );
else break;
errorlevel = 2;
free(buff_ori);
free(buff_cmp);
return false;
}
@ -1924,6 +1928,8 @@ INTERN bool compare_output( void )
if ( str_out->getsize() != dsize ) {
sprintf( errormessage, "file sizes do not match" );
errorlevel = 2;
free(buff_ori);
free(buff_cmp);
return false;
}
@ -1937,6 +1943,8 @@ INTERN bool compare_output( void )
if ( buff_ori[ b ] != buff_cmp[ b ] ) {
sprintf( errormessage, "difference found at 0x%X", i );
errorlevel = 2;
free(buff_ori);
free(buff_cmp);
return false;
}
}
@ -4977,6 +4985,9 @@ INTERN bool pjg_encode_ac_high( aricoder* enc, int cmp )
if ( ( absv_store == NULL ) || ( sgn_store == NULL ) || ( zdstls == NULL ) ) {
sprintf( errormessage, MEM_ERRMSG );
errorlevel = 2;
free(absv_store);
free(sgn_store);
free(zdstls);
return false;
}
@ -5638,6 +5649,9 @@ INTERN bool pjg_decode_ac_high( aricoder* dec, int cmp )
if ( ( absv_store == NULL ) || ( sgn_store == NULL ) ) {
sprintf( errormessage, MEM_ERRMSG );
errorlevel = 2;
free(absv_store);
free(sgn_store);
free(zdstls);
return false;
}
@ -7182,6 +7196,7 @@ INTERN bool dump_pgm( void )
if ( fp == NULL ){
sprintf( errormessage, FWR_ERRMSG, fn );
errorlevel = 2;
free( fn );
return false;
}
free( fn );
@ -7191,6 +7206,7 @@ INTERN bool dump_pgm( void )
if ( imgdata == NULL ) {
sprintf( errormessage, MEM_ERRMSG );
errorlevel = 2;
fclose( fp );
return false;
}

View file

@ -1894,6 +1894,7 @@ start_compress(pc_ctx_t *pctx, const char *filename, uint64_t chunksize, int lev
thread = 0;
wthread = 0;
dedupe_flag = RABIN_DEDUPE_SEGMENTED; // Silence the compiler
compressed_chunksize = 0;
if (pctx->encrypt_type) {
uchar_t pw[MAX_PW_LEN];
@ -2141,8 +2142,11 @@ start_compress(pc_ctx_t *pctx, const char *filename, uint64_t chunksize, int lev
*
* See start_decompress() routine for details of chunk header.
* We also keep extra 8-byte space for the last chunk's size.
* compressed_chunksize might also already be set to accomodate a HMAC
* when encrypting, so we have to add to than here. Otherwise it is set
* to 0.
*/
compressed_chunksize = chunksize + CHUNK_HDR_SZ + zlib_buf_extra(chunksize);
compressed_chunksize += chunksize + CHUNK_HDR_SZ + zlib_buf_extra(chunksize);
if (pctx->_props_func) {
pctx->_props_func(&props, level, chunksize);
if (chunksize + props.buf_extra > compressed_chunksize) {