Skip to content

Commit

Permalink
Add check for reusing server's nonce/salt
Browse files Browse the repository at this point in the history
  • Loading branch information
madeye committed Oct 19, 2018
1 parent 482040a commit 92cab35
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/aead.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ aead_encrypt_all(buffer_t *plaintext, cipher_t *cipher, size_t capacity)
/* copy salt to first pos */
memcpy(ciphertext->data, cipher_ctx.salt, salt_len);

ppbloom_add((void *)cipher_ctx.salt, salt_len);

aead_cipher_ctx_set_key(&cipher_ctx, 1);

size_t clen = ciphertext->len;
Expand Down Expand Up @@ -552,6 +554,8 @@ aead_encrypt(buffer_t *plaintext, cipher_ctx_t *cipher_ctx, size_t capacity)
memcpy(ciphertext->data, cipher_ctx->salt, salt_len);
aead_cipher_ctx_set_key(cipher_ctx, 1);
cipher_ctx->init = 1;

ppbloom_add((void *)cipher_ctx->salt, salt_len);
}

err = aead_chunk_encrypt(cipher_ctx,
Expand Down
4 changes: 4 additions & 0 deletions src/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ stream_encrypt_all(buffer_t *plaintext, cipher_t *cipher, size_t capacity)
cipher_ctx_set_nonce(&cipher_ctx, nonce, nonce_len, 1);
memcpy(ciphertext->data, nonce, nonce_len);

ppbloom_add((void *)nonce, nonce_len);

if (cipher->method >= SALSA20) {
crypto_stream_xor_ic((uint8_t *)(ciphertext->data + nonce_len),
(const uint8_t *)plaintext->data, (uint64_t)(plaintext->len),
Expand Down Expand Up @@ -399,6 +401,8 @@ stream_encrypt(buffer_t *plaintext, cipher_ctx_t *cipher_ctx, size_t capacity)
memcpy(ciphertext->data, cipher_ctx->nonce, nonce_len);
cipher_ctx->counter = 0;
cipher_ctx->init = 1;

ppbloom_add((void *)cipher_ctx->nonce, nonce_len);
}

if (cipher->method >= SALSA20) {
Expand Down

0 comments on commit 92cab35

Please sign in to comment.