Ejemplo n.º 1
0
        /// <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.");
            }

            // Only supports basic (or unspecified)
            if (parameters.Scheme != BlsScheme.Unknown &&
                parameters.Scheme != BlsScheme.Basic)
            {
                throw new NotSupportedException($"BLS scheme {parameters.Scheme} not supported.");
            }

            // TODO: If both are null, generate random key??

            _privateKey = parameters.PrivateKey?.AsSpan().ToArray();
            _publicKey  = parameters.PublicKey?.AsSpan().ToArray();
        }
Ejemplo n.º 2
0
        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]);
        }
Ejemplo n.º 3
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.TrySignHash(hash, signature, out var signBytesWritten);

            return(signature.ToArray());
        }
Ejemplo n.º 4
0
 public BLSHerumi(BLSParameters parameters)
 {
     // Only supports minimal public key size
     KeySizeValue = PrivateKeyLength * 8;
     ImportParameters(parameters);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Imports the specified parameters into the current BLS asymmetric algorithm.
 /// </summary>
 public abstract void ImportParameters(BLSParameters parameters);
Ejemplo n.º 6
0
 /// <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));
 }