Exemple #1
0
        public DHKeyPair GenerateKeyPair()
        {
            key_serial++;

            DHKeyPair _key_pair = new DHKeyPair(key_serial);

            _key_pair.SetPrivateKey(Utility.GetRandBigInt(OTRConstants.DH_PRIVATE_KEY_MINIMUM_LENGTH_BITS));
            _key_pair.SetPublicKey(BigInteger.ModPow(OTRConstants.RFC_3526_GENERATOR, _key_pair.GetPrivateKey(), OTRConstants.RFC_3526_PRIME_MODULO()));

            return(_key_pair);
        }
Exemple #2
0
        public DataExchangeKeys ComputeKeys(DHKeyPair my_key_pair, BigInteger buddy_public_key)
        {
            if (Utility.IsValidPublicKey(buddy_public_key) == false)
            {
                throw new ArgumentException("DataExchangeKeysManager:Buddy public key is invalid");
            }


            if (my_key_pair == null)
            {
                throw new ArgumentException("DataExchangeKeysManager:  My Key Pair cannot be null");
            }

            if (my_key_pair.GetPrivateKey() < 1)
            {
                throw new ArgumentException("DataExchangeKeysManager: Private key in my_key_pair value cannot be less than 0");
            }

            if (buddy_public_key < 1)
            {
                throw new ArgumentException("DataExchangeKeysManager: Buddy public key value cannot be less than 0");
            }



            if (my_key_pair.GetPublicKey() > buddy_public_key)
            {
                _end_type  = OTR_END_TYPE.HIGH_END;
                _send_byte = OTRConstants.HIGH_END_SEND_BYTE_VALUE;
                _recv_byte = OTRConstants.HIGH_END_RECV_BYTE_VALUE;
            }
            else
            {
                _end_type  = OTR_END_TYPE.LOW_END;
                _send_byte = OTRConstants.LOW_END_SEND_BYTE_VALUE;
                _recv_byte = OTRConstants.LOW_END_RECV_BYTE_VALUE;
            }



            _data_exchange_keys = new DataExchangeKeys();
            _data_exchange_keys.SetEndType(_end_type);


            _secret = Utility.ComputeSecret(my_key_pair, buddy_public_key, OTRConstants.RFC_3526_GENERATOR, OTRConstants.RFC_3526_PRIME_MODULO());

            Utility.SetSecByteMpi(_secret, ref _sec_data_byte_array_mpi);


            _data_exchange_keys.SetSecData(_sec_data_byte_array_mpi);


            ComputeSendKeys();
            ComputeRecvKeys();
            ComputeAesExtraKey();

            return(_data_exchange_keys);
        }
Exemple #3
0
        public AKEKeys ComputeKeys(DHKeyPair my_key_pair, BigInteger public_key)
        {
            if (Utility.IsValidPublicKey(public_key) == false)
            {
                throw new ArgumentException("AKEKeysManager:Public key is invalid");
            }


            if (my_key_pair == null)
            {
                throw new ArgumentException("AKEKeysManager:  My Key Pair cannot be null");
            }

            if (my_key_pair.GetPrivateKey() < 1)
            {
                throw new ArgumentException("AKEKeysManager: Private key in my_key_pair value cannot be less than 0");
            }

            if (public_key < 1)
            {
                throw new ArgumentException("AKEKeysManager: Public key value cannot be less than 0");
            }



            _ake_keys = new AKEKeys();


            _secret = Utility.ComputeSecret(my_key_pair, public_key, OTRConstants.RFC_3526_GENERATOR, OTRConstants.RFC_3526_PRIME_MODULO());

            Utility.SetSecByteMpi(_secret, ref _sec_data_byte_array_mpi);

            _ake_keys.SetSecData(_sec_data_byte_array_mpi);

            ComputeSessionIDByte();
            ComputeEncryptionKeysBytes();
            ComputeMACKeysBytes();



            return(_ake_keys);
        }