- Main Page
- Namespaces
- Classes
- Files

# eax.cpp

    00001 // eax.cpp - written and placed in the public domain by Wei Dai
    00002
    00003 #include "pch.h"
    00004 #include "eax.h"
    00005
    00006 NAMESPACE_BEGIN(CryptoPP)
    00007
    00008 void EAX_Base::SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs &params)
    00009 {
    00010         AccessMAC().SetKey(userKey, keylength, params);
    00011         m_buffer.New(2*AccessMAC().TagSize());
    00012 }
    00013
    00014 void EAX_Base::Resync(const byte *iv, size_t len)
    00015 {
    00016         MessageAuthenticationCode &mac = AccessMAC();
    00017         unsigned int blockSize = mac.TagSize();
    00018
    00019         memset(m_buffer, 0, blockSize);
    00020         mac.Update(m_buffer, blockSize);
    00021         mac.CalculateDigest(m_buffer+blockSize, iv, len);
    00022
    00023         m_buffer[blockSize-1] = 1;
    00024         mac.Update(m_buffer, blockSize);
    00025
    00026         m_ctr.SetCipherWithIV(AccessMAC().AccessCipher(), m_buffer+blockSize, blockSize);
    00027 }
    00028
    00029 size_t EAX_Base::AuthenticateBlocks(const byte *data, size_t len)
    00030 {
    00031         AccessMAC().Update(data, len);
    00032         return 0;
    00033 }
    00034
    00035 void EAX_Base::AuthenticateLastHeaderBlock()
    00036 {
    00037         assert(m_bufferedDataLength == 0);
    00038         MessageAuthenticationCode &mac = AccessMAC();
    00039         unsigned int blockSize = mac.TagSize();
    00040
    00041         mac.Final(m_buffer);
    00042         xorbuf(m_buffer+blockSize, m_buffer, blockSize);
    00043
    00044         memset(m_buffer, 0, blockSize);
    00045         m_buffer[blockSize-1] = 2;
    00046         mac.Update(m_buffer, blockSize);
    00047 }
    00048
    00049 void EAX_Base::AuthenticateLastFooterBlock(byte *tag, size_t macSize)
    00050 {
    00051         assert(m_bufferedDataLength == 0);
    00052         MessageAuthenticationCode &mac = AccessMAC();
    00053         unsigned int blockSize = mac.TagSize();
    00054
    00055         mac.TruncatedFinal(m_buffer, macSize);
    00056         xorbuf(tag, m_buffer, m_buffer+blockSize, macSize);
    00057 }
    00058
    00059 NAMESPACE_END