From 16c0f3e6c0eedbf81c936a9d1e7d6668176b4a47 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sun, 14 Sep 2014 00:56:48 +0300 Subject: [PATCH] Handle short string correctly in blowfish encription. --- stglibs/crypto.lib/blowfish.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/stglibs/crypto.lib/blowfish.c b/stglibs/crypto.lib/blowfish.c index 90c93b9d..e2f275e6 100644 --- a/stglibs/crypto.lib/blowfish.c +++ b/stglibs/crypto.lib/blowfish.c @@ -504,7 +504,16 @@ void EncryptString(void * d, const void * s, size_t length, const BLOWFISH_CTX * size_t pos = 0; while (pos < length) { - EncryptBlock(d + pos, s + pos, ctx); + if (pos + 8 < length) + EncryptBlock(d + pos, s + pos, ctx); + else + { + // Short string, use 0-padded buffer. + char buf[8]; + memset(buf, 0, sizeof(buf)); + memcpy(buf, s + pos, length - pos); + EncryptBlock(d + pos, buf, ctx); + } pos += 8; } } -- 2.44.2