From 9ae59819bea2c82a53eb680a7e5983406022b462 Mon Sep 17 00:00:00 2001 From: babarosaM33 Date: Mon, 13 Jan 2020 13:24:52 +0800 Subject: [PATCH 1/2] ppbloom:remove unnecessay bloom_check bbloom_add and bbloom_check are in fact the same function. let's make bbloom_add return collision information. --- src/aead.c | 3 +-- src/ppbloom.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/aead.c b/src/aead.c index 6452f336..99f235c8 100644 --- a/src/aead.c +++ b/src/aead.c @@ -695,11 +695,10 @@ aead_decrypt(buffer_t *ciphertext, cipher_ctx_t *cipher_ctx, size_t capacity) // Add the salt to bloom filter if (cipher_ctx->init == 1) { - if (ppbloom_check((void *)cipher_ctx->salt, salt_len) == 1) { + if (ppbloom_add((void *)cipher_ctx->salt, salt_len) == 1) { LOGE("crypto: AEAD: repeat salt detected"); return CRYPTO_ERROR; } - ppbloom_add((void *)cipher_ctx->salt, salt_len); cipher_ctx->init = 2; } diff --git a/src/ppbloom.c b/src/ppbloom.c index 17e0f019..511d5877 100644 --- a/src/ppbloom.c +++ b/src/ppbloom.c @@ -80,7 +80,7 @@ ppbloom_add(const void *buffer, int len) { int err; err = bloom_add(ppbloom + current, buffer, len); - if (err == -1) + if (err == -1 || err == 1) return err; bloom_count[current]++; From 9576dcea54bf9376b609b21194c663fbeec986ba Mon Sep 17 00:00:00 2001 From: babarosaM33 Date: Mon, 13 Jan 2020 13:34:34 +0800 Subject: [PATCH 2/2] initialize after pass check if check failes, no need to initialize crypto. --- src/aead.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/aead.c b/src/aead.c index 99f235c8..4932ea62 100644 --- a/src/aead.c +++ b/src/aead.c @@ -653,13 +653,13 @@ aead_decrypt(buffer_t *ciphertext, cipher_ctx_t *cipher_ctx, size_t capacity) memcpy(cipher_ctx->salt, cipher_ctx->chunk->data, salt_len); - aead_cipher_ctx_set_key(cipher_ctx, 0); - if (ppbloom_check((void *)cipher_ctx->salt, salt_len) == 1) { LOGE("crypto: AEAD: repeat salt detected"); return CRYPTO_ERROR; } + aead_cipher_ctx_set_key(cipher_ctx, 0); + memmove(cipher_ctx->chunk->data, cipher_ctx->chunk->data + salt_len, cipher_ctx->chunk->len - salt_len); cipher_ctx->chunk->len -= salt_len;