Advertisement
lewcpe

Arduino-Crypto-HMAC

Dec 7th, 2014
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.26 KB | None | 0 0
  1. #include <crypto.h>
  2.  
  3. int led = 13;
  4. //char * key = "0123456789012345678901234567890123456789012345678901234567890123"; //64 bytes
  5. uint8_t * key = (uint8_t *) "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C"
  6.                             "\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19"
  7.                             "\x1A\x1B\x1C\x1D\x1E\x1F !\"#$%&'()*+,-./0123456789:"
  8.                             ";<=>?";
  9.  
  10. hmac_sha1_ctx_t hctx;
  11. uint8_t mac[20];
  12.  
  13. // the setup routine runs once when you press reset:
  14. void setup() {                
  15.  
  16.   // initialize the digital pin as an output.
  17.   pinMode(led, OUTPUT);    
  18.   hmac_sha1_init(&hctx, key, 512);
  19.   hmac_sha1_lastBlock(&hctx, "Sample #1", 72);
  20.   hmac_sha1_final(mac, &hctx);
  21.   Serial.begin(9600);
  22.   while(!Serial);
  23.   Serial.println("Hohohoho");
  24.  
  25. }
  26.  
  27. // the loop routine runs over and over again forever:
  28. void loop() {
  29.   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  30.   delay(1000);               // wait for a second
  31.   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  32.   delay(1000);               // wait for a second
  33.   for(int c=0; c<20; c++){
  34.     Serial.print("0x");
  35.     Serial.print(mac[c], HEX);
  36.     Serial.print(" ");
  37.   }
  38.   Serial.println("");
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement