From 3a34db8ce42070f49400e10fc66a800ff3fd044a Mon Sep 17 00:00:00 2001 From: Valient Gough Date: Mon, 17 Jun 2013 05:57:10 +0000 Subject: [PATCH] adds openssl implementation of PBKDF2 hmac-sha256 git-svn-id: http://encfs.googlecode.com/svn/trunk@103 db9cf616-1c43-0410-9cb8-a902689de0d6 --- cipher/openssl.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/cipher/openssl.cpp b/cipher/openssl.cpp index c70c76a..2cbb1ea 100644 --- a/cipher/openssl.cpp +++ b/cipher/openssl.cpp @@ -457,6 +457,42 @@ class PbkdfPkcs5HmacSha1 : public PBKDF { }; REGISTER_CLASS(PbkdfPkcs5HmacSha1, PBKDF); +class PbkdfPkcs5HmacSha256 : public PBKDF { + public: + PbkdfPkcs5HmacSha256() {} + virtual ~PbkdfPkcs5HmacSha256() {} + + virtual bool makeKey(const char *password, int passwordLength, + const byte *salt, int saltLength, + int numIterations, + CipherKey *outKey) { + return PKCS5_PBKDF2_HMAC( + password, passwordLength, + const_cast(salt), saltLength, + numIterations, EVP_sha256(), + outKey->size(), outKey->data()) == 1; + } + + virtual CipherKey randomKey(int length) { + CipherKey key(length); + if (!OpenSSLCipher::randomize(&key)) + key.reset(); + return key; + } + + virtual bool pseudoRandom(byte *out, int length) { + return OpenSSLCipher::pseudoRandomize(out, length); + } + + static Properties GetProperties() { + Properties props; + props.mode = NAME_PBKDF2_HMAC_SHA256; + props.library = "OpenSSL"; + return props; + } +}; +REGISTER_CLASS(PbkdfPkcs5HmacSha256, PBKDF); + unsigned long pthreads_thread_id() {