A simple library to support serving https.

Dependents:   oldheating gps motorhome heating

Revision:
17:93feb2a51d58
Parent:
16:7eeb5f6626ad
Child:
18:e3cf22ba2a06
--- a/tls/tls-response.c	Sun Oct 06 08:00:30 2019 +0000
+++ b/tls/tls-response.c	Thu Oct 10 07:38:13 2019 +0000
@@ -8,7 +8,6 @@
 #include "log.h"
 #include "aes128.h"
 #include "random.h"
-#include "sha1.h"
 #include "tls-mac.h"
 #include "http.h"
 
@@ -35,7 +34,7 @@
     
     //Add the IV
     encryptIvPointer = p;
-    for (int i = 0; i < AES_BLOCKLEN; i++) *p++ = RandomGetByte();
+    for (int i = 0; i < TLS_LENGTH_CIPHER_BLOCK; i++) *p++ = RandomGetByte();
     
     encryptPayloadPointer = p;
     
@@ -48,7 +47,7 @@
     encryptPayloadSize = p - encryptPayloadPointer;
     
     //Add the MAC
-    TlsMacSha1(TLS_KEY_SIZE_MAC,
+    TlsMacSha1(TLS_LENGTH_MAC_KEY,
                pConnection->serverMacKey,
                pConnection->serverSequence,
                contentType,
@@ -57,7 +56,7 @@
                encryptPayloadSize,
                encryptPayloadPointer,
                p);
-    p += SHA1_HASH_SIZE;
+    p += TLS_LENGTH_MAC;
 
     *pp = p;
 }
@@ -66,7 +65,7 @@
 {
     uint8_t* p = *pp;
     
-    int paddingSize = AES_BLOCKLEN - 1 - (encryptPayloadSize + SHA1_HASH_SIZE + 1 - 1) % AES_BLOCKLEN;
+    int paddingSize = TLS_LENGTH_CIPHER_BLOCK - 1 - (encryptPayloadSize + TLS_LENGTH_MAC + 1 - 1) % TLS_LENGTH_CIPHER_BLOCK;
     LogF("- padding size %d\r\n", paddingSize);
     for (int i = 0; i < paddingSize; i++) *p++ = paddingSize;
     
@@ -112,7 +111,7 @@
     uint8_t* pSize = p;
     p += 2;
     *p++ = 0x03; *p++ = 0x03;
-    for (int i = 0; i < 32; i++)
+    for (int i = 0; i < TLS_LENGTH_RANDOM; i++)
     {
         uint8_t r = RandomGetByte();
         pConnection->serverRandom[i] = r;
@@ -166,15 +165,15 @@
     *p++ = TLS_HANDSHAKE_FINISHED;
     *p++ = 0x00;
     *p++ = 0x00;
-    *p++ = 0x0c; //Length 12
+    *p++ = TLS_LENGTH_VERIFY; //Length 12
     
     //Hash over all handshake payloads exchanged so far
-    uint8_t hash[32];
+    uint8_t hash[SHA256_HASH_SIZE];
     Sha256Finish(&pConnection->handshakeSha, hash);
     
     //Make verify data
     TlsPrfServerFinished(pSession->masterSecret, hash, p);    //Hash over all handshakes
-    p += 12;
+    p += TLS_LENGTH_VERIFY;
     
     encryptAddMac    (&p, pConnection, TLS_CONTENT_TYPE_HANDSHAKE);
     encryptAddPadding(&p);