crypto

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Deserialize

func Deserialize(serialized []byte) (*CiphertextBlob, *CryptoConfig, error)

func ExtractUnverifiedAAD

func ExtractUnverifiedAAD(ciphertext []byte) ([]byte, error)

func GetMaxSupportedVersion

func GetMaxSupportedVersion() uint8

func HMAC

func HMAC(algo MessageDigestAlgorithm, key *PeacemakrKey, buf []byte) ([]byte, error)

func ParseRsaPrivateKeyFromPemStr added in v0.0.4

func ParseRsaPrivateKeyFromPemStr(privPEM string) (*rsa.PrivateKey, error)

func ParseRsaPublicKeyFromPemStr added in v0.0.4

func ParseRsaPublicKeyFromPemStr(pubPEM string) (*rsa.PublicKey, error)

func PeacemakrInit

func PeacemakrInit() bool

func Serialize

func Serialize(blob *CiphertextBlob) ([]byte, error)

func Sign

func Sign(senderKey *PeacemakrKey, plaintext Plaintext, ciphertext *CiphertextBlob) error

func Verify

func Verify(senderKey *PeacemakrKey, plaintext *Plaintext, ciphertext *CiphertextBlob) error

Types

type AsymmetricCipher

type AsymmetricCipher int
const (
	NONE      AsymmetricCipher = 0
	RSA_2048  AsymmetricCipher = 1
	RSA_4096  AsymmetricCipher = 2
	ECDH_P256 AsymmetricCipher = 3
	ECDH_P384 AsymmetricCipher = 4
	ECDH_P521 AsymmetricCipher = 5
)

func GetECKeyTypeFromPrivPemStr added in v0.0.6

func GetECKeyTypeFromPrivPemStr(pubPEM string) (AsymmetricCipher, error)

func GetECKeyTypeFromPubPemStr added in v0.0.4

func GetECKeyTypeFromPubPemStr(pubPEM string) (AsymmetricCipher, error)

type CiphertextBlob

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

func Encrypt

func Encrypt(key *PeacemakrKey, plaintext Plaintext, rand RandomDevice) (*CiphertextBlob, error)

type CryptoConfig

type CryptoConfig struct {
	Mode             EncryptionMode
	SymmetricCipher  SymmetricCipher
	AsymmetricCipher AsymmetricCipher
	DigestAlgorithm  MessageDigestAlgorithm
}

func GetConfigFromPrivKey added in v0.0.6

func GetConfigFromPrivKey(privKey string) (CryptoConfig, error)

func GetConfigFromPubKey added in v0.0.4

func GetConfigFromPubKey(pubKey string) (CryptoConfig, error)

type DecryptCode

type DecryptCode int
const (
	DECRYPT_SUCCESS     DecryptCode = 0
	DECRYPT_NEED_VERIFY DecryptCode = 1
	DECRYPT_FAILED      DecryptCode = 2
)

type EncryptionMode

type EncryptionMode int
const (
	SYMMETRIC  EncryptionMode = 0
	ASYMMETRIC EncryptionMode = 1
)

type MessageDigestAlgorithm

type MessageDigestAlgorithm int
const (
	SHA_224 MessageDigestAlgorithm = 0
	SHA_256 MessageDigestAlgorithm = 1
	SHA_384 MessageDigestAlgorithm = 2
	SHA_512 MessageDigestAlgorithm = 3
)

type PeacemakrKey

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

func NewPeacemakrKey

func NewPeacemakrKey(config CryptoConfig, rand RandomDevice) *PeacemakrKey

func NewPeacemakrKeyFromBytes

func NewPeacemakrKeyFromBytes(config CryptoConfig, contents []byte) *PeacemakrKey

func NewPrivateKeyFromPEM added in v0.0.6

func NewPrivateKeyFromPEM(contents string, cfg *CryptoConfig) (*PeacemakrKey, error)

func NewPublicKeyFromPEM added in v0.0.6

func NewPublicKeyFromPEM(contents string, cfg *CryptoConfig) (*PeacemakrKey, error)

func NewSymmetricKeyFromPassword added in v0.0.6

func NewSymmetricKeyFromPassword(keylenBits int, passwordStr string, iterationCount int) (*PeacemakrKey, []byte, error)

func SymmetricKeyFromBytes added in v0.0.6

func SymmetricKeyFromBytes(keyBytes []byte) (*PeacemakrKey, error)

func SymmetricKeyFromPasswordAndSalt added in v0.0.6

func SymmetricKeyFromPasswordAndSalt(keylenBits int, passwordStr string, salt []byte, iterationCount int) (*PeacemakrKey, error)

func (*PeacemakrKey) Bytes added in v0.0.6

func (k *PeacemakrKey) Bytes() ([]byte, error)

func (*PeacemakrKey) Config added in v0.0.6

func (k *PeacemakrKey) Config() (CryptoConfig, error)

func (*PeacemakrKey) Destroy added in v0.0.6

func (k *PeacemakrKey) Destroy()

func (*PeacemakrKey) ECDHKeygen added in v0.0.6

func (k *PeacemakrKey) ECDHKeygen(peerKey *PeacemakrKey) *PeacemakrKey

func (*PeacemakrKey) HKDFKeygen added in v0.0.6

func (k *PeacemakrKey) HKDFKeygen(config CryptoConfig, keyID []byte) (*PeacemakrKey, error)

func (*PeacemakrKey) IsValid

func (k *PeacemakrKey) IsValid() bool

type Plaintext

type Plaintext struct {
	Data []byte
	Aad  []byte
}

func Decrypt

func Decrypt(key *PeacemakrKey, ciphertext *CiphertextBlob) (*Plaintext, bool, error)

type RandomDevice

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

func NewRandomDevice

func NewRandomDevice() RandomDevice

type SymmetricCipher

type SymmetricCipher int
const (
	AES_128_GCM       SymmetricCipher = 0
	AES_192_GCM       SymmetricCipher = 1
	AES_256_GCM       SymmetricCipher = 2
	CHACHA20_POLY1305 SymmetricCipher = 3
)

Jump to

Keyboard shortcuts

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