From 5fe8598f755bdfd15e96bb2ddcdbe9a41b8173a7 Mon Sep 17 00:00:00 2001 From: Chia-chi Yeh Date: Wed, 30 Dec 2009 10:38:39 +0800 Subject: keystore: compute the padding in an intuitive way. --- cmds/keystore/keystore.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'cmds') diff --git a/cmds/keystore/keystore.c b/cmds/keystore/keystore.c index 37155e4..4426874 100644 --- a/cmds/keystore/keystore.c +++ b/cmds/keystore/keystore.c @@ -170,16 +170,12 @@ static int8_t encrypt_blob(char *name, AES_KEY *aes_key) return SYSTEM_ERROR; } - length = (blob.length + blob.value - blob.encrypted) % AES_BLOCK_SIZE; - if (length) { - length = AES_BLOCK_SIZE - length; - } + length = blob.length + blob.value - blob.encrypted; + length = (length + AES_BLOCK_SIZE - 1) / AES_BLOCK_SIZE * AES_BLOCK_SIZE; - length += blob.length + blob.value - blob.digested; blob.length = htonl(blob.length); - MD5(blob.digested, length, blob.digest); + MD5(blob.digested, length - (blob.digested - blob.encrypted), blob.digest); - length += blob.digested - blob.encrypted; memcpy(vector, blob.vector, AES_BLOCK_SIZE); AES_cbc_encrypt(blob.encrypted, blob.encrypted, length, aes_key, vector, AES_ENCRYPT); -- cgit v1.1