From 3f73ba54c4698813f60cdfd97cfea2f7ef1d7001 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Fri, 17 May 2013 15:16:42 +0200 Subject: [PATCH] algos_enc: use faster unranking for decryption --- src/algos_enc.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/algos_enc.cpp b/src/algos_enc.cpp index 1da9583..0da60e9 100644 --- a/src/algos_enc.cpp +++ b/src/algos_enc.cpp @@ -371,18 +371,15 @@ static int fo_decrypt (const bvector&cipher, bvector&plain, H = hf (M2); /* - * prepare the error vector (again. Avoiding colex ranking which is - * little less deterministic than it could be (produces varying amounts - * of whitespace) + * Colex rank the vector to hash (it is faster than unranking) */ - bvector ev_rank, ev2; - ev_rank.resize (ranksize); + bvector ev_rank; + ev.colex_rank (ev_rank); + ev_rank.resize (ranksize, 0); for (i = 0; i < ranksize; ++i) - ev_rank[i] = 1 & (H[ (i >> 3) % H.size()] >> (i & 0x7) ); - ev_rank.colex_unrank (ev2, ciphersize, errorcount); + if (ev_rank[i] != 1 & (H[ (i >> 3) % H.size()] >> (i & 0x7) ) ) + return 8; - //now it should match, otherwise someone mangled the message. - if (ev != ev2) return 8; //if the message seems okay, unpad and return it. if (!message_unpad (M, plain) ) return 9;