go-blockchain/crypto/keyimage.go
Claude 9821ea4d21
feat(crypto): key derivation, one-time addresses, and key images
Add ECDH shared secret, ephemeral key derivation (DerivePublicKey,
DeriveSecretKey), and key image generation/validation to the CGo bridge.
Tests verify ECDH commutativity, output scanning round-trip, and key
image determinism.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-20 18:28:43 +00:00

33 lines
815 B
Go

// SPDX-Licence-Identifier: EUPL-1.2
package crypto
/*
#include "bridge.h"
*/
import "C"
import (
"fmt"
"unsafe"
)
// GenerateKeyImage computes the key image for a public/secret key pair.
// The key image is used for double-spend detection in ring signatures.
func GenerateKeyImage(pub [32]byte, sec [32]byte) ([32]byte, error) {
var ki [32]byte
rc := C.cn_generate_key_image(
(*C.uint8_t)(unsafe.Pointer(&pub[0])),
(*C.uint8_t)(unsafe.Pointer(&sec[0])),
(*C.uint8_t)(unsafe.Pointer(&ki[0])),
)
if rc != 0 {
return ki, fmt.Errorf("crypto: generate_key_image failed")
}
return ki, nil
}
// ValidateKeyImage checks that a key image is a valid curve point of the correct order.
func ValidateKeyImage(ki [32]byte) bool {
return C.cn_validate_key_image((*C.uint8_t)(unsafe.Pointer(&ki[0]))) == 0
}