Source File
ctr.go
Belonging Package
crypto/cipher
func ( Block, []byte) Stream {
if , := .(ctrAble); {
return .NewCTR()
}
if len() != .BlockSize() {
panic("cipher.NewCTR: IV length must equal block size")
}
:= streamBufferSize
if < .BlockSize() {
= .BlockSize()
}
return &ctr{
b: ,
ctr: dup(),
out: make([]byte, 0, ),
outUsed: 0,
}
}
func ( *ctr) () {
:= len(.out) - .outUsed
copy(.out, .out[.outUsed:])
.out = .out[:cap(.out)]
:= .b.BlockSize()
for <= len(.out)- {
.b.Encrypt(.out[:], .ctr)
+=
for := len(.ctr) - 1; >= 0; -- {
.ctr[]++
if .ctr[] != 0 {
break
}
}
}
.out = .out[:]
.outUsed = 0
}
func ( *ctr) (, []byte) {
if len() < len() {
panic("crypto/cipher: output smaller than input")
}
if subtle.InexactOverlap([:len()], ) {
panic("crypto/cipher: invalid buffer overlap")
}
for len() > 0 {
if .outUsed >= len(.out)-.b.BlockSize() {
.refill()
}
:= xorBytes(, , .out[.outUsed:])
= [:]
= [:]
.outUsed +=
}
![]() |
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. |