From 3109033e40937efdff0a42642459dbbce4f9f944 Mon Sep 17 00:00:00 2001 From: Haik Date: Sat, 17 Feb 2024 18:44:29 +0400 Subject: [PATCH] overload removal --- src/Pandatech.Crypto.Tests/Argon2IdTests.cs | 11 ----------- src/Pandatech.Crypto/Argon2Id.cs | 20 +++++--------------- src/Pandatech.Crypto/Pandatech.Crypto.csproj | 4 ++-- 3 files changed, 7 insertions(+), 28 deletions(-) diff --git a/src/Pandatech.Crypto.Tests/Argon2IdTests.cs b/src/Pandatech.Crypto.Tests/Argon2IdTests.cs index b818624..95beee1 100644 --- a/src/Pandatech.Crypto.Tests/Argon2IdTests.cs +++ b/src/Pandatech.Crypto.Tests/Argon2IdTests.cs @@ -23,17 +23,6 @@ public void HashVerify_ShouldBeValid() Assert.True(argon2Id.VerifyHash(password, hash)); } - [Fact] - public void HashVerify_ShouldBeValid_2() - { - var argon2Id = new Argon2Id(); - - var password = Password.GenerateRandom(32, true, true, true, true); - var hash = argon2Id.HashPassword(password); - - Assert.True(argon2Id.VerifyHash(hash, hash)); - } - [Fact] public void HashVerify_InvalidPassword_ShouldBeInvalid() { diff --git a/src/Pandatech.Crypto/Argon2Id.cs b/src/Pandatech.Crypto/Argon2Id.cs index fe97dd8..6cd0fc2 100644 --- a/src/Pandatech.Crypto/Argon2Id.cs +++ b/src/Pandatech.Crypto/Argon2Id.cs @@ -46,27 +46,17 @@ private byte[] HashPassword(string password, byte[] salt) return result; } - public bool VerifyHash(string password, byte[] hash) + public bool VerifyHash(string password, byte[] passwordHash) { - if (hash == null || hash.Length <= _options.SaltSize) + if (passwordHash == null || passwordHash.Length <= _options.SaltSize) { - throw new ArgumentException($"Hash must be at least {SaltSize} bytes.", nameof(hash)); + throw new ArgumentException($"Hash must be at least {SaltSize} bytes.", nameof(passwordHash)); } - var salt = hash.Take(_options.SaltSize).ToArray(); + var salt = passwordHash.Take(_options.SaltSize).ToArray(); var newHash = HashPassword(password, salt); - return ConstantTimeComparison(hash, newHash); - } - - public bool VerifyHash(byte[] passwordHash, byte[] hash) - { - if (hash == null || hash.Length <= _options.SaltSize) - { - throw new ArgumentException($"Hash must be at least {SaltSize} bytes.", nameof(hash)); - } - - return ConstantTimeComparison(hash, passwordHash); + return ConstantTimeComparison(passwordHash, newHash); } private static bool ConstantTimeComparison(IReadOnlyList a, IReadOnlyList b) diff --git a/src/Pandatech.Crypto/Pandatech.Crypto.csproj b/src/Pandatech.Crypto/Pandatech.Crypto.csproj index c419027..7e1832c 100644 --- a/src/Pandatech.Crypto/Pandatech.Crypto.csproj +++ b/src/Pandatech.Crypto/Pandatech.Crypto.csproj @@ -8,12 +8,12 @@ MIT pandatech.png Readme.md - 2.2.8 + 2.2.9 Pandatech.Crypto Pandatech, library, encryption, hash, algorythms, security PandaTech.Crypto is a .NET library simplifying common cryptograhic functions. https://github.com/PandaTechAM/be-lib-pandatech-crypto - Overload for argon + Overload for argon removal