Skip to content

Commit

Permalink
use primitive methods for < 8 bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Jan 3, 2020
1 parent c6331af commit 99d42c4
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions crypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func encrypt8(block cipher.Block, dst, src, buf []byte) {
base += 8
fallthrough
case 0:
xor.BytesA(dst[base:], src[base:], tbl)
xorBytes(dst[base:], src[base:], tbl)
}
}

Expand Down Expand Up @@ -409,7 +409,7 @@ func encrypt16(block cipher.Block, dst, src, buf []byte) {
base += 16
fallthrough
case 0:
xor.BytesA(dst[base:], src[base:], tbl)
xorBytes(dst[base:], src[base:], tbl)
}
}

Expand Down Expand Up @@ -500,7 +500,7 @@ func encryptVariant(block cipher.Block, dst, src, buf []byte) {
base += blocksize
fallthrough
case 0:
xor.BytesA(dst[base:], src[base:], tbl)
xorBytes(dst[base:], src[base:], tbl)
}
}

Expand Down Expand Up @@ -602,7 +602,7 @@ func decrypt8(block cipher.Block, dst, src, buf []byte) {
base += 8
fallthrough
case 0:
xor.BytesA(dst[base:], src[base:], tbl)
xorBytes(dst[base:], src[base:], tbl)
}
}

Expand Down Expand Up @@ -688,7 +688,7 @@ func decrypt16(block cipher.Block, dst, src, buf []byte) {
base += 16
fallthrough
case 0:
xor.BytesA(dst[base:], src[base:], tbl)
xorBytes(dst[base:], src[base:], tbl)
}
}

Expand Down Expand Up @@ -787,6 +787,22 @@ func decryptVariant(block cipher.Block, dst, src, buf []byte) {
base += blocksize
fallthrough
case 0:
xor.BytesA(dst[base:], src[base:], tbl)
xorBytes(dst[base:], src[base:], tbl)
}
}

// per bytes xors
func xorBytes(dst, a, b []byte) int {
n := len(a)
if len(b) < n {
n = len(b)
}
if n == 0 {
return 0
}

for i := 0; i < n; i++ {
dst[i] = a[i] ^ b[i]
}
return n
}

0 comments on commit 99d42c4

Please sign in to comment.