diff options
author | Malfurious <m@lfurio.us> | 2024-10-24 06:44:24 -0400 |
---|---|---|
committer | Malfurious <m@lfurio.us> | 2024-10-24 06:44:24 -0400 |
commit | 512aa4c77b3dc0d72db713a9215ff65a98a99ec3 (patch) | |
tree | 6db82e0109dc987b5b021f81d4e8a0926eb75ff7 /cryptopp562/dmac.h | |
parent | 428471d39fb8c205a9fad899c88c30a2cb7df685 (diff) | |
parent | 10affea371406c0ae4c080e5a19390a8e9bd154b (diff) | |
download | compass-512aa4c77b3dc0d72db713a9215ff65a98a99ec3.tar.gz compass-512aa4c77b3dc0d72db713a9215ff65a98a99ec3.zip |
Merge branch 'mbedtls'
Replace Crypto++ 5.6.2 with Mbed TLS 3.6.0
Newer compilers are starting to show the age of the crypto library we've
been using, as it is sometimes a pain to recompile compass lately. So,
the tracked version of Crypto++ was at least due for an upgrade.
However, I plan to soon begin reimplementing compass in C. So, I'm
taking this opportunity to first just migrate the cryptography library
to a newer C alternative. This branch does so, and integrates its use
into the current C++ version of compass.
* mbedtls:
Remove unnecessary exception handler catch block
Refactor random password generation to use mbedtls entropy source
Refactor SHA256 function to use mbedtls
Refactor AES functions to use mbedtls
Add Mbedtls library
Remove Crypto++ library
Diffstat (limited to 'cryptopp562/dmac.h')
-rw-r--r-- | cryptopp562/dmac.h | 93 |
1 files changed, 0 insertions, 93 deletions
diff --git a/cryptopp562/dmac.h b/cryptopp562/dmac.h deleted file mode 100644 index 80b54ac..0000000 --- a/cryptopp562/dmac.h +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef CRYPTOPP_DMAC_H -#define CRYPTOPP_DMAC_H - -#include "cbcmac.h" - -NAMESPACE_BEGIN(CryptoPP) - -//! _ -template <class T> -class CRYPTOPP_NO_VTABLE DMAC_Base : public SameKeyLengthAs<T>, public MessageAuthenticationCode -{ -public: - static std::string StaticAlgorithmName() {return std::string("DMAC(") + T::StaticAlgorithmName() + ")";} - - CRYPTOPP_CONSTANT(DIGESTSIZE=T::BLOCKSIZE) - - DMAC_Base() {} - - void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms); - void Update(const byte *input, size_t length); - void TruncatedFinal(byte *mac, size_t size); - unsigned int DigestSize() const {return DIGESTSIZE;} - -private: - byte *GenerateSubKeys(const byte *key, size_t keylength); - - size_t m_subkeylength; - SecByteBlock m_subkeys; - CBC_MAC<T> m_mac1; - typename T::Encryption m_f2; - unsigned int m_counter; -}; - -//! DMAC -/*! Based on "CBC MAC for Real-Time Data Sources" by Erez Petrank - and Charles Rackoff. T should be a class derived from BlockCipherDocumentation. -*/ -template <class T> -class DMAC : public MessageAuthenticationCodeFinal<DMAC_Base<T> > -{ -public: - DMAC() {} - DMAC(const byte *key, size_t length=DMAC_Base<T>::DEFAULT_KEYLENGTH) - {this->SetKey(key, length);} -}; - -template <class T> -void DMAC_Base<T>::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms) -{ - m_subkeylength = T::StaticGetValidKeyLength(T::BLOCKSIZE); - m_subkeys.resize(2*UnsignedMin((unsigned int)T::BLOCKSIZE, m_subkeylength)); - m_mac1.SetKey(GenerateSubKeys(key, length), m_subkeylength, params); - m_f2.SetKey(m_subkeys+m_subkeys.size()/2, m_subkeylength, params); - m_counter = 0; - m_subkeys.resize(0); -} - -template <class T> -void DMAC_Base<T>::Update(const byte *input, size_t length) -{ - m_mac1.Update(input, length); - m_counter = (unsigned int)((m_counter + length) % T::BLOCKSIZE); -} - -template <class T> -void DMAC_Base<T>::TruncatedFinal(byte *mac, size_t size) -{ - ThrowIfInvalidTruncatedSize(size); - - byte pad[T::BLOCKSIZE]; - byte padByte = byte(T::BLOCKSIZE-m_counter); - memset(pad, padByte, padByte); - m_mac1.Update(pad, padByte); - m_mac1.TruncatedFinal(mac, size); - m_f2.ProcessBlock(mac); - - m_counter = 0; // reset for next message -} - -template <class T> -byte *DMAC_Base<T>::GenerateSubKeys(const byte *key, size_t keylength) -{ - typename T::Encryption cipher(key, keylength); - memset(m_subkeys, 0, m_subkeys.size()); - cipher.ProcessBlock(m_subkeys); - m_subkeys[m_subkeys.size()/2 + T::BLOCKSIZE - 1] = 1; - cipher.ProcessBlock(m_subkeys+m_subkeys.size()/2); - return m_subkeys; -} - -NAMESPACE_END - -#endif |