 {
     if(CAN_MSGAVAIL == CAN.checkReceive())            // check if data coming
     {
+        // Read the actual message first
         id = CAN.getCanId(); // get CAN ID
-        CAN.readMsgBuf(&dlc, data);    // read data,  len: data length, buf: data buf        
-
-        PrintMessage();
-        TakeAction();
-    }
+        CAN.readMsgBuf(&dlc, data);    // read data,  len: data length, buf: data buf 
+
+        // Store the correct hash according to the received data
+        GetCorrectHash();
+
+        // Read in the Authentication messages and check if valid
+        if (Authenticate())
+        {
+            // It's valid, so take action
+            PrintMessage();
+            TakeAction();
+        }
+        else
+        {
+            // Invalid!
+            Serial.println("\n**UNAUTHORIZED MESSAGE**\n");
+        }
+    }
+}
+
+
+// Reads three CAN messages as authenticator messages
+bool Authenticate()
+{
+    // Fill the 3 msg buffers and check them as they are read in for efficiency
+    CAN.readMsgBuf(&dlc, msg1);
+    //if (!CheckAuthMessage(&msg1[0], 0, 8)) return false;
+    CAN.readMsgBuf(&dlc, msg2);
+    //if (!CheckAuthMessage(&msg2[0], 8, 8)) return false;
+    CAN.readMsgBuf(&dlc, msg3);
+    //if (!CheckAuthMessage(&msg3[0], 16, 4)) return false;
+    for(int i = 0; i < 8; i++)
+    {
+      Serial.print(msg1[i]);
+      Serial.print(".");
+    }
+    for(int i = 0; i < 8; i++)
+    {
+      Serial.print(msg2[i]);
+      Serial.print(".");
+    }
+    for(int i = 0; i < 4; i++)
+    {
+      Serial.print(msg3[i]);
+      Serial.print(".");
+    }
+    Serial.print('\n');
+    for(int i = 0; i < 20; i++)
+    {
+      Serial.print(correct_hash[i]);
+      Serial.print('.');
+    }
+    Serial.println('---------------------');
+    return true;
+}
+
+
+// Stores the correct hash in correcct_hash
+void GetCorrectHash()
+{
+    uint8_t keyLen;
+    uint8_t key[100];
+    GetKey(id, &key[0], keyLen); // get key and key length for this is
+    spritz_mac(&correct_hash[0], HASH_LEN, &data[0], dlc, key, keyLen); // create correct hash
+}
+
+
+// Checks an auth message against correct_hash
+bool CheckAuthMessage(uint8_t *buf, int start, int bufLen)
+{
+    for (int i = 0; i < bufLen; i++)
+    {
+      if (buf[i] != correct_hash[i + start])
+          return false;
+    }
+    return true;
 }
 
 

int redValue = 255;
int blueValue = 0;
int greenValue = 0;

void setup()
{


MCP_CAN CAN(SPI_CS_PIN);                                    // Set CS pin

uint8_t dlc = 0; // dlc
uint8_t data[8]; // data buffer
uint32_t id = 0; // CAN ID


// "Control Units" -- LED Lights to be controlled
