move ProtocolVersion struct members directly into RecordLayerHeader

This commit is contained in:
toddouska
2012-11-28 16:34:41 -08:00
parent 6280aa9c91
commit 6e4d33eb00
3 changed files with 26 additions and 24 deletions

View File

@@ -1279,7 +1279,8 @@ struct CYASSL_X509 {
/* record layer header for PlainText, Compressed, and CipherText */ /* record layer header for PlainText, Compressed, and CipherText */
typedef struct RecordLayerHeader { typedef struct RecordLayerHeader {
byte type; byte type;
ProtocolVersion version; byte pvMajor;
byte pvMinor;
byte length[2]; byte length[2];
} RecordLayerHeader; } RecordLayerHeader;
@@ -1287,7 +1288,8 @@ typedef struct RecordLayerHeader {
/* record layer header for DTLS PlainText, Compressed, and CipherText */ /* record layer header for DTLS PlainText, Compressed, and CipherText */
typedef struct DtlsRecordLayerHeader { typedef struct DtlsRecordLayerHeader {
byte type; byte type;
ProtocolVersion version; byte pvMajor;
byte pvMinor;
byte epoch[2]; /* increment on cipher state change */ byte epoch[2]; /* increment on cipher state change */
byte sequence_number[6]; /* per record */ byte sequence_number[6]; /* per record */
byte length[2]; byte length[2];

View File

@@ -1642,7 +1642,8 @@ static void AddRecordHeader(byte* output, word32 length, byte type, CYASSL* ssl)
/* record layer header */ /* record layer header */
rl = (RecordLayerHeader*)output; rl = (RecordLayerHeader*)output;
rl->type = type; rl->type = type;
rl->version = ssl->version; /* type and version same in each */ rl->pvMajor = ssl->version.major; /* type and version same in each */
rl->pvMinor = ssl->version.minor;
if (!ssl->options.dtls) if (!ssl->options.dtls)
c16toa((word16)length, rl->length); c16toa((word16)length, rl->length);
@@ -1944,9 +1945,7 @@ static int GetRecordHeader(CYASSL* ssl, const byte* input, word32* inOutIdx,
} }
/* catch version mismatch */ /* catch version mismatch */
if (rh->version.major != ssl->version.major || if (rh->pvMajor != ssl->version.major || rh->pvMinor != ssl->version.minor){
rh->version.minor != ssl->version.minor) {
if (ssl->options.side == SERVER_END && if (ssl->options.side == SERVER_END &&
ssl->options.acceptState == ACCEPT_BEGIN) ssl->options.acceptState == ACCEPT_BEGIN)
CYASSL_MSG("Client attempting to connect with different version"); CYASSL_MSG("Client attempting to connect with different version");
@@ -2975,8 +2974,8 @@ static INLINE int Decrypt(CYASSL* ssl, byte* plain, const byte* input,
c32toa(GetSEQIncrement(ssl, 1), additional + AEAD_SEQ_OFFSET); c32toa(GetSEQIncrement(ssl, 1), additional + AEAD_SEQ_OFFSET);
additional[AEAD_TYPE_OFFSET] = ssl->curRL.type; additional[AEAD_TYPE_OFFSET] = ssl->curRL.type;
additional[AEAD_VMAJ_OFFSET] = ssl->curRL.version.major; additional[AEAD_VMAJ_OFFSET] = ssl->curRL.pvMajor;
additional[AEAD_VMIN_OFFSET] = ssl->curRL.version.minor; additional[AEAD_VMIN_OFFSET] = ssl->curRL.pvMinor;
c16toa(sz - AES_GCM_EXP_IV_SZ - AEAD_AUTH_TAG_SZ, c16toa(sz - AES_GCM_EXP_IV_SZ - AEAD_AUTH_TAG_SZ,
additional + AEAD_LEN_OFFSET); additional + AEAD_LEN_OFFSET);
@@ -4190,7 +4189,8 @@ int SendAlert(CYASSL* ssl, int severity, int type)
else { else {
RecordLayerHeader *const rl = (RecordLayerHeader*)output; RecordLayerHeader *const rl = (RecordLayerHeader*)output;
rl->type = alert; rl->type = alert;
rl->version = ssl->version; rl->pvMajor = ssl->version.major;
rl->pvMinor = ssl->version.minor;
c16toa(ALERT_SIZE, rl->length); c16toa(ALERT_SIZE, rl->length);
XMEMCPY(output + RECORD_HEADER_SZ, input, ALERT_SIZE); XMEMCPY(output + RECORD_HEADER_SZ, input, ALERT_SIZE);
@@ -5208,7 +5208,7 @@ int SetCipherList(Suites* s, const char* list)
return SUITES_ERROR; return SUITES_ERROR;
} }
length = (word32)sizeof(ProtocolVersion) + RAN_LEN length = VERSION_SZ + RAN_LEN
+ idSz + ENUM_LEN + idSz + ENUM_LEN
+ ssl->suites->suiteSz + SUITE_LEN + ssl->suites->suiteSz + SUITE_LEN
+ COMP_LEN + ENUM_LEN; + COMP_LEN + ENUM_LEN;
@@ -5238,8 +5238,8 @@ int SetCipherList(Suites* s, const char* list)
AddHeaders(output, length, client_hello, ssl); AddHeaders(output, length, client_hello, ssl);
/* client hello, first version */ /* client hello, first version */
XMEMCPY(output + idx, &ssl->version, sizeof(ProtocolVersion)); output[idx++] = ssl->version.major;
idx += (int)sizeof(ProtocolVersion); output[idx++] = ssl->version.minor;
ssl->chVersion = ssl->version; /* store in case changed */ ssl->chVersion = ssl->version; /* store in case changed */
/* then random */ /* then random */
@@ -6133,7 +6133,7 @@ int SetCipherList(Suites* s, const char* list)
int sendSz; int sendSz;
int ret; int ret;
length = sizeof(ProtocolVersion) + RAN_LEN length = VERSION_SZ + RAN_LEN
+ ID_LEN + ENUM_LEN + ID_LEN + ENUM_LEN
+ SUITE_LEN + SUITE_LEN
+ ENUM_LEN; + ENUM_LEN;
@@ -6157,8 +6157,8 @@ int SetCipherList(Suites* s, const char* list)
#endif #endif
/* now write to output */ /* now write to output */
/* first version */ /* first version */
XMEMCPY(output + idx, &ssl->version, sizeof(ProtocolVersion)); output[idx++] = ssl->version.major;
idx += (word32)sizeof(ProtocolVersion); output[idx++] = ssl->version.minor;
/* then random */ /* then random */
if (!ssl->options.resuming) if (!ssl->options.resuming)
@@ -7603,8 +7603,8 @@ int SetCipherList(Suites* s, const char* list)
AddHeaders(output, length, hello_verify_request, ssl); AddHeaders(output, length, hello_verify_request, ssl);
XMEMCPY(output + idx, &ssl->chVersion, VERSION_SZ); output[idx++] = ssl->chVersion.major;
idx += VERSION_SZ; output[idx++] = ssl->chVersion.minor;
output[idx++] = cookieSz; output[idx++] = cookieSz;
if ((ret = EmbedGenerateCookie(output + idx, cookieSz, ssl)) < 0) if ((ret = EmbedGenerateCookie(output + idx, cookieSz, ssl)) < 0)

View File

@@ -1148,7 +1148,7 @@ static int ProcessServerHello(const byte* input, int* sslBytes,
{ {
ProtocolVersion pv; ProtocolVersion pv;
byte b; byte b;
int toRead = sizeof(ProtocolVersion) + RAN_LEN + ENUM_LEN; int toRead = VERSION_SZ + RAN_LEN + ENUM_LEN;
int doResume = 0; int doResume = 0;
/* make sure we didn't miss ClientHello */ /* make sure we didn't miss ClientHello */
@@ -1163,9 +1163,9 @@ static int ProcessServerHello(const byte* input, int* sslBytes,
return -1; return -1;
} }
XMEMCPY(&pv, input, sizeof(ProtocolVersion)); XMEMCPY(&pv, input, VERSION_SZ);
input += sizeof(ProtocolVersion); input += VERSION_SZ;
*sslBytes -= (int)sizeof(ProtocolVersion); *sslBytes -= VERSION_SZ;
session->sslServer->version = pv; session->sslServer->version = pv;
session->sslClient->version = pv; session->sslClient->version = pv;
@@ -1278,7 +1278,7 @@ static int ProcessClientHello(const byte* input, int* sslBytes,
{ {
byte bLen; byte bLen;
word16 len; word16 len;
int toRead = sizeof(ProtocolVersion) + RAN_LEN + ENUM_LEN; int toRead = VERSION_SZ + RAN_LEN + ENUM_LEN;
session->flags.clientHello = 1; /* don't process again */ session->flags.clientHello = 1; /* don't process again */
@@ -1289,8 +1289,8 @@ static int ProcessClientHello(const byte* input, int* sslBytes,
} }
/* skip, get negotiated one from server hello */ /* skip, get negotiated one from server hello */
input += sizeof(ProtocolVersion); input += VERSION_SZ;
*sslBytes -= (int)sizeof(ProtocolVersion); *sslBytes -= VERSION_SZ;
XMEMCPY(session->sslServer->arrays->clientRandom, input, RAN_LEN); XMEMCPY(session->sslServer->arrays->clientRandom, input, RAN_LEN);
XMEMCPY(session->sslClient->arrays->clientRandom, input, RAN_LEN); XMEMCPY(session->sslClient->arrays->clientRandom, input, RAN_LEN);