gcm

package
v1.0.2035 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GCMBlockSize         = 16
	GCMTagSize           = 16
	GCMMinimumTagSize    = 12 // NIST SP 800-38D recommends tags with 12 or more bytes.
	GCMStandardNonceSize = 12
)

Variables

This section is empty.

Functions

func CeilDiv

func CeilDiv(a, b int) int

func GCMCounterCrypt

func GCMCounterCrypt(out, in []byte, c Block, counter *[GCMBlockSize]byte)

counterCrypt crypts in to out using g.cipher in counter mode.

func IncCtr

func IncCtr(b []byte)

func NewCipher

func NewCipher(newCipher func([]byte) (cipher.Block, error)) func([]byte) (cipher.Block, error)

Types

type Block

type Block interface {
	cipher.Block

	Encrypt4(dst, src []byte)
	Decrypt4(dst, src []byte)

	Encrypt8(dst, src []byte)
	Decrypt8(dst, src []byte)
}

func WrapCipher

func WrapCipher(b cipher.Block) Block

type CTR

type CTR struct {
	Out []byte
	// contains filtered or unexported fields
}

func (*CTR) CopyCTR

func (x *CTR) CopyCTR(b []byte)

func (*CTR) Init

func (x *CTR) Init(b Block, iv []byte, ctrSize int)

func (*CTR) Refill

func (x *CTR) Refill(blocks int)

func (*CTR) Xor

func (x *CTR) Xor(out, in []byte)

type GCM

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

GCM represents a Galois Counter Mode with a specific key. See https://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/GCM/GCM-revised-spec.pdf

func (*GCM) Auth

func (g *GCM) Auth(out, ciphertext, additionalData []byte, tagMask *[GCMTagSize]byte)

func (*GCM) DeriveCounter

func (g *GCM) DeriveCounter(counter *[GCMBlockSize]byte, nonce []byte)

func (*GCM) Finish

func (g *GCM) Finish(out []byte, y *GCMFieldElement, ciphertextLen, additionalDataLen int, tagMask *[GCMTagSize]byte)

func (*GCM) Init

func (g *GCM) Init(cipher Block)

func (*GCM) Update

func (g *GCM) Update(y *GCMFieldElement, blocks []byte)

type GCMAble

type GCMAble interface {
	NewGCM(nonceSize, tagSize int) (cipher.AEAD, error)
}

gcmAble is an interface implemented by ciphers that have a specific optimized implementation of GCM, like crypto/aes. NewGCM will check for this interface and return the specific AEAD if found.

type GCMFieldElement

type GCMFieldElement struct {
	Low, High uint64
}

GCMFieldElement represents a value in GF(2¹²⁸). In order to reflect the GCM standard and make binary.BigEndian suitable for marshaling these values, the bits are stored in big endian order. For example:

the coefficient of x⁰ can be obtained by v.low >> 63.
the coefficient of x⁶³ can be obtained by v.low & 1.
the coefficient of x⁶⁴ can be obtained by v.high >> 63.
the coefficient of x¹²⁷ can be obtained by v.high & 1.

Jump to

Keyboard shortcuts

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