virgilcrypto

package
v4.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2018 License: BSD-3-Clause, BSD-3-Clause Imports: 28 Imported by: 9

Documentation

Index

Constants

View Source
const Curve25519PrivateKeySize = 32
View Source
const Curve25519PublicKeySize = 32
View Source
const Curve25519SharedKeySize = 32
View Source
const EC_PRIVATE_KEY = "PRIVATE KEY"
View Source
const ENCRYPTED_PRIVATE_KEY = "ENCRYPTED PRIVATE KEY"
View Source
const MINIMAL_KEY_LENGTH = 32
View Source
const PUBLIC_KEY = "PUBLIC KEY"

Variables

View Source
var (
	// ErrInvalidBlockSize indicates hash blocksize <= 0.
	ErrInvalidBlockSize = CryptoError("invalid blocksize")
	// ErrInvalidPKCS7Data indicates bad input to PKCS7 pad or unpad.
	ErrInvalidPKCS7Data = CryptoError("invalid PKCS7 data (empty or not padded)")
	// ErrInvalidPKCS7Padding indicates PKCS7 unpad fails to bad input.
	ErrInvalidPKCS7Padding = CryptoError("invalid padding on input")
)
View Source
var DefaultChunkSize = 1024 * 1024
View Source
var NewKeypair func() (Keypair, error)

Functions

func X3DHInit added in v4.0.3

func X3DHInit(ICa, EKa PrivateKey, ICb, LTCb, OTCb PublicKey) ([]byte, error)

func X3DHRespond added in v4.0.3

func X3DHRespond(ICa, EKa PublicKey, ICb, LTCb, OTCb PrivateKey) ([]byte, error)

Types

type CMSEnvelope

type CMSEnvelope struct {
	ContentType asn1.ObjectIdentifier
	Content     envelopedData `asn1:"tag:0,explicit"`
}

type Cipher

type Cipher interface {
	AddKeyRecipient(key *ed25519PublicKey) error
	AddPasswordRecipient(password []byte)
	Encrypt(data []byte) ([]byte, error)
	DecryptWithPassword(data []byte, password []byte) ([]byte, error)
	DecryptWithPrivateKey(data []byte, key *ed25519PrivateKey) ([]byte, error)
	EncryptStream(in io.Reader, out io.Writer) error
	DecryptStream(in io.Reader, out io.Writer, key *ed25519PrivateKey) error
	SignThenEncrypt(data []byte, signerKey *ed25519PrivateKey) ([]byte, error)
	DecryptThenVerify(data []byte, decryptionKey *ed25519PrivateKey, verifierPublicKeys ...*ed25519PublicKey) ([]byte, error)
}

func NewCipher

func NewCipher() Cipher

type Crypto

type Crypto interface {
	SetKeyType(keyType KeyType) error
	GenerateKeypair() (Keypair, error)
	ImportPrivateKey(data []byte, password string) (PrivateKey, error)
	ImportPublicKey(data []byte) (PublicKey, error)
	ExportPrivateKey(key PrivateKey, password string) ([]byte, error)
	ExportPublicKey(key PublicKey) ([]byte, error)
	Encrypt(data []byte, recipients ...PublicKey) ([]byte, error)
	EncryptStream(in io.Reader, out io.Writer, recipients ...PublicKey) error
	Decrypt(data []byte, key PrivateKey) ([]byte, error)
	DecryptStream(in io.Reader, out io.Writer, key PrivateKey) error
	DecryptThenVerify(data []byte, privateKeyForDecryption PrivateKey, verifierKey ...PublicKey) ([]byte, error)
	Sign(data []byte, signer PrivateKey) ([]byte, error)
	SignStream(in io.Reader, signer PrivateKey) ([]byte, error)
	SignThenEncrypt(data []byte, signerKey PrivateKey, recipients ...PublicKey) ([]byte, error)
	//Verify must return non nil error if the result is false
	Verify(data []byte, signature []byte, key PublicKey) (bool, error)
	VerifyStream(in io.Reader, signature []byte, key PublicKey) (bool, error)
	CalculateFingerprint(data []byte) []byte
	ExtractPublicKey(key PrivateKey) (PublicKey, error)
}
var DefaultCrypto Crypto

type CryptoError

type CryptoError string

func (CryptoError) Error

func (c CryptoError) Error() string

type CustomParam

type CustomParam struct {
	Key   string        `asn1:"utf8"`
	Value asn1.RawValue `asn1:"tag:2,explicit"`
}

type Envelope

type Envelope struct {
	Version      int
	Data         CMSEnvelope
	CustomParams []CustomParam `asn1:"set,explicit,optional"`
}

func (*Envelope) Validate

func (envelope *Envelope) Validate() error

type KeyType

type KeyType int

KeyType denotes algorithm used for key generation. See keytypes package

type Keypair

type Keypair interface {
	HasPublic() bool
	HasPrivate() bool
	PublicKey() PublicKey
	PrivateKey() PrivateKey
}

type PFS added in v4.0.3

type PFS interface {
	StartInitiatorSession(ICb, LTCb, OTCb PublicKey, ICa, EKa PrivateKey, aliceCardId, bobCardId string) (sess *PFSSession, err error)
	StartResponderSession(ICa, EKa PublicKey, ICb, LTCb, OTCb PrivateKey, aliceCardId, bobCardId string) (sess *PFSSession, err error)
}

type PFSSession added in v4.0.3

type PFSSession struct {
	SK, AD, SessionID []byte
}

func (*PFSSession) Decrypt added in v4.0.3

func (s *PFSSession) Decrypt(salt, ciphertext []byte) ([]byte, error)

func (*PFSSession) Encrypt added in v4.0.3

func (s *PFSSession) Encrypt(plaintext []byte) (salt, ciphertext []byte)

