Exemplo n.º 1
0
        /// <summary>
        /// Derives the keys client for the client.
        /// </summary>
        /// <returns><c>true</c>, if keys client was derived, <c>false</c> otherwise.</returns>
        /// <param name="publicIdentKey">Public identification key.</param>
        /// <param name="publicPreKey">Public pre key.</param>
        /// <param name="signedOneTimeKey">Public one time key.</param>
        public bool DeriveKeysClient(byte[] publicIdentKey, byte[] publicPreKey, byte[] signedOneTimeKey)
        {
            if (publicIdentKey == null)
            {
                throw new EncryptionKeyIsMissingException("Public IdentKey is null");
            }
            if (publicPreKey == null)
            {
                throw new EncryptionKeyIsMissingException("Public PreKey is null");
            }

            this.publicIdentKey = publicIdentKey;
            this.publicPreKey   = publicPreKey;


            ephemeralKeyPair = NewKeypair();

            // ephermeral And Public Pre Key
            KeyPair ePPK = new KeyPair();

            // ephermeral and Public One Time Key
            KeyPair ePOTK = new KeyPair();


            // own Pre Key and Public Pre Key
            KeyPair oPKPPK = new KeyPair();
            // own Pre Key and Public One Time Key
            KeyPair oPKPOTK = new KeyPair();

            // TODO: overgive pre key :)

            //      if (oldKeyPair) {
            //          if (publicOneTimeKey != null) {
            //              NativeLibsodium.crypto_kx_client_session_keys (ePOTK.publicKey, ePOTK.privateKey, ephemeralKeyPair.publicKey, ephemeralKeyPair.privateKey, publicOneTimeKey);
            //              NativeLibsodium.crypto_kx_client_session_keys (oPKPOTK.publicKey, oPKPOTK.privateKey, oldOwnPreKeyPair.publicKey, oldOwnPreKeyPair.privateKey, publicOneTimeKey);
            //          }
            //          NativeLibsodium.crypto_kx_client_session_keys (ePPK.publicKey, ePPK.privateKey, ephemeralKeyPair.publicKey, ephemeralKeyPair.privateKey, publicPreKey);
            //          NativeLibsodium.crypto_kx_client_session_keys (oPKPPK.publicKey, oPKPPK.privateKey, oldOwnPreKeyPair.publicKey, oldOwnPreKeyPair.privateKey, publicPreKey);
            //      } else {
            if (signedOneTimeKey != null)
            {
                // get the onetime key
                publicOneTimeKey = SignByteOpen(signedOneTimeKey, publicPreKey);

                NativeLibsodium.crypto_kx_client_session_keys(ePOTK.publicKey, ePOTK.secretKey, ephemeralKeyPair.publicKey, ephemeralKeyPair.secretKey, publicOneTimeKey);
                NativeLibsodium.crypto_kx_client_session_keys(oPKPOTK.publicKey, oPKPOTK.secretKey, ownPreKeyPair.publicKey, ownPreKeyPair.secretKey, publicOneTimeKey);
            }
            NativeLibsodium.crypto_kx_client_session_keys(ePPK.publicKey, ePPK.secretKey, ephemeralKeyPair.publicKey, ephemeralKeyPair.secretKey, publicPreKey);
            NativeLibsodium.crypto_kx_client_session_keys(oPKPPK.publicKey, oPKPPK.secretKey, ownPreKeyPair.publicKey, ownPreKeyPair.secretKey, publicPreKey);


            DeriveSessionKeys(ePPK, oPKPPK, oPKPOTK, ePOTK);
            return(true);
        }
Exemplo n.º 2
0
        public bool DeriveKeysClient(bool oldKeyPair = false)
        {
            if (publicIdentKey == null || publicPreKey == null)
            {
                return(false);
                //throw new EncryptionKeyIsMissingException();
            }

            ephemeralKeyPair = NewKeypair();

            // ephermeral And Public Pre Key
            KeyPair ePPK = new KeyPair();

            // ephermeral and Public One Time Key
            KeyPair ePOTK = new KeyPair();

            // own Pre Key and Public Pre Key
            KeyPair oPKPPK = new KeyPair();
            // own Pre Key and Public One Time Key
            KeyPair oPKPOTK = new KeyPair();

            // TODO: overgive pre key :)

            //		if (oldKeyPair) {
            //			if (publicOneTimeKey != null) {
            //				NativeLibsodium.crypto_kx_client_session_keys (ePOTK.publicKey, ePOTK.privateKey, ephemeralKeyPair.publicKey, ephemeralKeyPair.privateKey, publicOneTimeKey);
            //				NativeLibsodium.crypto_kx_client_session_keys (oPKPOTK.publicKey, oPKPOTK.privateKey, oldOwnPreKeyPair.publicKey, oldOwnPreKeyPair.privateKey, publicOneTimeKey);
            //			}
            //			NativeLibsodium.crypto_kx_client_session_keys (ePPK.publicKey, ePPK.privateKey, ephemeralKeyPair.publicKey, ephemeralKeyPair.privateKey, publicPreKey);
            //			NativeLibsodium.crypto_kx_client_session_keys (oPKPPK.publicKey, oPKPPK.privateKey, oldOwnPreKeyPair.publicKey, oldOwnPreKeyPair.privateKey, publicPreKey);
            //		} else {
            if (publicOneTimeKey != null)
            {
                NativeLibsodium.crypto_kx_client_session_keys(ePOTK.publicKey, ePOTK.secretKey, ephemeralKeyPair.publicKey, ephemeralKeyPair.secretKey, publicOneTimeKey);
                NativeLibsodium.crypto_kx_client_session_keys(oPKPOTK.publicKey, oPKPOTK.secretKey, ownPreKeyPair.publicKey, ownPreKeyPair.secretKey, publicOneTimeKey);
            }
            NativeLibsodium.crypto_kx_client_session_keys(ePPK.publicKey, ePPK.secretKey, ephemeralKeyPair.publicKey, ephemeralKeyPair.secretKey, publicPreKey);
            NativeLibsodium.crypto_kx_client_session_keys(oPKPPK.publicKey, oPKPPK.secretKey, ownPreKeyPair.publicKey, ownPreKeyPair.secretKey, publicPreKey);

            DeriveSessionKeys(ePPK, oPKPPK, oPKPOTK, ePOTK);
            return(true);
        }
Exemplo n.º 3
0
 public void ComputeKeysClient()
 {
     NativeLibsodium.crypto_kx_client_session_keys(sessionReceiveKey, sessionSendKey, ownIdentKeyPair.publicKey, ownIdentKeyPair.secretKey, publicIdentKey);
 }
Exemplo n.º 4
0
 public override void DeriveClientSessionKeys(byte[] data, KeyPair ownKeyPair)
 {
     NativeLibsodium.crypto_kx_client_session_keys(sessionReceiveKey, sessionSendKey, ownKeyPair.publicKey, ownKeyPair.secretKey, data);
 }