Documentation
¶
Index ¶
- Constants
- Variables
- func AssembleJFKAuthenticator(transientKey, exponentialA, exponentialB, nonceA, nonceB []byte, ...) []byte
- func DecodeFreenetIdentity(identityBase64 string) ([]byte, []byte, error)
- func SerializeJFKMessage1(msg *JFKMessage1, unknownInitiator bool) []byte
- func VerifyJFKAuthenticator(...) bool
- type ECDHContext
- type JFKMessage1
- type JFKMessage2
- type NodeIdentity
- func (ni *NodeIdentity) GetIdentity() []byte
- func (ni *NodeIdentity) GetIdentityHash() []byte
- func (ni *NodeIdentity) GetIdentityHashHash() []byte
- func (ni *NodeIdentity) GetPrivateKey() *ecdsa.PrivateKey
- func (ni *NodeIdentity) GetPublicKey() *ecdsa.PublicKey
- func (ni *NodeIdentity) Sign(data []byte) ([]byte, error)
- func (ni *NodeIdentity) Verify(data, signature []byte, pubKey *ecdsa.PublicKey) bool
Constants ¶
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 )
const (
// IdentityLength is the length of a node identity
IdentityLength = 32
)
Variables ¶
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 ¶
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