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

Side by Side Diff: src/pkg/crypto/cipher/ocfb_test.go

Issue 3183043: code review 3183043: crypto/cipher: add CFB and OCFB mode. (Closed)
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:
View unified diff | Download patch
« no previous file with comments | « src/pkg/crypto/cipher/ocfb.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package cipher
6
7 import (
8 "bytes"
9 "crypto/aes"
10 "crypto/rand"
11 "testing"
12 )
13
14 func TestOCFB(t *testing.T) {
15 block, err := aes.NewCipher(commonKey128)
16 if err != nil {
17 t.Error(err)
18 return
19 }
20
21 plaintext := []byte("this is the plaintext")
22 randData := make([]byte, block.BlockSize())
23 rand.Reader.Read(randData)
24 ocfb, prefix := NewOCFBEncrypter(block, randData)
25 ciphertext := make([]byte, len(plaintext))
26 ocfb.XORKeyStream(ciphertext, plaintext)
27
28 ocfbdec := NewOCFBDecrypter(block, prefix)
29 if ocfbdec == nil {
30 t.Error("NewOCFBDecrypter failed")
31 return
32 }
33 plaintextCopy := make([]byte, len(plaintext))
34 ocfbdec.XORKeyStream(plaintextCopy, ciphertext)
35
36 if !bytes.Equal(plaintextCopy, plaintext) {
37 t.Errorf("got: %x, want: %x", plaintextCopy, plaintext)
38 }
39 }
OLDNEW
« no previous file with comments | « src/pkg/crypto/cipher/ocfb.go ('k') | no next file » | no next file with comments »

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