next up previous contents index
Next: Automatic Decoder supporting Cryptography Up: Symmetric Key Cryptography Previous: Example for a Stream-Cipher   Contents   Index


Authentication ( OMACCoder )

Definition

The class OMACCoder can be used for authentication. It implements the One-Key CBC MAC algorithm by Iwata and Kurosawa [49]. A MAC (= message authentication code) is a kind of checksum that is generated for a message m. In contrast to a usual checksum a MAC does not only depend on m but also on a secret key k. A MAC can be used if a sender wants to transfer m through an insecure channel to a receiver. If the sender also transmits the MAC then the receiver can verify that m has not been altered and that it originates from someone who knows k.
Important: OMACCoder does not encipher or decipher any data, it only computes and verifies MACs!

The behaviour of this coder depends on the MAC_in_stream flag. If it is false then encoding and decoding are equivalent: Both methods copy the source stream to the target stream and compute a MAC. If the flag is true then in encoding mode the source stream is copied to the target stream, a MAC is computed and appended to the target stream. In decoding mode the MAC at the end of source stream is removed and the original data is copied to the target stream, a MAC is computed and compared with the MAC found in the source stream. If the two MACs differ an error is signaled. The method MAC_is_valid may be used to check whether the source stream is authentic.

The class OMACCoder< BlkCipher > is parameterized with a block-cipher BlkCipher, which can be one of the following: Rijndael (default), Blowfish, Twofish (see Section block-ciphers for more information). OMACCoder also supports fast seek operations (see Section decoding_ifstream).

#include < LEDA/coding/authentication.h >

Creation

OMACCoder< BlkCipher > C(streambuf* src_stream = 0, streambuf* tgt_stream = 0, bool own_streams = false)
    creates an instance C which uses the given source and target streams. If own_streams is set, then C is responsible for the destruction of the streams, otherwise the pointers src_stream and tgt_stream must be valid during the life-time of C.

OMACCoder< BlkCipher > C(const char* src_file_name, const char* tgt_file_name)
    creates an instance C which uses file-streams for input and output.

Operations

Standard Operations

void C.encode() encodes the source stream and writes the output to the target stream.

void C.decode() decodes the source stream and writes the output to the target stream.

uint32 C.calculate_length_of_encoded_data(uint32 input_length)
    calculates the length (in bytes) of the output when encoding some input of the given length with the current settings. (This function is helpful for encoding memory chunks (see below).)

uint32 C.encode_memory_chunk(const char* in_buf, uint32 in_len, char* out_buf, uint32 out_len)
    encodes the memory chunk starting at in_buf with size in_len into the buffer starting at out_buf with size out_len. The function returns actual length of the encoded chunk which may be smaller than out_len. If the output buffer is too small for the encoded data the failure flag will be set (see below). Note: The output data is slightly longer than the input data due to padding and header data.

uint32 C.decode_memory_chunk(const char* in_buf, uint32 in_len, char* out_buf, uint32 out_len)
    decodes a memory chunk. The meaning of the parameters and the return value is the same as in the previous function.

streambuf* C.get_src_stream() returns the current source stream.

void C.set_src_stream(streambuf* src_stream, bool own_stream = false)
    sets the source stream (cf. constructor).

void C.set_src_file(const char* file_name)
    sets a file as source stream.

streambuf* C.get_tgt_stream() returns the current target stream.

void C.set_tgt_stream(streambuf* tgt_stream, bool own_Stream = false)
    sets the target stream (cf. constructor).

void C.set_tgt_file(const char* file_name)
    sets a file as target stream.

void C.reset(bool keep_parameters = true)
    puts C in the same state as the default constructor. If keep_parameters is false the parameters are set to their default values and the key is set to the empty key.

bool C.failed() returns true if an error occured.

bool C.finished() returns true if the coding is finished.

string C.get_description() provides a description for C.

Additional Operations

uint16 C.get_default_key_size() returns the default key size.

uint16 C.get_accepted_key_size(uint16& min, uint16& max)
    provides the minimum and maximum key size (in bytes). The return value is the default key size.

void C.set_key(const CryptKey& key)
    sets the key.

bool C.has_key() queries whether a key has been set.

CryptKey C.get_key() returns the current key.

const byte* C.check() checks the source stream and returns the computed MAC. No target stream needs to be set. (If a target stream is set check coincides with decode).

bool C.MAC_is_valid() returns whether C has a valid MAC.

string C.get_MAC_as_hex_string() returns the MAC for the stream that has been processed last as hexadecimal string.

const byte* C.compute_MAC(string str) computes a MAC for a string. (Sets source and target stream to nil.)

void C.set_MAC_in_stream_flag(bool mac_in_stream)
    sets the MAC_in_stream flag.

bool C.get_MAC_in_stream_flag()
    returns the MAC_in_stream flag.


next up previous contents index
Next: Automatic Decoder supporting Cryptography Up: Symmetric Key Cryptography Previous: Example for a Stream-Cipher   Contents   Index