Skip to content

Commit

Permalink
src: Test all Incremental classes with sliced messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel-lucas6 committed Jul 30, 2023
1 parent 41d2258 commit 444f792
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/Geralt.Tests/BLAKE2bTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,13 @@ public void Incremental_Valid(string hash, string message, string? key = null)
Span<byte> k = key != null ? Convert.FromHexString(key) : Span<byte>.Empty;

using var blake2b = new IncrementalBLAKE2b(h.Length, k);
blake2b.Update(m);
if (m.Length > 1) {
blake2b.Update(m[..(m.Length / 2)]);
blake2b.Update(m[(m.Length / 2)..]);
}
else {
blake2b.Update(m);
}
blake2b.Finalize(h);

Assert.AreEqual(hash, Convert.ToHexString(h).ToLower());
Expand Down
16 changes: 14 additions & 2 deletions src/Geralt.Tests/Ed25519Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,13 @@ public void Incremental_Sign_Valid(string signature, string message, string priv
Span<byte> sk = Convert.FromHexString(privateKey);

using var ed25519ph = new IncrementalEd25519();
ed25519ph.Update(m);
if (m.Length > 1) {
ed25519ph.Update(m[..(m.Length / 2)]);
ed25519ph.Update(m[(m.Length / 2)..]);
}
else {
ed25519ph.Update(m);
}
ed25519ph.Finalize(s, sk);

Assert.AreEqual(signature, Convert.ToHexString(s).ToLower());
Expand Down Expand Up @@ -338,7 +344,13 @@ public void Incremental_Verify_Valid(string signature, string message, string pr
Span<byte> pk = Convert.FromHexString(privateKey)[^Ed25519.PublicKeySize..];

using var ed25519ph = new IncrementalEd25519();
ed25519ph.Update(m);
if (m.Length > 1) {
ed25519ph.Update(m[..(m.Length / 2)]);
ed25519ph.Update(m[(m.Length / 2)..]);
}
else {
ed25519ph.Update(m);
}

bool valid = ed25519ph.Verify(s, pk);

Expand Down
8 changes: 7 additions & 1 deletion src/Geralt.Tests/Poly1305Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@ public void Incremental_Valid(string tag, string message, string oneTimeKey)
Span<byte> k = Convert.FromHexString(oneTimeKey);

using var poly1305 = new IncrementalPoly1305(k);
poly1305.Update(m);
if (m.Length > 1) {
poly1305.Update(m[..(m.Length / 2)]);
poly1305.Update(m[(m.Length / 2)..]);
}
else {
poly1305.Update(m);
}
poly1305.Finalize(t);

Assert.AreEqual(tag, Convert.ToHexString(t).ToLower());
Expand Down

0 comments on commit 444f792

Please sign in to comment.