Skip to content

Commit

Permalink
crypto/*: document use or non-use of constant-time algorithms
Browse files Browse the repository at this point in the history
Fixes #16821.

Change-Id: I63d5f3d7cfba1c76259912d754025c5f3cbe4a56
Reviewed-on: https://go-review.googlesource.com/31573
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
  • Loading branch information
rsc committed Dec 7, 2016
1 parent bc075e6 commit 850e55b
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/crypto/aes/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

// 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

// This file contains AES constants - 8720 bytes of initialized data.
Expand Down
4 changes: 4 additions & 0 deletions src/crypto/cipher/gcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ type gcm struct {

// NewGCM returns the given 128-bit, block cipher wrapped in Galois Counter Mode
// with the standard nonce length.
//
// In general, the GHASH operation performed by this implementation of GCM is not constant-time.
// An exception is when the underlying Block was created by aes.NewCipher
// on systems with hardware support for AES. See the crypto/aes package documentation for details.
func NewGCM(cipher Block) (AEAD, error) {
return NewGCMWithNonceSize(cipher, gcmStandardNonceSize)
}
Expand Down
2 changes: 2 additions & 0 deletions src/crypto/dsa/dsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// license that can be found in the LICENSE file.

// Package dsa implements the Digital Signature Algorithm, as defined in FIPS 186-3.
//
// The DSA operations in this package are not implemented using constant-time algorithms.
package dsa

import (
Expand Down
6 changes: 6 additions & 0 deletions src/crypto/elliptic/elliptic.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,18 +367,24 @@ func initP521() {
}

// P256 returns a Curve which implements P-256 (see FIPS 186-3, section D.2.3)
//
// The cryptographic operations are implemented using constant-time algorithms.
func P256() Curve {
initonce.Do(initAll)
return p256
}

// P384 returns a Curve which implements P-384 (see FIPS 186-3, section D.2.4)
//
// The cryptographic operations do not use constant-time algorithms.
func P384() Curve {
initonce.Do(initAll)
return p384
}

// P521 returns a Curve which implements P-521 (see FIPS 186-3, section D.2.5)
//
// The cryptographic operations do not use constant-time algorithms.
func P521() Curve {
initonce.Do(initAll)
return p521
Expand Down
4 changes: 3 additions & 1 deletion src/crypto/elliptic/p224.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ func initP224() {
p224FromBig(&p224.b, p224.B)
}

// P224 returns a Curve which implements P-224 (see FIPS 186-3, section D.2.2)
// P224 returns a Curve which implements P-224 (see FIPS 186-3, section D.2.2).
//
// The cryptographic operations are implemented using constant-time algorithms.
func P224() Curve {
initonce.Do(initAll)
return p224
Expand Down
2 changes: 2 additions & 0 deletions src/crypto/rsa/rsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
// with v1.5/OAEP and signing/verifying with v1.5/PSS. If one needs to abstract
// over the public-key primitive, the PrivateKey struct implements the
// Decrypter and Signer interfaces from the crypto package.
//
// The RSA operations in this package are not implemented using constant-time algorithms.
package rsa

import (
Expand Down
5 changes: 4 additions & 1 deletion src/math/big/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,11 @@ func (x *Int) BitLen() int {

// Exp sets z = x**y mod |m| (i.e. the sign of m is ignored), and returns z.
// If y <= 0, the result is 1 mod |m|; if m == nil or m == 0, z = x**y.
// See Knuth, volume 2, section 4.6.3.
//
// Modular exponentation of inputs of a particular size is not a
// cryptographically constant-time operation.
func (z *Int) Exp(x, y, m *Int) *Int {
// See Knuth, volume 2, section 4.6.3.
var yWords nat
if !y.neg {
yWords = y.abs
Expand Down

0 comments on commit 850e55b

Please sign in to comment.