Documentation
¶
Index ¶
- Constants
- Variables
- func DecryptDataCTR(data, key, iv []byte) ([]byte, error)
- func DecryptDataPCFB(data, key, iv []byte) ([]byte, error)
- func DecryptHashedDocname(encryptedHashedDocname, cryptoKey []byte) ([]byte, error)
- func EncryptDataCTR(data, key, iv []byte) ([]byte, error)
- func EncryptDataPCFB(data, key, iv []byte) ([]byte, error)
- func EncryptHashedDocname(hashedDocname, cryptoKey []byte) ([]byte, error)
- func GenerateSSKKeypair() ([]byte, []byte, error)
- func GetSSKExtraBytes(cryptoAlgorithm byte) []byte
- func HashData(data []byte) []byte
- func HashDocname(docname string) []byte
- func SignData(data []byte, privKeyBytes []byte) (r, s *big.Int, err error)
- func VerifySignature(data []byte, pubKeyBytes []byte, r, s *big.Int) bool
- type BaseKey
- type ClientCHK
- func (c *ClientCHK) Clone() *ClientCHK
- func (c *ClientCHK) Equals(other *ClientCHK) bool
- func (c *ClientCHK) GetCompressionAlgorithm() int16
- func (c *ClientCHK) GetCryptoAlgorithm() byte
- func (c *ClientCHK) GetCryptoKey() []byte
- func (c *ClientCHK) GetExtra() []byte
- func (c *ClientCHK) GetNodeCHK() *NodeCHK
- func (c *ClientCHK) GetRoutingKey() []byte
- func (c *ClientCHK) GetURI() *FreenetURI
- func (c *ClientCHK) HashCode() int
- func (c *ClientCHK) IsControlDocument() bool
- func (c *ClientCHK) ToNormalizedDouble() float64
- func (c *ClientCHK) WriteBinary(w io.Writer) error
- func (c *ClientCHK) WriteRawBinaryKey(w io.Writer) error
- type ClientSSK
- func (c *ClientSSK) Clone() *ClientSSK
- func (c *ClientSSK) Equals(other *ClientSSK) bool
- func (c *ClientSSK) GetCryptoAlgorithm() byte
- func (c *ClientSSK) GetCryptoKey() []byte
- func (c *ClientSSK) GetDocName() string
- func (c *ClientSSK) GetEncryptedHashedDocname() []byte
- func (c *ClientSSK) GetNodeKey(clone bool) (*NodeSSK, error)
- func (c *ClientSSK) GetPubKey() *dsa.PublicKey
- func (c *ClientSSK) GetPubKeyHash() []byte
- func (c *ClientSSK) GetRoutingKey() []byte
- func (c *ClientSSK) GetURI() *FreenetURI
- func (c *ClientSSK) HashCode() int
- func (c *ClientSSK) SetPubKey(pubKey *dsa.PublicKey) error
- func (c *ClientSSK) ToNormalizedDouble() float64
- func (c *ClientSSK) VerifyDocname() error
- type FreenetURI
- func (uri *FreenetURI) Clone() *FreenetURI
- func (uri *FreenetURI) Equals(other *FreenetURI) bool
- func (uri *FreenetURI) GetEdition() int64
- func (uri *FreenetURI) GetSiteName() string
- func (uri *FreenetURI) SetEdition(edition int64) error
- func (uri *FreenetURI) String() string
- func (uri *FreenetURI) ToClientCHK() (*ClientCHK, error)
- func (uri *FreenetURI) ToClientSSK() (*ClientSSK, error)
- func (uri *FreenetURI) WriteBinary(w io.Writer) error
- type Key
- type NodeCHK
- func (nchk *NodeCHK) Clone() Key
- func (nchk *NodeCHK) Equals(other Key) bool
- func (nchk *NodeCHK) GetCryptoAlgorithm() byte
- func (nchk *NodeCHK) GetFullKey() []byte
- func (nchk *NodeCHK) GetKeyBytes() []byte
- func (nchk *NodeCHK) GetType() uint16
- func (nchk *NodeCHK) ToNormalizedDouble() float64
- func (nchk *NodeCHK) Write(w io.Writer) error
- type NodeSSK
- func (nssk *NodeSSK) Clone() Key
- func (nssk *NodeSSK) Equals(other Key) bool
- func (nssk *NodeSSK) GetCryptoAlgorithm() byte
- func (nssk *NodeSSK) GetEncryptedHashedDocname() []byte
- func (nssk *NodeSSK) GetFullKey() []byte
- func (nssk *NodeSSK) GetKeyBytes() []byte
- func (nssk *NodeSSK) GetPubKey() *dsa.PublicKey
- func (nssk *NodeSSK) GetPubKeyHash() []byte
- func (nssk *NodeSSK) GetType() uint16
- func (nssk *NodeSSK) SetPubKey(pubKey *dsa.PublicKey) error
- func (nssk *NodeSSK) ToNormalizedDouble() float64
- func (nssk *NodeSSK) Write(w io.Writer) error
Constants ¶
const ( ClientCHKExtraLength = 5 ClientCHKCryptoKeyLength = 32 )
const ( CompressionNone int16 = -1 CompressionGZIP int16 = 0 CompressionBZIP2 int16 = 1 CompressionLZMA int16 = 2 CompressionLZMA_NEW int16 = 3 )
Compression algorithms
const ( ClientSSKCryptoKeyLength = 32 ClientSSKExtraLength = 5 )
const ( // Crypto algorithms AlgoAESPCFB256SHA256 byte = 2 AlgoAESCTR256SHA256 byte = 3 // Hash algorithms HashSHA256 = 1 // Key lengths RoutingKeyLength = 32 CryptoKeyLength = 32 // Base types CHKBaseType uint8 = 1 SSKBaseType uint8 = 2 )
Key constants
const ( NodeCHKKeyLength = 32 NodeCHKFullKeyLength = 34 // 2 (type) + 32 (routing key) )
const ( NodeSSKPubKeyHashSize = 32 NodeSSKEHDocnameSize = 32 NodeSSKRoutingKeyLength = 32 NodeSSKFullKeyLength = 66 // 2 (type) + 32 (ehDocname) + 32 (pubKeyHash) NodeSSKVersion = 1 )
Variables ¶
var ValidKeyTypes = []string{"CHK", "SSK", "KSK", "USK"}
Valid key types
Functions ¶
func DecryptDataCTR ¶
DecryptDataCTR decrypts data using AES-256-CTR mode
func DecryptDataPCFB ¶
DecryptDataPCFB decrypts data using AES-256-PCFB mode
func DecryptHashedDocname ¶
DecryptHashedDocname decrypts the encrypted hashed docname
func EncryptDataCTR ¶
EncryptDataCTR encrypts data using AES-256-CTR mode
func EncryptDataPCFB ¶
EncryptDataPCFB encrypts data using AES-256-PCFB mode (Freenet's variant) PCFB is similar to CFB but with specific padding
func EncryptHashedDocname ¶
EncryptHashedDocname encrypts the hashed docname with the crypto key This is used for SSK key generation: E(H(docname))
func GenerateSSKKeypair ¶
GenerateSSKKeypair generates a new SSK keypair (DSA) Returns private key bytes and public key bytes
func GetSSKExtraBytes ¶
GetSSKExtraBytes creates the extra bytes for an SSK
func HashDocname ¶
HashDocname computes SHA256 hash of a document name
Types ¶
type BaseKey ¶
type BaseKey struct {
// contains filtered or unexported fields
}
BaseKey provides common functionality for all key types
func (*BaseKey) GetRoutingKey ¶
GetRoutingKey returns the routing key
func (*BaseKey) ToNormalizedDouble ¶
ToNormalizedDouble converts key to 0.0-1.0 range for routing This matches the Java implementation's keyDigestAsNormalizedDouble
type ClientCHK ¶
type ClientCHK struct {
// contains filtered or unexported fields
}
ClientCHK represents a client-level Content Hash Key Contains both routing information and decryption key
func NewClientCHK ¶
func NewClientCHK(routingKey, cryptoKey []byte, cryptoAlgorithm byte, compressionAlgorithm int16, controlDocument bool) (*ClientCHK, error)
NewClientCHK creates a new ClientCHK
func NewClientCHKFromData ¶
NewClientCHKFromData creates a ClientCHK by encrypting data and computing its hash This is used for inserting new data into the network
func NewClientCHKFromURI ¶
func NewClientCHKFromURI(uri *FreenetURI) (*ClientCHK, error)
NewClientCHKFromURI creates a ClientCHK from a FreenetURI
func ReadClientCHK ¶
ReadClientCHK deserializes a ClientCHK from a reader
func (*ClientCHK) GetCompressionAlgorithm ¶
GetCompressionAlgorithm returns the compression algorithm
func (*ClientCHK) GetCryptoAlgorithm ¶
GetCryptoAlgorithm returns the crypto algorithm
func (*ClientCHK) GetCryptoKey ¶
GetCryptoKey returns the decryption key
func (*ClientCHK) GetNodeCHK ¶
GetNodeCHK returns the corresponding NodeCHK (for routing)
func (*ClientCHK) GetRoutingKey ¶
GetRoutingKey returns the routing key
func (*ClientCHK) GetURI ¶
func (c *ClientCHK) GetURI() *FreenetURI
GetURI converts this ClientCHK to a FreenetURI
func (*ClientCHK) IsControlDocument ¶
IsControlDocument returns whether this is a control document (metadata)
func (*ClientCHK) ToNormalizedDouble ¶
ToNormalizedDouble converts key to 0.0-1.0 range for routing
func (*ClientCHK) WriteBinary ¶
WriteBinary writes the key in binary format with type prefix
type ClientSSK ¶
type ClientSSK struct {
// contains filtered or unexported fields
}
ClientSSK represents a client-level Signed Subspace Key Contains document name, public key, and decryption information
func NewClientSSK ¶
func NewClientSSK(docName string, pubKeyHash, extra []byte, pubKey *dsa.PublicKey, cryptoKey []byte) (*ClientSSK, error)
NewClientSSK creates a new ClientSSK
func NewClientSSKFromURI ¶
func NewClientSSKFromURI(uri *FreenetURI) (*ClientSSK, error)
NewClientSSKFromURI creates a ClientSSK from a FreenetURI
func (*ClientSSK) GetCryptoAlgorithm ¶
GetCryptoAlgorithm returns the crypto algorithm
func (*ClientSSK) GetCryptoKey ¶
GetCryptoKey returns the decryption key
func (*ClientSSK) GetDocName ¶
GetDocName returns the document name
func (*ClientSSK) GetEncryptedHashedDocname ¶
GetEncryptedHashedDocname returns E(H(docname))
func (*ClientSSK) GetNodeKey ¶
GetNodeKey returns the corresponding NodeSSK (for routing)
func (*ClientSSK) GetPubKeyHash ¶
GetPubKeyHash returns the public key hash
func (*ClientSSK) GetRoutingKey ¶
GetRoutingKey returns the routing key (for compatibility)
func (*ClientSSK) GetURI ¶
func (c *ClientSSK) GetURI() *FreenetURI
GetURI converts this ClientSSK to a FreenetURI
func (*ClientSSK) ToNormalizedDouble ¶
ToNormalizedDouble converts key to 0.0-1.0 range for routing
func (*ClientSSK) VerifyDocname ¶
VerifyDocname verifies that the docname matches the encrypted hashed docname
type FreenetURI ¶
type FreenetURI struct {
KeyType string // "CHK", "SSK", "KSK", "USK"
DocName string // document name (SSK, KSK, USK)
MetaStr []string // manifest path components
RoutingKey []byte // 32 bytes (CHK, SSK, USK) - for SSK it's pubKeyHash
CryptoKey []byte // 32 bytes (CHK, SSK, USK)
Extra []byte // 5 bytes - algorithm info
SuggestedEdition int64 // only for USK (-1 = not specified)
// contains filtered or unexported fields
}
FreenetURI represents a Freenet/Hyphanet URI Format: freenet:[KeyType@]RoutingKey,CryptoKey,Extra[/docname][/meta1/meta2/...]
func ParseFreenetURI ¶
func ParseFreenetURI(uriStr string) (*FreenetURI, error)
ParseFreenetURI parses a Freenet URI string
func (*FreenetURI) Clone ¶
func (uri *FreenetURI) Clone() *FreenetURI
Clone creates a deep copy of the URI
func (*FreenetURI) Equals ¶
func (uri *FreenetURI) Equals(other *FreenetURI) bool
Equals checks if two URIs are equal
func (*FreenetURI) GetEdition ¶
func (uri *FreenetURI) GetEdition() int64
GetEdition returns the edition for USK URIs
func (*FreenetURI) GetSiteName ¶
func (uri *FreenetURI) GetSiteName() string
GetSiteName returns the site name portion of the URI
func (*FreenetURI) SetEdition ¶
func (uri *FreenetURI) SetEdition(edition int64) error
SetEdition sets the edition for USK URIs
func (*FreenetURI) String ¶
func (uri *FreenetURI) String() string
String converts the URI to a string representation
func (*FreenetURI) ToClientCHK ¶
func (uri *FreenetURI) ToClientCHK() (*ClientCHK, error)
ToClientCHK converts this URI to a ClientCHK (if it's a CHK URI)
func (*FreenetURI) ToClientSSK ¶
func (uri *FreenetURI) ToClientSSK() (*ClientSSK, error)
ToClientSSK converts this URI to a ClientSSK (if it's an SSK/USK URI)
func (*FreenetURI) WriteBinary ¶
func (uri *FreenetURI) WriteBinary(w io.Writer) error
WriteBinary writes the URI in binary format
type Key ¶
type Key interface {
// GetRoutingKey returns the routing key bytes used for network routing
GetRoutingKey() []byte
// GetKeyBytes returns the key-specific bytes (implementation-dependent)
GetKeyBytes() []byte
// GetFullKey returns the complete serialized key including type
GetFullKey() []byte
// GetType returns the key type (high byte = base type, low byte = crypto algorithm)
GetType() uint16
// ToNormalizedDouble converts the key to a 0.0-1.0 value for location-based routing
ToNormalizedDouble() float64
// Write serializes the key to a writer
Write(w io.Writer) error
// Clone creates a deep copy of the key
Clone() Key
// Equals checks if two keys are equal
Equals(other Key) bool
}
Key is the base interface for all Freenet keys
type NodeCHK ¶
type NodeCHK struct {
BaseKey
// contains filtered or unexported fields
}
NodeCHK represents a node-level Content Hash Key (immutable content) This is used for routing and does not contain decryption information
func NewNodeCHK ¶
NewNodeCHK creates a new NodeCHK from a routing key and crypto algorithm
func ReadNodeCHK ¶
ReadNodeCHK deserializes a NodeCHK from a reader
func ReadNodeCHKWithType ¶
ReadNodeCHKWithType deserializes a NodeCHK including its type prefix
func (*NodeCHK) GetCryptoAlgorithm ¶
GetCryptoAlgorithm returns the crypto algorithm
func (*NodeCHK) GetFullKey ¶
GetFullKey returns the complete serialized key
func (*NodeCHK) GetKeyBytes ¶
GetKeyBytes returns the routing key for CHK
func (*NodeCHK) ToNormalizedDouble ¶
ToNormalizedDouble converts key to 0.0-1.0 range for routing
type NodeSSK ¶
type NodeSSK struct {
BaseKey
// contains filtered or unexported fields
}
NodeSSK represents a node-level Signed Subspace Key (mutable content) This is used for routing and does not contain decryption information
func NewNodeSSK ¶
func NewNodeSSK(pubKeyHash, ehDocname []byte, pubKey *dsa.PublicKey, cryptoAlgorithm byte) (*NodeSSK, error)
NewNodeSSK creates a new NodeSSK
func ReadNodeSSK ¶
ReadNodeSSK deserializes a NodeSSK from a reader
func ReadNodeSSKWithType ¶
ReadNodeSSKWithType deserializes a NodeSSK including its type prefix
func (*NodeSSK) GetCryptoAlgorithm ¶
GetCryptoAlgorithm returns the crypto algorithm
func (*NodeSSK) GetEncryptedHashedDocname ¶
GetEncryptedHashedDocname returns the encrypted hashed docname
func (*NodeSSK) GetFullKey ¶
GetFullKey returns the complete serialized key
func (*NodeSSK) GetKeyBytes ¶
GetKeyBytes returns the encrypted hashed docname for SSK
func (*NodeSSK) GetPubKeyHash ¶
GetPubKeyHash returns the public key hash
func (*NodeSSK) ToNormalizedDouble ¶
ToNormalizedDouble converts key to 0.0-1.0 range for routing