Debian Codegraph @

siv/xorend.go

raw symbols SCIP
1 // Copyright 2012 Aaron Jacobs. All Rights Reserved.
2 // Author: [email protected] (Aaron Jacobs)
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15
16 package siv
17
18 import (
19 "log"
20
21 "github.com/jacobsa/crypto/common"
22 )
23
24 // The xorend operator of RFC 5297.
25 //
26 // Given strings A and B with len(A) >= len(B), let D be len(A) - len(B). Write
27 // A[:D] followed by xor(A[D:], B) into dst. In other words, xor B over the
28 // rightmost end of A and write the result into dst.
29 func xorend(dst, a, b []byte) {
30 aLen := len(a)
31 bLen := len(b)
32 dstLen := len(dst)
33
34 if dstLen < aLen || aLen < bLen {
35 log.Panicf("Bad buffer lengths: %d, %d, %d", dstLen, aLen, bLen)
36 }
37
38 // Copy the left part.
39 difference := aLen - bLen
40 copy(dst, a[:difference])
41
42 // XOR in the right part.
43 common.Xor(dst[difference:difference+bLen], a[difference:], b)
44 }