Help us shape the future of Go! Take the 2026 Go Developer Survey

hsm

package
v0.0.0-...-6e8450d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package hsm provides PKCS#11-backed storage for FROST key shares.

In production each participant's secret share lives inside the HSM. The share is written once during the key ceremony and is never exported (CKA_EXTRACTABLE = false). All subsequent use is in-HSM: the policy engine asks the HSM to produce a partial signature; the raw scalar bytes never leave the device boundary.

For the prototype we use SoftHSM2 so the whole stack can be exercised on a developer machine without physical hardware.

Index

Constants

View Source
const (
	// ShareKeyType is the CKK_GENERIC_SECRET type used to store 32-byte scalars.
	ShareKeyType = pkcs11.CKK_GENERIC_SECRET

	// ShareKeyClass is the object class for secret key objects.
	ShareKeyClass = pkcs11.CKO_SECRET_KEY
)

Variables

View Source
var ErrShareExists = errors.New("hsm: share already exists")

ErrShareExists is returned when StoreShare is called with a label that already exists in the token. Labels are unique per ceremony+index to prevent accidental overwrite.

Functions

func CeremonyID

func CeremonyID(groupPubKey []byte) string

CeremonyID derives a deterministic ID from the group public key bytes so that every participant independently computes the same label without out-of-band coordination.

func ShareLabel

func ShareLabel(ceremonyID string, index uint32) string

ShareLabel builds the canonical label for a participant's share.

ceremonyID -- a short identifier for the key ceremony (e.g. "ceremony-2024-01")
index      -- 1-indexed participant number (matches FROST convention)

Types

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store holds an open PKCS#11 session against a single token slot. One Store is created per participant during the key ceremony and re-opened at node startup.

func New

func New(lib string, slot uint, pin string) (*Store, error)

New opens a PKCS#11 context against the given shared-library path (e.g. /usr/local/lib/softhsm/libsofthsm2.so), logs in with the supplied PIN, and returns a ready Store. Call Close when done.

func (*Store) Close

func (s *Store) Close() error

Close logs out, closes the session, and releases the PKCS#11 context.

func (*Store) DeleteShare

func (s *Store) DeleteShare(label string) error

DeleteShare removes a previously stored share by label. Used during key rotation or ceremony teardown.

func (*Store) SignHMAC

func (s *Store) SignHMAC(label string, msg []byte) ([]byte, error)

SignHMAC produces an HMAC-SHA256 commitment using the stored share as the key and msg as the message. This is used in the FROST nonce-binding step: each participant commits to their nonce by signing the session transcript with their share -- without ever exposing the share bytes.

The operation is performed entirely inside the HSM via C_Sign with CKM_SHA256_HMAC. The key material never crosses the HSM boundary.

func (*Store) StoreShare

func (s *Store) StoreShare(label string, share [32]byte) error

StoreShare writes a 32-byte FROST secret share to the HSM as a CKO_SECRET_KEY / CKK_GENERIC_SECRET object.

label encodes "share-<ceremonyID>-<participantIndex>" so that multiple ceremonies can coexist in one token without collisions.

The object is created with:

  • CKA_EXTRACTABLE = false (bytes cannot be exported via C_WrapKey)
  • CKA_SENSITIVE = true (bytes will not appear in C_GetAttributeValue)
  • CKA_TOKEN = true (persists across sessions)

In SoftHSM2, EXTRACTABLE=false is enforced by the library; on a real HSM it is enforced in tamper-resistant hardware.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL