frostfs-sdk-csharp/src/FrostFS.SDK.Cryptography/Tz/Helper.cs
Ivan Pchelintsev 11eff4e23e [#1] Move files to top level directory
Signed-off-by: Ivan Pchelintsev <i.pchelintsev@yadro.com>
2024-05-22 14:29:20 +03:00

30 lines
695 B
C#

using System.Security.Cryptography;
namespace FrostFS.SDK.Cryptography.Tz
{
public static class Helper
{
public static ulong NextUlong(this RandomNumberGenerator rng)
{
var buff = new byte[8];
rng.GetBytes(buff);
return BitConverter.ToUInt64(buff, 0);
}
public static int GetLeadingZeros(ulong value)
{
var i = 64;
while (value != 0)
{
value >>= 1;
i--;
}
return i;
}
public static int GetNonZeroLength(this ulong value)
{
return 64 - GetLeadingZeros(value);
}
}
}