/// <summary> /// Returns address from the given seed. Uses CPU for calculation. /// </summary> public static string TestCpu(byte[] seed) { byte[] secretBytes = new byte[32]; byte[] indexBytes = new byte[4]; byte[] publicKeyBytes = new byte[32]; byte[] checksumBytes = new byte[5]; byte[] tmp = new byte[64]; Job.AddressBuffer addressBuffer = new(Job.AddressPrefix.Length + 60); addressBuffer.Append(Job.AddressPrefix); var hasher = Blake2b.CreateIncrementalHasher(32); hasher.Update(seed); hasher.Update(indexBytes); hasher.Finish(secretBytes); Chaos.NaCl.Internal.Ed25519Ref10.Ed25519Operations.crypto_public_key( secretBytes, 0, publicKeyBytes, 0, tmp); Blake2b.ComputeAndWriteHash(5, publicKeyBytes, checksumBytes); Job.Reverse(checksumBytes); Job.NanoBase32(publicKeyBytes, ref addressBuffer); Job.NanoBase32(checksumBytes, ref addressBuffer); return(addressBuffer.ToString()); }
public static string Create(string data) { Span <byte> hash = stackalloc byte[DigestLength]; Blake2b.ComputeAndWriteHash(DigestLength, MemoryMarshal.AsBytes(data.AsSpan()), hash); return(Encode(hash)); }
public static ColorProfile GetOrAdd(ReadOnlySpan <byte> bytes) { Span <byte> hash = stackalloc byte[Unsafe.SizeOf <Guid>()]; Blake2b.ComputeAndWriteHash(Unsafe.SizeOf <Guid>(), bytes, hash); var guid = MemoryMarshal.Read <Guid>(hash); return((dic.TryGetValue(guid, out var wref) && wref.TryGetTarget(out var prof)) ? prof : addOrUpdate(guid, bytes)); }
public static ColorProfile GetOrAdd(ReadOnlySpan <byte> bytes) { #if BUILTIN_SPAN Span <byte> hash = stackalloc byte[16]; Blake2b.ComputeAndWriteHash(16, bytes, hash); #else var hash = Blake2b.ComputeHash(16, bytes); #endif var guid = new Guid(hash); return((dic.TryGetValue(guid, out var wref) && wref.TryGetTarget(out var prof)) ? prof : addOrUpdate(guid, bytes)); }
private static byte[] blake2bNoAllocSelfTest() { Span <byte> buff = stackalloc byte[Blake2b.DefaultDigestLength]; var inc = Blake2b.CreateIncrementalHasher(blake2bCheck.Length); foreach (int diglen in new[] { 20, 32, 48, 64 }) { foreach (int msglen in new[] { 0, 3, 128, 129, 255, 1024 }) { var msg = getTestSequence(msglen); var key = getTestSequence(diglen); Blake2b.ComputeAndWriteHash(diglen, msg, buff); inc.Update(buff.Slice(0, diglen)); Blake2b.ComputeAndWriteHash(diglen, key, msg, buff); inc.Update(buff.Slice(0, diglen)); } } return(inc.TryFinish(buff, out int len) ? buff.Slice(0, len).ToArray() : Array.Empty <byte>()); }
public override void Run(object?arg) { string prefix1 = string.Concat(AddressPrefix, "3", keyword); string prefix2 = string.Concat(AddressPrefix, "1", keyword); string suffix1 = keyword; byte[] seedBytes = new byte[32]; byte[] secretBytes = new byte[32]; byte[] indexBytes = new byte[4]; byte[] publicKeyBytes = new byte[32]; byte[] checksumBytes = new byte[5]; byte[] tmp = new byte[64]; AddressBuffer addressBuffer = new(AddressPrefix.Length + 60); bool canMatchPrefix = this.canMatchPrefix; bool canMatchSuffix = this.canMatchSuffix; CancellationToken cancellationToken = this.cancellationToken; System.Action <string, string> resultCallback = this.resultCallback; addressBuffer.Append(AddressPrefix); while (!cancellationToken.IsCancellationRequested) { random.GetBytes(seedBytes); var hasher = Blake2b.CreateIncrementalHasher(32); hasher.Update(seedBytes); hasher.Update(indexBytes); hasher.Finish(secretBytes); Chaos.NaCl.Internal.Ed25519Ref10.Ed25519Operations.crypto_public_key( secretBytes, 0, publicKeyBytes, 0, tmp); Blake2b.ComputeAndWriteHash(5, publicKeyBytes, checksumBytes); Reverse(checksumBytes); NanoBase32(publicKeyBytes, ref addressBuffer); NanoBase32(checksumBytes, ref addressBuffer); bool isMatched = false; if (canMatchPrefix) { isMatched = addressBuffer.StartsWith(prefix1) || addressBuffer.StartsWith(prefix2); } if (!isMatched && canMatchSuffix) { isMatched = addressBuffer.EndsWith(suffix1); } if (isMatched) { var address = addressBuffer.ToString(); if (resultCallback != null) { resultCallback.Invoke(HexUtils.HexFromByteArray(seedBytes), address); } else { FoundSeed = HexUtils.HexFromByteArray(seedBytes); FoundAddress = address; break; } } ++attempts; addressBuffer.Length = AddressPrefix.Length; } }