type PrivateKey

type PrivateKey interface {
	ReceiverID() []byte
	ExtractPublicKey() (PublicKey, error)
	Encode(password []byte) ([]byte, error)
	Empty() bool
}

func DecodePrivateKey

func DecodePrivateKey(keyBytes, password []byte) (key PrivateKey, err error)

type PublicKey

type PublicKey interface {
	ReceiverID() []byte
	Encode() ([]byte, error)
	Empty() bool
}

func DecodePublicKey

func DecodePublicKey(keyBytes []byte) (PublicKey, error)

type StructuralError

type StructuralError struct {
	Msg string
}

A StructuralError suggests that the ASN.1 data is valid, but the Go type which is receiving it doesn't match.

func (StructuralError) Error

func (e StructuralError) Error() string

type SyntaxError

type SyntaxError struct {
	Msg string
}

A SyntaxError suggests that the ASN.1 data is invalid.

func (SyntaxError) Error

func (e SyntaxError) Error() string

type VirgilChunkCipher

type VirgilChunkCipher interface {
	Encrypt(key, nonce, ad []byte, chunkSize int, in io.Reader, out io.Writer) error
	Decrypt(key, nonce, ad []byte, chunkSize int, in io.Reader, out io.Writer) error
}
var ChunkCipher VirgilChunkCipher

type VirgilCrypto

type VirgilCrypto struct {
	Cipher func() Cipher
}

func (*VirgilCrypto) CalculateFingerprint

func (c *VirgilCrypto) CalculateFingerprint(data []byte) []byte

func (*VirgilCrypto) Decrypt

func (c *VirgilCrypto) Decrypt(data []byte, key PrivateKey) ([]byte, error)

func (*VirgilCrypto) DecryptStream

func (c *VirgilCrypto) DecryptStream(in io.Reader, out io.Writer, key PrivateKey) error

func (*VirgilCrypto) DecryptThenVerify

func (c *VirgilCrypto) DecryptThenVerify(data []byte, decryptionKey PrivateKey, verifierKeys ...PublicKey) ([]byte, error)

func (*VirgilCrypto) Encrypt

func (c *VirgilCrypto) Encrypt(data []byte, recipients ...PublicKey) ([]byte, error)

func (*VirgilCrypto) EncryptStream

func (c *VirgilCrypto) EncryptStream(in io.Reader, out io.Writer, recipients ...PublicKey) error

func (*VirgilCrypto) ExportPrivateKey

func (c *VirgilCrypto) ExportPrivateKey(key PrivateKey, password string) ([]byte, error)

func (*VirgilCrypto) ExportPublicKey

func (c *VirgilCrypto) ExportPublicKey(key PublicKey) ([]byte, error)

func (*VirgilCrypto) ExtractPublicKey

func (c *VirgilCrypto) ExtractPublicKey(key PrivateKey) (PublicKey, error)

func (*VirgilCrypto) GenerateKeypair

func (c *VirgilCrypto) GenerateKeypair() (Keypair, error)

func (*VirgilCrypto) ImportPrivateKey

func (c *VirgilCrypto) ImportPrivateKey(data []byte, password string) (PrivateKey, error)

func (*VirgilCrypto) ImportPublicKey

func (c *VirgilCrypto) ImportPublicKey(data []byte) (PublicKey, error)

func (*VirgilCrypto) SetKeyType

func (c *VirgilCrypto) SetKeyType(keyType KeyType) error

func (*VirgilCrypto) Sign

func (c *VirgilCrypto) Sign(data []byte, signer PrivateKey) ([]byte, error)

func (*VirgilCrypto) SignStream

func (c *VirgilCrypto) SignStream(in io.Reader, signer PrivateKey) ([]byte, error)

func (*VirgilCrypto) SignThenEncrypt

func (c *VirgilCrypto) SignThenEncrypt(data []byte, signerKey PrivateKey, recipients ...PublicKey) ([]byte, error)

func (*VirgilCrypto) StartInitiatorSession added in v4.0.3

func (c *VirgilCrypto) StartInitiatorSession(ICb, LTCb, OTCb PublicKey, ICa, EKa PrivateKey, aliceCardId, bobCardId string) (sess *PFSSession, err error)

func (*VirgilCrypto) StartResponderSession added in v4.0.3

func (c *VirgilCrypto) StartResponderSession(ICa, EKa PublicKey, ICb, LTCb, OTCb PrivateKey, aliceCardId, bobCardId string) (sess *PFSSession, err error)

func (*VirgilCrypto) Verify

func (c *VirgilCrypto) Verify(data []byte, signature []byte, key PublicKey) (bool, error)

func (*VirgilCrypto) VerifyStream

func (c *VirgilCrypto) VerifyStream(in io.Reader, signature []byte, key PublicKey) (bool, error)

type VirgilHash

type VirgilHash interface {
	New() hash.Hash
	Sum(data []byte) []byte
}
var Hash VirgilHash

type VirgilSigner

type VirgilSigner interface {
	Sign(data []byte, signer PrivateKey) ([]byte, error)
	SignStream(data io.Reader, signer PrivateKey) ([]byte, error)
}
var Signer VirgilSigner

type VirgilStreamCipher

type VirgilStreamCipher interface {
	Encrypt(key, nonce, ad []byte, in io.Reader, out io.Writer) error
	Decrypt(key, nonce, ad []byte, in io.Reader, out io.Writer) error
}
var StreamCipher VirgilStreamCipher

type VirgilVerifier

type VirgilVerifier interface {
	Verify(data []byte, key PublicKey, signature []byte) (bool, error)
	VerifyStream(data io.Reader, key PublicKey, signature []byte) (bool, error)
}
var Verifier VirgilVerifier

type WrongPasswordError

type WrongPasswordError struct {
	CryptoError
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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