Skip to content

Commit

Permalink
[core] Add auth tag to the sender buffer.
Browse files Browse the repository at this point in the history
The additional space to be used for auth tag in GCM AEAD.
  • Loading branch information
maxsharabayko committed Sep 30, 2022
1 parent 6dd47c3 commit e94d3e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
11 changes: 6 additions & 5 deletions srtcore/buffer_snd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void CRateEstimator::updateInputRate(const time_point& time, int pkts, int bytes
}
}

CSndBuffer::CSndBuffer(int size, int maxpld)
CSndBuffer::CSndBuffer(int size, int maxpld, int authtag)
: m_BufLock()
, m_pBlock(NULL)
, m_pFirstBlock(NULL)
Expand All @@ -172,6 +172,7 @@ CSndBuffer::CSndBuffer(int size, int maxpld)
, m_iNextMsgNo(1)
, m_iSize(size)
, m_iBlockLen(maxpld)
, m_iAuthTagSize(authtag)
, m_iCount(0)
, m_iBytesCount(0)
{
Expand Down Expand Up @@ -233,7 +234,7 @@ void CSndBuffer::addBuffer(const char* data, int len, SRT_MSGCTRL& w_mctrl)
int32_t& w_seqno = w_mctrl.pktseq;
int64_t& w_srctime = w_mctrl.srctime;
const int& ttl = w_mctrl.msgttl;
const int iPktLen = m_iBlockLen; // Payload length per packet.
const int iPktLen = m_iBlockLen - m_iAuthTagSize; // Payload length per packet.
int iNumBlocks = len / iPktLen;
if ((len % m_iBlockLen) != 0)
++iNumBlocks;
Expand Down Expand Up @@ -336,7 +337,7 @@ void CSndBuffer::addBuffer(const char* data, int len, SRT_MSGCTRL& w_mctrl)

int CSndBuffer::addBufferFromFile(fstream& ifs, int len)
{
const int iPktLen = m_iBlockLen; // Payload length per packet.
const int iPktLen = m_iBlockLen - m_iAuthTagSize; // Payload length per packet.
int iNumBlocks = len / iPktLen;
if ((len % m_iBlockLen) != 0)
++iNumBlocks;
Expand Down Expand Up @@ -416,7 +417,7 @@ int CSndBuffer::readData(CPacket& w_packet, steady_clock::time_point& w_srctime,
// Make the packet REFLECT the data stored in the buffer.
w_packet.m_pcData = m_pCurrBlock->m_pcData;
readlen = m_pCurrBlock->m_iLength;
w_packet.setLength(readlen);
w_packet.setLength(readlen, m_iBlockLen);
w_packet.m_iSeqNo = m_pCurrBlock->m_iSeqNo;

// 1. On submission (addBuffer), the KK flag is set to EK_NOENC (0).
Expand Down Expand Up @@ -589,7 +590,7 @@ int CSndBuffer::readData(const int offset, CPacket& w_packet, steady_clock::time

w_packet.m_pcData = p->m_pcData;
const int readlen = p->m_iLength;
w_packet.setLength(readlen);
w_packet.setLength(readlen, m_iBlockLen);

// XXX Here the value predicted to be applied to PH_MSGNO field is extracted.
// As this function is predicted to extract the data to send as a rexmited packet,
Expand Down
10 changes: 6 additions & 4 deletions srtcore/buffer_snd.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ class CSndBuffer

/// @brief CSndBuffer constructor.
/// @param size initial number of blocks (each block to store one packet payload).
/// @param maxpld maximum packet payload.
CSndBuffer(int size = 32, int maxpld = 1500);
/// @param maxpld maximum packet payload (including auth tag).
/// @param authtag auth tag length in bytes (16 for GCM, 0 otherwise).
CSndBuffer(int size = 32, int maxpld = 1500, int authtag = 0);
~CSndBuffer();

public:
Expand Down Expand Up @@ -259,7 +260,7 @@ class CSndBuffer
struct Block
{
char* m_pcData; // pointer to the data block
int m_iLength; // payload length of the block.
int m_iLength; // payload length of the block (excluding auth tag).

int32_t m_iMsgNoBitset; // message number
int32_t m_iSeqNo; // sequence number for scheduling
Expand Down Expand Up @@ -295,7 +296,8 @@ class CSndBuffer
int32_t m_iNextMsgNo; // next message number

int m_iSize; // buffer size (number of packets)
const int m_iBlockLen; // maximum length of a block holding packet payload (excluding packet header).
const int m_iBlockLen; // maximum length of a block holding packet payload and AUTH tag (excluding packet header).
const int m_iAuthTagSize; // Authentication tag size (if GCM is enabled).
int m_iCount; // number of used blocks

int m_iBytesCount; // number of payload bytes in queue
Expand Down

0 comments on commit e94d3e1

Please sign in to comment.