// Copyright 2025 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.
// Package mlkemtest provides testing functions for the ML-KEM algorithm.
package mlkemtestimport (fips140mlkem)// Encapsulate768 implements derandomized ML-KEM-768 encapsulation// (ML-KEM.Encaps_internal from FIPS 203) using the provided encapsulation key// ek and 32 bytes of randomness.//// It must only be used for known-answer tests.func ( *mlkem.EncapsulationKey768, []byte) (, []byte, error) {iflen() != 32 {returnnil, nil, errors.New("mlkemtest: Encapsulate768: random must be 32 bytes") }iffips140only.Enforced() {returnnil, nil, errors.New("crypto/mlkem/mlkemtest: use of derandomized encapsulation is not allowed in FIPS 140-only mode") } , := fips140mlkem.NewEncapsulationKey768(.Bytes())if != nil {returnnil, nil, errors.New("mlkemtest: Encapsulate768: failed to reconstruct key: " + .Error()) } , = .EncapsulateInternal((*[32]byte)())return , , nil}// Encapsulate1024 implements derandomized ML-KEM-1024 encapsulation// (ML-KEM.Encaps_internal from FIPS 203) using the provided encapsulation key// ek and 32 bytes of randomness.//// It must only be used for known-answer tests.func ( *mlkem.EncapsulationKey1024, []byte) (, []byte, error) {iflen() != 32 {returnnil, nil, errors.New("mlkemtest: Encapsulate1024: random must be 32 bytes") }iffips140only.Enforced() {returnnil, nil, errors.New("crypto/mlkem/mlkemtest: use of derandomized encapsulation is not allowed in FIPS 140-only mode") } , := fips140mlkem.NewEncapsulationKey1024(.Bytes())if != nil {returnnil, nil, errors.New("mlkemtest: Encapsulate1024: failed to reconstruct key: " + .Error()) } , = .EncapsulateInternal((*[32]byte)())return , , nil}
The pages are generated with Goldsv0.8.3-preview. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.