Skip to content

Commit

Permalink
crypto/aes: move ppc64le to cipher_asm.go
Browse files Browse the repository at this point in the history
Move the aesCipherGCM struct definition into cipher_asm.go, it is
needed to compile this file, but isn't used on PPC64.

Also, generate a KeySizeError if the key length is not supported
as was done in the ppc64le implementation, and is done in the
generic code.

Change-Id: I025fc63d614b57dac65a18d1ac3dbeec99356292
Reviewed-on: https://go-review.googlesource.com/c/go/+/399254
Reviewed-by: Filippo Valsorda <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: David Chase <[email protected]>
Reviewed-by: Lynn Boger <[email protected]>
Reviewed-by: Filippo Valsorda <[email protected]>
Run-TryBot: Paul Murphy <[email protected]>
  • Loading branch information
pmur committed May 5, 2022
1 parent fa603aa commit 6269dc2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 96 deletions.
7 changes: 0 additions & 7 deletions src/crypto/aes/aes_gcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ const (

var errOpen = errors.New("cipher: message authentication failed")

// aesCipherGCM implements crypto/cipher.gcmAble so that crypto/cipher.NewGCM
// will use the optimised implementation in this file when possible. Instances
// of this type only exist when hasGCMAsm returns true.
type aesCipherGCM struct {
aesCipherAsm
}

// Assert that aesCipherGCM implements the gcmAble interface.
var _ gcmAble = (*aesCipherGCM)(nil)

Expand Down
15 changes: 13 additions & 2 deletions src/crypto/aes/cipher_asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build amd64 || arm64
//go:build amd64 || arm64 || ppc64le

package aes

import (
"crypto/cipher"
"crypto/internal/subtle"
"internal/cpu"
"internal/goarch"
)

import "crypto/internal/boring"
Expand All @@ -29,7 +30,15 @@ type aesCipherAsm struct {
aesCipher
}

var supportsAES = cpu.X86.HasAES || cpu.ARM64.HasAES
// aesCipherGCM implements crypto/cipher.gcmAble so that crypto/cipher.NewGCM
// will use the optimised implementation in aes_gcm.go when possible.
// Instances of this type only exist when hasGCMAsm returns true. Likewise,
// the gcmAble implementation is in aes_gcm.go.
type aesCipherGCM struct {
aesCipherAsm
}

var supportsAES = cpu.X86.HasAES || cpu.ARM64.HasAES || goarch.IsPpc64le == 1
var supportsGFMUL = cpu.X86.HasPCLMULQDQ || cpu.ARM64.HasPMULL

func newCipher(key []byte) (cipher.Block, error) {
Expand All @@ -46,6 +55,8 @@ func newCipher(key []byte) (cipher.Block, error) {
rounds = 12
case 256 / 8:
rounds = 14
default:
return nil, KeySizeError(len(key))
}

expandKeyAsm(rounds, &key[0], &c.enc[0], &c.dec[0])
Expand Down
87 changes: 0 additions & 87 deletions src/crypto/aes/cipher_ppc64le.go

This file was deleted.

0 comments on commit 6269dc2

Please sign in to comment.