Loading...
Searching...
No Matches
ocb.h File Reference

Offset Codebook (OCB3) AEAD mode as specified in RFC 7253. More...

Detailed Description

Offset Codebook (OCB3) AEAD mode as specified in RFC 7253.

NOTE: The OCB algorithm is covered by patents in the USA owned by Phillip Rogaway. A free licence is granted for any open-source or non-military project. Check http://web.cs.ucdavis.edu/~rogaway/ocb/grant.htm for details.

Author
Mathias Tausig mathi.nosp@m.as@t.nosp@m.ausig.nosp@m..at

Definition in file ocb.h.

#include "crypto/ciphers.h"
#include <stdint.h>
#include <stddef.h>
+ Include dependency graph for ocb.h:

Go to the source code of this file.

Functions

int32_t cipher_encrypt_ocb (const cipher_t *cipher, const uint8_t *auth_data, size_t auth_data_len, uint8_t tag_len, const uint8_t *nonce, size_t nonce_len, const uint8_t *input, size_t input_len, uint8_t *output)
 Encrypt and authenticate data of arbitrary length in OCB mode.
 
int32_t cipher_decrypt_ocb (const cipher_t *cipher, const uint8_t *auth_data, size_t auth_data_len, uint8_t tag_len, const uint8_t *nonce, size_t nonce_len, const uint8_t *input, size_t input_len, uint8_t *output)
 Decrypt and verify the authentication of OCB encrypted data.
 

OCB error codes

#define OCB_ERR_INVALID_NONCE_LENGTH   (-2)
 Returned if a nonce of bad length (empty or more than 15 bytes) was used.
 
#define OCB_ERR_INVALID_BLOCK_LENGTH   (-3)
 OCB only works with ciphers with a block size of 128 bit.
 
#define OCB_ERR_INVALID_DATA_LENGTH   (-3)
 Returned if the amount of input data cannot be handled by this implementation.
 
#define OCB_ERR_INVALID_TAG_LENGTH   (-4)
 Returned if a tag of bad length was requested (empty or more than 16 bytes)
 
#define OCB_ERR_INVALID_TAG   (-5)
 Returned if the authentication failed during decryption.
 

Macro Definition Documentation

◆ OCB_ERR_INVALID_BLOCK_LENGTH

#define OCB_ERR_INVALID_BLOCK_LENGTH   (-3)

OCB only works with ciphers with a block size of 128 bit.

Definition at line 46 of file ocb.h.

◆ OCB_ERR_INVALID_DATA_LENGTH

#define OCB_ERR_INVALID_DATA_LENGTH   (-3)

Returned if the amount of input data cannot be handled by this implementation.

Definition at line 50 of file ocb.h.

◆ OCB_ERR_INVALID_NONCE_LENGTH

#define OCB_ERR_INVALID_NONCE_LENGTH   (-2)

Returned if a nonce of bad length (empty or more than 15 bytes) was used.

Definition at line 42 of file ocb.h.

◆ OCB_ERR_INVALID_TAG

#define OCB_ERR_INVALID_TAG   (-5)

Returned if the authentication failed during decryption.

Definition at line 58 of file ocb.h.

◆ OCB_ERR_INVALID_TAG_LENGTH

#define OCB_ERR_INVALID_TAG_LENGTH   (-4)

Returned if a tag of bad length was requested (empty or more than 16 bytes)

Definition at line 54 of file ocb.h.

Function Documentation

◆ cipher_decrypt_ocb()

int32_t cipher_decrypt_ocb ( const cipher_t cipher,
const uint8_t *  auth_data,
size_t  auth_data_len,
uint8_t  tag_len,
const uint8_t *  nonce,
size_t  nonce_len,
const uint8_t *  input,
size_t  input_len,
uint8_t *  output 
)

Decrypt and verify the authentication of OCB encrypted data.

Parameters
cipherAlready initialized cipher struct
auth_dataAdditional data to authenticate in MAC
auth_data_lenLength of additional data
tag_lenLength of the appended tag (at least 1, at most 16 bytes)
nonceNonce for the encryption (must be unique)
nonce_lenLength of the nonce in bytes (at most 15)
inputpointer to the ciphertext with the tag appended
input_lenlength of the input data. input_len - tag_len must be smaller than INT32_MAX (2^31-1)
outputpointer to allocated memory for the plaintext data. It has to be of size input_len - tag_len. Will contain only zeroes, if the authentication fails.
Returns
Length of the plaintext data or a (negative) error code

◆ cipher_encrypt_ocb()

int32_t cipher_encrypt_ocb ( const cipher_t cipher,
const uint8_t *  auth_data,
size_t  auth_data_len,
uint8_t  tag_len,
const uint8_t *  nonce,
size_t  nonce_len,
const uint8_t *  input,
size_t  input_len,
uint8_t *  output 
)

Encrypt and authenticate data of arbitrary length in OCB mode.

Parameters
cipherAlready initialized cipher struct
auth_dataAdditional data to authenticate in MAC
auth_data_lenLength of additional data
tag_lenLength of the appended tag (at least 1, at most 16 bytes)
nonceNonce for the encryption (must be unique)
nonce_lenLength of the nonce in bytes (at most 15)
inputpointer to input data to encrypt
input_lenlength of the input data. input_len + tag_len must be smaller than INT32_MAX (2^31-1)
outputpointer to allocated memory for encrypted data. The tag will be appended to the ciphertext. It has to be of size data_len + tag_len.
Returns
Length of the encrypted data (including the tag) or a (negative) error code