public (byte[] publicKey, byte[] secretKey) KeyGen(ReadOnlySpan <byte> inputKeyMaterial) { var parameters = new BLSParameters() { InputKeyMaterial = inputKeyMaterial.ToArray() }; _bls.ImportParameters(parameters); throw new NotImplementedException(); //return (new byte[0], new byte[0]); }
public byte[] Sign(ReadOnlySpan <byte> secretKey, ReadOnlySpan <byte> message) { var parameters = new BLSParameters() { PrivateKey = secretKey.ToArray() }; _bls.ImportParameters(parameters); var hash = new Span <byte>(new byte[32]); var hashSuccess = _bls.HashAlgorithm.TryComputeHash(message, hash, out var hashBytesWritten); var signature = new Span <byte>(new byte[96]); var signSuccess = _bls.TrySignData(hash, signature, out var signBytesWritten); return(signature.ToArray()); }
/// <inheritdoc /> public override void ImportParameters(BLSParameters parameters) { if (parameters.PrivateKey != null && parameters.PrivateKey.Length != PrivateKeyLength) { throw new ArgumentOutOfRangeException(nameof(parameters.PrivateKey), parameters.PrivateKey.Length, $"Private key must be {PrivateKeyLength} bytes long."); } if (parameters.PublicKey != null && parameters.PublicKey.Length != PublicKeyLength) { throw new ArgumentOutOfRangeException(nameof(parameters.PublicKey), parameters.PublicKey.Length, $"Public key must be {PublicKeyLength} bytes long."); } if (parameters.InputKeyMaterial != null) { throw new NotSupportedException("BLS input key material not supported."); } // Only supports minimal public key size (or unspecified) if (parameters.Variant != BlsVariant.Unknown && parameters.Variant != BlsVariant.MinimalPublicKeySize) { throw new NotSupportedException( $"BLS variant {parameters.Variant} not supported. Must be {BlsVariant.MinimalPublicKeySize}, or leave unset."); } // Only supports basic (or unspecified) if (parameters.Scheme != BlsScheme.Unknown && parameters.Scheme != BlsScheme.ProofOfPossession) { throw new NotSupportedException( $"BLS scheme {parameters.Scheme} not supported. Must be {BlsScheme.ProofOfPossession}, or leave unset."); } // TODO: If both are null, generate random key?? _privateKey = parameters.PrivateKey?.AsSpan().ToArray(); _publicKey = parameters.PublicKey?.AsSpan().ToArray(); }
/// <summary> /// Imports the specified parameters into the current BLS asymmetric algorithm. /// </summary> public abstract void ImportParameters(BLSParameters parameters);
/// <summary> /// Creates a new BLS asymmetric algorithm with the specified parameters. /// </summary> public static BLS Create(BLSParameters parameters) { // TODO: Load default from config (not sure how new .NET Core does it; old Framework used to use app.config) return(new BLSHerumi(parameters)); }
public BLSHerumi(BLSParameters parameters) { // Only supports minimal public key size KeySizeValue = PrivateKeyLength * 8; ImportParameters(parameters); }