Andrew Boyson / crypto

Dependents:   oldheating gps motorhome heating

Revision:
19:f22327e8be7b
Parent:
17:93feb2a51d58
--- a/tls/tls-prf.c	Thu Oct 10 15:29:05 2019 +0000
+++ b/tls/tls-prf.c	Tue Oct 15 07:26:15 2019 +0000
@@ -4,6 +4,8 @@
 #include "prf.h"
 #include "tls-defs.h"
 #include "sha256.h"
+#include "sha1.h"
+#include "aes128cbc.h"
 
 void TlsPrfMasterSecret(uint8_t * preMasterSecret, uint8_t* clientRandom, uint8_t* serverRandom, uint8_t* masterSecret)
 {
@@ -19,10 +21,10 @@
     for (int i = 0; i < TLS_LENGTH_MASTER_SECRET; i++) masterSecret[i] = hash[i];                      //just take the first 48 bytes
 }
 
-void TlsPrfKeys(uint8_t * masterSecret, uint8_t* clientRandom, uint8_t* serverRandom, uint8_t* client_MAC_key,
-                                                                                      uint8_t* server_MAC_key,
-                                                                                      uint8_t* client_key,
-                                                                                      uint8_t* server_key)
+void TlsPrfKeysAes128Sha1(uint8_t * masterSecret, uint8_t* clientRandom, uint8_t* serverRandom, uint8_t* client_MAC_key,
+                                                                                                uint8_t* server_MAC_key,
+                                                                                                uint8_t* client_key,
+                                                                                                uint8_t* server_key)
 {
     const int SEED_LENGTH = 13 + TLS_LENGTH_RANDOM + TLS_LENGTH_RANDOM;
     uint8_t* seed = alloca(SEED_LENGTH);
@@ -33,10 +35,10 @@
     const int ITERATIONS = 4;
     uint8_t* hash = alloca(SHA256_HASH_SIZE * ITERATIONS);                                      //4 iterations of 32 bytes
     PrfHmacSha256(masterSecret, TLS_LENGTH_MASTER_SECRET, seed, SEED_LENGTH, ITERATIONS, hash); //4 iteration will generate the keys required
-    for (int i = 0; i < TLS_LENGTH_MAC_KEY;    i++) client_MAC_key[i] = hash[i                                                                  ];
-    for (int i = 0; i < TLS_LENGTH_MAC_KEY;    i++) server_MAC_key[i] = hash[i + TLS_LENGTH_MAC_KEY                                             ];
-    for (int i = 0; i < TLS_LENGTH_CIPHER_KEY; i++) client_key[i]     = hash[i + TLS_LENGTH_MAC_KEY + TLS_LENGTH_MAC_KEY                        ];
-    for (int i = 0; i < TLS_LENGTH_CIPHER_KEY; i++) server_key[i]     = hash[i + TLS_LENGTH_MAC_KEY + TLS_LENGTH_MAC_KEY + TLS_LENGTH_CIPHER_KEY];
+    for (int i = 0; i < SHA1_HASH_SIZE;       i++) client_MAC_key[i] = hash[i                                                         ];
+    for (int i = 0; i < SHA1_HASH_SIZE;       i++) server_MAC_key[i] = hash[i + SHA1_HASH_SIZE                                        ];
+    for (int i = 0; i < AES128CBC_BLOCK_SIZE; i++) client_key[i]     = hash[i + SHA1_HASH_SIZE + SHA1_HASH_SIZE                       ];
+    for (int i = 0; i < AES128CBC_BLOCK_SIZE; i++) server_key[i]     = hash[i + SHA1_HASH_SIZE + SHA1_HASH_SIZE + AES128CBC_BLOCK_SIZE];
 }
 
 void TlsPrfServerFinished(uint8_t * masterSecret, uint8_t* handshakeHash, uint8_t* verify)