_crypto

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package xts implements the XTS cipher mode as specified in IEEE P1619/D16.

XTS mode is typically used for disk encryption, which presents a number of novel problems that make more common modes inapplicable. The disk is conceptually an array of sectors and we must be able to encrypt and decrypt a sector in isolation. However, an attacker must not be able to transpose two sectors of plaintext by transposing their ciphertext.

XTS wraps a block cipher with Rogaway's XEX mode in order to build a tweakable block cipher. This allows each sector to have a unique tweak and effectively create a unique key for each sector.

XTS does not provide any authentication. An attacker can manipulate the ciphertext and randomise a block (16 bytes) of the plaintext. This package does not implement ciphertext-stealing so sectors must be a multiple of 16 bytes.

Note that XTS is usually not appropriate for any use besides disk encryption. Most users should use an AEAD mode like GCM (from crypto/cipher.NewGCM) instead.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyOverlap

func AnyOverlap(x, y []byte) bool

func DecryptAes128Ecb

func DecryptAes128Ecb(data, key []byte) []byte

func InexactOverlap

func InexactOverlap(x, y []byte) bool

InexactOverlap reports whether x and y share memory at any non-corresponding index. The memory beyond the slice length is ignored. Note that x and y can have different lengths and still not have any inexact overlap.

InexactOverlap can be used to implement the requirements of the crypto/cipher AEAD, Block, BlockMode and Stream interfaces.

Types

type Cipher

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

Cipher contains an expanded key structure. It is safe for concurrent use if the underlying block cipher is safe for concurrent use.

func NewCipher

func NewCipher(cipherFunc func([]byte) (cipher.Block, error), key []byte) (c *Cipher, err error)

NewCipher creates a Cipher given a function for creating the underlying block cipher (which must have a block size of 16 bytes). The key must be twice the length of the underlying cipher's key.

func (*Cipher) Decrypt

func (c *Cipher) Decrypt(plaintext, ciphertext []byte, tweak *[16]byte)

Decrypt decrypts a sector of ciphertext and puts the result into plaintext. Plaintext and ciphertext must overlap entirely or not at all. Sectors must be a multiple of 16 bytes and less than 2²⁴ bytes.

func (*Cipher) Encrypt

func (c *Cipher) Encrypt(ciphertext, plaintext []byte, sectorNum uint64)

Encrypt encrypts a sector of plaintext and puts the result into ciphertext. Plaintext and ciphertext must overlap entirely or not at all. Sectors must be a multiple of 16 bytes and less than 2²⁴ bytes.

Jump to

Keyboard shortcuts

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