@@ -950,7 +950,11 @@ private static int Char64(char character)
950950 /// <summary>Blowfish encipher a single 64-bit block encoded as two 32-bit halves.</summary>
951951 /// <param name="blockArray">An array containing the two 32-bit half blocks.</param>
952952 /// <param name="offset"> The position in the array of the blocks.</param>
953+ #if HAS_SPAN
954+ private void Encipher ( Span < uint > blockArray , int offset )
955+ #else
953956 private void Encipher ( uint [ ] blockArray , int offset )
957+ #endif
954958 {
955959 uint block = blockArray [ offset ] ;
956960 uint r = blockArray [ offset + 1 ] ;
@@ -985,7 +989,11 @@ private void Encipher(uint[] blockArray, int offset)
985989 /// <param name="data">The string to extract the data from.</param>
986990 /// <param name="offset"> [in,out] The current offset.</param>
987991 /// <returns>The next word of material from data.</returns>
992+ #if HAS_SPAN
993+ private static uint StreamToWord ( ReadOnlySpan < byte > data , ref int offset )
994+ #else
988995 private static uint StreamToWord ( byte [ ] data , ref int offset )
996+ #endif
989997 {
990998 int i ;
991999 uint word = 0 ;
@@ -1009,11 +1017,19 @@ private void InitializeKey()
10091017
10101018 /// <summary>Key the Blowfish cipher.</summary>
10111019 /// <param name="keyBytes">The key byte array.</param>
1020+ #if HAS_SPAN
1021+ private void Key ( ReadOnlySpan < byte > keyBytes )
1022+ #else
10121023 private void Key ( byte [ ] keyBytes )
1024+ #endif
10131025 {
10141026 int i ;
10151027 int koffp = 0 ;
1028+ #if HAS_SPAN
1029+ Span < uint > lr = stackalloc uint [ 2 ] { 0 , 0 } ;
1030+ #else
10161031 uint [ ] lr = { 0 , 0 } ;
1032+ #endif
10171033 int plen = _p . Length , slen = _s . Length ;
10181034
10191035 for ( i = 0 ; i < plen ; i ++ )
@@ -1043,12 +1059,20 @@ private void Key(byte[] keyBytes)
10431059 /// <param name="saltBytes"> Salt byte array.</param>
10441060 /// <param name="inputBytes">Input byte array.</param>
10451061 // ReSharper disable once InconsistentNaming
1062+ #if HAS_SPAN
1063+ private void EKSKey ( ReadOnlySpan < byte > saltBytes , ReadOnlySpan < byte > inputBytes )
1064+ #else
10461065 private void EKSKey ( byte [ ] saltBytes , byte [ ] inputBytes )
1066+ #endif
10471067 {
10481068 int i ;
10491069 int passwordOffset = 0 ;
10501070 int saltOffset = 0 ;
1071+ #if HAS_SPAN
1072+ Span < uint > lr = stackalloc uint [ 2 ] { 0 , 0 } ;
1073+ #else
10511074 uint [ ] lr = { 0 , 0 } ;
1075+ #endif
10521076 int plen = _p . Length , slen = _s . Length ;
10531077
10541078 for ( i = 0 ; i < plen ; i ++ )
@@ -1082,13 +1106,23 @@ private void EKSKey(byte[] saltBytes, byte[] inputBytes)
10821106 /// <param name="saltBytes"> The salt byte array to hash with.</param>
10831107 /// <param name="workFactor"> The binary logarithm of the number of rounds of hashing to apply.</param>
10841108 /// <returns>A byte array containing the hashed result.</returns>
1085- internal byte [ ] CryptRaw ( byte [ ] inputBytes , byte [ ] saltBytes , int workFactor )
1109+ #if HAS_SPAN
1110+ internal byte [ ] CryptRaw ( ReadOnlySpan < byte > inputBytes , ReadOnlySpan < byte > saltBytes , int workFactor )
1111+ #else
1112+ internal byte [ ] CryptRaw ( byte [ ] inputBytes , byte [ ] saltBytes , int workFactor )
1113+ #endif
10861114 {
10871115 int i ;
10881116 int j ;
10891117
1118+ #if HAS_SPAN
1119+ Span < uint > cdata = stackalloc uint [ BfCryptCiphertext . Length ] ;
1120+ BfCryptCiphertext . CopyTo ( cdata ) ;
1121+ #else
10901122 uint [ ] cdata = new uint [ BfCryptCiphertext . Length ] ;
10911123 Array . Copy ( BfCryptCiphertext , cdata , BfCryptCiphertext . Length ) ;
1124+ #endif
1125+
10921126 int clen = cdata . Length ;
10931127
10941128 if ( workFactor < MinRounds || workFactor > MaxRounds )
0 commit comments