add additional cipher modes

This commit is contained in:
Günter Obiltschnig 2018-03-06 19:46:24 +01:00
parent ccefee0d55
commit e19f33351d
2 changed files with 27 additions and 15 deletions

View File

@ -48,11 +48,14 @@ public:
MODE_ECB, /// Electronic codebook (plain concatenation)
MODE_CBC, /// Cipher block chaining (default)
MODE_CFB, /// Cipher feedback
MODE_OFB /// Output feedback
MODE_OFB, /// Output feedback
MODE_CTR, /// Counter mode
MODE_GCM, /// Galois/Counter mode
MODE_CCM /// Counter with CBC-MAC
};
CipherKeyImpl(const std::string& name,
const std::string& passphrase,
CipherKeyImpl(const std::string& name,
const std::string& passphrase,
const std::string& salt,
int iterationCount,
const std::string& digest);
@ -60,10 +63,10 @@ public:
/// the given cipher name, passphrase, salt value
/// and iteration count.
CipherKeyImpl(const std::string& name,
const ByteVec& key,
CipherKeyImpl(const std::string& name,
const ByteVec& key,
const ByteVec& iv);
/// Creates a new CipherKeyImpl object, using the
/// Creates a new CipherKeyImpl object, using the
/// given cipher name, key and initialization vector.
CipherKeyImpl(const std::string& name);
@ -87,7 +90,7 @@ public:
Mode mode() const;
/// Returns the Cipher's mode of operation.
const ByteVec& getKey() const;
/// Returns the key for the Cipher.
@ -102,7 +105,7 @@ public:
const EVP_CIPHER* cipher();
/// Returns the cipher object
private:
void generateKey(const std::string& passphrase,
const std::string& salt,

View File

@ -25,8 +25,8 @@ namespace Poco {
namespace Crypto {
CipherKeyImpl::CipherKeyImpl(const std::string& name,
const std::string& passphrase,
CipherKeyImpl::CipherKeyImpl(const std::string& name,
const std::string& passphrase,
const std::string& salt,
int iterationCount,
const std::string& digest):
@ -54,8 +54,8 @@ CipherKeyImpl::CipherKeyImpl(const std::string& name,
}
CipherKeyImpl::CipherKeyImpl(const std::string& name,
const ByteVec& key,
CipherKeyImpl::CipherKeyImpl(const std::string& name,
const ByteVec& key,
const ByteVec& iv):
_pCipher(0),
_pDigest(0),
@ -71,7 +71,7 @@ CipherKeyImpl::CipherKeyImpl(const std::string& name,
throw Poco::NotFoundException("Cipher " + name + " was not found");
}
CipherKeyImpl::CipherKeyImpl(const std::string& name):
_pCipher(0),
_pDigest(0),
@ -114,6 +114,15 @@ CipherKeyImpl::Mode CipherKeyImpl::mode() const
case EVP_CIPH_OFB_MODE:
return MODE_OFB;
case EVP_CIPH_CTR_MODE:
return MODE_CTR;
case EVP_CIPH_GCM_MODE:
return MODE_GCM;
case EVP_CIPH_CCM_MODE:
return MODE_CCM;
}
throw Poco::IllegalStateException("Unexpected value of EVP_CIPHER_mode()");
}
@ -125,7 +134,7 @@ void CipherKeyImpl::generateKey()
getRandomBytes(vec, keySize());
setKey(vec);
getRandomBytes(vec, ivSize());
setIV(vec);
}
@ -134,7 +143,7 @@ void CipherKeyImpl::generateKey()
void CipherKeyImpl::getRandomBytes(ByteVec& vec, std::size_t count)
{
Poco::RandomInputStream random;
vec.clear();
vec.reserve(count);