From 61ccf0941c752b8d6bcc489dcdedd3604e536926 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Mon, 25 Jul 2022 14:32:14 +0700 Subject: Improve Pack usage --- crypto/src/crypto/digests/Blake2bDigest.cs | 8 +++----- 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++) { -- cgit 1.4.1