From 17bf5a53ec9ca89491a54d19001190fde51fa820 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Wed, 22 Nov 2023 14:12:33 +0700 Subject: Refactoring in CtrSP800Drbg --- crypto/src/crypto/prng/drbg/CtrSP800Drbg.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crypto/src/crypto/prng/drbg/CtrSP800Drbg.cs b/crypto/src/crypto/prng/drbg/CtrSP800Drbg.cs index 2721e9440..1ea7cdf63 100644 --- a/crypto/src/crypto/prng/drbg/CtrSP800Drbg.cs +++ b/crypto/src/crypto/prng/drbg/CtrSP800Drbg.cs @@ -720,7 +720,10 @@ namespace Org.BouncyCastle.Crypto.Prng.Drbg */ private void PadKey(byte[] keyMaster, int keyOff, byte[] tmp, int tmpOff) { - tmp[tmpOff + 0] = (byte)(keyMaster[keyOff + 0] & 0xfe); +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + PadKey(keyMaster.AsSpan(keyOff), tmp.AsSpan(tmpOff)); +#else + tmp[tmpOff + 0] = (byte)(keyMaster[keyOff + 0] & 0xfe); tmp[tmpOff + 1] = (byte)((keyMaster[keyOff + 0] << 7) | ((keyMaster[keyOff + 1] & 0xfc) >> 1)); tmp[tmpOff + 2] = (byte)((keyMaster[keyOff + 1] << 6) | ((keyMaster[keyOff + 2] & 0xf8) >> 2)); tmp[tmpOff + 3] = (byte)((keyMaster[keyOff + 2] << 5) | ((keyMaster[keyOff + 3] & 0xf0) >> 3)); @@ -730,6 +733,7 @@ namespace Org.BouncyCastle.Crypto.Prng.Drbg tmp[tmpOff + 7] = (byte)(keyMaster[keyOff + 6] << 1); DesParameters.SetOddParity(tmp, tmpOff, 8); +#endif } #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER -- cgit 1.4.1