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

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

Issue 24250044: crypto/cipher: speed up xor operations in CBC, OBF, CTR... (Closed)
Left Patch Set: diff -r c8d3de543c1b https://code.google.com/p/go Created 10 years, 3 months ago
Right Patch Set: diff -r c8d3de543c1b https://code.google.com/p/go Created 10 years, 3 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/ofb.go ('k') | src/pkg/crypto/cipher/xor_test.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 2013 The Go Authors. All rights reserved. 1 // Copyright 2013 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 "runtime" 8 "runtime"
9 "unsafe" 9 "unsafe"
10 ) 10 )
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // TODO(hanwen): if (dst, a, b) have common alignment 57 // TODO(hanwen): if (dst, a, b) have common alignment
58 // we could still try fastXORBytes. It is not clear 58 // we could still try fastXORBytes. It is not clear
59 // how often this happens, and it's only worth it if 59 // how often this happens, and it's only worth it if
60 // the block encryption itself is hardware 60 // the block encryption itself is hardware
61 // accelerated. 61 // accelerated.
62 return safeXORBytes(dst, a, b) 62 return safeXORBytes(dst, a, b)
63 } 63 }
64 } 64 }
65 65
66 // fastXORWords XORs multiples of 4 or 8 bytes (depending on architecture.) 66 // fastXORWords XORs multiples of 4 or 8 bytes (depending on architecture.)
67 // The arguments are assumed to be of equal length.
67 func fastXORWords(dst, a, b []byte) { 68 func fastXORWords(dst, a, b []byte) {
68 dw := *(*[]uintptr)(unsafe.Pointer(&dst)) 69 dw := *(*[]uintptr)(unsafe.Pointer(&dst))
69 aw := *(*[]uintptr)(unsafe.Pointer(&a)) 70 aw := *(*[]uintptr)(unsafe.Pointer(&a))
70 bw := *(*[]uintptr)(unsafe.Pointer(&b)) 71 bw := *(*[]uintptr)(unsafe.Pointer(&b))
71
72 n := len(b) / wordSize 72 n := len(b) / wordSize
73 for i := 0; i < n; i++ { 73 for i := 0; i < n; i++ {
74 dw[i] = aw[i] ^ bw[i] 74 dw[i] = aw[i] ^ bw[i]
75 } 75 }
76 } 76 }
77 77
78 func xorWords(dst, a, b []byte) { 78 func xorWords(dst, a, b []byte) {
79 if supportsUnaligned { 79 if supportsUnaligned {
80 fastXORWords(dst, a, b) 80 fastXORWords(dst, a, b)
81 } else { 81 } else {
82 safeXORBytes(dst, a, b) 82 safeXORBytes(dst, a, b)
83 } 83 }
84 } 84 }
LEFTRIGHT

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