/// <summary> /// Combines a hash and domain to the input format used by Herumi (the G2 initial X value). /// </summary> /// <returns>true if the operation was successful; false if the destination is not large enough to hold the result</returns> public bool TryCombineHashAndDomain(ReadOnlySpan <byte> hash, ReadOnlySpan <byte> domain, Span <byte> destination, out int bytesWritten) { if (destination.Length < 2 * InitialXPartLength) { bytesWritten = 0; return(false); } if (hash.Length != HashLength) { throw new ArgumentOutOfRangeException(nameof(hash), hash.Length, $"Hash with domain must be {HashLength} bytes long."); } if (domain.Length != DomainLength) { throw new ArgumentOutOfRangeException(nameof(domain), domain.Length, $"Domain must be {DomainLength} bytes long."); } var hashWithDomain = new Span <byte>(new byte[HashLength + DomainLength]); hash.CopyTo(hashWithDomain); domain.CopyTo(hashWithDomain.Slice(HashLength)); unsafe { fixed(byte *destinationPtr = destination) fixed(byte *hashPtr = hashWithDomain) { Bls384Interop.HashWithDomainToFp2(destinationPtr, hashPtr); } } bytesWritten = 2 * InitialXPartLength; return(true); }