Example #1
0
        ///// <summary>
        ///// Calculate public key from private key seed
        ///// </summary>
        ///// <param name="privateKeySeed">Private key seed value</param>
        ///// <returns></returns>
        //public static byte[] PublicKeyFromSeed(byte[] privateKeySeed) {
        //	Contract.Requires<ArgumentNullException>(privateKeySeed != null);
        //	Contract.Requires<ArgumentException>(privateKeySeed.Length == PrivateKeySeedSize);

        //	byte[] privateKey;
        //	byte[] publicKey;
        //	KeyPairFromSeed(out publicKey, out privateKey, privateKeySeed);
        //	CryptoBytes.Wipe(privateKey);
        //	return publicKey;
        //}

        ///// <summary>
        ///// Calculate expanded form of private key from the key seed.
        ///// </summary>
        ///// <param name="privateKeySeed">Private key seed value</param>
        ///// <returns>Expanded form of the private key</returns>
        //public static byte[] ExpandedPrivateKeyFromSeed(byte[] privateKeySeed) {
        //	Contract.Requires<ArgumentNullException>(privateKeySeed != null);
        //	Contract.Requires<ArgumentException>(privateKeySeed.Length == PrivateKeySeedSize);

        //	byte[] privateKey;
        //	byte[] publicKey;
        //	KeyPairFromSeed(out publicKey, out privateKey, privateKeySeed);
        //	CryptoBytes.Wipe(publicKey);
        //	return privateKey;
        //}

        ///// <summary>
        ///// Calculate key pair from the key seed.
        ///// </summary>
        ///// <param name="publicKey">Public key</param>
        ///// <param name="expandedPrivateKey">Expanded form of the private key</param>
        ///// <param name="privateKeySeed">Private key seed value</param>
        //public static void KeyPairFromSeed(out byte[] publicKey, out byte[] expandedPrivateKey, byte[] privateKeySeed) {
        //	Contract.Requires<ArgumentNullException>(privateKeySeed != null);
        //	Contract.Requires<ArgumentException>(privateKeySeed.Length == PrivateKeySeedSize);

        //	var pk = new byte[PublicKeySize];
        //	var sk = new byte[ExpandedPrivateKeySize];

        //	Ed25519Operations.crypto_sign_keypair(pk, 0, sk, 0, privateKeySeed, 0);
        //	publicKey = pk;
        //	expandedPrivateKey = sk;
        //}

        public static void PrehashedKeyPairFromSeed(out byte[] publicKey, out byte[] prehashedPrivateKey, byte[] privateKeySeed)
        {
            Contract.Requires <ArgumentNullException>(privateKeySeed != null);
            Contract.Requires <ArgumentException>(privateKeySeed.Length == PrivateKeySeedSize);

            var pk  = new byte[PublicKeySize];
            var sk  = new byte[ExpandedPrivateKeySize];
            var skh = new byte[ExpandedPrivateKeySize];

            Ed25519Operations.crypto_sign_keypair(pk, 0, sk, 0, privateKeySeed, 0);
            publicKey = pk;
            Ed25519Operations.crypto_sign_private_prehash(sk, skh);
            prehashedPrivateKey = skh;
        }