github.com/varialus/godfly@v0.0.0-20130904042352-1934f9f095ab/src/pkg/crypto/aes/cipher_asm.go (about)

     1  // Copyright 2012 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // +build amd64
     6  
     7  package aes
     8  
     9  // defined in asm_$GOARCH.s
    10  func hasAsm() bool
    11  func encryptBlockAsm(nr int, xk *uint32, dst, src *byte)
    12  func decryptBlockAsm(nr int, xk *uint32, dst, src *byte)
    13  func expandKeyAsm(nr int, key *byte, enc *uint32, dec *uint32)
    14  
    15  var useAsm = hasAsm()
    16  
    17  func encryptBlock(xk []uint32, dst, src []byte) {
    18  	if useAsm {
    19  		encryptBlockAsm(len(xk)/4-1, &xk[0], &dst[0], &src[0])
    20  	} else {
    21  		encryptBlockGo(xk, dst, src)
    22  	}
    23  }
    24  func decryptBlock(xk []uint32, dst, src []byte) {
    25  	if useAsm {
    26  		decryptBlockAsm(len(xk)/4-1, &xk[0], &dst[0], &src[0])
    27  	} else {
    28  		decryptBlockGo(xk, dst, src)
    29  	}
    30  }
    31  func expandKey(key []byte, enc, dec []uint32) {
    32  	if useAsm {
    33  		rounds := 10
    34  		switch len(key) {
    35  		case 128 / 8:
    36  			rounds = 10
    37  		case 192 / 8:
    38  			rounds = 12
    39  		case 256 / 8:
    40  			rounds = 14
    41  		}
    42  		expandKeyAsm(rounds, &key[0], &enc[0], &dec[0])
    43  	} else {
    44  		expandKeyGo(key, enc, dec)
    45  	}
    46  }