Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: oldheating gps motorhome heating
tls/tls-mac.c
- Committer:
- andrewboyson
- Date:
- 2019-09-11
- Revision:
- 9:f354b4859b0b
- Child:
- 17:93feb2a51d58
File content as of revision 9:f354b4859b0b:
#include <stdint.h>
#include "hmac-sha1.h"
/*
Calculate the MAC
seq_num + TLSCompressed.type + TLSCompressed.version + TLSCompressed.length + TLSCompressed.fragment
sequence='0000000000000000', rechdr='16 03 03', datalen='00 10'
*/
void TlsMacSha1(int macKeyLength,
uint8_t* macKey,
uint64_t sequence,
uint8_t contentType,
uint8_t versionH,
uint8_t versionL,
int payloadLength,
uint8_t* payload,
uint8_t* mac)
{
struct HmacSha1Struct md;
HmacSha1Start (&md, macKey, macKeyLength);
uint8_t prequel[8 + 5];
uint8_t *p = prequel;
for (int i = 0; i < 7; i++) *p++ = 0; //sequence
*p++ = sequence;
*p++ = contentType;
*p++ = versionH;
*p++ = versionL;
*p++ = payloadLength >> 8;
*p++ = payloadLength;
HmacSha1Add (&md, prequel, sizeof(prequel));
HmacSha1Add (&md, payload, payloadLength);
HmacSha1Finish(&md, mac);
}