6 #if CRYPTOPP_MSC_VERSION 7 # pragma warning(disable: 4127 4189) 28 static
void Mash(const
byte *in,
size_t inLen,
byte *out,
size_t outLen,
int iterations)
40 for(i=0; i<outLen; i+=H::DIGESTSIZE)
42 b[0] = (
byte) (i >> 8);
45 hash.Update(in, inLen);
49 while (iterations-- > 1)
51 memcpy(buf, outBuf, bufSize);
52 for (i=0; i<bufSize; i+=H::DIGESTSIZE)
54 b[0] = (
byte) (i >> 8);
57 hash.Update(buf, bufSize);
62 memcpy(out, outBuf, outLen);
65 template <
class BC,
class H,
class Info>
66 static void GenerateKeyIV(
const byte *passphrase,
size_t passphraseLength,
const byte *salt,
size_t saltLength,
unsigned int iterations,
byte *key,
byte *IV)
69 memcpy(temp, passphrase, passphraseLength);
70 memcpy(temp+passphraseLength, salt, saltLength);
72 Mash<H>(temp, passphraseLength + saltLength, keyIV, Info::KEYLENGTH+Info::BLOCKSIZE, iterations);
73 memcpy(key, keyIV, Info::KEYLENGTH);
74 memcpy(IV, keyIV+Info::KEYLENGTH, Info::BLOCKSIZE);
79 template <
class BC,
class H,
class Info>
81 :
ProxyFilter(NULL, 0, 0, attachment), m_passphrase((const
byte *)passphrase, strlen(passphrase))
87 template <
class BC,
class H,
class Info>
95 template <
class BC,
class H,
class Info>
104 hash.Update((
byte *)&t,
sizeof(t));
106 hash.Update((
byte *)&c,
sizeof(c));
111 hash.Update(salt, SALTLENGTH);
112 hash.Final(keyCheck);
119 GenerateKeyIV<BC,H,Info>(
m_passphrase, m_passphrase.
size(), salt, SALTLENGTH, ITERATIONS, key, IV);
121 m_cipher.SetKeyWithIV(key, key.size(), IV);
127 template <
class BC,
class H,
class Info>
136 template <
class BC,
class H,
class Info>
138 :
ProxyFilter(NULL, SALTLENGTH+BLOCKSIZE, 0, attachment)
139 , m_state(WAITING_FOR_KEYCHECK)
141 , m_throwException(throwException)
147 template <
class BC,
class H,
class Info>
149 :
ProxyFilter(NULL, SALTLENGTH+BLOCKSIZE, 0, attachment)
158 template <
class BC,
class H,
class Info>
161 CheckKey(inString, inString+SALTLENGTH);
164 template <
class BC,
class H,
class Info>
181 template <
class BC,
class H,
class Info>
188 hash.Update(salt, SALTLENGTH);
193 GenerateKeyIV<BC,H,Info>(
m_passphrase, m_passphrase.
size(), salt, SALTLENGTH, ITERATIONS, key, IV);
195 m_cipher.SetKeyWithIV(key, key.size(), IV);
198 decryptor->
Put(keyCheck, BLOCKSIZE);
200 decryptor->
Get(check+BLOCKSIZE, BLOCKSIZE);
216 template <
class H,
class MAC>
217 static MAC* NewDataEncryptorMAC(
const byte *passphrase,
size_t passphraseLength)
219 size_t macKeyLength = MAC::StaticGetValidKeyLength(16);
222 Mash<H>(passphrase, passphraseLength, macKey, macKeyLength, 1);
223 return new MAC(macKey, macKeyLength);
226 template <
class BC,
class H,
class MAC,
class Info>
229 , m_mac(NewDataEncryptorMAC<
H,MAC>((const
byte *)passphrase, strlen(passphrase)))
234 template <
class BC,
class H,
class MAC,
class Info>
237 ,
m_mac(NewDataEncryptorMAC<
H,MAC>(passphrase, passphraseLength))
242 template <
class BC,
class H,
class MAC,
class Info>
251 template <
class BC,
class H,
class MAC,
class Info>
254 ,
m_mac(NewDataEncryptorMAC<
H,MAC>((const
byte *)passphrase, strlen(passphrase)))
255 , m_throwException(throwException)
260 template <
class BC,
class H,
class MAC,
class Info>
263 ,
m_mac(NewDataEncryptorMAC<
H,MAC>(passphrase, passphraseLength))
269 template <
class BC,
class H,
class MAC,
class Info>
275 template <
class BC,
class H,
class MAC,
class Info>
281 template <
class BC,
class H,
class MAC,
class Info>
An invalid argument was detected.
Exception thrown when a bad key is encountered in DefaultDecryptorWithMAC and LegacyDecryptorWithMAC...
Base class for Filter classes that are proxies for a chain of other filters.
member_ptr< BufferedTransformation > m_filter
void LastPut(const byte *inString, size_t length)
Input the last block of data.
HashVerificationFilter * m_hashVerifier
CBC_Mode< BC >::Decryption m_cipher
bool GetLastResult() const
unsigned int BytePrecision(const T &value)
Returns the number of 8-bit bytes or octets required for a value.
#define NAMESPACE_BEGIN(x)
DataDecryptor< BC, H, Info >::State CurrentState() const
Password-based Encryptor.
Abstract base classes that provide a uniform interface to this library.
size_type size() const
Provides the count of elements in the SecBlock.
Password-based Decryptor.
Classes for automatic resource management.
Classes for DefaultEncryptor, DefaultDecryptor, DefaultEncryptorWithMAC and DefaultDecryptorWithMAC.
Library configuration file.
Pointer that overloads operator ->
DataEncryptor(const char *passphrase, BufferedTransformation *attachment=NULL)
Construct a DataEncryptor.
void LastPut(const byte *inString, size_t length)
Input the last block of data.
void FirstPut(const byte *inString)
Classes for an unlimited queue to store bytes.
#define CRYPTOPP_COMPILE_ASSERT(assertion)
Filter wrapper for HashTransformation.
Filter wrapper for HashTransformation.
Password-based encryptor with MAC.
bool CheckLastMAC() const
DataEncryptorWithMAC(const char *passphrase, BufferedTransformation *attachment=NULL)
Constructs a DataEncryptorWithMAC.
BufferedTransformation * AttachedTransformation()
Retrieve attached transformation.
Indicates the message should be passed to an attached transformation.
SecByteBlock m_passphrase
Algorithm information for password-based encryptors and decryptors.
void LastPut(const byte *inString, size_t length)
Input the last block of data.
CBC_Mode< BC >::Encryption m_cipher
Implementation of BufferedTransformation's attachment interface.
void * memcpy(void *a, const void *b, size_t c)
#define CRYPTOPP_UNUSED(x)
SecByteBlock m_passphrase
DataDecryptor(const char *passphrase, BufferedTransformation *attachment=NULL, bool throwException=true)
Constructs a DataDecryptor.
DataDecryptorWithMAC(const char *passphrase, BufferedTransformation *attachment=NULL, bool throwException=true)
Constructs a DataDecryptor.
Password-based decryptor with MAC.
void FirstPut(const byte *)
void LastPut(const byte *inString, size_t length)
Input the last block of data.
T1 RoundUpToMultipleOf(const T1 &n, const T2 &m)
Rounds a value up to a multiple of a second value.
const T & STDMAX(const T &a, const T &b)
Replacement function for std::max.
void CheckKey(const byte *salt, const byte *keyCheck)
void SetFilter(Filter *filter)
Sets the OutputProxy filter.
Exception thrown when an incorrect MAC is encountered in DefaultDecryptorWithMAC and LegacyDecryptorW...
bool VerifyBufsEqual(const byte *buf, const byte *mask, size_t count)
Performs a near constant-time comparison of two equally sized buffers.