From 2d6161cdb640ff3f1fc742acf2f8fc3d00b5a479 Mon Sep 17 00:00:00 2001 From: alexmullins Date: Sat, 31 Oct 2015 20:49:00 -0500 Subject: [PATCH] Change CTR from exported to non-exported --- README.txt | 7 +++++-- ctr.go | 2 +- reader.go | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.txt b/README.txt index 02847b5..074111b 100644 --- a/README.txt +++ b/README.txt @@ -11,11 +11,14 @@ hello.txt -> compress -> encrypt -> .zip -> decrypt -> decompress -> hello.txt Roadmap ============================================================================== -Reading - Works. See ctr.go for implementation. +Reading - Done. TODO: + 1.Change to streaming authentication and decryption + 2.Check for AE-2 and skip CRC check to align with WinZip spec. Writing - Not started. Testing - Needs more. + WinZip AES specifies ============================================================================== 1. Encryption-Decryption w/ AES-CTR (128, 192, or 256 bits) @@ -67,5 +70,5 @@ Refer to http://www.winzip.com/aes_info.htm#winzip11 for the reasoning. 16. Storage Format (file data payload) totals CompressedSize64 bytes: a. Salt - 8, 12, or 16 bytes depending on keysize b. Password Verification Value - 2 bytes - c. Encrypted Data - compressed size - satl - pwv - auth lengths + c. Encrypted Data - compressed size - salt - pwv - auth lengths d. Authentication code - 10 bytes diff --git a/ctr.go b/ctr.go index 03c9ba5..360fae0 100644 --- a/ctr.go +++ b/ctr.go @@ -30,7 +30,7 @@ const streamBufferSize = 512 // NewWinZipCTR returns a Stream which encrypts/decrypts using the given Block in // counter mode. The counter is initially set to 1. -func NewWinZipCTR(block cipher.Block) cipher.Stream { +func newWinZipCTR(block cipher.Block) cipher.Stream { bufSize := streamBufferSize if bufSize < block.BlockSize() { bufSize = block.BlockSize() diff --git a/reader.go b/reader.go index 5186d38..4f655dc 100644 --- a/reader.go +++ b/reader.go @@ -209,7 +209,7 @@ func newDecryptionReader(r io.Reader, f *File) (io.Reader, error) { if saltLen == 0 { return nil, ErrDecryption } - // Is there a better method than reading in the entire contents? + // Change to a streaming content := make([]byte, f.CompressedSize64) if _, err := io.ReadFull(r, content); err != nil { return nil, ErrDecryption @@ -240,7 +240,7 @@ func decryptStream(ciphertext, key []byte) io.Reader { if err != nil { return nil } - stream := NewWinZipCTR(block) + stream := newWinZipCTR(block) // Not decrypting stream correctly if the number of bytes being read is >16 reader := cipher.StreamReader{S: stream, R: bytes.NewReader(ciphertext)} return reader