package aes
import (
"crypto/cipher"
"crypto/internal/alias"
"crypto/internal/boring"
"strconv"
)
const BlockSize = 16
type aesCipher struct {
l uint8
enc [28 + 32 ]uint32
dec [28 + 32 ]uint32
}
type KeySizeError int
func (k KeySizeError ) Error () string {
return "crypto/aes: invalid key size " + strconv .Itoa (int (k ))
}
func NewCipher (key []byte ) (cipher .Block , error ) {
k := len (key )
switch k {
default :
return nil , KeySizeError (k )
case 16 , 24 , 32 :
break
}
if boring .Enabled {
return boring .NewAESCipher (key )
}
return newCipher (key )
}
func newCipherGeneric(key []byte ) (cipher .Block , error ) {
c := aesCipher {l : uint8 (len (key ) + 28 )}
expandKeyGo (key , c .enc [:c .l ], c .dec [:c .l ])
return &c , nil
}
func (c *aesCipher ) BlockSize () int { return BlockSize }
func (c *aesCipher ) Encrypt (dst , src []byte ) {
if len (src ) < BlockSize {
panic ("crypto/aes: input not full block" )
}
if len (dst ) < BlockSize {
panic ("crypto/aes: output not full block" )
}
if alias .InexactOverlap (dst [:BlockSize ], src [:BlockSize ]) {
panic ("crypto/aes: invalid buffer overlap" )
}
encryptBlockGo (c .enc [:c .l ], dst , src )
}
func (c *aesCipher ) Decrypt (dst , src []byte ) {
if len (src ) < BlockSize {
panic ("crypto/aes: input not full block" )
}
if len (dst ) < BlockSize {
panic ("crypto/aes: output not full block" )
}
if alias .InexactOverlap (dst [:BlockSize ], src [:BlockSize ]) {
panic ("crypto/aes: invalid buffer overlap" )
}
decryptBlockGo (c .dec [:c .l ], dst , src )
}
The pages are generated with Golds v0.7.0-preview . (GOOS=linux 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 @zigo_101 (reachable from the left QR code) to get the latest news of Golds .