Skip to content

Commit

Permalink
优化更新
Browse files Browse the repository at this point in the history
  • Loading branch information
deatil committed Dec 9, 2024
1 parent 5395d9c commit 0040681
Show file tree
Hide file tree
Showing 144 changed files with 881 additions and 806 deletions.
14 changes: 7 additions & 7 deletions cipher/anubis/anubis.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const BlockSize = 16
type KeySizeError int

func (k KeySizeError) Error() string {
return fmt.Sprintf("cryptobin/anubis: invalid key size %d", int(k))
return fmt.Sprintf("go-cryptobin/anubis: invalid key size %d", int(k))
}

type anubisCipher struct {
Expand Down Expand Up @@ -42,31 +42,31 @@ func (this *anubisCipher) BlockSize() int {

func (this *anubisCipher) Encrypt(dst, src []byte) {
if len(src) < BlockSize {
panic("cryptobin/anubis: input not full block")
panic("go-cryptobin/anubis: input not full block")
}

if len(dst) < BlockSize {
panic("cryptobin/anubis: output not full block")
panic("go-cryptobin/anubis: output not full block")
}

if alias.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
panic("cryptobin/anubis: invalid buffer overlap")
panic("go-cryptobin/anubis: invalid buffer overlap")
}

this.crypt(dst, src, this.roundKeyEnc)
}

func (this *anubisCipher) Decrypt(dst, src []byte) {
if len(src) < BlockSize {
panic("cryptobin/anubis: input not full block")
panic("go-cryptobin/anubis: input not full block")
}

if len(dst) < BlockSize {
panic("cryptobin/anubis: output not full block")
panic("go-cryptobin/anubis: output not full block")
}

if alias.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
panic("cryptobin/anubis: invalid buffer overlap")
panic("go-cryptobin/anubis: invalid buffer overlap")
}

this.crypt(dst, src, this.roundKeyDec)
Expand Down
14 changes: 7 additions & 7 deletions cipher/anubis2/anubis.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const BlockSize = 16
type KeySizeError int

func (k KeySizeError) Error() string {
return fmt.Sprintf("cryptobin/anubis: invalid key size %d", int(k))
return fmt.Sprintf("go-cryptobin/anubis: invalid key size %d", int(k))
}

type anubisCipher struct {
Expand Down Expand Up @@ -42,31 +42,31 @@ func (this *anubisCipher) BlockSize() int {

func (this *anubisCipher) Encrypt(dst, src []byte) {
if len(src) < BlockSize {
panic("cryptobin/anubis: input not full block")
panic("go-cryptobin/anubis: input not full block")
}

if len(dst) < BlockSize {
panic("cryptobin/anubis: output not full block")
panic("go-cryptobin/anubis: output not full block")
}

if alias.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
panic("cryptobin/anubis: invalid buffer overlap")
panic("go-cryptobin/anubis: invalid buffer overlap")
}

this.crypt(dst, src, this.roundKeyEnc)
}

func (this *anubisCipher) Decrypt(dst, src []byte) {
if len(src) < BlockSize {
panic("cryptobin/anubis: input not full block")
panic("go-cryptobin/anubis: input not full block")
}

if len(dst) < BlockSize {
panic("cryptobin/anubis: output not full block")
panic("go-cryptobin/anubis: output not full block")
}

if alias.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
panic("cryptobin/anubis: invalid buffer overlap")
panic("go-cryptobin/anubis: invalid buffer overlap")
}

this.crypt(dst, src, this.roundKeyDec)
Expand Down
14 changes: 7 additions & 7 deletions cipher/aria/aria.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const BlockSize = 16
type KeySizeError int

func (k KeySizeError) Error() string {
return fmt.Sprintf("cryptobin/aria: invalid key size %d", int(k))
return fmt.Sprintf("go-cryptobin/aria: invalid key size %d", int(k))
}

type ariaCipher struct {
Expand Down Expand Up @@ -48,31 +48,31 @@ func (c *ariaCipher) BlockSize() int {

func (c *ariaCipher) Encrypt(dst, src []byte) {
if len(src) < BlockSize {
panic("cryptobin/aria: input not full block")
panic("go-cryptobin/aria: input not full block")
}

if len(dst) < BlockSize {
panic("cryptobin/aria: output not full block")
panic("go-cryptobin/aria: output not full block")
}

if alias.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
panic("cryptobin/aria: invalid buffer overlap")
panic("go-cryptobin/aria: invalid buffer overlap")
}

c.cryptBlock(dst, src, c.enc)
}

func (c *ariaCipher) Decrypt(dst, src []byte) {
if len(src) < BlockSize {
panic("cryptobin/aria: input not full block")
panic("go-cryptobin/aria: input not full block")
}

if len(dst) < BlockSize {
panic("cryptobin/aria: output not full block")
panic("go-cryptobin/aria: output not full block")
}

if alias.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
panic("cryptobin/aria: invalid buffer overlap")
panic("go-cryptobin/aria: invalid buffer overlap")
}

c.cryptBlock(dst, src, c.dec)
Expand Down
2 changes: 1 addition & 1 deletion cipher/aria/aria_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestInvalidKeySize(t *testing.T) {
if _, ok := err.(KeySizeError); !ok {
t.Errorf("expected KeySizeError, got %v", err)
}
if msg := err.Error(); msg != fmt.Sprintf("cryptobin/aria: invalid key size %d", k) {
if msg := err.Error(); msg != fmt.Sprintf("go-cryptobin/aria: invalid key size %d", k) {
t.Errorf("wrong error message %s", msg)
}
}
Expand Down
14 changes: 7 additions & 7 deletions cipher/ascon/ascon.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (
TagSize = 16
)

var errOpen = errors.New("cryptobin/ascon: message authentication failed")
var errOpen = errors.New("go-cryptobin/ascon: message authentication failed")

type ascon struct {
k0, k1 uint64
Expand All @@ -52,7 +52,7 @@ type ascon struct {
// NewCipher creates a 128-bit ASCON-128 AEAD.
func NewCipher(key []byte) (cipher.AEAD, error) {
if len(key) != KeySize {
return nil, errors.New("cryptobin/ascon: bad key length")
return nil, errors.New("go-cryptobin/ascon: bad key length")
}

return &ascon{
Expand All @@ -65,7 +65,7 @@ func NewCipher(key []byte) (cipher.AEAD, error) {
// NewCiphera creates a 128-bit ASCON-128a AEAD.
func NewCiphera(key []byte) (cipher.AEAD, error) {
if len(key) != KeySize {
return nil, errors.New("cryptobin/ascon: bad key length")
return nil, errors.New("go-cryptobin/ascon: bad key length")
}

return &ascon{
Expand All @@ -85,7 +85,7 @@ func (a *ascon) Overhead() int {

func (a *ascon) Seal(dst, nonce, plaintext, additionalData []byte) []byte {
if len(nonce) != NonceSize {
panic("cryptobin/ascon: incorrect nonce length: " + strconv.Itoa(len(nonce)))
panic("go-cryptobin/ascon: incorrect nonce length: " + strconv.Itoa(len(nonce)))
}

n0 := getu64(nonce[0:])
Expand All @@ -102,7 +102,7 @@ func (a *ascon) Seal(dst, nonce, plaintext, additionalData []byte) []byte {

ret, out := alias.SliceForAppend(dst, len(plaintext)+TagSize)
if alias.InexactOverlap(out, plaintext) {
panic("cryptobin/ascon: invalid buffer overlap")
panic("go-cryptobin/ascon: invalid buffer overlap")
}

if a.iv == iv128a {
Expand All @@ -124,7 +124,7 @@ func (a *ascon) Seal(dst, nonce, plaintext, additionalData []byte) []byte {

func (a *ascon) Open(dst, nonce, ciphertext, additionalData []byte) ([]byte, error) {
if len(nonce) != NonceSize {
panic("cryptobin/ascon: incorrect nonce length: " + strconv.Itoa(len(nonce)))
panic("go-cryptobin/ascon: incorrect nonce length: " + strconv.Itoa(len(nonce)))
}

if len(ciphertext) < TagSize {
Expand All @@ -148,7 +148,7 @@ func (a *ascon) Open(dst, nonce, ciphertext, additionalData []byte) ([]byte, err

ret, out := alias.SliceForAppend(dst, len(ciphertext))
if alias.InexactOverlap(out, ciphertext) {
panic("cryptobin/ascon: invalid buffer overlap")
panic("go-cryptobin/ascon: invalid buffer overlap")
}

if a.iv == iv128a {
Expand Down
14 changes: 7 additions & 7 deletions cipher/belt/belt.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const BlockSize = 16
type KeySizeError int

func (k KeySizeError) Error() string {
return fmt.Sprintf("cryptobin/belt: invalid key size %d", int(k))
return fmt.Sprintf("go-cryptobin/belt: invalid key size %d", int(k))
}

type beltCipher struct {
Expand Down Expand Up @@ -45,31 +45,31 @@ func (c *beltCipher) BlockSize() int {

func (c *beltCipher) Encrypt(dst, src []byte) {
if len(src) < BlockSize {
panic("cryptobin/belt: input not full block")
panic("go-cryptobin/belt: input not full block")
}

if len(dst) < BlockSize {
panic("cryptobin/belt: output not full block")
panic("go-cryptobin/belt: output not full block")
}

if alias.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
panic("cryptobin/belt: invalid buffer overlap")
panic("go-cryptobin/belt: invalid buffer overlap")
}

c.encrypt(dst, src)
}

func (c *beltCipher) Decrypt(dst, src []byte) {
if len(src) < BlockSize {
panic("cryptobin/belt: input not full block")
panic("go-cryptobin/belt: input not full block")
}

if len(dst) < BlockSize {
panic("cryptobin/belt: output not full block")
panic("go-cryptobin/belt: output not full block")
}

if alias.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
panic("cryptobin/belt: invalid buffer overlap")
panic("go-cryptobin/belt: invalid buffer overlap")
}

c.decrypt(dst, src)
Expand Down
14 changes: 7 additions & 7 deletions cipher/camellia/camellia.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const BlockSize = 16
type KeySizeError int

func (k KeySizeError) Error() string {
return "cryptobin/camellia: invalid key size " + strconv.Itoa(int(k))
return "go-cryptobin/camellia: invalid key size " + strconv.Itoa(int(k))
}

type camelliaCipher struct {
Expand Down Expand Up @@ -51,31 +51,31 @@ func (this *camelliaCipher) BlockSize() int {

func (this *camelliaCipher) Encrypt(dst, src []byte) {
if len(src) < BlockSize {
panic("cryptobin/camellia: input not full block")
panic("go-cryptobin/camellia: input not full block")
}

if len(dst) < BlockSize {
panic("cryptobin/camellia: output not full block")
panic("go-cryptobin/camellia: output not full block")
}

if alias.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
panic("cryptobin/camellia: invalid buffer overlap")
panic("go-cryptobin/camellia: invalid buffer overlap")
}

this.encrypt(dst, src)
}

func (this *camelliaCipher) Decrypt(dst, src []byte) {
if len(src) < BlockSize {
panic("cryptobin/camellia: input not full block")
panic("go-cryptobin/camellia: input not full block")
}

if len(dst) < BlockSize {
panic("cryptobin/camellia: output not full block")
panic("go-cryptobin/camellia: output not full block")
}

if alias.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
panic("cryptobin/camellia: invalid buffer overlap")
panic("go-cryptobin/camellia: invalid buffer overlap")
}

this.decrypt(dst, src)
Expand Down
12 changes: 6 additions & 6 deletions cipher/cascade/cascade.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ func (this *cascadeCipher) Encrypt(dst, src []byte) {
bs := this.bs

if len(src) < bs {
panic("cryptobin/cascade: input not full block")
panic("go-cryptobin/cascade: input not full block")
}

if len(dst) < bs {
panic("cryptobin/cascade: output not full block")
panic("go-cryptobin/cascade: output not full block")
}

if alias.InexactOverlap(dst[:bs], src[:bs]) {
panic("cryptobin/cascade: invalid buffer overlap")
panic("go-cryptobin/cascade: invalid buffer overlap")
}

this.encrypt(dst, src)
Expand All @@ -55,15 +55,15 @@ func (this *cascadeCipher) Decrypt(dst, src []byte) {
bs := this.bs

if len(src) < bs {
panic("cryptobin/cascade: input not full block")
panic("go-cryptobin/cascade: input not full block")
}

if len(dst) < bs {
panic("cryptobin/cascade: output not full block")
panic("go-cryptobin/cascade: output not full block")
}

if alias.InexactOverlap(dst[:bs], src[:bs]) {
panic("cryptobin/cascade: invalid buffer overlap")
panic("go-cryptobin/cascade: invalid buffer overlap")
}

this.decrypt(dst, src)
Expand Down
14 changes: 7 additions & 7 deletions cipher/cast/cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const BlockSize = 16
type KeySizeError int

func (k KeySizeError) Error() string {
return "cryptobin/cast: invalid key size " + strconv.Itoa(int(k))
return "go-cryptobin/cast: invalid key size " + strconv.Itoa(int(k))
}

type castCipher struct {
Expand Down Expand Up @@ -42,31 +42,31 @@ func (this *castCipher) BlockSize() int {

func (this *castCipher) Encrypt(dst, src []byte) {
if len(src) < BlockSize {
panic("cryptobin/cast: input not full block")
panic("go-cryptobin/cast: input not full block")
}

if len(dst) < BlockSize {
panic("cryptobin/cast: output not full block")
panic("go-cryptobin/cast: output not full block")
}

if alias.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
panic("cryptobin/cast: invalid buffer overlap")
panic("go-cryptobin/cast: invalid buffer overlap")
}

this.encrypt(dst, src)
}

func (this *castCipher) Decrypt(dst, src []byte) {
if len(src) < BlockSize {
panic("cryptobin/cast: input not full block")
panic("go-cryptobin/cast: input not full block")
}

if len(dst) < BlockSize {
panic("cryptobin/cast: output not full block")
panic("go-cryptobin/cast: output not full block")
}

if alias.InexactOverlap(dst[:BlockSize], src[:BlockSize]) {
panic("cryptobin/cast: invalid buffer overlap")
panic("go-cryptobin/cast: invalid buffer overlap")
}

this.decrypt(dst, src)
Expand Down
Loading

0 comments on commit 0040681

Please sign in to comment.