Exemple #1
0
 //Make these private
 private byte[] GetEncryptedPublicKey(byte[] key, UInt64 counter)
 {
     return(Utility.AESGetEncrypt(key, GetPublicKeyMpiBytes(), counter));
 }
Exemple #2
0
        private void ComputeSignatureValues(AKEKeys ake_keys, byte[] x_byte_array_data, UInt64 aes_counter, bool is_top_half_keys)
        {
            if (ake_keys == null)
            {
                throw new ArgumentException("ComputeSignatureValues: AKE keys object should not be null");
            }


            if (is_top_half_keys == true && (ake_keys.GetAESKey1() == null || ake_keys.GetAESKey1().Length < 1))
            {
                throw new ArgumentException("ComputeSignatureValues: The AKE AES key 1 should not be null/empty");
            }

            if (is_top_half_keys == false && (ake_keys.GetAESKey2() == null || ake_keys.GetAESKey2().Length < 1))
            {
                throw new ArgumentException("ComputeSignatureValues: The AKE AES key 2 should not be null/empty");
            }



            if (x_byte_array_data == null || x_byte_array_data.Length < 1)
            {
                throw new ArgumentException("ComputeSignatureValues: The x_byte_array_data cannot be null/empty");
            }

            if (aes_counter < 0)
            {
                throw new ArgumentException("ComputeSignatureValues: The aes counter value cannot be less than zero");
            }


            byte[] _encrypted_signature_byte_array = null;

            if (is_top_half_keys == true)
            {
                _encrypted_signature_byte_array = Utility.AESGetEncrypt(ake_keys.GetAESKey1(), x_byte_array_data, aes_counter);
            }
            else
            {
                _encrypted_signature_byte_array = Utility.AESGetEncrypt(ake_keys.GetAESKey2(), x_byte_array_data, aes_counter);
            }


            try
            {
                Utility.EncodeOTRDataBE(_encrypted_signature_byte_array, ref _encoded_encrypted_signature_byte_array);
            }
            catch (Exception ex)
            {
                throw new InvalidDataException("ComputeSignatureValues:" + ex.ToString());
            }



            if (is_top_half_keys == true && (ake_keys.GetMACKey2() == null || ake_keys.GetMACKey2().Length < 1))
            {
                throw new InvalidDataException("ComputeSignatureValues: The AKE MAC key 2 should not be null/empty");
            }


            if (is_top_half_keys == false && (ake_keys.GetMACKey4() == null || ake_keys.GetMACKey4().Length < 1))
            {
                throw new InvalidDataException("ComputeSignatureValues: The AKE MAC key 4 should not be null/empty");
            }



            if (is_top_half_keys == true)
            {
                _hashed_encoded_encrypted_byte_array = Utility.SHA256GetKeyedHash(ake_keys.GetMACKey2(), _encoded_encrypted_signature_byte_array);
            }
            else
            {
                _hashed_encoded_encrypted_byte_array = Utility.SHA256GetKeyedHash(ake_keys.GetMACKey4(), _encoded_encrypted_signature_byte_array);
            }



            _truncated_hash_signature = new byte[OTRConstants.MAC_SIGNATURE_LENGTH_BITS / 8];


            Buffer.BlockCopy(_hashed_encoded_encrypted_byte_array, 0, _truncated_hash_signature, 0, _truncated_hash_signature.Length);
        }