Added buffer length when calling encrypt/decrypt. Write the extra two bytes.
Replacing http://review.webrtc.org/893004/. BUG=934 TEST=Run ViE Autotest Encryption with Valgrind. Review URL: https://webrtc-codereview.appspot.com/901006 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2938 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
443df96c8e
commit
34e83b8e8d
@ -31,45 +31,53 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
virtual void encrypt(int channel_no, unsigned char * in_data,
|
||||
unsigned char * out_data, int bytes_in, int* bytes_out)
|
||||
virtual void encrypt(int channel_no, unsigned char* in_data,
|
||||
unsigned char* out_data, int bytes_in, int* bytes_out)
|
||||
{
|
||||
for (int i = 0; i < bytes_in; i++)
|
||||
{
|
||||
out_data[i] = ~in_data[i];
|
||||
}
|
||||
assert(*bytes_out >= bytes_in + 2);
|
||||
*bytes_out = bytes_in + 2;
|
||||
out_data[bytes_in] = 'a';
|
||||
out_data[bytes_in + 1] = 'b';
|
||||
}
|
||||
|
||||
virtual void decrypt(int channel_no, unsigned char * in_data,
|
||||
unsigned char * out_data, int bytes_in, int* bytes_out)
|
||||
virtual void decrypt(int channel_no, unsigned char* in_data,
|
||||
unsigned char* out_data, int bytes_in, int* bytes_out)
|
||||
{
|
||||
for (int i = 0; i < bytes_in - 2; i++)
|
||||
{
|
||||
out_data[i] = ~in_data[i];
|
||||
}
|
||||
assert(*bytes_out >= bytes_in - 2);
|
||||
*bytes_out = bytes_in - 2;
|
||||
}
|
||||
|
||||
virtual void encrypt_rtcp(int channel_no, unsigned char * in_data,
|
||||
unsigned char * out_data, int bytes_in,
|
||||
virtual void encrypt_rtcp(int channel_no, unsigned char* in_data,
|
||||
unsigned char* out_data, int bytes_in,
|
||||
int* bytes_out)
|
||||
{
|
||||
for (int i = 0; i < bytes_in; i++)
|
||||
{
|
||||
out_data[i] = ~in_data[i];
|
||||
}
|
||||
assert(*bytes_out >= bytes_in + 2);
|
||||
*bytes_out = bytes_in + 2;
|
||||
out_data[bytes_in] = 'a';
|
||||
out_data[bytes_in + 1] = 'b';
|
||||
}
|
||||
|
||||
virtual void decrypt_rtcp(int channel_no, unsigned char * in_data,
|
||||
unsigned char * out_data, int bytes_in,
|
||||
virtual void decrypt_rtcp(int channel_no, unsigned char* in_data,
|
||||
unsigned char* out_data, int bytes_in,
|
||||
int* bytes_out)
|
||||
{
|
||||
for (int i = 0; i < bytes_in - 2; i++)
|
||||
{
|
||||
out_data[i] = ~in_data[i];
|
||||
}
|
||||
assert(*bytes_out >= bytes_in - 2);
|
||||
*bytes_out = bytes_in - 2;
|
||||
}
|
||||
};
|
||||
|
@ -164,7 +164,7 @@ int ViEReceiver::InsertRTPPacket(const WebRtc_Word8* rtp_packet,
|
||||
CriticalSectionScoped cs(receive_cs_.get());
|
||||
|
||||
if (external_decryption_) {
|
||||
int decrypted_length = 0;
|
||||
int decrypted_length = kViEMaxMtu;
|
||||
external_decryption_->decrypt(channel_id_, received_packet,
|
||||
decryption_buffer_, received_packet_length,
|
||||
&decrypted_length);
|
||||
@ -202,7 +202,7 @@ int ViEReceiver::InsertRTCPPacket(const WebRtc_Word8* rtcp_packet,
|
||||
CriticalSectionScoped cs(receive_cs_.get());
|
||||
|
||||
if (external_decryption_) {
|
||||
int decrypted_length = 0;
|
||||
int decrypted_length = kViEMaxMtu;
|
||||
external_decryption_->decrypt_rtcp(channel_id_, received_packet,
|
||||
decryption_buffer_,
|
||||
received_packet_length,
|
||||
|
@ -137,6 +137,8 @@ int ViESender::SendPacket(int vie_id, const void* data, int len) {
|
||||
// TODO(mflodman) Change decrypt to get rid of this cast.
|
||||
void* tmp_ptr = const_cast<void*>(data);
|
||||
unsigned char* send_packet = static_cast<unsigned char*>(tmp_ptr);
|
||||
|
||||
// Data length for packets sent to possible encryption and to the transport.
|
||||
int send_packet_length = len;
|
||||
|
||||
if (rtp_dump_) {
|
||||
@ -144,10 +146,13 @@ int ViESender::SendPacket(int vie_id, const void* data, int len) {
|
||||
}
|
||||
|
||||
if (external_encryption_) {
|
||||
external_encryption_->encrypt(channel_id_, send_packet,
|
||||
encryption_buffer_, send_packet_length,
|
||||
static_cast<int*>(&send_packet_length));
|
||||
// Encryption buffer size.
|
||||
int encrypted_packet_length = kViEMaxMtu;
|
||||
|
||||
external_encryption_->encrypt(channel_id_, send_packet, encryption_buffer_,
|
||||
send_packet_length, &encrypted_packet_length);
|
||||
send_packet = encryption_buffer_;
|
||||
send_packet_length = encrypted_packet_length;
|
||||
}
|
||||
const int bytes_sent = transport_->SendPacket(channel_id_, send_packet,
|
||||
send_packet_length);
|
||||
@ -171,6 +176,8 @@ int ViESender::SendRTCPPacket(int vie_id, const void* data, int len) {
|
||||
// TODO(mflodman) Change decrypt to get rid of this cast.
|
||||
void* tmp_ptr = const_cast<void*>(data);
|
||||
unsigned char* send_packet = static_cast<unsigned char*>(tmp_ptr);
|
||||
|
||||
// Data length for packets sent to possible encryption and to the transport.
|
||||
int send_packet_length = len;
|
||||
|
||||
if (rtp_dump_) {
|
||||
@ -178,10 +185,14 @@ int ViESender::SendRTCPPacket(int vie_id, const void* data, int len) {
|
||||
}
|
||||
|
||||
if (external_encryption_) {
|
||||
// Encryption buffer size.
|
||||
int encrypted_packet_length = kViEMaxMtu;
|
||||
|
||||
external_encryption_->encrypt_rtcp(
|
||||
channel_id_, send_packet, encryption_buffer_, send_packet_length,
|
||||
static_cast<int*>(&send_packet_length));
|
||||
&encrypted_packet_length);
|
||||
send_packet = encryption_buffer_;
|
||||
send_packet_length = encrypted_packet_length;
|
||||
}
|
||||
|
||||
const int bytes_sent = transport_->SendRTCPPacket(channel_id_, send_packet,
|
||||
|
Loading…
x
Reference in New Issue
Block a user