cryptoimpl

package
v5.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2019 License: BSD-3-Clause Imports: 28 Imported by: 0

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 (
	OidSha256 = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 4, 2, 1}
	OidSha384 = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 4, 2, 2}
	OidSha512 = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 4, 2, 3}
)
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() (*ed25519Keypair, error)
View Source
var UnsupportedKeyErr = CryptoError("key unsupported")

Functions

func DecodePrivateKey

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

func DecodePublicKey

func DecodePublicKey(keyBytes []byte) (*ed25519PublicKey, error)

func EDHInit

func EDHInit(ICa, EKa *ed25519PrivateKey, ICb, LTCb, OTCb *ed25519PublicKey) ([]byte, error)

func EDHRespond

func EDHRespond(ICa, EKa *ed25519PublicKey, ICb, LTCb, OTCb *ed25519PrivateKey) ([]byte, error)

func ZeroData

func ZeroData(data []byte)

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 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:"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 PFS

type PFS interface {
	StartPFSSession(ICb, LTCb, OTCb *ed25519PublicKey, ICa, EKa *ed25519PrivateKey, additionalData []byte) (sess *PFSSession, err error)
	ReceivePFCSession(ICa, EKa *ed25519PublicKey, ICb, LTCb, OTCb *ed25519PrivateKey, additionalData []byte) (sess *PFSSession, err error)
}

type PFSSession

type PFSSession struct {
	SKa, SKb, AD, SessionID []byte
	Initiator               bool
}

func (*PFSSession) Decrypt

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

func (*PFSSession) Encrypt

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

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 VirgilAccessTokenSigner

type VirgilAccessTokenSigner struct {
	Crypto *VirgilCrypto
}

func NewVirgilAccessTokenSigner

func NewVirgilAccessTokenSigner() *VirgilAccessTokenSigner

func (*VirgilAccessTokenSigner) GenerateTokenSignature

func (t *VirgilAccessTokenSigner) GenerateTokenSignature(data []byte, privateKey interface {
	IsPrivate() bool
	Identifier() []byte
}) ([]byte, error)

func (*VirgilAccessTokenSigner) GetAlgorithm

func (t *VirgilAccessTokenSigner) GetAlgorithm() string

func (*VirgilAccessTokenSigner) VerifyTokenSignature

func (t *VirgilAccessTokenSigner) VerifyTokenSignature(data []byte, signature []byte, publicKey interface {
	IsPublic() bool
	Identifier() []byte
}) error

type VirgilCardCrypto

type VirgilCardCrypto struct {
	Crypto *VirgilCrypto
}

func NewVirgilCardCrypto

func NewVirgilCardCrypto() *VirgilCardCrypto

func (*VirgilCardCrypto) ExportPublicKey

func (c *VirgilCardCrypto) ExportPublicKey(key interface {
	IsPublic() bool
	Identifier() []byte
}) ([]byte, error)

func (*VirgilCardCrypto) GenerateSHA512

func (c *VirgilCardCrypto) GenerateSHA512(data []byte) []byte

func (*VirgilCardCrypto) GenerateSignature

func (c *VirgilCardCrypto) GenerateSignature(data []byte, key interface {
	IsPrivate() bool
	Identifier() []byte
}) ([]byte, error)

func (*VirgilCardCrypto) ImportPublicKey

func (c *VirgilCardCrypto) ImportPublicKey(data []byte) (interface {
	IsPublic() bool
	Identifier() []byte
}, error)

func (*VirgilCardCrypto) VerifySignature

func (c *VirgilCardCrypto) VerifySignature(data []byte, signature []byte, key interface {
	IsPublic() bool
	Identifier() []byte
}) error

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 {
	MakeCipher            func() Cipher
	UseSHA256Fingerprints bool
}

func NewVirgilCrypto

func NewVirgilCrypto() *VirgilCrypto

func (*VirgilCrypto) CalculateIdentifier

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

func (*VirgilCrypto) Decrypt

func (c *VirgilCrypto) Decrypt(data []byte, key interface {
	IsPrivate() bool
	Identifier() []byte
}) ([]byte, error)

func (*VirgilCrypto) DecryptStream

func (c *VirgilCrypto) DecryptStream(in io.Reader, out io.Writer, key interface {
	IsPrivate() bool
	Identifier() []byte
}) error

func (*VirgilCrypto) DecryptThenVerify

func (c *VirgilCrypto) DecryptThenVerify(data []byte, decryptionKey interface {
	IsPrivate() bool
	Identifier() []byte
}, verifierKeys ...interface {
	IsPublic() bool
	Identifier() []byte
}) ([]byte, error)

func (*VirgilCrypto) Encrypt

