Documentation ¶
Overview ¶
Package glome implements GLOME protocol.
Index ¶
Constants ¶
const ( // PrivateKeySize is the size of a PrivateKey in bytes. PrivateKeySize = 32 // PublicKeySize is the size of a PublicKey in bytes. PublicKeySize = 32 // MaxTagSize is the maximum size allowed for a Tag MaxTagSize = 32 // MinTagSize is the minimum size allowed for a Tag MinTagSize = 1 )
Variables ¶
var ( // ErrInvalidPublicKey denotes that a slice that intend to be a public key is not of desired length ErrInvalidPublicKey = fmt.Errorf("invalid public key - byte slice len is not %d", PublicKeySize) // ErrInvalidPrivateKey denotes that a slice that intend to be a private key is not of desired length ErrInvalidPrivateKey = fmt.Errorf("invalid private key - byte slice len is not %d", PrivateKeySize) // ErrInvalidTagSize denotes that provided integer is not suitable to be minPeerTagSize ErrInvalidTagSize = fmt.Errorf("invalid tag size - minPeerTagSize must be in range %d-%d", MinTagSize, MaxTagSize) // ErrInvalidReader denotes that library failed to read PrivateKeySize bytes from given Reader. ErrInvalidReader = fmt.Errorf("invalid reader - failed to read %d bytes", PrivateKeySize) )
Functions ¶
func GenerateKeys ¶
func GenerateKeys(rand io.Reader) (*PublicKey, *PrivateKey, error)
GenerateKeys generates a public/private key pair using entropy from rand.
Types ¶
type Dialog ¶
type Dialog struct { User PublicKey // User's Public key Peer PublicKey // Peer's Public key // contains filtered or unexported fields }
Dialog allow tag managing functionalities for GLOME protocol.
Has to be generated with the methods Exchange or TruncatedExchange or Private key. For example:
pubKey, privKey, err := glome.GenerateKeys(rand.Reader) if err != nil { [...] } ex, err := privkey.Exchange(peerKey)
If TruncatedExchange is selected, minPeerTagSize can be different to MaxTagSize. See documentation in method Check for more information on truncation.
func (*Dialog) Check ¶
Check method checks if a tag matches some provided message and counter. The method generates the matching tag following GLOME protocol specification in the context of a communication from the users' peers to the users and then is compared with the tag provided.
For the tag to be accepted it has to be equal in all its length to the correct tag. Also, its length must be at least MinPeerTagLength and always smaller than MaxTagSize.
type PrivateKey ¶
type PrivateKey [PrivateKeySize]byte
PrivateKey is the type of GLOME public keys.
It can be initialized either by casting a [PrivateKeySize]byte array or from a byte slice with the PrivateKeyFromSlice function.
Examples:
- Generate Private Key as existing byte array: b := [32]byte{0,2,...,7,6} p := glome.PrivateKey(b)
- Generate from byte slice: s := b[:] p, err := glome.PrivateKeyFromSlice(s) if err != nil { [...] }
- Read from File: p, err := ioutil.ReadFile(filename) if err != nil { [...] } priv, err := glome.PrivateKeyFromSlice(p) if err != nil { [...] }
func PrivateKeyFromSlice ¶
func PrivateKeyFromSlice(b []byte) (*PrivateKey, error)
PrivateKeyFromSlice generates a private key from a slice. Fail if len of slice is not PrivateKeySize
func (*PrivateKey) Exchange ¶
func (priv *PrivateKey) Exchange(peer *PublicKey) (*Dialog, error)
Exchange generates a Dialog struct. It performs GLOME handshake, and stores create a Dialog from the user to the peer. Sets minPeerTagSize as MaxTagSize.
func (*PrivateKey) Public ¶
func (priv *PrivateKey) Public() (*PublicKey, error)
Public returns the PublicKey corresponding to priv.
func (*PrivateKey) TruncatedExchange ¶
func (priv *PrivateKey) TruncatedExchange(peer *PublicKey, m uint) (*Dialog, error)
TruncatedExchange generates a Dialog struct. It performs GLOME handshake, and stores create a Dialog from the user to the peer. Sets param m as minPeerTagSize.
type PublicKey ¶
type PublicKey [PublicKeySize]byte
PublicKey is the type of GLOME public Keys.
It can be initialized either by casting a [PublicKeySize]byte array or from a byte slice with the PublicKeyFromSlice function. Examples:
- Generate Public Key as existing byte array b := [32]byte{0,2,...,7,6} p := glome.PublicKey(b)
- Generate from byte slice s := b[:] p, err := glome.PublicKeyFromSlice(s) if err != nil { [...] }
- Read from File p, err := ioutil.ReadFile(filename) if err != nil { [...] } priv, err := glome.PublicKeyFromSlice(p) if err != nil { [...] }
func PublicKeyFromSlice ¶
PublicKeyFromSlice generates a PublicKey object from slice. Return ErrInvalidPublicKey if slice's length is not PublicKeySize.