示例#1
0
        /// <summary>
        /// Generates the ECDH shared secret between two Ed25519 public keys and returns it.
        /// </summary>
        /// <param name="a">An Ed25519 private key.</param>
        /// <param name="b">An Ed25519 public key.</param>
        public static byte[] SharedSecret(ECPrivKeyModel a, ECPubKeyModel b)
        {
#pragma warning disable CS0618 // Type or member is obsolete but can be ignored here since this function just needs more testing.
            return(Ed25519.KeyExchange(b.key, a.key));

#pragma warning restore CS0618 // Type or member is obsolete but can be ignored here since this function just needs more testing.
        }
示例#2
0
        /// <summary>
        /// Generates a new Ed25519 <see cref="SignedPreKeyModel"/> and returns it.
        /// </summary>
        /// <param name="id">The id of the <see cref="SignedPreKeyModel"/>.</param>
        /// <param name="identiyKey">The private part of an <see cref="IdentityKeyPairModel"/> used for signing.</param>
        public static SignedPreKeyModel GenerateSignedPreKey(uint id, ECPrivKeyModel identiyKey)
        {
            PreKeyModel preKey = GeneratePreKey(id);

            byte[] signature = Ed25519.Sign(preKey.pubKey.key, identiyKey.key);
            return(new SignedPreKeyModel(preKey, signature));
        }
示例#3
0
 /// <summary>
 /// Generates the signature of the given <paramref name="preKey"/> and returns it.
 /// </summary>
 /// <param name="preKey">The <see cref="PreKeyModel"/> that should be signed.</param>
 /// <param name="identiyKey">The private Key used for signing the given <paramref name="preKey"/>.</param>
 /// <returns>The signature of the given <paramref name="preKey"/>.</returns>
 public static byte[] SignPreKey(PreKeyModel preKey, ECPrivKeyModel identiyKey)
 {
     byte[] pubKey    = preKey.pubKey.ToByteArrayWithPrefix();
     byte[] signature = new byte[Ed25519.SignatureSize];
     Ed25519.Sign(identiyKey.key, 0, pubKey, 0, pubKey.Length, signature, 0);
     return(signature);
 }
示例#4
0
        public void Test_SignPreKey()
        {
            ECPrivKeyModel       priv            = new ECPrivKeyModel(SharedUtils.HexStringToByteArray("1498b5467a63dffa2dc9d9e069caf075d16fc33fdd4c3b01bfadae6433767d93"));
            ECPubKeyModel        pub             = new ECPubKeyModel(SharedUtils.HexStringToByteArray("b7a3c12dc0c8c748ab07525b701122b88bd78f600c76342d27f25e5f92444cde"));
            IdentityKeyPairModel identityKeyPair = new IdentityKeyPairModel(priv, pub);

            for (uint id = 1; id < 250; id++)
            {
                byte[] data = Encoding.ASCII.GetBytes("Message for Ed25519 signing");

                byte[] signature = new byte[Ed25519.SignatureSize];
                Ed25519.Sign(identityKeyPair.privKey.key, 0, data, 0, data.Length, signature, 0);
                byte[] sigRef       = SharedUtils.HexStringToByteArray("6dd355667fae4eb43c6e0ab92e870edb2de0a88cae12dbd8591507f584fe4912babff497f1b8edf9567d2483d54ddc6459bea7855281b7a246a609e3001a4e08");
                string sigRefBase64 = Convert.ToBase64String(sigRef);
                string sigBase64    = Convert.ToBase64String(signature);
                Assert.AreEqual(sigBase64, sigRefBase64);
            }
        }
示例#5
0
 /// <summary>
 /// Generates the ECDH shared secret between two Ed25519 public keys and returns it.
 /// </summary>
 /// <param name="a">An Ed25519 private key.</param>
 /// <param name="b">An Ed25519 public key.</param>
 public static byte[] SharedSecret(ECPrivKeyModel a, ECPubKeyModel b)
 {
     return(X25519KeyAgreement.Agreement(a.key, b.key));
 }
示例#6
0
 public GenericECKeyPairModel(ECPrivKeyModel privKey, ECPubKeyModel pubKey) : base(privKey, pubKey)
 {
 }
示例#7
0
 public EphemeralKeyPairModel(ECPrivKeyModel privKey, ECPubKeyModel pubKey) : base(privKey, pubKey)
 {
 }
示例#8
0
 public IdentityKeyPairModel(ECPrivKeyModel privKey, ECPubKeyModel pubKey) : base(privKey, pubKey)
 {
 }