crypto

package
v0.0.0-...-804f56e Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2018 License: Zlib Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Curve            = elliptic.P521()
	ErrUnexpectedMAC = errors.New("Computed and expected MAC tags do not match.")
)
View Source
var (
	// ErrInvalidBlockSize indicates hash blocksize <= 0.
	ErrInvalidBlockSize = errors.New("invalid blocksize")

	// ErrInvalidPKCS7Data indicates bad input to PKCS7 pad or unpad.
	ErrInvalidPKCS7Data = errors.New("invalid PKCS7 data (empty or not padded)")

	// ErrInvalidPKCS7Padding indicates PKCS7 unpad fails to bad input.
	ErrInvalidPKCS7Padding = errors.New("invalid padding on input")
)

PKCS7 errors.

Functions

func CheckMAC

func CheckMAC(message, messageMAC, key []byte) bool

CheckMAC verifies computes a MAC for message and compares it against messageMAC

func DeriveKey

func DeriveKey(mother []byte, keysize int) []byte

DeriveKey creates a key of size keysize from binary data.

func ECDH

func ECDH(priv []byte, x, y *big.Int) []byte

ECDH Performs combines public and private ECDH parameters and derives an AES key from the shared secret.

func PKCS7Pad

func PKCS7Pad(b []byte, blocksize int) ([]byte, error)

pkcs7Pad right-pads the given byte slice with 1 to n bytes, where n is the block size. The size of the result is x times n, where x is at least 1.

func PKCS7Unpad

func PKCS7Unpad(b []byte, blocksize int) ([]byte, error)

pkcs7Unpad validates and unpads data from the given bytes slice. The returned value will be 1 to n bytes smaller depending on the amount of padding, where n is the block size.

Types

type EncryptedMessage

type EncryptedMessage struct {
	Sid int    // The index of this sender's key to use in this diffie-hellman
	Rid int    // The index of the receiver's key to use in this diffie-hellman
	Nxt []byte // Elliptic-Curve public data for the next message (encrypted)
	IV  []byte // AES IV used to encrypt the message and HMAC key
	Msg []byte // AES encrypted message data
	Key []byte // AES encrypted HMAC key
	Tag []byte // HMAC integrity tag
}

func EncryptMessage

func EncryptMessage(clearText, aesKey, nxt []byte, sid, rid int) (msg *EncryptedMessage, err error)

Encrypt encrypts clearText aesKey, and advertises the next key nxt in the resulting message structure. sid and rid indicate to the receiver which keys should be used to decrypt the message.

func (*EncryptedMessage) Decrypt

func (message *EncryptedMessage) Decrypt(aesKey []byte) (clearText, nextKey []byte, err error)

Decrypt decrypts a message that was encrypted with EncryptMessage. It returns the original encrypted message, along with public key that was advertised in the message.

Jump to

Keyboard shortcuts

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