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; }
private void AddOldMacKeys(DataExchangeKeys old_data_exchange_keys) { if (old_data_exchange_keys == null) return; _old_rx_mac_keys.Add(old_data_exchange_keys.GetMACKeyRecv()); _old_rx_mac_keys.Add(old_data_exchange_keys.GetMACKeySend()); }
public DataExchangeKeys GetDataExchangeKeys() { _data_exchange_keys_holder = _recent_data_exchange_keys; _recent_data_exchange_keys = _data_exhange_key_manager. ComputeKeys(_my_recent_dh_key_pair, _my_buddy_recent_dh_public_key); _counter++; if (_data_exchange_keys_holder != _recent_data_exchange_keys) { _old_data_exchange_keys = _data_exchange_keys_holder; _data_exchange_keys_holder = null; AddOldMacKeys(_old_data_exchange_keys); } return _recent_data_exchange_keys; }