Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(618)

Delta Between Two Patch Sets: src/pkg/crypto/cipher/cfb_test.go

Issue 3183043: code review 3183043: crypto/cipher: add CFB and OCFB mode. (Closed)
Left Patch Set: Created 14 years, 4 months ago
Right Patch Set: code review 3183043: crypto/cipher: add CFB and OCFB mode. Created 14 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/crypto/cipher/cfb.go ('k') | src/pkg/crypto/cipher/ocfb.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2010 The Go Authors. All rights reserved. 1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package cipher 5 package cipher
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "crypto/aes" 9 "crypto/aes"
10 "crypto/rand" 10 "crypto/rand"
11 "testing" 11 "testing"
12 ) 12 )
13 13
14 func TestCFB(t *testing.T) { 14 func TestCFB(t *testing.T) {
15 block, err := aes.NewCipher(commonKey128) 15 block, err := aes.NewCipher(commonKey128)
16 if err != nil { 16 if err != nil {
17 t.Error(err) 17 t.Error(err)
18 return 18 return
19 } 19 }
20 20
21 plaintext := []byte("this is the plaintext") 21 plaintext := []byte("this is the plaintext")
22 iv := make([]byte, block.BlockSize()) 22 iv := make([]byte, block.BlockSize())
23 rand.Reader.Read(iv) 23 rand.Reader.Read(iv)
24 » cfb := NewCFB(block, iv, false /* decrypting? */) 24 » cfb := NewCFBEncrypter(block, iv)
25 ciphertext := make([]byte, len(plaintext)) 25 ciphertext := make([]byte, len(plaintext))
26 cfb.XORKeyStream(ciphertext, plaintext) 26 cfb.XORKeyStream(ciphertext, plaintext)
27 27
28 » cfbdec := NewCFB(block, iv, true /* decrypting? */) 28 » cfbdec := NewCFBDecrypter(block, iv)
29 plaintextCopy := make([]byte, len(plaintext)) 29 plaintextCopy := make([]byte, len(plaintext))
30 cfbdec.XORKeyStream(plaintextCopy, ciphertext) 30 cfbdec.XORKeyStream(plaintextCopy, ciphertext)
31 31
32 if !bytes.Equal(plaintextCopy, plaintext) { 32 if !bytes.Equal(plaintextCopy, plaintext) {
33 t.Errorf("got: %x, want: %x", plaintextCopy, plaintext) 33 t.Errorf("got: %x, want: %x", plaintextCopy, plaintext)
34 } 34 }
35 } 35 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b