Skip to content

Commit

Permalink
Added clarifying comments to WinZip AES code.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmoinvaz committed Apr 6, 2023
1 parent 3c0995b commit 16cbb2a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mz_strm_wzaes.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ int32_t mz_stream_wzaes_open(void *stream, const char *path, int32_t mode) {
mz_crypt_pbkdf2((uint8_t *)password, password_length, salt_value, salt_length,
MZ_AES_KEYING_ITERATIONS, kbuf, 2 * key_length + MZ_AES_PW_VERIFY_SIZE);

/* Initialize the encryption nonce and buffer pos */
/* Initialize the buffer pos */
wzaes->crypt_pos = MZ_AES_BLOCK_SIZE;

/* Use fixed zeroed IV/nonce for CTR mode */
memset(wzaes->nonce, 0, sizeof(wzaes->nonce));

/* Initialize for encryption using key 1 */
Expand Down Expand Up @@ -171,7 +173,7 @@ static int32_t mz_stream_wzaes_ctr_encrypt(void *stream, uint8_t *buf, int32_t s
while (j < 8 && !++wzaes->nonce[j])
j += 1;

/* Encrypt the nonce to form next xor buffer */
/* Encrypt the nonce using ECB mode to form next xor buffer */
memcpy(wzaes->crypt_block, wzaes->nonce, MZ_AES_BLOCK_SIZE);
mz_crypt_aes_encrypt(wzaes->aes, wzaes->crypt_block, sizeof(wzaes->crypt_block));
pos = 0;
Expand Down

0 comments on commit 16cbb2a

Please sign in to comment.