1 // Copyright 2016 The Gorilla WebSocket Authors. All rights reserved. Use of
2 // this source code is governed by a BSD-style license that can be found in the
11 const wordSize = int(unsafe.Sizeof(uintptr(0)))
13 func maskBytes(key [4]byte, pos int, b []byte) int {
14 // Mask one byte at a time for small buffers.
15 if len(b) < 2*wordSize {
23 // Mask one byte at a time to word boundary.
24 if n := int(uintptr(unsafe.Pointer(&b[0]))) % wordSize; n != 0 {
26 for i := range b[:n] {
33 // Create aligned word size key.
38 kw := *(*uintptr)(unsafe.Pointer(&k))
40 // Mask one word at a time.
41 n := (len(b) / wordSize) * wordSize
42 for i := 0; i < n; i += wordSize {
43 *(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&b[0])) + uintptr(i))) ^= kw
46 // Mask one byte at a time for remaining bytes.