[airplay] Update pairing, fix compiler complain about const initialization
This commit is contained in:
parent
541e022a0e
commit
9805f03d10
|
@ -72,6 +72,10 @@ struct pair_cipher_context
|
|||
uint64_t encryption_counter;
|
||||
uint64_t decryption_counter;
|
||||
|
||||
// For rollback
|
||||
uint64_t encryption_counter_prev;
|
||||
uint64_t decryption_counter_prev;
|
||||
|
||||
const char *errmsg;
|
||||
};
|
||||
|
||||
|
|
|
@ -568,11 +568,11 @@ pair_decrypt(uint8_t **plaintext, size_t *plaintext_len, uint8_t *ciphertext, si
|
|||
void
|
||||
pair_encrypt_rollback(struct pair_cipher_context *cctx)
|
||||
{
|
||||
cctx->encryption_counter--;
|
||||
cctx->encryption_counter = cctx->encryption_counter_prev;
|
||||
}
|
||||
|
||||
void
|
||||
pair_decrypt_rollback(struct pair_cipher_context *cctx)
|
||||
{
|
||||
cctx->decryption_counter--;
|
||||
cctx->decryption_counter = cctx->decryption_counter_prev;
|
||||
}
|
||||
|
|
|
@ -1761,6 +1761,8 @@ pair_encrypt(uint8_t **ciphertext, size_t *ciphertext_len, uint8_t *plaintext, s
|
|||
*ciphertext_len = nblocks * (sizeof(block_len) + AUTHTAG_LENGTH) + plaintext_len;
|
||||
*ciphertext = malloc(*ciphertext_len);
|
||||
|
||||
cctx->encryption_counter_prev = cctx->encryption_counter;
|
||||
|
||||
for (i = 0, plain_block = plaintext, cipher_block = *ciphertext; i < nblocks; i++)
|
||||
{
|
||||
// If it is the last block we will encrypt only the remaining data
|
||||
|
@ -1811,6 +1813,8 @@ pair_decrypt(uint8_t **plaintext, size_t *plaintext_len, uint8_t *ciphertext, si
|
|||
// blocks in the ciphertext yet we can't calculate the exact required length.
|
||||
*plaintext = malloc(ciphertext_len);
|
||||
|
||||
cctx->decryption_counter_prev = cctx->decryption_counter;
|
||||
|
||||
for (plain_block = *plaintext, cipher_block = ciphertext; cipher_block < ciphertext + ciphertext_len; )
|
||||
{
|
||||
memcpy(&block_len, cipher_block, sizeof(block_len)); // TODO BE or LE?
|
||||
|
@ -1876,4 +1880,29 @@ const struct pair_definition pair_homekit_normal =
|
|||
.pair_decrypt = pair_decrypt,
|
||||
};
|
||||
|
||||
const struct pair_definition pair_homekit_transient = pair_homekit_normal;
|
||||
const struct pair_definition pair_homekit_transient =
|
||||
{
|
||||
.pair_setup_new = pair_setup_new,
|
||||
.pair_setup_free = pair_setup_free,
|
||||
.pair_setup_result = pair_setup_result,
|
||||
|
||||
.pair_setup_request1 = pair_setup_request1,
|
||||
.pair_setup_request2 = pair_setup_request2,
|
||||
.pair_setup_request3 = pair_setup_request3,
|
||||
|
||||
.pair_setup_response1 = pair_setup_response1,
|
||||
.pair_setup_response2 = pair_setup_response2,
|
||||
.pair_setup_response3 = pair_setup_response3,
|
||||
|
||||
.pair_verify_request1 = pair_verify_request1,
|
||||
.pair_verify_request2 = pair_verify_request2,
|
||||
|
||||
.pair_verify_response1 = pair_verify_response1,
|
||||
.pair_verify_response2 = pair_verify_response2,
|
||||
|
||||
.pair_cipher_new = pair_cipher_new,
|
||||
.pair_cipher_free = pair_cipher_free,
|
||||
|
||||
.pair_encrypt = pair_encrypt,
|
||||
.pair_decrypt = pair_decrypt,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue