Arduino Cryptography Library
|
Abstract base class for Extendable-Output Functions (XOFs). More...
#include <XOF.h>
Public Member Functions | |
XOF () | |
Constructs a new XOF object. | |
virtual | ~XOF () |
Destroys this XOF object. More... | |
virtual size_t | blockSize () const =0 |
Size of the internal block used by the XOF algorithm, in bytes. More... | |
virtual void | reset ()=0 |
Resets the XOF ready for a new session. More... | |
virtual void | update (const void *data, size_t len)=0 |
Updates the XOF with more data. More... | |
virtual void | extend (uint8_t *data, size_t len)=0 |
Generates extendable output from this XOF. More... | |
virtual void | encrypt (uint8_t *output, const uint8_t *input, size_t len)=0 |
Encrypts an input buffer with extendable output from this XOF. More... | |
void | decrypt (uint8_t *output, const uint8_t *input, size_t len) |
Decrypts an input buffer with extendable output from this XOF. More... | |
virtual void | clear ()=0 |
Clears the hash state, removing all sensitive data, and then resets the XOF ready for a new session. More... | |
Abstract base class for Extendable-Output Functions (XOFs).
Extendable-Output Functions, or XOFs, are a new class of cryptographic primitive that was defined by NIST during the SHA-3 standardization process. Essentially an XOF is a hash algorithm that has an arbitrary-length output instead of a fixed-length digest.
XOFs can be used for a variety of cryptographic tasks:
To use an XOF, it is first reset() and then data is added via multiple calls to update():
Once all input data has been added, the XOF switches into extend mode to generate the arbitrary-length output data:
Mask generation and key derivation is achieved as follows, where the key is unique for each invocation:
Stream ciphers can be constructed as follows, using the special encrypt() function that XOR's the output of extend() with the input plaintext to generate the output ciphertext (or alternatively XOR's the output of extend() with the ciphertext to recover the plaintext):
If the key is reused, then the IV must be different for each session or the encryption scheme can be easily broken. It is better to generate a new key and IV combination for every session.
It may also be a good idea to include some tag information with the input data to distinguish different uses of the XOF. For example:
If the same key and IV was used with a different package, then it would not generate the same output as "MyCrypt".
NIST warns that XOFs should not be used in place of hash functions. This is because of related outputs: if the same input is provided to an XOF with different output lengths, then the shorter output will be a prefix of the larger. This breaks the expected collision-resistance of regular hash functions. There is typically no need to use an XOF for hashing because NIST has already defined SHA3_256 and SHA3_512 for that purpose.
Reference: http://en.wikipedia.org/wiki/SHA-3
|
virtual |
|
pure virtual |
|
pure virtual |
|
inline |
Decrypts an input buffer with extendable output from this XOF.
output | The output buffer to write to, which may be the same buffer as input. The output buffer must have at least as many bytes as the input buffer. |
input | The input buffer to read from. |
len | The number of bytes to encrypt. |
This is a convenience function that merely calls encrypt().
|
pure virtual |
Encrypts an input buffer with extendable output from this XOF.
output | The output buffer to write to, which may be the same buffer as input. The output buffer must have at least as many bytes as the input buffer. |
input | The input buffer to read from. |
len | The number of bytes to encrypt. |
This function is a convenience that generates data with extend() and then XOR's it with the contents of input to generate the output. This function can also be used to decrypt.
The encrypt() function can be called multiple times with different regions of the plaintext data.
Implemented in SHAKE.
|
pure virtual |
|
pure virtual |
|
pure virtual |