Change CTR from exported to non-exported

This commit is contained in:
alexmullins 2015-10-31 20:49:00 -05:00
parent 99096bc20c
commit 2d6161cdb6
3 changed files with 8 additions and 5 deletions

View File

@ -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

2
ctr.go
View File

@ -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()

View File

@ -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