mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-11-03 19:17:29 -05:00 
			
		
		
		
	The vendor/ folder was created with the help of @FiloSottile's gvt and vendorcheck. Any dependencies of Caddy plugins outside this repo are not vendored. We do not remove any unused, vendored packages because vendorcheck -u only checks using the current build configuration; i.e. packages that may be imported by files toggled by build tags of other systems. CI tests have been updated to ignore the vendor/ folder. When Go 1.9 is released, a few of the go commands should be revised to again use ./... as it will ignore the vendor folder by default.
		
			
				
	
	
		
			80 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			80 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
// Copyright 2012 The Go Authors. All rights reserved.
 | 
						|
// Use of this source code is governed by a BSD-style
 | 
						|
// license that can be found in the LICENSE file.
 | 
						|
 | 
						|
package aes12
 | 
						|
 | 
						|
// defined in asm_amd64.s
 | 
						|
func hasAsm() bool
 | 
						|
func encryptBlockAsm(nr int, xk *uint32, dst, src *byte)
 | 
						|
func decryptBlockAsm(nr int, xk *uint32, dst, src *byte)
 | 
						|
func expandKeyAsm(nr int, key *byte, enc *uint32, dec *uint32)
 | 
						|
 | 
						|
type aesCipherAsm struct {
 | 
						|
	aesCipher
 | 
						|
}
 | 
						|
 | 
						|
var useAsm = hasAsm()
 | 
						|
 | 
						|
func newCipher(key []byte) (Block, error) {
 | 
						|
	if !useAsm {
 | 
						|
		return newCipherGeneric(key)
 | 
						|
	}
 | 
						|
	n := len(key) + 28
 | 
						|
	c := aesCipherAsm{aesCipher{make([]uint32, n), make([]uint32, n)}}
 | 
						|
	rounds := 10
 | 
						|
	switch len(key) {
 | 
						|
	case 128 / 8:
 | 
						|
		rounds = 10
 | 
						|
	case 192 / 8:
 | 
						|
		rounds = 12
 | 
						|
	case 256 / 8:
 | 
						|
		rounds = 14
 | 
						|
	}
 | 
						|
	expandKeyAsm(rounds, &key[0], &c.enc[0], &c.dec[0])
 | 
						|
	if hasGCMAsm() {
 | 
						|
		return &aesCipherGCM{c}, nil
 | 
						|
	}
 | 
						|
 | 
						|
	return &c, nil
 | 
						|
}
 | 
						|
 | 
						|
func (c *aesCipherAsm) BlockSize() int { return BlockSize }
 | 
						|
 | 
						|
func (c *aesCipherAsm) 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")
 | 
						|
	}
 | 
						|
	encryptBlockAsm(len(c.enc)/4-1, &c.enc[0], &dst[0], &src[0])
 | 
						|
}
 | 
						|
 | 
						|
func (c *aesCipherAsm) 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")
 | 
						|
	}
 | 
						|
	decryptBlockAsm(len(c.dec)/4-1, &c.dec[0], &dst[0], &src[0])
 | 
						|
}
 | 
						|
 | 
						|
// expandKey is used by BenchmarkExpand to ensure that the asm implementation
 | 
						|
// of key expansion is used for the benchmark when it is available.
 | 
						|
func expandKey(key []byte, enc, dec []uint32) {
 | 
						|
	if useAsm {
 | 
						|
		rounds := 10 // rounds needed for AES128
 | 
						|
		switch len(key) {
 | 
						|
		case 192 / 8:
 | 
						|
			rounds = 12
 | 
						|
		case 256 / 8:
 | 
						|
			rounds = 14
 | 
						|
		}
 | 
						|
		expandKeyAsm(rounds, &key[0], &enc[0], &dec[0])
 | 
						|
	} else {
 | 
						|
		expandKeyGo(key, enc, dec)
 | 
						|
	}
 | 
						|
}
 |