Debian Codegraph @

age/internal/mlkemtest/mlkemtest.go

raw symbols SCIP
1 //go:build !go1.26 && !fips140v1.0
2
3 package mlkemtest
4
5 import (
6 "crypto/mlkem"
7 "errors"
8 "unsafe"
9 )
10
11 // Reach ungracefully into the internals of crypto/internal/fips140/mlkem to
12 // perform derandomized encapsulation, which will be exposed in Go 1.26.
13
14 func Encapsulate768(ek *mlkem.EncapsulationKey768, rand []byte) (sharedKey, ciphertext []byte, err error) {
15 if len(rand) != 32 {
16 return nil, nil, errors.New("invalid ML-KEM-768 randomness size")
17 }
18 key := (*mlkem768EncapsulationKey)(unsafe.Pointer(ek))
19 sharedKey, ciphertext = mlkem768EncapsulateInternal(key.key, (*[32]byte)(rand))
20 return sharedKey, ciphertext, nil
21 }
22
23 type mlkem768EncapsulationKey struct {
24 key unsafe.Pointer // *crypto/internal/fips140/mlkem.EncapsulationKey768
25 }
26
27 //go:linkname mlkem768EncapsulateInternal crypto/internal/fips140/mlkem.(*EncapsulationKey768).EncapsulateInternal
28 func mlkem768EncapsulateInternal(ek unsafe.Pointer, m *[32]byte) (sharedKey, ciphertext []byte)
29
30 func Encapsulate1024(ek *mlkem.EncapsulationKey1024, rand []byte) (sharedKey, ciphertext []byte, err error) {
31 if len(rand) != 32 {
32 return nil, nil, errors.New("invalid ML-KEM-1024 randomness size")
33 }
34 key := (*mlkem1024EncapsulationKey)(unsafe.Pointer(ek))
35 sharedKey, ciphertext = mlkem1024EncapsulateInternal(key.key, (*[32]byte)(rand))
36 return sharedKey, ciphertext, nil
37 }
38
39 type mlkem1024EncapsulationKey struct {
40 key unsafe.Pointer // *crypto/internal/fips140/mlkem.EncapsulationKey1024
41 }
42
43 //go:linkname mlkem1024EncapsulateInternal crypto/internal/fips140/mlkem.(*EncapsulationKey1024).EncapsulateInternal
44 func mlkem1024EncapsulateInternal(ek unsafe.Pointer, m *[32]byte) (sharedKey, ciphertext []byte)