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@17:93feb2a51d58, 2019-10-10 (annotated)
- Committer:
- andrewboyson
- Date:
- Thu Oct 10 07:38:13 2019 +0000
- Revision:
- 17:93feb2a51d58
- Parent:
- 9:f354b4859b0b
Defined a lot of lengths eg 20 -> SHA1_HASH_LENGTH
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| andrewboyson | 9:f354b4859b0b | 1 | #include <stdint.h> |
| andrewboyson | 9:f354b4859b0b | 2 | #include "hmac-sha1.h" |
| andrewboyson | 9:f354b4859b0b | 3 | |
| andrewboyson | 9:f354b4859b0b | 4 | /* |
| andrewboyson | 9:f354b4859b0b | 5 | Calculate the MAC |
| andrewboyson | 9:f354b4859b0b | 6 | seq_num + TLSCompressed.type + TLSCompressed.version + TLSCompressed.length + TLSCompressed.fragment |
| andrewboyson | 9:f354b4859b0b | 7 | sequence='0000000000000000', rechdr='16 03 03', datalen='00 10' |
| andrewboyson | 9:f354b4859b0b | 8 | */ |
| andrewboyson | 9:f354b4859b0b | 9 | |
| andrewboyson | 9:f354b4859b0b | 10 | void TlsMacSha1(int macKeyLength, |
| andrewboyson | 9:f354b4859b0b | 11 | uint8_t* macKey, |
| andrewboyson | 9:f354b4859b0b | 12 | uint64_t sequence, |
| andrewboyson | 9:f354b4859b0b | 13 | uint8_t contentType, |
| andrewboyson | 9:f354b4859b0b | 14 | uint8_t versionH, |
| andrewboyson | 9:f354b4859b0b | 15 | uint8_t versionL, |
| andrewboyson | 9:f354b4859b0b | 16 | int payloadLength, |
| andrewboyson | 9:f354b4859b0b | 17 | uint8_t* payload, |
| andrewboyson | 9:f354b4859b0b | 18 | uint8_t* mac) |
| andrewboyson | 9:f354b4859b0b | 19 | { |
| andrewboyson | 9:f354b4859b0b | 20 | struct HmacSha1Struct md; |
| andrewboyson | 9:f354b4859b0b | 21 | HmacSha1Start (&md, macKey, macKeyLength); |
| andrewboyson | 9:f354b4859b0b | 22 | uint8_t prequel[8 + 5]; |
| andrewboyson | 9:f354b4859b0b | 23 | uint8_t *p = prequel; |
| andrewboyson | 17:93feb2a51d58 | 24 | *p++ = sequence >> 56; |
| andrewboyson | 17:93feb2a51d58 | 25 | *p++ = sequence >> 48; |
| andrewboyson | 17:93feb2a51d58 | 26 | *p++ = sequence >> 40; |
| andrewboyson | 17:93feb2a51d58 | 27 | *p++ = sequence >> 32; |
| andrewboyson | 17:93feb2a51d58 | 28 | *p++ = sequence >> 24; |
| andrewboyson | 17:93feb2a51d58 | 29 | *p++ = sequence >> 16; |
| andrewboyson | 17:93feb2a51d58 | 30 | *p++ = sequence >> 8; |
| andrewboyson | 17:93feb2a51d58 | 31 | *p++ = sequence >> 0; |
| andrewboyson | 9:f354b4859b0b | 32 | *p++ = contentType; |
| andrewboyson | 9:f354b4859b0b | 33 | *p++ = versionH; |
| andrewboyson | 9:f354b4859b0b | 34 | *p++ = versionL; |
| andrewboyson | 9:f354b4859b0b | 35 | *p++ = payloadLength >> 8; |
| andrewboyson | 9:f354b4859b0b | 36 | *p++ = payloadLength; |
| andrewboyson | 9:f354b4859b0b | 37 | HmacSha1Add (&md, prequel, sizeof(prequel)); |
| andrewboyson | 9:f354b4859b0b | 38 | HmacSha1Add (&md, payload, payloadLength); |
| andrewboyson | 9:f354b4859b0b | 39 | HmacSha1Finish(&md, mac); |
| andrewboyson | 9:f354b4859b0b | 40 | } |