Skip to content

Commit 84a7a45

Browse files
committed
Add ZipConstants entries for AESAuthCodeLength and AESPasswordVerifyLength, so the values can be shared
1 parent 067c051 commit 84a7a45

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

src/ICSharpCode.SharpZipLib/Encryption/ZipAESStream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public ZipAESStream(Stream stream, ZipAESTransform transform, CryptoStreamMode m
3737
}
3838

3939
// The final n bytes of the AES stream contain the Auth Code.
40-
private const int AUTH_CODE_LENGTH = 10;
40+
private const int AUTH_CODE_LENGTH = Zip.ZipConstants.AESAuthCodeLength;
4141

4242
// Blocksize is always 16 here, even for AES-256 which has transform.InputBlockSize of 32.
4343
private const int CRYPTO_BLOCK_SIZE = 16;

src/ICSharpCode.SharpZipLib/Encryption/ZipAESTransform.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ static class HashAlgorithmName
3333
}
3434
#endif
3535

36-
private const int PWD_VER_LENGTH = 2;
37-
3836
// WinZip use iteration count of 1000 for PBKDF2 key generation
3937
private const int KEY_ROUNDS = 1000;
4038

@@ -84,7 +82,7 @@ public ZipAESTransform(string key, byte[] saltBytes, int blockSize, bool writeMo
8482

8583
// Use empty IV for AES
8684
_encryptor = rm.CreateEncryptor(key1bytes, new byte[16]);
87-
_pwdVerifier = pdb.GetBytes(PWD_VER_LENGTH);
85+
_pwdVerifier = pdb.GetBytes(Zip.ZipConstants.AESPasswordVerifyLength);
8886
//
8987
_hmacsha1 = IncrementalHash.CreateHMAC(HashAlgorithmName.SHA1, key2bytes);
9088
_writeMode = writeMode;

src/ICSharpCode.SharpZipLib/Zip/ZipConstants.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,16 @@ public static class ZipConstants
345345
[Obsolete("Use CryptoHeaderSize instead")]
346346
public const int CRYPTO_HEADER_SIZE = 12;
347347

348+
/// <summary>
349+
/// The number of bytes in the WinZipAes Auth Code.
350+
/// </summary>
351+
internal const int AESAuthCodeLength = 10;
352+
353+
/// <summary>
354+
/// The number of bytes in the password verifier for WinZipAes.
355+
/// </summary>
356+
internal const int AESPasswordVerifyLength = 2;
357+
348358
/// <summary>
349359
/// The size of the Zip64 central directory locator.
350360
/// </summary>

0 commit comments

Comments
 (0)