ceremonyclient/node/keys/x448_key.go
Cassandra Heart dbd95bd9e9
v2.1.0 (#439)
* v2.1.0 [omit consensus and adjacent] - this commit will be amended with the full release after the file copy is complete

* 2.1.0 main node rollup
2025-09-30 02:48:15 -05:00

54 lines
1.2 KiB
Go

package keys
import (
"crypto/rand"
"github.com/pkg/errors"
"source.quilibrium.com/quilibrium/monorepo/nekryptology/pkg/core/curves"
qcrypto "source.quilibrium.com/quilibrium/monorepo/types/crypto"
)
type X448Key struct {
privateKey curves.Scalar
}
func NewX448Key() *X448Key {
privkey := curves.ED448().Scalar.Random(rand.Reader)
return &X448Key{privateKey: privkey}
}
func X448KeyFromBytes(data []byte) (*X448Key, error) {
privkey, err := curves.ED448().Scalar.SetBytes(data)
if err != nil {
return nil, errors.Wrap(err, "from bytes")
}
return &X448Key{privateKey: privkey}, nil
}
// AgreeWith implements Agreement.
func (x *X448Key) AgreeWith(publicKey []byte) (shared []byte, err error) {
pubkey, err := curves.ED448().NewGeneratorPoint().FromAffineCompressed(
publicKey,
)
if err != nil {
return nil, errors.Wrap(err, "agree with")
}
return pubkey.Mul(x.privateKey).ToAffineCompressed(), nil
}
// Private implements Agreement.
func (x *X448Key) Private() []byte {
return x.privateKey.Bytes()
}
// Public implements Agreement.
func (x *X448Key) Public() []byte {
pubkey := curves.ED448().NewGeneratorPoint().Mul(x.privateKey)
return pubkey.ToAffineCompressed()
}
var _ qcrypto.Agreement = (*X448Key)(nil)