diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-07-25 14:32:14 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-07-25 14:32:14 +0700 |
commit | 61ccf0941c752b8d6bcc489dcdedd3604e536926 (patch) | |
tree | e4207121312e8e8141cb633f7a50f433cae41451 | |
parent | Digest tweaks (diff) | |
download | BouncyCastle.NET-ed25519-61ccf0941c752b8d6bcc489dcdedd3604e536926.tar.xz |
Improve Pack usage
-rw-r--r-- | crypto/src/crypto/digests/Blake2bDigest.cs | 8 | ||||
-rw-r--r-- | crypto/src/crypto/digests/Blake2sDigest.cs | 8 |
2 files changed, 6 insertions, 10 deletions
diff --git a/crypto/src/crypto/digests/Blake2bDigest.cs b/crypto/src/crypto/digests/Blake2bDigest.cs index bc25e5258..1ac9cfa35 100644 --- a/crypto/src/crypto/digests/Blake2bDigest.cs +++ b/crypto/src/crypto/digests/Blake2bDigest.cs @@ -382,9 +382,10 @@ namespace Org.BouncyCastle.Crypto.Digests Array.Clear(buffer, 0, buffer.Length);// Holds eventually the key if input is null Array.Clear(internalState, 0, internalState.Length); + byte[] bytes = new byte[8]; for (int i = 0; i < chainValue.Length && (i * 8 < digestLength); i++) { - byte[] bytes = Pack.UInt64_To_LE(chainValue[i]); + Pack.UInt64_To_LE(chainValue[i], bytes, 0); if (i * 8 < digestLength - 8) { @@ -429,10 +430,7 @@ namespace Org.BouncyCastle.Crypto.Digests InitializeInternalState(); ulong[] m = new ulong[16]; - for (int j = 0; j < 16; j++) - { - m[j] = Pack.LE_To_UInt64(message, messagePos + j * 8); - } + Pack.LE_To_UInt64(message, messagePos, m); for (int round = 0; round < ROUNDS; round++) { diff --git a/crypto/src/crypto/digests/Blake2sDigest.cs b/crypto/src/crypto/digests/Blake2sDigest.cs index 432b0f4d2..f50419126 100644 --- a/crypto/src/crypto/digests/Blake2sDigest.cs +++ b/crypto/src/crypto/digests/Blake2sDigest.cs @@ -402,9 +402,10 @@ namespace Org.BouncyCastle.Crypto.Digests Array.Clear(buffer, 0, buffer.Length);// Holds eventually the key if input is null Array.Clear(internalState, 0, internalState.Length); + byte[] bytes = new byte[4]; for (int i = 0; i < chainValue.Length && (i * 4 < digestLength); i++) { - byte[] bytes = Pack.UInt32_To_LE(chainValue[i]); + Pack.UInt32_To_LE(chainValue[i], bytes, 0); if (i * 4 < digestLength - 4) { @@ -448,10 +449,7 @@ namespace Org.BouncyCastle.Crypto.Digests InitializeInternalState(); uint[] m = new uint[16]; - for (int j = 0; j < 16; j++) - { - m[j] = Pack.LE_To_UInt32(message, messagePos + j * 4); - } + Pack.LE_To_UInt32(message, messagePos, m); for (int round = 0; round < ROUNDS; round++) { |