// Copyright 2009 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 aes implements AES encryption (formerly Rijndael), as defined in // U.S. Federal Information Processing Standards Publication 197. // // The AES operations in this package are not implemented using constant-time algorithms. // An exception is when running on systems with enabled hardware support for AES // that makes these operations constant-time. Examples include amd64 systems using AES-NI // extensions and s390x systems using Message-Security-Assist extensions. // On such systems, when the result of NewCipher is passed to cipher.NewGCM, // the GHASH operation used by GCM is also constant-time. package aes import ( "math/bits" ) // Multiply b and c as GF(2) polynomials modulo poly func mul(b, c uint32) uint32 { i := b j := c s := uint32(0) for k := uint32(1); k < 0x100 && j != 0; k <<= 1 { // Invariant: k == 1<>8 } } return te }() // Lookup tables for decryption. var decLut = func() (td [4][256]uint32) { for i := 0; i < 256; i++ { s := uint32(sbox1[i]) s9 := mul(s, 0x9) sb := mul(s, 0xb) sd := mul(s, 0xd) se := mul(s, 0xe) w := se<<24 | s9<<16 | sd<<8 | sb for j := 0; j < 4; j++ { td[j][i] = bits.ReverseBytes32(w) w = w<<24 | w>>8 } } return td }()