func (c *VirgilCrypto) Encrypt(data []byte, recipients ...interface {
	IsPublic() bool
	Identifier() []byte
}) ([]byte, error)

func (*VirgilCrypto) EncryptStream

func (c *VirgilCrypto) EncryptStream(in io.Reader, out io.Writer, recipients ...interface {
	IsPublic() bool
	Identifier() []byte
}) error

func (*VirgilCrypto) ExportPrivateKey

func (c *VirgilCrypto) ExportPrivateKey(key interface {
	IsPrivate() bool
	Identifier() []byte
}, password string) ([]byte, error)

func (*VirgilCrypto) ExportPublicKey

func (c *VirgilCrypto) ExportPublicKey(key interface {
	IsPublic() bool
	Identifier() []byte
}) ([]byte, error)

func (*VirgilCrypto) ExtractPublicKey

func (c *VirgilCrypto) ExtractPublicKey(key interface {
	IsPrivate() bool
	Identifier() []byte
}) (interface {
	IsPublic() bool
	Identifier() []byte
}, error)

func (*VirgilCrypto) GenerateKeypair

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

func (*VirgilCrypto) ImportPrivateKey

func (c *VirgilCrypto) ImportPrivateKey(data []byte, password string) (interface {
	IsPrivate() bool
	Identifier() []byte
}, error)

func (*VirgilCrypto) ImportPublicKey

func (c *VirgilCrypto) ImportPublicKey(data []byte) (interface {
	IsPublic() bool
	Identifier() []byte
}, error)

func (*VirgilCrypto) ReceivePFCSession

func (c *VirgilCrypto) ReceivePFCSession(ICa, EKa *ed25519PublicKey, ICb, LTCb, OTCb *ed25519PrivateKey, additionalData []byte) (sess *PFSSession, err error)

func (*VirgilCrypto) SetKeyType

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

func (*VirgilCrypto) Sign

func (c *VirgilCrypto) Sign(data []byte, key interface {
	IsPrivate() bool
	Identifier() []byte
}) ([]byte, error)

func (*VirgilCrypto) SignStream

func (c *VirgilCrypto) SignStream(in io.Reader, key interface {
	IsPrivate() bool
	Identifier() []byte
}) ([]byte, error)

func (*VirgilCrypto) SignThenEncrypt

func (c *VirgilCrypto) SignThenEncrypt(data []byte, signerKey interface {
	IsPrivate() bool
	Identifier() []byte
}, recipients ...interface {
	IsPublic() bool
	Identifier() []byte
}) ([]byte, error)

func (*VirgilCrypto) StartPFSSession

func (c *VirgilCrypto) StartPFSSession(ICb, LTCb, OTCb *ed25519PublicKey, ICa, EKa *ed25519PrivateKey, additionalData []byte) (sess *PFSSession, err error)

func (*VirgilCrypto) VerifyHashSignature

func (c *VirgilCrypto) VerifyHashSignature(hash []byte, signature []byte, key interface {
	IsPublic() bool
	Identifier() []byte
}) error

func (*VirgilCrypto) VerifySignature

func (c *VirgilCrypto) VerifySignature(data []byte, signature []byte, key interface {
	IsPublic() bool
	Identifier() []byte
}) error

func (*VirgilCrypto) VerifyStream

func (c *VirgilCrypto) VerifyStream(in io.Reader, signature []byte, key interface {
	IsPublic() bool
	Identifier() []byte
}) error

type VirgilHash

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

type VirgilPrivateKeyExporter

type VirgilPrivateKeyExporter struct {
	Crypto   *VirgilCrypto
	Password string
}

func NewPrivateKeyExporter

func NewPrivateKeyExporter(password string) *VirgilPrivateKeyExporter

func (*VirgilPrivateKeyExporter) ExportPrivateKey

func (v *VirgilPrivateKeyExporter) ExportPrivateKey(key interface {
	IsPrivate() bool
	Identifier() []byte
}) ([]byte, error)

func (*VirgilPrivateKeyExporter) ImportPrivateKey

func (v *VirgilPrivateKeyExporter) ImportPrivateKey(data []byte) (interface {
	IsPrivate() bool
	Identifier() []byte
}, error)

type VirgilSigner

type VirgilSigner interface {
	Sign(data []byte, signer *ed25519PrivateKey) ([]byte, error)
	SignHash(hash []byte, signer *ed25519PrivateKey) ([]byte, error)
	SignStream(data io.Reader, signer *ed25519PrivateKey) ([]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 *ed25519PublicKey, signature []byte) error
	VerifyHash(hash []byte, key *ed25519PublicKey, signature []byte) error
	VerifyStream(data io.Reader, key *ed25519PublicKey, signature []byte) 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