ceremonyclient/nekryptology/pkg/ted25519/frost/challenge_derive.go
Cassandra Heart 12996487c3
v2.1.0.18 (#508)
* experiment: reject bad peer info messages

* v2.1.0.18 preview

* add tagged sync

* Add missing hypergraph changes

* small tweaks to sync

* allow local sync, use it for provers with workers

* missing file

* resolve build error

* resolve sync issue, remove raw sync

* resolve deletion promotion bug

* resolve sync abstraction leak from tree deletion changes

* rearrange prover sync

* remove pruning from sync

* restore removed sync flag

* fix: sync, event stream deadlock, heuristic scoring of better shards

* resolve hanging shutdown + pubsub proxy issue

* further bugfixes: sync (restore old leaf sync), pubsub shutdown, merge events

* fix: clean up rust ffi, background coverage events, and sync tweaks

* fix: linking issue for channel, connectivity test aggression, sync regression, join tests

* fix: disjoint sync, improper application of filter

* resolve sync/reel/validation deadlock

* adjust sync to handle no leaf edge cases, multi-path segment traversal

* use simpler sync

* faster, simpler sync with some debug extras

* migration to recalculate

* don't use batch

* square up the roots

* fix nil pointer

* fix: seniority calculation, sync race condition, migration

* make sync dumber

* fix: tree deletion issue

* fix: missing seniority merge request canonical serialization

* address issues from previous commit test

* stale workers should be cleared

* remove missing gap check

* rearrange collect, reduce sync logging noise

* fix: the disjoint leaf/branch sync case

* nuclear option on sync failures

* v2.1.0.18, finalized
2026-02-08 23:51:51 -06:00

69 lines
2.1 KiB
Go

//
// Copyright Coinbase, Inc. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
package frost
import (
"crypto/sha512"
"math/big"
"golang.org/x/crypto/sha3"
"source.quilibrium.com/quilibrium/monorepo/nekryptology/pkg/core/curves"
)
type ChallengeDerive interface {
DeriveChallenge(msg []byte, pubKey curves.Point, r curves.Point) (curves.Scalar, error)
}
type Ed25519ChallengeDeriver struct{}
func (ed Ed25519ChallengeDeriver) DeriveChallenge(msg []byte, pubKey curves.Point, r curves.Point) (curves.Scalar, error) {
h := sha512.New()
_, _ = h.Write(r.ToAffineCompressed())
_, _ = h.Write(pubKey.ToAffineCompressed())
_, _ = h.Write(msg)
return new(curves.ScalarEd25519).SetBytesWide(h.Sum(nil))
}
// Ed448ChallengeDeriver implements ChallengeDerive for Ed448 curves
// Ed448 uses SHAKE256 for hashing per RFC 8032
type Ed448ChallengeDeriver struct{}
func (ed Ed448ChallengeDeriver) DeriveChallenge(msg []byte, pubKey curves.Point, r curves.Point) (curves.Scalar, error) {
// Ed448 challenge derivation per RFC 8032:
// SHAKE256(dom4(0, "") || R || A || M, 114) reduced mod L
//
// dom4(phflag, context) = "SigEd448" || octet(phflag) || octet(len(context)) || context
// For pure Ed448 (no prehash, empty context): dom4(0, "") = "SigEd448" || 0x00 || 0x00
h := sha3.NewShake256()
// Write dom4 prefix for Ed448
_, _ = h.Write([]byte("SigEd448"))
_, _ = h.Write([]byte{0x00}) // phflag = 0 (not prehashed)
_, _ = h.Write([]byte{0x00}) // context length = 0
// Write R || A || M
_, _ = h.Write(r.ToAffineCompressed())
_, _ = h.Write(pubKey.ToAffineCompressed())
_, _ = h.Write(msg)
// Read 114 bytes (2 * 57 = 114, matching circl's hashSize)
raw := [114]byte{}
_, _ = h.Read(raw[:])
// Convert little-endian bytes to big.Int for proper modular reduction
// The hash output is in little-endian format
reversed := make([]byte, 114)
for i := 0; i < 114; i++ {
reversed[113-i] = raw[i]
}
hashInt := new(big.Int).SetBytes(reversed)
// SetBigInt performs proper modular reduction by the group order
return new(curves.ScalarEd448).SetBigInt(hashInt)
}