gcm

package
v0.0.0-...-811459a Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2017 License: ISC Imports: 5 Imported by: 0

Documentation

Overview

Package gcm supports gcm encryption - gcm is authenticated by default

Index

Constants

View Source
const KeySize = generate.KeySize

KeySize // generic KeySize

NonceSize // generic NonceSize from RFC5084

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(key, ciphertext []byte, nonceSize int) ([]byte, error)

Decrypt decrypts data using AES-GCM

func DecryptString

func DecryptString(key, ciphertext string, nonceSize int) (string, error)

DecryptString is a convenience function for working with strings

func DecryptStringWithID

func DecryptStringWithID(message string, k KeyRetriever, nonceSize int) (string, error)

DecryptStringWithID is a helper function to work with strings instead of bytes

func DecryptWithID

func DecryptWithID(message []byte, k KeyRetriever, nonceSize int) ([]byte, error)

DecryptWithID takes an encrypted message and a KeyForID function (to get a key from a cache or a database perhaps) It checks the first 4 bytes for prepended header data, in this case, a sender ID

func Encrypt

func Encrypt(key, plaintext []byte, nonceSize int) ([]byte, error)

Encrypt secures a message using AES-GCM.

func EncryptString

func EncryptString(key, plaintext string, nonceSize int) (string, error)

EncryptString is a convenience function for working with strings

func EncryptStringWithID

func EncryptStringWithID(key, message string, sender uint32, nonceSize int) (string, error)

EncryptStringWithID is a helper function to work with strings instead of bytes

func EncryptWithID

func EncryptWithID(key, message []byte, sender uint32, nonceSize int) ([]byte, error)

EncryptWithID secures a message and prepends a 4-byte sender ID to the message. The end bit is tricky, because gcm.Seal modifies buf, and this is necessary

Types

type Cipher

type Cipher struct {
	NonceSize int
}

Cipher to implement the BlockCipher interface

func New

func New() *Cipher

New returns a new GCM cipher

func (*Cipher) Decrypt

func (c *Cipher) Decrypt(key, ciphertext []byte) ([]byte, error)

Decrypt implements the BlockCipher interface

func (*Cipher) DecryptWithID

func (c *Cipher) DecryptWithID(message []byte, k KeyRetriever) ([]byte, error)

DecryptWithID calls the package DecryptWithID and passes c.NonceSize

func (*Cipher) Encrypt

func (c *Cipher) Encrypt(key, plaintext []byte) ([]byte, error)

Encrypt implements the BlockCipher interface

func (*Cipher) EncryptWithID

func (c *Cipher) EncryptWithID(key, plaintext []byte, sender uint32) ([]byte, error)

EncryptWithID calls the package EncryptWithID and passes c.NonceSize

func (*Cipher) KeySize

func (c *Cipher) KeySize() int

KeySize returns the GCM key size

type GCMHelper

type GCMHelper struct {
	KeyForIDFunc func(uint32) ([]byte, error)
}

GCMHelper is designed to make it easy to call EncryptWithID and DecryptWithID by assigning the KeyForIDFunc it implements KeyRetriever and provides convenience functions It also serves as an example for how to use KeyRetriever

func NewGCMHelper

func NewGCMHelper(f func(uint32) ([]byte, error)) *GCMHelper

NewGCMHelper returns a new helper

func (*GCMHelper) KeyForID

func (h *GCMHelper) KeyForID(u uint32) ([]byte, error)

KeyForID implements the KeyRetriever interface, it should be used to get a Key for the given ID

type KeyRetriever

type KeyRetriever interface {
	KeyForID(uint32) ([]byte, error)
}

KeyRetriever represents a type that should be used in order to retrieve a key from a datastore

Jump to

Keyboard shortcuts

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