Arduino Cryptography Library
Public Member Functions | Protected Member Functions | Friends | List of all members
XTSCommon Class Reference

Concrete base class to assist with implementing XTS mode for 128-bit block ciphers. More...

#include <XTS.h>

Inheritance diagram for XTSCommon:
XTS< T1, T2 > XTSSingleKeyCommon XTSSingleKey< T >

Public Member Functions

virtual ~XTSCommon ()
 Clears all sensitive information and destroys this object.
 
virtual size_t keySize () const
 Gets the size of the key for XTS mode. More...
 
size_t tweakSize () const
 Gets the maximum supported size for the tweak. More...
 
size_t sectorSize () const
 Gets the size of sectors encrypted or decrypted by this class. More...
 
bool setSectorSize (size_t size)
 Sets the size of sectors encrypted or decrypted by this class. More...
 
virtual bool setKey (const uint8_t *key, size_t len)
 Sets the key to use for XTS mode. More...
 
bool setTweak (const uint8_t *tweak, size_t len)
 Sets the tweak value for the current sector to encrypt or decrypt. More...
 
void encryptSector (uint8_t *output, const uint8_t *input)
 Encrypts an entire sector of data. More...
 
void decryptSector (uint8_t *output, const uint8_t *input)
 Decrypts an entire sector of data. More...
 
void clear ()
 Clears all security-sensitive state from this XTS object.
 

Protected Member Functions

 XTSCommon ()
 Constructs an XTS object with a default sector size of 512 bytes.
 
void setBlockCiphers (BlockCipher *cipher1, BlockCipher *cipher2)
 Sets the two block ciphers to use for XTS mode. More...
 

Friends

class XTSSingleKeyCommon
 

Detailed Description

Concrete base class to assist with implementing XTS mode for 128-bit block ciphers.

References: IEEE Std. 1619-2007, NIST SP 800-38E, a href="http://web.cs.ucdavis.edu/~rogaway/papers/offsets.pdf">XEX.

See also
XTS, XTSSingleKey

Definition at line 30 of file XTS.h.

Member Function Documentation

◆ decryptSector()

void XTSCommon::decryptSector ( uint8_t *  output,
const uint8_t *  input 
)

Decrypts an entire sector of data.

Parameters
outputThe output buffer to write the plaintext to, which can be the same as input.
inputThe input buffer to read the ciphertext from.

The input and output buffers must be at least sectorSize() bytes in length.

See also
encryptSector(), setKey(), setTweak()

Definition at line 215 of file XTS.cpp.

◆ encryptSector()

void XTSCommon::encryptSector ( uint8_t *  output,
const uint8_t *  input 
)

Encrypts an entire sector of data.

Parameters
outputThe output buffer to write the ciphertext to, which can be the same as input.
inputThe input buffer to read the plaintext from.

The input and output buffers must be at least sectorSize() bytes in length.

See also
decryptSector(), setKey(), setTweak()

Definition at line 170 of file XTS.cpp.

◆ keySize()

size_t XTSCommon::keySize ( ) const
virtual

Gets the size of the key for XTS mode.

The key size for XTS mode is twice the size of the underlying block cipher key size.

See also
setKey(), tweakSize()

Reimplemented in XTSSingleKeyCommon.

Definition at line 62 of file XTS.cpp.

◆ sectorSize()

size_t XTSCommon::sectorSize ( ) const
inline

Gets the size of sectors encrypted or decrypted by this class.

The default value is 512 bytes.

See also
setSectorSize()

Definition at line 38 of file XTS.h.

◆ setBlockCiphers()

void XTSCommon::setBlockCiphers ( BlockCipher cipher1,
BlockCipher cipher2 
)
inlineprotected

Sets the two block ciphers to use for XTS mode.

Parameters
cipher1Points to the first block cipher object, which must be capable of both encryption and decryption.
cipher2Points to the second block cipher object, which must be capable of both encryption but does not need to be capable of decryption.

Both block ciphers must have a 128-bit block size.

Definition at line 51 of file XTS.h.

◆ setKey()

bool XTSCommon::setKey ( const uint8_t *  key,
size_t  len 
)
virtual

Sets the key to use for XTS mode.

Parameters
keyPoints to the key.
lenThe size of the key in bytes which must be twice the size of the underlying block cipher's key size.
Returns
Returns true if the key was set or false if len was incorrect.

This function should be followed by a call to setTweak() to specify the sector-specific tweak.

See also
keySize(), setTweak(), encryptSector()

Reimplemented in XTSSingleKeyCommon.

Definition at line 119 of file XTS.cpp.

◆ setSectorSize()

bool XTSCommon::setSectorSize ( size_t  size)

Sets the size of sectors encrypted or decrypted by this class.

Parameters
sizeThe sector size in bytes, which must be greater than or equal to 16.
Returns
Returns false if size is less than 16.
See also
sectorSize(), encryptSector()

Definition at line 97 of file XTS.cpp.

◆ setTweak()

bool XTSCommon::setTweak ( const uint8_t *  tweak,
size_t  len 
)

Sets the tweak value for the current sector to encrypt or decrypt.

Parameters
tweakPoints to the tweak.
lenThe length of the tweak which must be less than or equal to 16.
Returns
Returns true if the tweak was set or false if len was incorrect.

If len is less than 16, then the tweak will be zero-padded to 16 bytes.

The tweak is encrypted with the second half of the XTS key to generate the actual tweak value for the sector.

See also
tweakSize(), setKey(), encryptSector()

Definition at line 142 of file XTS.cpp.

◆ tweakSize()

size_t XTSCommon::tweakSize ( ) const

Gets the maximum supported size for the tweak.

This function returns 16, which indicates that any tweak up to 16 bytes in size can be specified via setTweak().

Definition at line 73 of file XTS.cpp.


The documentation for this class was generated from the following files: