Skip to content

Commit e94d3e1

Browse files
committed
[core] Add auth tag to the sender buffer.
The additional space to be used for auth tag in GCM AEAD.
1 parent 6dd47c3 commit e94d3e1

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

srtcore/buffer_snd.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void CRateEstimator::updateInputRate(const time_point& time, int pkts, int bytes
162162
}
163163
}
164164

165-
CSndBuffer::CSndBuffer(int size, int maxpld)
165+
CSndBuffer::CSndBuffer(int size, int maxpld, int authtag)
166166
: m_BufLock()
167167
, m_pBlock(NULL)
168168
, m_pFirstBlock(NULL)
@@ -172,6 +172,7 @@ CSndBuffer::CSndBuffer(int size, int maxpld)
172172
, m_iNextMsgNo(1)
173173
, m_iSize(size)
174174
, m_iBlockLen(maxpld)
175+
, m_iAuthTagSize(authtag)
175176
, m_iCount(0)
176177
, m_iBytesCount(0)
177178
{
@@ -233,7 +234,7 @@ void CSndBuffer::addBuffer(const char* data, int len, SRT_MSGCTRL& w_mctrl)
233234
int32_t& w_seqno = w_mctrl.pktseq;
234235
int64_t& w_srctime = w_mctrl.srctime;
235236
const int& ttl = w_mctrl.msgttl;
236-
const int iPktLen = m_iBlockLen; // Payload length per packet.
237+
const int iPktLen = m_iBlockLen - m_iAuthTagSize; // Payload length per packet.
237238
int iNumBlocks = len / iPktLen;
238239
if ((len % m_iBlockLen) != 0)
239240
++iNumBlocks;
@@ -336,7 +337,7 @@ void CSndBuffer::addBuffer(const char* data, int len, SRT_MSGCTRL& w_mctrl)
336337

337338
int CSndBuffer::addBufferFromFile(fstream& ifs, int len)
338339
{
339-
const int iPktLen = m_iBlockLen; // Payload length per packet.
340+
const int iPktLen = m_iBlockLen - m_iAuthTagSize; // Payload length per packet.
340341
int iNumBlocks = len / iPktLen;
341342
if ((len % m_iBlockLen) != 0)
342343
++iNumBlocks;
@@ -416,7 +417,7 @@ int CSndBuffer::readData(CPacket& w_packet, steady_clock::time_point& w_srctime,
416417
// Make the packet REFLECT the data stored in the buffer.
417418
w_packet.m_pcData = m_pCurrBlock->m_pcData;
418419
readlen = m_pCurrBlock->m_iLength;
419-
w_packet.setLength(readlen);
420+
w_packet.setLength(readlen, m_iBlockLen);
420421
w_packet.m_iSeqNo = m_pCurrBlock->m_iSeqNo;
421422

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

590591
w_packet.m_pcData = p->m_pcData;
591592
const int readlen = p->m_iLength;
592-
w_packet.setLength(readlen);
593+
w_packet.setLength(readlen, m_iBlockLen);
593594

594595
// XXX Here the value predicted to be applied to PH_MSGNO field is extracted.
595596
// As this function is predicted to extract the data to send as a rexmited packet,

srtcore/buffer_snd.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,9 @@ class CSndBuffer
157157

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

164165
public:
@@ -259,7 +260,7 @@ class CSndBuffer
259260
struct Block
260261
{
261262
char* m_pcData; // pointer to the data block
262-
int m_iLength; // payload length of the block.
263+
int m_iLength; // payload length of the block (excluding auth tag).
263264

264265
int32_t m_iMsgNoBitset; // message number
265266
int32_t m_iSeqNo; // sequence number for scheduling
@@ -295,7 +296,8 @@ class CSndBuffer
295296
int32_t m_iNextMsgNo; // next message number
296297

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

301303
int m_iBytesCount; // number of payload bytes in queue

0 commit comments

Comments
 (0)