#nullable enable
using Internal.Cryptography;
+using System.Buffers.Binary;
using System.Diagnostics;
using static Interop.BCrypt;
offset = sizeof(KeyBlobMagicNumber) + sizeof(int); // skip Magic and cbKey
// Read out a (V1) BCRYPT_DSA_KEY_BLOB structure.
- dsaParams.Counter = FromBigEndian(Interop.BCrypt.Consume(dsaBlob, ref offset, 4));
+ dsaParams.Counter = BinaryPrimitives.ReadInt32BigEndian(Interop.BCrypt.Consume(dsaBlob, ref offset, 4));
dsaParams.Seed = Interop.BCrypt.Consume(dsaBlob, ref offset, Sha1HashOutputSize);
dsaParams.Q = Interop.BCrypt.Consume(dsaBlob, ref offset, Sha1HashOutputSize);
offset = sizeof(BCRYPT_DSA_KEY_BLOB_V2) - 4; //skip to Count[4]
// Read out a BCRYPT_DSA_KEY_BLOB_V2 structure.
- dsaParams.Counter = FromBigEndian(Interop.BCrypt.Consume(dsaBlob, ref offset, 4));
+ dsaParams.Counter = BinaryPrimitives.ReadInt32BigEndian(Interop.BCrypt.Consume(dsaBlob, ref offset, 4));
Debug.Assert(offset == sizeof(BCRYPT_DSA_KEY_BLOB_V2), $"Expected offset = sizeof(BCRYPT_DSA_KEY_BLOB_V2), got {offset} != {sizeof(BCRYPT_DSA_KEY_BLOB_V2)}");
}
}
- private static int FromBigEndian(byte[] b)
- {
- return (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3];
- }
-
/// <summary>
/// This function checks the magic value in the key blob header
/// </summary>
}
return oddParityKey;
}
-
- internal static void ConvertIntToByteArray(uint value, byte[] dest)
- {
- Debug.Assert(dest != null);
- Debug.Assert(dest.Length == 4);
- dest[0] = (byte)((value & 0xFF000000) >> 24);
- dest[1] = (byte)((value & 0xFF0000) >> 16);
- dest[2] = (byte)((value & 0xFF00) >> 8);
- dest[3] = (byte)(value & 0xFF);
- }
}
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Buffers.Binary;
using System.Diagnostics;
using Internal.Cryptography;
for (int ib = 0; ib < rgbT.Length;)
{
// Increment counter -- up to 2^32 * sizeof(Hash)
- Helpers.ConvertIntToByteArray(counter++, rgbCounter);
+ BinaryPrimitives.WriteUInt32BigEndian(rgbCounter, counter++);
hasher.TransformBlock(rgbSeed, 0, rgbSeed.Length, rgbSeed, 0);
hasher.TransformFinalBlock(rgbCounter, 0, 4);
Debug.Assert(hasher.Hash != null);
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Buffers.Binary;
using System.Diagnostics;
using System.IO;
using System.Runtime.Versioning;
get
{
byte[] keySize = CapiHelper.GetKeyParameter(SafeKeyHandle, Constants.CLR_KEYLEN);
- _keySize = (keySize[0] | (keySize[1] << 8) | (keySize[2] << 16) | (keySize[3] << 24));
+ _keySize = BinaryPrimitives.ReadInt32LittleEndian(keySize);
return _keySize;
}
}