Advertisement
AnthonyCagliano

Untitled

Nov 14th, 2022
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. } else if(ctl==RSA_SETUP){
  2. size_t rsa_len = len - 1;
  3. uint8_t e_buf[rsa_len];
  4. console_insert_line("generating secrets.", MSG_NORMAL);
  5. csrand_fill(secrets, sizeof secrets);
  6. console_insert_line("rsa encrypting secrets.", MSG_NORMAL);
  7. rsa_encrypt(secrets, sizeof secrets, e_buf, pkt_content, rsa_len, SHA256);
  8. console_insert_line("sending secrets.", MSG_NORMAL);
  9. inet_send_packet(1, AES_SECRET_ACK, e_buf, rsa_len);
  10.  
  11. } else if(ctl==AES_SECRET_ACK){
  12. console_insert_line("encrypting user token.", MSG_NORMAL);
  13. size_t username_len = strlen(username);
  14. uint8_t pt[TOKEN_LEN + username_len];
  15. uint8_t ct[TOKEN_LEN + username_len];
  16. uint8_t iv[AES_IVSIZE];
  17. uint8_t hmac_digest[SHA256_DIGEST_LEN];
  18. hmac_ctx hmac;
  19. aes_ctx aes;
  20.  
  21. memcpy(pt, token, TOKEN_LEN);
  22. strncpy(&pt[TOKEN_LEN], username, USERNAME_MAX_LEN);
  23.  
  24. csrand_fill(iv, sizeof iv);
  25. aes_init(&aes, secrets, AES_SECRET_LEN, iv, AES_MODE_CTR);
  26. aes_encrypt(&aes, pt, sizeof pt, ct);
  27.  
  28. hmac_init(&hmac, &secrets[AES_SECRET_LEN], HMAC_SECRET_LEN, SHA256);
  29. hmac_update(&hmac, iv, sizeof iv);
  30. hmac_update(&hmac, ct, sizeof ct);
  31. hmac_final(&hmac, hmac_digest);
  32.  
  33. inet_send_packet(3, LOGIN,
  34. iv, sizeof iv,
  35. ct, sizeof ct,
  36. hmac_digest, sizeof hmac_digest);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement