Beispiel #1
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;
        }
Beispiel #2
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;
        }
        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;
        }
Beispiel #4
0
        public static BigInteger ComputeSecret(DHKeyPair my_key_pair, BigInteger public_key, BigInteger generator, BigInteger prime_modulo)
        {
            if (my_key_pair == null)
                throw new ArgumentException("ComputeSecret:  My Key Pair cannot be null");

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

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

            if (generator < 1)
                throw new ArgumentException("ComputeSecret: Generator value cannot be less than 0");

            if (prime_modulo < 1)
                throw new ArgumentException("ComputeSecret: Prime Modulo value cannot be less than 0");

            return BigInteger.ModPow(public_key, my_key_pair.GetPrivateKey(), prime_modulo);
        }