Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- } else if(ctl==RSA_SETUP){
- size_t rsa_len = len - 1;
- uint8_t e_buf[rsa_len];
- console_insert_line("generating secrets.", MSG_NORMAL);
- csrand_fill(secrets, sizeof secrets);
- console_insert_line("rsa encrypting secrets.", MSG_NORMAL);
- rsa_encrypt(secrets, sizeof secrets, e_buf, pkt_content, rsa_len, SHA256);
- console_insert_line("sending secrets.", MSG_NORMAL);
- inet_send_packet(1, AES_SECRET_ACK, e_buf, rsa_len);
- } else if(ctl==AES_SECRET_ACK){
- console_insert_line("encrypting user token.", MSG_NORMAL);
- size_t username_len = strlen(username);
- uint8_t pt[TOKEN_LEN + username_len];
- uint8_t ct[TOKEN_LEN + username_len];
- uint8_t iv[AES_IVSIZE];
- uint8_t hmac_digest[SHA256_DIGEST_LEN];
- hmac_ctx hmac;
- aes_ctx aes;
- memcpy(pt, token, TOKEN_LEN);
- strncpy(&pt[TOKEN_LEN], username, USERNAME_MAX_LEN);
- csrand_fill(iv, sizeof iv);
- aes_init(&aes, secrets, AES_SECRET_LEN, iv, AES_MODE_CTR);
- aes_encrypt(&aes, pt, sizeof pt, ct);
- hmac_init(&hmac, &secrets[AES_SECRET_LEN], HMAC_SECRET_LEN, SHA256);
- hmac_update(&hmac, iv, sizeof iv);
- hmac_update(&hmac, ct, sizeof ct);
- hmac_final(&hmac, hmac_digest);
- inet_send_packet(3, LOGIN,
- iv, sizeof iv,
- ct, sizeof ct,
- hmac_digest, sizeof hmac_digest);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement