-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Description
Proposal Details
I propose to move the golang.org/x/crypto/chacha20poly1305 package into the standard library with the name crypto/chacha20poly1305 as part of #65269.
golang.org/x/crypto/chacha20poly1305 would then be updated to just be a wrapper around crypto/chacha20poly1305.
golang.org/x/crypto/chacha20poly1305 is already heavily used in the standard library as a crypto/tls and crypto/internal/hpke cipher. More than 4,000 external projects depend on it.
The API surface is quite small, I would port it with the same functionality, but making the New and NewX function return concrete types rather than cipher.AEAD so that we can extend in the future.
// Package chacha20poly1305 implements the ChaCha20-Poly1305 AEAD
// and its extended nonce variant XChaCha20-Poly1305, as specified in RFC 8439
// and draft-irtf-cfrg-xchacha-01.
package chacha20poly1305
const (
// KeySize is the size of the key used by this AEAD, in bytes.
KeySize = 32
// NonceSize is the size of the nonce used with the standard variant of this
// AEAD, in bytes.
//
// Note that this is too short to be safely generated at random if the same
// key is reused more than 2³² times.
NonceSize = 12
// NonceSizeX is the size of the nonce used with the XChaCha20-Poly1305
// variant of this AEAD, in bytes.
NonceSizeX = 24
// Overhead is the size of the Poly1305 authentication tag, and the
// difference between a ciphertext length and its plaintext.
Overhead = 16
)
type Chacha20Poly1305 []byte
// New returns a ChaCha20-Poly1305 AEAD that uses the given 256-bit key.
func New(key []byte) (*Chacha20Poly1305, error)
func (*Chacha20Poly1305) NonceSize() int
func (*Chacha20Poly1305) Overhead() int
func (*Chacha20Poly1305) Seal(dst, nonce, plaintext, additionalData []byte) []byte
func (*Chacha20Poly1305) Open(dst, nonce, ciphertext, additionalData []byte) ([]byte, error)
type XChacha20Poly1305 []byte
// NewX returns a XChaCha20-Poly1305 AEAD that uses the given 256-bit key.
func NewX(key []byte) (*XChacha20Poly1305, error)
func (*XChacha20Poly1305) NonceSize() int
func (*XChacha20Poly1305) Overhead() int
func (*XChacha20Poly1305) Seal(dst, nonce, plaintext, additionalData []byte) []byte
func (*XChacha20Poly1305) Open(dst, nonce, ciphertext, additionalData []byte) ([]byte, error)chacha20poly1305 internally uses golang.org/x/crypto/chacha20 and golang.org/x/crypto/internal/poly1305. I propose keep depending on golang.org/x/crypto/chacha20 (until its ported to the standard library, if ever), and copy golang.org/x/crypto/internal/poly1305 into a standard library internal package.
@golang/security @golang/proposal-review