Skip to content

Commit

Permalink
overload removal
Browse files Browse the repository at this point in the history
  • Loading branch information
Haik committed Feb 17, 2024
1 parent 7899bcc commit 3109033
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 28 deletions.
11 changes: 0 additions & 11 deletions src/Pandatech.Crypto.Tests/Argon2IdTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
20 changes: 5 additions & 15 deletions src/Pandatech.Crypto/Argon2Id.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<byte> a, IReadOnlyList<byte> b)
Expand Down
4 changes: 2 additions & 2 deletions src/Pandatech.Crypto/Pandatech.Crypto.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
<Copyright>MIT</Copyright>
<PackageIcon>pandatech.png</PackageIcon>
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<Version>2.2.8</Version>
<Version>2.2.9</Version>
<Title>Pandatech.Crypto</Title>
<PackageTags>Pandatech, library, encryption, hash, algorythms, security</PackageTags>
<Description>PandaTech.Crypto is a .NET library simplifying common cryptograhic functions.</Description>
<RepositoryUrl>https://github.com/PandaTechAM/be-lib-pandatech-crypto</RepositoryUrl>
<PackageReleaseNotes>Overload for argon</PackageReleaseNotes>
<PackageReleaseNotes>Overload for argon removal</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 3109033

Please sign in to comment.