crypto

package
v0.0.0-...-840fb12 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// JFK protocol constants
	HashLength          = 32 // SHA256
	NonceSize           = 32
	ModulusLengthP256   = 65 // Uncompressed ECDH P-256 public key
	SignatureLengthP256 = 64 // ECDSA P-256 signature (r+s)

	// Setup types
	SetupOpennetSeednode = 1
)
View Source
const (
	// IdentityLength is the length of a node identity
	IdentityLength = 32
)

Variables

View Source
var (
	JFKPrefixInitiator = []byte("I")
	JFKPrefixResponder = []byte("R")
)

Functions

func AssembleJFKAuthenticator

func AssembleJFKAuthenticator(transientKey, exponentialA, exponentialB, nonceA, nonceB []byte, ipAddress []byte) []byte

AssembleJFKAuthenticator creates the JFK authenticator HMAC

func DecodeFreenetIdentity

func DecodeFreenetIdentity(identityBase64 string) ([]byte, []byte, error)

DecodeFreenetIdentity decodes a Freenet base64 identity string Returns the raw identity and its hash

func SerializeJFKMessage1

func SerializeJFKMessage1(msg *JFKMessage1, unknownInitiator bool) []byte

SerializeJFKMessage1 serializes a JFK Message 1 to bytes

func VerifyJFKAuthenticator

func VerifyJFKAuthenticator(transientKey, exponentialA, exponentialB, nonceA, nonceB, ipAddress, authenticator []byte) bool

VerifyJFKAuthenticator verifies the JFK authenticator HMAC

Types

type ECDHContext

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

ECDHContext holds an ECDH key exchange context

func NewECDHContext

func NewECDHContext(nodeIdentity *NodeIdentity) (*ECDHContext, error)

NewECDHContext creates a new ECDH context using P-256 curve

func (*ECDHContext) ComputeSharedSecret

func (ctx *ECDHContext) ComputeSharedSecret(peerPubKey []byte) ([]byte, error)

ComputeSharedSecret computes the shared secret with a peer's public key

func (*ECDHContext) GetPublicKeyBytes

func (ctx *ECDHContext) GetPublicKeyBytes() []byte

GetPublicKeyBytes returns the public key in network format

func (*ECDHContext) GetSignature

func (ctx *ECDHContext) GetSignature() []byte

GetSignature returns the ECDSA signature of the public key

type JFKMessage1

type JFKMessage1 struct {
	NonceHash          []byte // SHA256(Nonce)
	InitiatorExponent  []byte // g^i (ECDH public key)
	InitiatorIdentHash []byte // Hash of initiator identity (for unknown initiator)
}

JFKMessage1 represents the first JFK handshake message

func BuildJFKMessage1

func BuildJFKMessage1(ecdhCtx *ECDHContext, unknownInitiator bool, identityHash []byte) (*JFKMessage1, []byte, error)

BuildJFKMessage1 constructs a JFK Message 1

type JFKMessage2

type JFKMessage2 struct {
	NonceInitiatorHash []byte
	NonceResponder     []byte
	ResponderExponent  []byte
	Signature          []byte
	Authenticator      []byte
}

JFKMessage2 represents the second JFK handshake message

func ParseJFKMessage2

func ParseJFKMessage2(data []byte) (*JFKMessage2, error)

ParseJFKMessage2 parses a JFK Message 2 from bytes

type NodeIdentity

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

NodeIdentity represents a node's cryptographic identity

func NewNodeIdentity

func NewNodeIdentity() (*NodeIdentity, error)

NewNodeIdentity creates a new node identity with generated keys

func (*NodeIdentity) GetIdentity

func (ni *NodeIdentity) GetIdentity() []byte

GetIdentity returns the raw identity bytes

func (*NodeIdentity) GetIdentityHash

func (ni *NodeIdentity) GetIdentityHash() []byte

GetIdentityHash returns the identity hash (setup key)

func (*NodeIdentity) GetIdentityHashHash

func (ni *NodeIdentity) GetIdentityHashHash() []byte

GetIdentityHashHash returns the hash of the identity hash

func (*NodeIdentity) GetPrivateKey

func (ni *NodeIdentity) GetPrivateKey() *ecdsa.PrivateKey

GetPrivateKey returns the ECDSA private key

func (*NodeIdentity) GetPublicKey

func (ni *NodeIdentity) GetPublicKey() *ecdsa.PublicKey

GetPublicKey returns the ECDSA public key

func (*NodeIdentity) Sign

func (ni *NodeIdentity) Sign(data []byte) ([]byte, error)

Sign signs data with the ECDSA private key

func (*NodeIdentity) Verify

func (ni *NodeIdentity) Verify(data, signature []byte, pubKey *ecdsa.PublicKey) bool

Verify verifies a signature

Jump to

Keyboard shortcuts

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