Skip to content

Commit a6a393f

Browse files
FiloSottilegopherbot
authored andcommitted
all: bump go.mod version and drop compatibility shims
Also, remove the legacy import annotations. Fixes golang/go#68147 Change-Id: Ibfcc9322f27224c0ba92ea42cd56912a7d8783fd Reviewed-on: https://go-review.googlesource.com/c/crypto/+/594256 Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Filippo Valsorda <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]>
1 parent 1c74500 commit a6a393f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+110
-2532
lines changed

acme/http.go

+20-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"io"
1616
"math/big"
1717
"net/http"
18+
"runtime/debug"
1819
"strconv"
1920
"strings"
2021
"time"
@@ -271,9 +272,27 @@ func (c *Client) httpClient() *http.Client {
271272
}
272273

273274
// packageVersion is the version of the module that contains this package, for
274-
// sending as part of the User-Agent header. It's set in version_go112.go.
275+
// sending as part of the User-Agent header.
275276
var packageVersion string
276277

278+
func init() {
279+
// Set packageVersion if the binary was built in modules mode and x/crypto
280+
// was not replaced with a different module.
281+
info, ok := debug.ReadBuildInfo()
282+
if !ok {
283+
return
284+
}
285+
for _, m := range info.Deps {
286+
if m.Path != "golang.org/x/crypto" {
287+
continue
288+
}
289+
if m.Replace == nil {
290+
packageVersion = m.Version
291+
}
292+
break
293+
}
294+
}
295+
277296
// userAgent returns the User-Agent header value. It includes the package name,
278297
// the module version (if available), and the c.UserAgent value (if set).
279298
func (c *Client) userAgent() string {

acme/version_go112.go

-27
This file was deleted.

bcrypt/bcrypt.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// Package bcrypt implements Provos and Mazières's bcrypt adaptive hashing
66
// algorithm. See http://www.usenix.org/event/usenix99/provos/provos.pdf
7-
package bcrypt // import "golang.org/x/crypto/bcrypt"
7+
package bcrypt
88

99
// The code is a port of Provos and Mazières's C implementation.
1010
import (

blake2s/blake2s.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
//
1717
// BLAKE2X is a construction to compute hash values larger than 32 bytes. It
1818
// can produce hash values between 0 and 65535 bytes.
19-
package blake2s // import "golang.org/x/crypto/blake2s"
19+
package blake2s
2020

2121
import (
22+
"crypto"
2223
"encoding/binary"
2324
"errors"
2425
"hash"
@@ -55,6 +56,13 @@ func Sum256(data []byte) [Size]byte {
5556
// and BinaryUnmarshaler for state (de)serialization as documented by hash.Hash.
5657
func New256(key []byte) (hash.Hash, error) { return newDigest(Size, key) }
5758

59+
func init() {
60+
crypto.RegisterHash(crypto.BLAKE2s_256, func() hash.Hash {
61+
h, _ := New256(nil)
62+
return h
63+
})
64+
}
65+
5866
// New128 returns a new hash.Hash computing the BLAKE2s-128 checksum given a
5967
// non-empty key. Note that a 128-bit digest is too small to be secure as a
6068
// cryptographic hash and should only be used as a MAC, thus the key argument

blake2s/register.go

-21
This file was deleted.

blowfish/cipher.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// Deprecated: any new system should use AES (from crypto/aes, if necessary in
1212
// an AEAD mode like crypto/cipher.NewGCM) or XChaCha20-Poly1305 (from
1313
// golang.org/x/crypto/chacha20poly1305).
14-
package blowfish // import "golang.org/x/crypto/blowfish"
14+
package blowfish
1515

1616
// The code is a port of Bruce Schneier's C implementation.
1717
// See https://www.schneier.com/blowfish.html.

bn256/bn256.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
// elliptic curve. This package is frozen, and not implemented in constant time.
2424
// There is a more complete implementation at github.com/cloudflare/bn256, but
2525
// note that it suffers from the same security issues of the underlying curve.
26-
package bn256 // import "golang.org/x/crypto/bn256"
26+
package bn256
2727

2828
import (
2929
"crypto/rand"

cast5/cast5.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// Deprecated: any new system should use AES (from crypto/aes, if necessary in
1212
// an AEAD mode like crypto/cipher.NewGCM) or XChaCha20-Poly1305 (from
1313
// golang.org/x/crypto/chacha20poly1305).
14-
package cast5 // import "golang.org/x/crypto/cast5"
14+
package cast5
1515

1616
import (
1717
"errors"

chacha20poly1305/chacha20poly1305.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Package chacha20poly1305 implements the ChaCha20-Poly1305 AEAD and its
66
// extended nonce variant XChaCha20-Poly1305, as specified in RFC 8439 and
77
// draft-irtf-cfrg-xchacha-01.
8-
package chacha20poly1305 // import "golang.org/x/crypto/chacha20poly1305"
8+
package chacha20poly1305
99

1010
import (
1111
"crypto/cipher"

cryptobyte/asn1/asn1.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// Package asn1 contains supporting types for parsing and building ASN.1
66
// messages with the cryptobyte package.
7-
package asn1 // import "golang.org/x/crypto/cryptobyte/asn1"
7+
package asn1
88

99
// Tag represents an ASN.1 identifier octet, consisting of a tag number
1010
// (indicating a type) and class (such as context-specific or constructed).

cryptobyte/string.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//
1616
// See the documentation and examples for the Builder and String types to get
1717
// started.
18-
package cryptobyte // import "golang.org/x/crypto/cryptobyte"
18+
package cryptobyte
1919

2020
// String represents a string of bytes. It provides methods for parsing
2121
// fixed-length and length-prefixed values from it.

curve25519/curve25519.go

+35-4
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,25 @@
66
// performs scalar multiplication on the elliptic curve known as Curve25519.
77
// See RFC 7748.
88
//
9-
// Starting in Go 1.20, this package is a wrapper for the X25519 implementation
9+
// This package is a wrapper for the X25519 implementation
1010
// in the crypto/ecdh package.
11-
package curve25519 // import "golang.org/x/crypto/curve25519"
11+
package curve25519
12+
13+
import "crypto/ecdh"
1214

1315
// ScalarMult sets dst to the product scalar * point.
1416
//
1517
// Deprecated: when provided a low-order point, ScalarMult will set dst to all
1618
// zeroes, irrespective of the scalar. Instead, use the X25519 function, which
1719
// will return an error.
1820
func ScalarMult(dst, scalar, point *[32]byte) {
19-
scalarMult(dst, scalar, point)
21+
if _, err := x25519(dst, scalar[:], point[:]); err != nil {
22+
// The only error condition for x25519 when the inputs are 32 bytes long
23+
// is if the output would have been the all-zero value.
24+
for i := range dst {
25+
dst[i] = 0
26+
}
27+
}
2028
}
2129

2230
// ScalarBaseMult sets dst to the product scalar * base where base is the
@@ -25,7 +33,12 @@ func ScalarMult(dst, scalar, point *[32]byte) {
2533
// It is recommended to use the X25519 function with Basepoint instead, as
2634
// copying into fixed size arrays can lead to unexpected bugs.
2735
func ScalarBaseMult(dst, scalar *[32]byte) {
28-
scalarBaseMult(dst, scalar)
36+
curve := ecdh.X25519()
37+
priv, err := curve.NewPrivateKey(scalar[:])
38+
if err != nil {
39+
panic("curve25519: internal error: scalarBaseMult was not 32 bytes")
40+
}
41+
copy(dst[:], priv.PublicKey().Bytes())
2942
}
3043

3144
const (
@@ -57,3 +70,21 @@ func X25519(scalar, point []byte) ([]byte, error) {
5770
var dst [32]byte
5871
return x25519(&dst, scalar, point)
5972
}
73+
74+
func x25519(dst *[32]byte, scalar, point []byte) ([]byte, error) {
75+
curve := ecdh.X25519()
76+
pub, err := curve.NewPublicKey(point)
77+
if err != nil {
78+
return nil, err
79+
}
80+
priv, err := curve.NewPrivateKey(scalar)
81+
if err != nil {
82+
return nil, err
83+
}
84+
out, err := priv.ECDH(pub)
85+
if err != nil {
86+
return nil, err
87+
}
88+
copy(dst[:], out)
89+
return dst[:], nil
90+
}

curve25519/curve25519_compat.go

-105
This file was deleted.

curve25519/curve25519_go120.go

-46
This file was deleted.

0 commit comments

Comments
 (0)