primitives

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AESGCMIVSize is the acceptable IV size defined by RFC 5116.
	AESGCMIVSize = 12
	// AESGCMTagSize is the acceptable tag size defined by RFC 5116.
	AESGCMTagSize = 16
)

Variables

This section is empty.

Functions

func GetHashFunc

func GetHashFunc(hash string) func() hash.Hash

GetHashFunc returns the corresponding hash function of the given hash name.

func NewAESGCMAEAD

func NewAESGCMAEAD(key types.Key, randomService services.CPRNGService) (types.AEAD, error)

NewAESGCMAEAD NewAESGCM returns an AESGCMAEAD instance, where key is the AES key with length 16 bytes (AES-128) or 32 bytes (AES-256).

func NewRSASSAPKCS1SHA

func NewRSASSAPKCS1SHA(hashFunc func() hash.Hash, hashID crypto.Hash, randomService services.CPRNGService) (types.Unwrapping, error)

NewRSASSAPKCS1SHA returns an RSASSAPKCS1SHA instance

func NewXChaCha20Poly1305AEAD

func NewXChaCha20Poly1305AEAD(key types.Key, randomService services.CPRNGService) (types.AEAD, error)

NewXChaCha20Poly1305AEAD returns an XChaCha20Poly1305AEAD instance. The key argument should be a 32-bytes key.

func ValidateAESKeySize

func ValidateAESKeySize(sizeInBytes uint32) error

ValidateAESKeySize checks if the given key size is a valid AES key size.

Types

type AESGCMAEAD

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

AESGCMAEAD is an implementation of AEAD interface.

func (*AESGCMAEAD) Decrypt

func (a *AESGCMAEAD) Decrypt(ciphertext, associatedData []byte) ([]byte, error)

Decrypt decrypts ciphertext with iv as the initialization vector and associatedData as associated data.

If prependIV is true, the iv argument and the first AESGCMIVSize bytes of ciphertext must be equal. The ciphertext argument is as follows:

| iv | actual ciphertext | tag |

If false, the ciphertext argument is as follows:

| actual ciphertext | tag |

func (*AESGCMAEAD) Encrypt

func (a *AESGCMAEAD) Encrypt(plaintext, associatedData []byte) ([]byte, error)

Encrypt encrypts plaintext with iv as the initialization vector and associatedData as associated data.

If prependIV is true, the returned ciphertext contains both the IV used for encryption and the actual ciphertext. If false, the returned ciphertext contains only the actual ciphertext.

Note: The crypto library's AES-GCM implementation always returns the ciphertext with an AESGCMTagSize (16-byte) tag.

type RSASSAPKCS1SHA

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

RSASSAPKCS1SHA is an implementation of AEAD interface.

func (*RSASSAPKCS1SHA) UnwrapKey

func (a *RSASSAPKCS1SHA) UnwrapKey(wdk []byte, epk []byte, fp []byte, password []byte) (dk []byte, err error)

Unwrap the wrapped private key.

type XChaCha20Poly1305AEAD

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

XChaCha20Poly1305AEAD is an implementation of AEAD interface.

func (*XChaCha20Poly1305AEAD) Decrypt

func (a *XChaCha20Poly1305AEAD) Decrypt(ciphertext, associatedData []byte) ([]byte, error)

Decrypt decrypts ciphertext with associatedData.

func (*XChaCha20Poly1305AEAD) Encrypt

func (a *XChaCha20Poly1305AEAD) Encrypt(plaintext, associatedData []byte) ([]byte, error)

Encrypt encrypts plaintext with associatedData. The resulting ciphertext consists of two parts: (1) the nonce used for encryption and (2) the actual ciphertext.

Jump to

Keyboard shortcuts

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