summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-11-22 14:12:33 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-11-22 14:12:33 +0700
commit17bf5a53ec9ca89491a54d19001190fde51fa820 (patch)
tree0ed78a890a36bc35f593c15e266907b433d3e8d0
parentThrow UnsupportedException instead (diff)
downloadBouncyCastle.NET-ed25519-17bf5a53ec9ca89491a54d19001190fde51fa820.tar.xz
Refactoring in CtrSP800Drbg
-rw-r--r--crypto/src/crypto/prng/drbg/CtrSP800Drbg.cs6
1 files changed, 5 insertions, 1 deletions
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