From 7d35d0a67fd93d2e73351d12cf86d30a288f939e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20=C5=81ojewski?= Date: Sun, 30 Sep 2018 20:06:08 +0200 Subject: [PATCH] Whirlpool hash algorithm --- CHANGELOG.md | 2 ++ README.md | 1 + lib/Crypto/Whirlpool.php | 58 +++++++++++++++++++++++++++++++ tests/Crypto/WhirlpoolTest.php | 62 ++++++++++++++++++++++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 lib/Crypto/Whirlpool.php create mode 100644 tests/Crypto/WhirlpoolTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index e499412..e264aeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- Whirlpool hash algorithm ### Fixed - Error when 'Display name' not set - Encoding of iteration for 'Extended DES (Crypt)' diff --git a/README.md b/README.md index faa18a3..d7792ea 100644 --- a/README.md +++ b/README.md @@ -197,6 +197,7 @@ SHA512 Whirlpool | No salt supported. | a96b16ebb691dbe968b0d66d0d924cff5cf5de5e SSHA256 | Generates 32 chars salt. | {SSHA256}+WxTB3JxprNteeovsuSYtgI+UkVPA9lfwGoYkz3Ff7hjd1FSdmlTMkNsSExyR21KM3NvNTZ5V0p4WXJMUjFzUg== SSHA512 | Generates 32 chars salt. | {SSHA512}It+v1kAEUBbhMJYJ2swAtz+RLE6ispv/FB6G/ALhK/YWwEmrloY+0jzrWIfmu+rWUXp8u0Tg4jLXypC5oXAW00IyYnRVdEZJbE9wak96bkNRVWFCYmlJNWxrdTA0QmhL WoltLab Community Framework 2.x | Double salted bcrypt. | $2a$08$XEQDKNU/Vbootwxv5Gp7gujxFX/RUFsZLvQPYM435Dd3/p17fto02 +Whirlpool | | 74dfc2b27acfa364da55f93a5caee29ccad3557247eda238831b3e9bd931b01d77fe994e4f12b9d4cfa92a124461d2065197d8cf7f33fc88566da2db2a4d6eae ## Development diff --git a/lib/Crypto/Whirlpool.php b/lib/Crypto/Whirlpool.php new file mode 100644 index 0000000..7ae6360 --- /dev/null +++ b/lib/Crypto/Whirlpool.php @@ -0,0 +1,58 @@ + + * @author Marcin Łojewski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace OCA\UserSQL\Crypto; + +use OCP\IL10N; + +/** + * Whirlpool hash implementation. + * + * @author Marcin Łojewski + */ +class Whirlpool extends AbstractAlgorithm +{ + /** + * The class constructor. + * + * @param IL10N $localization The localization service. + */ + public function __construct(IL10N $localization) + { + parent::__construct($localization); + } + + /** + * @inheritdoc + */ + public function getPasswordHash($password) + { + return hash('whirlpool', $password); + } + + /** + * @inheritdoc + */ + protected function getAlgorithmName() + { + return "Whirlpool"; + } +} diff --git a/tests/Crypto/WhirlpoolTest.php b/tests/Crypto/WhirlpoolTest.php new file mode 100644 index 0000000..ff92af0 --- /dev/null +++ b/tests/Crypto/WhirlpoolTest.php @@ -0,0 +1,62 @@ + + * @author Marcin Łojewski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Tests\UserSQL\Crypto; + +use OCA\UserSQL\Crypto\IPasswordAlgorithm; +use OCA\UserSQL\Crypto\Whirlpool; +use OCP\IL10N; +use Test\TestCase; + +/** + * Unit tests for class SHA512Whirlpool. + * + * @author Marcin Łojewski + */ +class WhirlpoolTest extends TestCase +{ + /** + * @var IPasswordAlgorithm + */ + private $crypto; + + public function testCheckPassword() + { + $this->assertTrue( + $this->crypto->checkPassword( + "password", + "74dfc2b27acfa364da55f93a5caee29ccad3557247eda238831b3e9bd931b01d77fe994e4f12b9d4cfa92a124461d2065197d8cf7f33fc88566da2db2a4d6eae" + ) + ); + } + + public function testPasswordHash() + { + $hash = $this->crypto->getPasswordHash("password"); + $this->assertTrue($this->crypto->checkPassword("password", $hash)); + } + + protected function setUp() + { + parent::setUp(); + $this->crypto = new Whirlpool($this->createMock(IL10N::class)); + } +}