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

Delta Between Two Patch Sets: src/pkg/crypto/des/des_test.go

Issue 12072045: code review 12072045: crypto/des: faster permutation. (Closed)
Left Patch Set: Created 10 years, 8 months ago
Right Patch Set: diff -r cc5858966b08 https://go.googlecode.com/hg/ Created 10 years, 8 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:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/crypto/des/const.go ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2011 The Go Authors. All rights reserved. 1 // Copyright 2011 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 des 5 package des
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "testing" 9 "testing"
10 ) 10 )
(...skipping 1486 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 1497
1498 out := make([]byte, len(tt.out)) 1498 out := make([]byte, len(tt.out))
1499 c.Decrypt(out, tt.out) 1499 c.Decrypt(out, tt.out)
1500 1500
1501 if !bytes.Equal(out, tt.in) { 1501 if !bytes.Equal(out, tt.in) {
1502 t.Errorf("#%d: result: %x want: %x", i, out, tt.in) 1502 t.Errorf("#%d: result: %x want: %x", i, out, tt.in)
1503 } 1503 }
1504 } 1504 }
1505 } 1505 }
1506 1506
1507 func TestInitialPermute(t *testing.T) {
1508 for i := uint(0); i < 64; i++ {
1509 bit := uint64(1) << i
1510 got := permuteInitialBlock(bit)
1511 want := uint64(1) << finalPermutation[63-i]
1512 if got != want {
1513 t.Errorf("permute(%x) = %x, want %x", bit, got, want)
1514 }
1515 }
1516 }
1517
1518 func TestFinalPermute(t *testing.T) {
1519 for i := uint(0); i < 64; i++ {
1520 bit := uint64(1) << i
1521 got := permuteFinalBlock(bit)
1522 want := uint64(1) << initialPermutation[63-i]
1523 if got != want {
1524 t.Errorf("permute(%x) = %x, want %x", bit, got, want)
1525 }
1526 }
1527 }
1528
1529 func TestExpandBlock(t *testing.T) {
1530 for i := uint(0); i < 32; i++ {
1531 bit := uint32(1) << i
1532 got := expandBlock(bit)
1533 want := permuteBlock(uint64(bit), expansionFunction[:])
1534 if got != want {
1535 t.Errorf("expand(%x) = %x, want %x", bit, got, want)
1536 }
1537 }
1538 }
1539
1507 func BenchmarkEncrypt(b *testing.B) { 1540 func BenchmarkEncrypt(b *testing.B) {
1508 tt := encryptDESTests[0] 1541 tt := encryptDESTests[0]
1509 c, err := NewCipher(tt.key) 1542 c, err := NewCipher(tt.key)
1510 if err != nil { 1543 if err != nil {
1511 b.Fatal("NewCipher:", err) 1544 b.Fatal("NewCipher:", err)
1512 } 1545 }
1513 out := make([]byte, len(tt.in)) 1546 out := make([]byte, len(tt.in))
1514 b.SetBytes(int64(len(out))) 1547 b.SetBytes(int64(len(out)))
1515 b.ResetTimer() 1548 b.ResetTimer()
1516 for i := 0; i < b.N; i++ { 1549 for i := 0; i < b.N; i++ {
1517 c.Encrypt(out, tt.in) 1550 c.Encrypt(out, tt.in)
1518 } 1551 }
1519 } 1552 }
1520 1553
1521 func BenchmarkDecrypt(b *testing.B) { 1554 func BenchmarkDecrypt(b *testing.B) {
1522 tt := encryptDESTests[0] 1555 tt := encryptDESTests[0]
1523 c, err := NewCipher(tt.key) 1556 c, err := NewCipher(tt.key)
1524 if err != nil { 1557 if err != nil {
1525 b.Fatal("NewCipher:", err) 1558 b.Fatal("NewCipher:", err)
1526 } 1559 }
1527 out := make([]byte, len(tt.out)) 1560 out := make([]byte, len(tt.out))
1528 b.SetBytes(int64(len(out))) 1561 b.SetBytes(int64(len(out)))
1529 b.ResetTimer() 1562 b.ResetTimer()
1530 for i := 0; i < b.N; i++ { 1563 for i := 0; i < b.N; i++ {
1531 c.Decrypt(out, tt.out) 1564 c.Decrypt(out, tt.out)
1532 } 1565 }
1533 } 1566 }
LEFTRIGHT

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