Skip to content

Commit 850e55b

Browse files
committed
crypto/*: document use or non-use of constant-time algorithms
Fixes #16821. Change-Id: I63d5f3d7cfba1c76259912d754025c5f3cbe4a56 Reviewed-on: https://go-review.googlesource.com/31573 Run-TryBot: Russ Cox <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent bc075e6 commit 850e55b

File tree

7 files changed

+28
-2
lines changed

7 files changed

+28
-2
lines changed

src/crypto/aes/const.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
// Package aes implements AES encryption (formerly Rijndael), as defined in
66
// U.S. Federal Information Processing Standards Publication 197.
7+
//
8+
// The AES operations in this package are not implemented using constant-time algorithms.
9+
// An exception is when running on systems with enabled hardware support for AES
10+
// that makes these operations constant-time. Examples include amd64 systems using AES-NI
11+
// extensions and s390x systems using Message-Security-Assist extensions.
12+
// On such systems, when the result of NewCipher is passed to cipher.NewGCM,
13+
// the GHASH operation used by GCM is also constant-time.
714
package aes
815

916
// This file contains AES constants - 8720 bytes of initialized data.

src/crypto/cipher/gcm.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ type gcm struct {
7474

7575
// NewGCM returns the given 128-bit, block cipher wrapped in Galois Counter Mode
7676
// with the standard nonce length.
77+
//
78+
// In general, the GHASH operation performed by this implementation of GCM is not constant-time.
79+
// An exception is when the underlying Block was created by aes.NewCipher
80+
// on systems with hardware support for AES. See the crypto/aes package documentation for details.
7781
func NewGCM(cipher Block) (AEAD, error) {
7882
return NewGCMWithNonceSize(cipher, gcmStandardNonceSize)
7983
}

src/crypto/dsa/dsa.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// license that can be found in the LICENSE file.
44

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

810
import (

src/crypto/elliptic/elliptic.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,18 +367,24 @@ func initP521() {
367367
}
368368

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

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

381385
// P521 returns a Curve which implements P-521 (see FIPS 186-3, section D.2.5)
386+
//
387+
// The cryptographic operations do not use constant-time algorithms.
382388
func P521() Curve {
383389
initonce.Do(initAll)
384390
return p521

src/crypto/elliptic/p224.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ func initP224() {
3535
p224FromBig(&p224.b, p224.B)
3636
}
3737

38-
// P224 returns a Curve which implements P-224 (see FIPS 186-3, section D.2.2)
38+
// P224 returns a Curve which implements P-224 (see FIPS 186-3, section D.2.2).
39+
//
40+
// The cryptographic operations are implemented using constant-time algorithms.
3941
func P224() Curve {
4042
initonce.Do(initAll)
4143
return p224

src/crypto/rsa/rsa.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
// with v1.5/OAEP and signing/verifying with v1.5/PSS. If one needs to abstract
1919
// over the public-key primitive, the PrivateKey struct implements the
2020
// Decrypter and Signer interfaces from the crypto package.
21+
//
22+
// The RSA operations in this package are not implemented using constant-time algorithms.
2123
package rsa
2224

2325
import (

src/math/big/int.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,11 @@ func (x *Int) BitLen() int {
404404

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

0 commit comments

Comments
 (0)