Exemple #1
0
        private static byte[] ComputeX(DSASigner dsa_signer, byte[] dsa_public_key_bytes_encoded, byte[] key_id_byte_array, byte[] hashed_m_byte_array_data)
        {
            if (key_id_byte_array == null || key_id_byte_array.Length < 1)
            {
                throw new ArgumentException("ComputeX: The key id byte array should not be null/empty");
            }


            if (hashed_m_byte_array_data == null || hashed_m_byte_array_data.Length < 1)
            {
                throw new ArgumentException("ComputeX: The hashed m byte array should not be null/empty");
            }

            if (dsa_signer == null)
            {
                throw new ArgumentException("ComputeX: DSA signer object cannot be null");
            }


            byte[] _signature_r_byte_array = null;
            byte[] _signature_s_byte_array = null;

            dsa_signer.GenerateSignature(hashed_m_byte_array_data, ref _signature_r_byte_array, ref _signature_s_byte_array);

            if (_signature_r_byte_array == null || _signature_r_byte_array.Length < 1)
            {
                throw new InvalidDataException("ComputeX: The computed DSA signature parameter 'r' byte array cannot be null/empty");
            }

            if (_signature_s_byte_array == null || _signature_s_byte_array.Length < 1)
            {
                throw new InvalidDataException("ComputeX: The computed DSA signature parameter 's' byte array cannot be null/empty");
            }



            byte[] _hashed_m_data_signature   = null;
            byte[] _encoded_key_id_byte_array = null;



            try
            {
                byte[] _encoded_signature_r_byte_array = null;
                byte[] _encoded_signature_s_byte_array = null;

                /* This is unnecessary. It's just here to complement DecodeMacfromBytes used in IsEncryptedSignatureVerified().
                 * It should be removed if performance becomes an issue. */
                Utility.EncodeOTRMacBE(_signature_r_byte_array, ref _encoded_signature_r_byte_array);
                Utility.EncodeOTRMacBE(_signature_s_byte_array, ref _encoded_signature_s_byte_array);



                if (_encoded_signature_r_byte_array == null || _encoded_signature_r_byte_array.Length < 1)
                {
                    throw new InvalidDataException("ComputeX: The encoded DSA signature parameter 'r' byte array cannot be null/empty");
                }

                if (_encoded_signature_s_byte_array == null || _encoded_signature_s_byte_array.Length < 1)
                {
                    throw new InvalidDataException("ComputeX: The encoded DSA signature parameter 's' byte array cannot be null/empty");
                }


                _hashed_m_data_signature = new byte[_encoded_signature_r_byte_array.Length + _encoded_signature_s_byte_array.Length];

                Buffer.BlockCopy(_encoded_signature_r_byte_array, 0, _hashed_m_data_signature, 0, _encoded_signature_r_byte_array.Length);
                Buffer.BlockCopy(_encoded_signature_s_byte_array, 0, _hashed_m_data_signature, _encoded_signature_r_byte_array.Length, _encoded_signature_s_byte_array.Length);


                Utility.EncodeOTRInt(key_id_byte_array, ref _encoded_key_id_byte_array);
            }
            catch (Exception ex)
            {
                throw new InvalidDataException("ComputeX:" + ex.ToString());
            }



            if (_encoded_key_id_byte_array == null || _encoded_key_id_byte_array.Length < 1)
            {
                throw new InvalidDataException("ComputeX: The encoded key id byte array should not be null/empty");
            }



            int _x_data_array_length = _encoded_key_id_byte_array.Length + dsa_public_key_bytes_encoded.Length + _hashed_m_data_signature.Length;


            byte[] _x_data_array = new byte[_x_data_array_length];

            Buffer.BlockCopy(dsa_public_key_bytes_encoded, 0, _x_data_array, 0, dsa_public_key_bytes_encoded.Length);
            Buffer.BlockCopy(_encoded_key_id_byte_array, 0, _x_data_array, dsa_public_key_bytes_encoded.Length, _encoded_key_id_byte_array.Length);
            Buffer.BlockCopy(_hashed_m_data_signature, 0, _x_data_array, dsa_public_key_bytes_encoded.Length + _encoded_key_id_byte_array.Length, _hashed_m_data_signature.Length);



            return(_x_data_array);
        }