Source File
sum_generic.go
Belonging Package
golang.org/x/crypto/poly1305
package poly1305
import
func ( *[TagSize]byte, []byte, *[32]byte) {
:= newMACGeneric()
.Write()
.Sum()
}
func ( *[32]byte) macGeneric {
:= macGeneric{}
initialize(, &.macState)
return
}
func ( *macGeneric) ( []byte) (int, error) {
:= len()
if .offset > 0 {
:= copy(.buffer[.offset:], )
if .offset+ < TagSize {
.offset +=
return , nil
}
= [:]
.offset = 0
updateGeneric(&.macState, .buffer[:])
}
if := len() - (len() % TagSize); > 0 {
updateGeneric(&.macState, [:])
= [:]
}
if len() > 0 {
.offset += copy(.buffer[.offset:], )
}
return , nil
}
func ( *[32]byte, *macState) {
.r[0] = binary.LittleEndian.Uint64([0:8]) & rMask0
.r[1] = binary.LittleEndian.Uint64([8:16]) & rMask1
.s[0] = binary.LittleEndian.Uint64([16:24])
.s[1] = binary.LittleEndian.Uint64([24:32])
}
type uint128 struct {
lo, hi uint64
}
func (, uint64) uint128 {
, := bitsMul64(, )
return uint128{, }
}
func (, uint128) uint128 {
, := bitsAdd64(.lo, .lo, 0)
, := bitsAdd64(.hi, .hi, )
if != 0 {
panic("poly1305: unexpected overflow")
}
return uint128{, }
}
func ( uint128) uint128 {
.lo = .lo>>2 | (.hi&3)<<62
.hi = .hi >> 2
return
}
if len() >= TagSize {
, = bitsAdd64(, binary.LittleEndian.Uint64([0:8]), 0)
, = bitsAdd64(, binary.LittleEndian.Uint64([8:16]), )
+= + 1
= [TagSize:]
} else {
var [TagSize]byte
copy([:], )
[len()] = 1
, = bitsAdd64(, binary.LittleEndian.Uint64([0:8]), 0)
, = bitsAdd64(, binary.LittleEndian.Uint64([8:16]), )
+=
= nil
}
if .hi != 0 {
panic("poly1305: unexpected overflow")
}
if .hi != 0 {
panic("poly1305: unexpected overflow")
}
:=
:= add128(, ) // These two additions don't overflow thanks again
:= add128(, ) // to the 4 masked bits at the top of r0 and r1.
:=
:= .lo
, := bitsAdd64(.lo, .hi, 0)
, := bitsAdd64(.lo, .hi, )
, := bitsAdd64(.lo, .hi, )
, , = , , &maskLow2Bits
:= uint128{ & maskNotLow2Bits, }
}
.h[0], .h[1], .h[2] = , ,
}
const (
maskLow2Bits uint64 = 0x0000000000000003
maskNotLow2Bits uint64 = ^maskLow2Bits
)
, := bitsAdd64(, [0], 0)
, _ = bitsAdd64(, [1], )
binary.LittleEndian.PutUint64([0:8], )
binary.LittleEndian.PutUint64([8:16], )
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |