Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Hacker <dd0t@users.sourceforge.net>2014-10-03 03:19:29 +0400
committerStefan Hacker <dd0t@users.sourceforge.net>2014-10-03 03:19:29 +0400
commit5131d9e3036bb7de94967dd026f2c7f4ec91645d (patch)
treec166aa7a4b93d7581a67038fcbd999c1ed1a9c02 /src/murmur/PBKDF2.h
parent813aceb854949a863e095930423d8d49793e4be8 (diff)
Review and refactor of PBKDF2 support patch.
* Adjusted to coding guidelines * Pulled out PBKDF2 functionality into own class * Make benchmark a best of N approach with guaranteed minimum * Fixed broken database migration code. Don't try to alter tables and instead rely on them being re-created with the new fields. * Fixed some typos in ini. Also move to the setting to the end so ppl. don't get the idea they have to change this. * Chose a scarier name for the plain hash function * Use int instead of size_t for iteration counts as it is the datatype used in the OpenSSL API. Otherwise we just have to much pain with constantly converting and might expose ourselves to size issues in the future. * Moved new UserInfo enum entry to the end as to preserve the order
Diffstat (limited to 'src/murmur/PBKDF2.h')
-rw-r--r--src/murmur/PBKDF2.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/murmur/PBKDF2.h b/src/murmur/PBKDF2.h
new file mode 100644
index 000000000..068779ceb
--- /dev/null
+++ b/src/murmur/PBKDF2.h
@@ -0,0 +1,85 @@
+/* Copyright (C) 2013, tkmorris <mauricioarozi@gmail.com>
+ Copyright (C) 2014, Stefan Hacker <dd0t@users.sourceforge.net>
+
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ - Neither the name of the Mumble Developers nor the names of its
+ contributors may be used to endorse or promote products derived from this
+ software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+#ifndef MUMBLE_MURMUR_PBKDF2_H_
+#define MUMBLE_MURMUR_PBKDF2_H_
+
+#include <stddef.h>
+
+class QString;
+
+///
+/// Fully static wrapper class for PBKF2 password hashing functionality used in Murmur.
+///
+/// @note Using int all over the place because OpenSSL uses them in its C interface
+/// and we want to make sure not to parameterize it in unexpected ways.
+///
+class PBKDF2 {
+ public:
+ ///
+ /// @return Upper bound on iterations possible in
+ /// BENCHMARK_DURATION_TARGET_IN_MS on this machine.
+ ///
+ static int benchmark();
+
+ /// Performs a PBKDF2 hash operation using EVP_sha384.
+ ///
+ /// @param hexSalt Hex encoded salt to use in operation.
+ /// @param password Password to hash.
+ /// @param iterationCount Number of PBKDF2 iterations to apply.
+ /// @return Hex encoded password hash of DERIVED_KEY_LENGTH octets.
+ /// Null string if hashing failed.
+ ///
+ static QString getHash(const QString& hexSalt,
+ const QString& password,
+ int iterationCount);
+
+ ///
+ /// @return SALT_LENGTH octets of hex encoded random salt.
+ /// Null string if not enough entropy was available.
+ ///
+ static QString getSalt();
+
+ /// Length of hash in octets
+ static const int DERIVED_KEY_LENGTH = 48;
+ /// Length salt in octests
+ static const int SALT_LENGTH = 8;
+
+ /// Duration for hash operation the benchmark function should target
+ static const int BENCHMARK_DURATION_TARGET_IN_MS = 10;
+ /// Benchmark returns highest iteration number of N benchmark attemps
+ static const size_t BENCHMARK_N = 40;
+ /// Lower bound of iteration count returned by benchmark
+ /// regardless of duration (should be divisible by 2)
+ static const int BENCHMARK_MINIMUM_ITERATION_COUNT = 1000;
+
+};
+
+#endif // MUMBLE_MURMUR_PBKDF2_H_