Several fixes for issue #21.
This commit is contained in:
parent
d5ceda559e
commit
376a56622b
3 changed files with 61 additions and 1 deletions
|
@ -150,6 +150,8 @@ genShortMsg(int hashbitlen)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf("genShortMsg: Couldn't read Principal Submitter\n");
|
printf("genShortMsg: Couldn't read Principal Submitter\n");
|
||||||
|
fclose(fp_in);
|
||||||
|
fclose(fp_out);
|
||||||
return KAT_HEADER_ERROR;
|
return KAT_HEADER_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,6 +167,8 @@ genShortMsg(int hashbitlen)
|
||||||
|
|
||||||
if ( !ReadHex(fp_in, Msg, msgbytelen, "Msg = ") ) {
|
if ( !ReadHex(fp_in, Msg, msgbytelen, "Msg = ") ) {
|
||||||
printf("ERROR: unable to read 'Msg' from <ShortMsgKAT.txt>\n");
|
printf("ERROR: unable to read 'Msg' from <ShortMsgKAT.txt>\n");
|
||||||
|
fclose(fp_in);
|
||||||
|
fclose(fp_out);
|
||||||
return KAT_DATA_ERROR;
|
return KAT_DATA_ERROR;
|
||||||
}
|
}
|
||||||
Keccak_Hash(hashbitlen, Msg, msglen, MD);
|
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:") ) {
|
if ( FindMarker(fp_in, "# Principal Submitter:") ) {
|
||||||
rv = fscanf(fp_in, "%[^\n]\n", line);
|
rv = fscanf(fp_in, "%[^\n]\n", line);
|
||||||
|
fclose(fp_in);
|
||||||
|
fclose(fp_out);
|
||||||
fprintf(fp_out, "# Principal Submitter:%s\n", line);
|
fprintf(fp_out, "# Principal Submitter:%s\n", line);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -238,6 +244,8 @@ genShortMsgSponge(unsigned int rate, unsigned int capacity, int outputLength, co
|
||||||
|
|
||||||
if ( !ReadHex(fp_in, Msg, msgbytelen, "Msg = ") ) {
|
if ( !ReadHex(fp_in, Msg, msgbytelen, "Msg = ") ) {
|
||||||
printf("ERROR: unable to read 'Msg' from <ShortMsgKAT.txt>\n");
|
printf("ERROR: unable to read 'Msg' from <ShortMsgKAT.txt>\n");
|
||||||
|
fclose(fp_in);
|
||||||
|
fclose(fp_out);
|
||||||
return KAT_DATA_ERROR;
|
return KAT_DATA_ERROR;
|
||||||
}
|
}
|
||||||
fprintf(fp_out, "\nLen = %d\n", msglen);
|
fprintf(fp_out, "\nLen = %d\n", msglen);
|
||||||
|
@ -299,6 +307,8 @@ genLongMsg(int hashbitlen)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf("genLongMsg: Couldn't read Principal Submitter\n");
|
printf("genLongMsg: Couldn't read Principal Submitter\n");
|
||||||
|
fclose(fp_in);
|
||||||
|
fclose(fp_out);
|
||||||
return KAT_HEADER_ERROR;
|
return KAT_HEADER_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,6 +322,8 @@ genLongMsg(int hashbitlen)
|
||||||
|
|
||||||
if ( !ReadHex(fp_in, Msg, msgbytelen, "Msg = ") ) {
|
if ( !ReadHex(fp_in, Msg, msgbytelen, "Msg = ") ) {
|
||||||
printf("ERROR: unable to read 'Msg' from <LongMsgKAT.txt>\n");
|
printf("ERROR: unable to read 'Msg' from <LongMsgKAT.txt>\n");
|
||||||
|
fclose(fp_in);
|
||||||
|
fclose(fp_out);
|
||||||
return KAT_DATA_ERROR;
|
return KAT_DATA_ERROR;
|
||||||
}
|
}
|
||||||
#ifdef AllowExtendedFunctions
|
#ifdef AllowExtendedFunctions
|
||||||
|
@ -386,6 +398,8 @@ genExtremelyLongMsg(int hashbitlen)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf("genExtremelyLongMsg: Couldn't read Principal Submitter\n");
|
printf("genExtremelyLongMsg: Couldn't read Principal Submitter\n");
|
||||||
|
fclose(fp_in);
|
||||||
|
fclose(fp_out);
|
||||||
return KAT_HEADER_ERROR;
|
return KAT_HEADER_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,6 +407,8 @@ genExtremelyLongMsg(int hashbitlen)
|
||||||
rv = fscanf(fp_in, "%d", &repeat);
|
rv = fscanf(fp_in, "%d", &repeat);
|
||||||
else {
|
else {
|
||||||
printf("ERROR: unable to read 'Repeat' from <ExtremelyLongMsgKAT.txt>\n");
|
printf("ERROR: unable to read 'Repeat' from <ExtremelyLongMsgKAT.txt>\n");
|
||||||
|
fclose(fp_in);
|
||||||
|
fclose(fp_out);
|
||||||
return KAT_DATA_ERROR;
|
return KAT_DATA_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,6 +416,8 @@ genExtremelyLongMsg(int hashbitlen)
|
||||||
rv = fscanf(fp_in, "%s", Text);
|
rv = fscanf(fp_in, "%s", Text);
|
||||||
else {
|
else {
|
||||||
printf("ERROR: unable to read 'Text' from <ExtremelyLongMsgKAT.txt>\n");
|
printf("ERROR: unable to read 'Text' from <ExtremelyLongMsgKAT.txt>\n");
|
||||||
|
fclose(fp_in);
|
||||||
|
fclose(fp_out);
|
||||||
return KAT_DATA_ERROR;
|
return KAT_DATA_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,15 +425,21 @@ genExtremelyLongMsg(int hashbitlen)
|
||||||
|
|
||||||
if ( (retval = Keccak_Init(&state, hashbitlen)) != KAT_SUCCESS ) {
|
if ( (retval = Keccak_Init(&state, hashbitlen)) != KAT_SUCCESS ) {
|
||||||
printf("Keccak_Init returned <%d> in genExtremelyLongMsg\n", retval);
|
printf("Keccak_Init returned <%d> in genExtremelyLongMsg\n", retval);
|
||||||
|
fclose(fp_in);
|
||||||
|
fclose(fp_out);
|
||||||
return KAT_HASH_ERROR;
|
return KAT_HASH_ERROR;
|
||||||
}
|
}
|
||||||
for ( i=0; i<repeat; i++ )
|
for ( i=0; i<repeat; i++ )
|
||||||
if ( (retval = Keccak_Update(&state, Text, 512)) != KAT_SUCCESS ) {
|
if ( (retval = Keccak_Update(&state, Text, 512)) != KAT_SUCCESS ) {
|
||||||
printf("Keccak_Update returned <%d> in genExtremelyLongMsg\n", retval);
|
printf("Keccak_Update returned <%d> in genExtremelyLongMsg\n", retval);
|
||||||
|
fclose(fp_in);
|
||||||
|
fclose(fp_out);
|
||||||
return KAT_HASH_ERROR;
|
return KAT_HASH_ERROR;
|
||||||
}
|
}
|
||||||
if ( (retval = Keccak_Final(&state, MD)) != KAT_SUCCESS ) {
|
if ( (retval = Keccak_Final(&state, MD)) != KAT_SUCCESS ) {
|
||||||
printf("Keccak_Final returned <%d> in genExtremelyLongMsg\n", retval);
|
printf("Keccak_Final returned <%d> in genExtremelyLongMsg\n", retval);
|
||||||
|
fclose(fp_in);
|
||||||
|
fclose(fp_out);
|
||||||
return KAT_HASH_ERROR;
|
return KAT_HASH_ERROR;
|
||||||
}
|
}
|
||||||
#ifdef AllowExtendedFunctions
|
#ifdef AllowExtendedFunctions
|
||||||
|
@ -476,11 +500,15 @@ genMonteCarlo(int hashbitlen)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf("genMonteCarlo: Couldn't read Principal Submitter\n");
|
printf("genMonteCarlo: Couldn't read Principal Submitter\n");
|
||||||
|
fclose(fp_in);
|
||||||
|
fclose(fp_out);
|
||||||
return KAT_HEADER_ERROR;
|
return KAT_HEADER_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !ReadHex(fp_in, Seed, 128, "Seed = ") ) {
|
if ( !ReadHex(fp_in, Seed, 128, "Seed = ") ) {
|
||||||
printf("ERROR: unable to read 'Seed' from <MonteCarlo.txt>\n");
|
printf("ERROR: unable to read 'Seed' from <MonteCarlo.txt>\n");
|
||||||
|
fclose(fp_in);
|
||||||
|
fclose(fp_out);
|
||||||
return KAT_DATA_ERROR;
|
return KAT_DATA_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -544,11 +572,15 @@ genMonteCarloSqueezing(int hashbitlen)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf("genMonteCarlo: Couldn't read Principal Submitter\n");
|
printf("genMonteCarlo: Couldn't read Principal Submitter\n");
|
||||||
|
fclose(fp_in);
|
||||||
|
fclose(fp_out);
|
||||||
return KAT_HEADER_ERROR;
|
return KAT_HEADER_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !ReadHex(fp_in, Seed, 128, "Seed = ") ) {
|
if ( !ReadHex(fp_in, Seed, 128, "Seed = ") ) {
|
||||||
printf("ERROR: unable to read 'Seed' from <MonteCarlo.txt>\n");
|
printf("ERROR: unable to read 'Seed' from <MonteCarlo.txt>\n");
|
||||||
|
fclose(fp_in);
|
||||||
|
fclose(fp_out);
|
||||||
return KAT_DATA_ERROR;
|
return KAT_DATA_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -556,14 +588,20 @@ genMonteCarloSqueezing(int hashbitlen)
|
||||||
|
|
||||||
if ( (retval = Keccak_Init(&state, hashbitlen)) != KAT_SUCCESS ) {
|
if ( (retval = Keccak_Init(&state, hashbitlen)) != KAT_SUCCESS ) {
|
||||||
printf("Keccak_Init returned <%d> in genMonteCarloSqueezing\n", retval);
|
printf("Keccak_Init returned <%d> in genMonteCarloSqueezing\n", retval);
|
||||||
|
fclose(fp_in);
|
||||||
|
fclose(fp_out);
|
||||||
return KAT_HASH_ERROR;
|
return KAT_HASH_ERROR;
|
||||||
}
|
}
|
||||||
if ( (retval = Keccak_Update(&state, Seed, 128*8)) != KAT_SUCCESS ) {
|
if ( (retval = Keccak_Update(&state, Seed, 128*8)) != KAT_SUCCESS ) {
|
||||||
printf("Keccak_Update returned <%d> in genMonteCarloSqueezing\n", retval);
|
printf("Keccak_Update returned <%d> in genMonteCarloSqueezing\n", retval);
|
||||||
|
fclose(fp_in);
|
||||||
|
fclose(fp_out);
|
||||||
return KAT_HASH_ERROR;
|
return KAT_HASH_ERROR;
|
||||||
}
|
}
|
||||||
if ( (retval = Keccak_Final(&state, 0)) != KAT_SUCCESS ) {
|
if ( (retval = Keccak_Final(&state, 0)) != KAT_SUCCESS ) {
|
||||||
printf("Keccak_Final returned <%d> in genMonteCarloSqueezing\n", retval);
|
printf("Keccak_Final returned <%d> in genMonteCarloSqueezing\n", retval);
|
||||||
|
fclose(fp_in);
|
||||||
|
fclose(fp_out);
|
||||||
return KAT_HASH_ERROR;
|
return KAT_HASH_ERROR;
|
||||||
}
|
}
|
||||||
bytelen = 64;
|
bytelen = 64;
|
||||||
|
@ -571,6 +609,8 @@ genMonteCarloSqueezing(int hashbitlen)
|
||||||
for ( i=0; i<1000; i++ ) {
|
for ( i=0; i<1000; i++ ) {
|
||||||
if ( (retval = (HashReturn)Squeeze(&state, MD, bytelen*8)) != KAT_SUCCESS ) {
|
if ( (retval = (HashReturn)Squeeze(&state, MD, bytelen*8)) != KAT_SUCCESS ) {
|
||||||
printf("Squeeze returned <%d> in genMonteCarloSqueezing\n", retval);
|
printf("Squeeze returned <%d> in genMonteCarloSqueezing\n", retval);
|
||||||
|
fclose(fp_in);
|
||||||
|
fclose(fp_out);
|
||||||
return KAT_HASH_ERROR;
|
return KAT_HASH_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1902,6 +1902,8 @@ INTERN bool compare_output( void )
|
||||||
if ( ( buff_ori == NULL ) || ( buff_cmp == NULL ) ) {
|
if ( ( buff_ori == NULL ) || ( buff_cmp == NULL ) ) {
|
||||||
sprintf( errormessage, MEM_ERRMSG );
|
sprintf( errormessage, MEM_ERRMSG );
|
||||||
errorlevel = 2;
|
errorlevel = 2;
|
||||||
|
free(buff_ori);
|
||||||
|
free(buff_cmp);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1916,6 +1918,8 @@ INTERN bool compare_output( void )
|
||||||
sprintf( errormessage, "error in input stream" );
|
sprintf( errormessage, "error in input stream" );
|
||||||
else break;
|
else break;
|
||||||
errorlevel = 2;
|
errorlevel = 2;
|
||||||
|
free(buff_ori);
|
||||||
|
free(buff_cmp);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1924,6 +1928,8 @@ INTERN bool compare_output( void )
|
||||||
if ( str_out->getsize() != dsize ) {
|
if ( str_out->getsize() != dsize ) {
|
||||||
sprintf( errormessage, "file sizes do not match" );
|
sprintf( errormessage, "file sizes do not match" );
|
||||||
errorlevel = 2;
|
errorlevel = 2;
|
||||||
|
free(buff_ori);
|
||||||
|
free(buff_cmp);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1937,6 +1943,8 @@ INTERN bool compare_output( void )
|
||||||
if ( buff_ori[ b ] != buff_cmp[ b ] ) {
|
if ( buff_ori[ b ] != buff_cmp[ b ] ) {
|
||||||
sprintf( errormessage, "difference found at 0x%X", i );
|
sprintf( errormessage, "difference found at 0x%X", i );
|
||||||
errorlevel = 2;
|
errorlevel = 2;
|
||||||
|
free(buff_ori);
|
||||||
|
free(buff_cmp);
|
||||||
return false;
|
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 ) ) {
|
if ( ( absv_store == NULL ) || ( sgn_store == NULL ) || ( zdstls == NULL ) ) {
|
||||||
sprintf( errormessage, MEM_ERRMSG );
|
sprintf( errormessage, MEM_ERRMSG );
|
||||||
errorlevel = 2;
|
errorlevel = 2;
|
||||||
|
free(absv_store);
|
||||||
|
free(sgn_store);
|
||||||
|
free(zdstls);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5638,6 +5649,9 @@ INTERN bool pjg_decode_ac_high( aricoder* dec, int cmp )
|
||||||
if ( ( absv_store == NULL ) || ( sgn_store == NULL ) ) {
|
if ( ( absv_store == NULL ) || ( sgn_store == NULL ) ) {
|
||||||
sprintf( errormessage, MEM_ERRMSG );
|
sprintf( errormessage, MEM_ERRMSG );
|
||||||
errorlevel = 2;
|
errorlevel = 2;
|
||||||
|
free(absv_store);
|
||||||
|
free(sgn_store);
|
||||||
|
free(zdstls);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7182,6 +7196,7 @@ INTERN bool dump_pgm( void )
|
||||||
if ( fp == NULL ){
|
if ( fp == NULL ){
|
||||||
sprintf( errormessage, FWR_ERRMSG, fn );
|
sprintf( errormessage, FWR_ERRMSG, fn );
|
||||||
errorlevel = 2;
|
errorlevel = 2;
|
||||||
|
free( fn );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
free( fn );
|
free( fn );
|
||||||
|
@ -7191,6 +7206,7 @@ INTERN bool dump_pgm( void )
|
||||||
if ( imgdata == NULL ) {
|
if ( imgdata == NULL ) {
|
||||||
sprintf( errormessage, MEM_ERRMSG );
|
sprintf( errormessage, MEM_ERRMSG );
|
||||||
errorlevel = 2;
|
errorlevel = 2;
|
||||||
|
fclose( fp );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1894,6 +1894,7 @@ start_compress(pc_ctx_t *pctx, const char *filename, uint64_t chunksize, int lev
|
||||||
thread = 0;
|
thread = 0;
|
||||||
wthread = 0;
|
wthread = 0;
|
||||||
dedupe_flag = RABIN_DEDUPE_SEGMENTED; // Silence the compiler
|
dedupe_flag = RABIN_DEDUPE_SEGMENTED; // Silence the compiler
|
||||||
|
compressed_chunksize = 0;
|
||||||
|
|
||||||
if (pctx->encrypt_type) {
|
if (pctx->encrypt_type) {
|
||||||
uchar_t pw[MAX_PW_LEN];
|
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.
|
* See start_decompress() routine for details of chunk header.
|
||||||
* We also keep extra 8-byte space for the last chunk's size.
|
* 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) {
|
if (pctx->_props_func) {
|
||||||
pctx->_props_func(&props, level, chunksize);
|
pctx->_props_func(&props, level, chunksize);
|
||||||
if (chunksize + props.buf_extra > compressed_chunksize) {
|
if (chunksize + props.buf_extra > compressed_chunksize) {
|
||||||
|
|
Loading…
Reference in a new issue