move var declarations to the beginning of the block
parent
7744b613d7
commit
cdcebdc1e2
|
|
@ -137,6 +137,7 @@ int AsconEncrypt(wc_AsconCtx* ctx)
|
|||
byte salt[SALT_SIZE] = {0};
|
||||
byte tag[ASCON_AEAD128_TAG_SZ] = {0};
|
||||
int chunk_read = BLOCK_SIZE;
|
||||
long j;
|
||||
|
||||
|
||||
if (fseek(ctx->inFile, 0, SEEK_END) != SUCCESS) {
|
||||
|
|
@ -204,7 +205,7 @@ int AsconEncrypt(wc_AsconCtx* ctx)
|
|||
}
|
||||
|
||||
/* Loop reading a block at a time */
|
||||
for (long j = 0; j <= ctx->inFileLength; j += BLOCK_SIZE) {
|
||||
for (j = 0; j <= ctx->inFileLength; j += BLOCK_SIZE) {
|
||||
if (chunk_read > ctx->inFileLength - j) {
|
||||
chunk_read = ctx->inFileLength - j;
|
||||
}
|
||||
|
|
@ -302,6 +303,7 @@ int AsconDecrypt(wc_AsconCtx* ctx)
|
|||
if (ctx->inFileLength >= FILE_HEADER_SIZE) {
|
||||
int chunk_read = BLOCK_SIZE;
|
||||
int i = 0;
|
||||
long j;
|
||||
|
||||
/* read the file header and extract salt, nonce, and tag */
|
||||
if (fread(ctx->cipherText, 1, FILE_HEADER_SIZE, ctx->inFile) != FILE_HEADER_SIZE) {
|
||||
|
|
@ -351,7 +353,7 @@ int AsconDecrypt(wc_AsconCtx* ctx)
|
|||
/* Start decrypting ciphertext */
|
||||
ctx->inFileLength -= FILE_HEADER_SIZE;
|
||||
|
||||
for (long j = 0; j <= ctx->inFileLength; j += BLOCK_SIZE) {
|
||||
for (j = 0; j <= ctx->inFileLength; j += BLOCK_SIZE) {
|
||||
if (chunk_read > ctx->inFileLength - j) {
|
||||
chunk_read = ctx->inFileLength - j;
|
||||
}
|
||||
|
|
@ -466,6 +468,9 @@ int main(int argc, char** argv)
|
|||
printf("Memory allocation for ctx failed.\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
|
||||
ctx->ascon = NULL;
|
||||
ctx->key = NULL;
|
||||
ctx->password = NULL;
|
||||
|
|
|
|||
|
|
@ -56,12 +56,15 @@ int main(int argc, char** argv)
|
|||
int ret = 1;
|
||||
#ifdef HAVE_ASCON
|
||||
wc_AsconHash256* asconHash = NULL;
|
||||
byte hash[ASCON_HASH256_SZ] = {0};
|
||||
byte* rawInput = NULL;
|
||||
FILE* inputStream = NULL;
|
||||
char* fName = NULL;
|
||||
long fileLength = 0;
|
||||
int chunkRead = BLOCK_SIZE;
|
||||
byte hash[ASCON_HASH256_SZ] = {0};
|
||||
byte* rawInput = NULL;
|
||||
FILE* inputStream = NULL;
|
||||
char* fName = NULL;
|
||||
long fileLength = 0;
|
||||
int chunkRead = BLOCK_SIZE;
|
||||
long i;
|
||||
int j;
|
||||
size_t read;
|
||||
|
||||
if (argc < 2)
|
||||
usage();
|
||||
|
|
@ -105,12 +108,12 @@ int main(int argc, char** argv)
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
for (long i = 0; i < fileLength; i += BLOCK_SIZE) {
|
||||
for (i = 0; i < fileLength; i += BLOCK_SIZE) {
|
||||
if (chunkRead > fileLength - i)
|
||||
chunkRead = fileLength - i;
|
||||
|
||||
/* Read blocks from input file into a byte array*/
|
||||
size_t read = fread(rawInput, 1, chunkRead, inputStream);
|
||||
read = fread(rawInput, 1, chunkRead, inputStream);
|
||||
if (read != chunkRead) {
|
||||
printf("ERROR: Failed to read the size of input file\n");
|
||||
goto cleanup;
|
||||
|
|
@ -132,8 +135,8 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
printf("Hash result is: ");
|
||||
for (int i = 0; i < ASCON_HASH256_SZ; i++)
|
||||
printf("%02x", hash[i]);
|
||||
for (j = 0; j < ASCON_HASH256_SZ; j++)
|
||||
printf("%02x", hash[j]);
|
||||
printf("\n");
|
||||
|
||||
cleanup:
|
||||
|
|
|
|||
Loading…
Reference in New Issue