Go · 557 bytes Raw Blame History
1 // SPDX-License-Identifier: AGPL-3.0-or-later
2
3 package sealbox
4
5 import (
6 "golang.org/x/crypto/curve25519"
7 )
8
9 // derivePublic computes the X25519 public key from a 32-byte private
10 // key. NaCl's box package doesn't expose this directly when loading a
11 // pre-existing private key (only `GenerateKey` returns both halves);
12 // we use curve25519.X25519 against the basepoint to derive.
13 func derivePublic(pub, priv *[32]byte) error {
14 out, err := curve25519.X25519(priv[:], curve25519.Basepoint)
15 if err != nil {
16 return err
17 }
18 copy(pub[:], out)
19 return nil
20 }
21