security

package
v0.0.0-...-43c9aad Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Secp256k1 = "secp256k1"

	Ed25519 = "ed25519"
)
View Source
const (
	PublicKeySize  = ed25519.PublicKeySize
	PrivateKeySize = ed25519.PrivateKeySize
	SignatureSize  = ed25519.SignatureSize
)
View Source
const AESHeaderSize = 8 + aes.BlockSize
View Source
const SignatureField = "dgst_ed25519_blake2b"

Variables

View Source
var ErrInvalidID = errors.New("ID is neither a public or private key")
View Source
var ErrInvalidSignature = errors.New("signature is invalid")

Functions

func AppendToSignedHash

func AppendToSignedHash(s SignedHash, i Identity) error

func DecodeKeys

func DecodeKeys(id string) (cryptKey []byte, signKey []byte, err error)

func DecryptAES

func DecryptAES(encrypted []byte, key []byte) ([]byte, error)

DecryptAES decrypts an encrypted byte array using AES decryption with the provided key.

func DecryptBlock

func DecryptBlock(key []byte, nonce []byte, cipherdata []byte) ([]byte, error)

func DelIdentity

func DelIdentity(id string) error

func DiffieHellmanKey

func DiffieHellmanKey(identity Identity, id string) ([]byte, error)

func EcDecrypt

func EcDecrypt(identity Identity, data []byte) ([]byte, error)

func EcEncrypt

func EcEncrypt(id string, data []byte) ([]byte, error)

func EncryptAES

func EncryptAES(data []byte, key []byte) ([]byte, error)

EncryptAES encrypts a byte array using AES encryption with the provided key.

func EncryptBlock

func EncryptBlock(key []byte, nonce []byte, data []byte) ([]byte, error)

func EncryptingReader

func EncryptingReader(keyId uint64, keyFunc func(uint64) []byte, r io.ReadSeekCloser) (io.ReadSeekCloser, error)

EncryptedWriter wraps w with an OFB cipher stream.

func FileHash

func FileHash(name string) ([]byte, error)

func GenerateBytesKey

func GenerateBytesKey(size int) []byte

func Marshal

func Marshal(identity Identity, v any, signatureField string) ([]byte, error)

func NewHash

func NewHash() hash.Hash

func QuickHash

func QuickHash(data []byte) []byte

func SetIdentity

func SetIdentity(i Identity) error

func Sign

func Sign(identity Identity, data []byte) ([]byte, error)

func Unmarshal

func Unmarshal(data []byte, v any, signatureField string) (id string, err error)

func Verify

func Verify(id string, data []byte, sig []byte) bool

func VerifySignedHash

func VerifySignedHash(s SignedHash, trusts []Identity, hash []byte) bool

Types

type HashReader

type HashReader struct {
	Hash hash.Hash
	// contains filtered or unexported fields
}

func NewHashReader

func NewHashReader(r io.ReadSeekCloser) (*HashReader, error)

func (*HashReader) Close

func (s *HashReader) Close() error

func (*HashReader) Read

func (s *HashReader) Read(p []byte) (n int, err error)

func (*HashReader) Seek

func (s *HashReader) Seek(offset int64, whence int) (int64, error)

type HashWriter

type HashWriter struct {
	Hash hash.Hash
	// contains filtered or unexported fields
}

func NewHashWriter

func NewHashWriter(w io.Writer) (*HashWriter, error)

func (*HashWriter) Write

func (s *HashWriter) Write(p []byte) (n int, err error)

type Identity

type Identity struct {
	Id      string    `json:"i"`           // public key
	Nick    string    `json:"n,omitempty"` // nickname
	Email   string    `json:"e,omitempty"` // email
	ModTime time.Time `json:"m"`           // last modification time

	Private string `json:"p,omitempty"` // private key
	Avatar  []byte `json:"a,omitempty"` // avatar
}

func GetIdentities

func GetIdentities() ([]Identity, error)

func GetIdentity

func GetIdentity(id string) (Identity, error)

func NewIdentity

func NewIdentity(nick string) (Identity, error)

func NewIdentityFromId

func NewIdentityFromId(nick, privateId string) (Identity, error)

func (Identity) Public

func (i Identity) Public() Identity

type Key

type Key struct {
	Public  []byte `json:"pu"`
	Private []byte `json:"pr,omitempty"`
}

type PrivateKey

type PrivateKey ed25519.PrivateKey

type Public

type Public struct {
	Id    PublicKey
	Nick  string
	Email string
}

type PublicKey

type PublicKey ed25519.PublicKey

type SignedData

type SignedData struct {
	Signature [SignatureSize]byte
	Signer    PublicKey
}

type SignedHash

type SignedHash struct {
	Hash       []byte
	Signatures map[string][]byte
}

func NewSignedHash

func NewSignedHash(hash []byte, i Identity) (SignedHash, error)

type SignedHashEvidence

type SignedHashEvidence struct {
	Key       []byte `json:"k"`
	Signature []byte `json:"s"`
}

type StreamReader

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

func (*StreamReader) Close

func (sr *StreamReader) Close() error

func (*StreamReader) Read

func (sr *StreamReader) Read(p []byte) (n int, err error)

func (*StreamReader) Seek

func (sr *StreamReader) Seek(offset int64, whence int) (int64, error)

type StreamWriter

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

func DecryptingWriter

func DecryptingWriter(keyFunc func(uint64) []byte, w io.Writer) (*StreamWriter, error)

EncryptedWriter wraps w with an OFB cipher stream.

func (*StreamWriter) Write

func (sr *StreamWriter) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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