From: Aki Tuomi Date: Tue, 1 Nov 2016 19:50:29 +0000 (+0200) Subject: auth: Use buffer_truncate_rshift_bits X-Git-Tag: 2.3.0.rc1~2690 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e1d4f6f6ab3cedc30c7477820c394fbd3769964c;p=thirdparty%2Fdovecot%2Fcore.git auth: Use buffer_truncate_rshift_bits --- diff --git a/src/auth/auth-policy.c b/src/auth/auth-policy.c index c79aba9395..27cedbabd0 100755 --- a/src/auth/auth-policy.c +++ b/src/auth/auth-policy.c @@ -449,18 +449,7 @@ void auth_policy_create_json(struct policy_lookup_ctx *context, digest->result(ctx, ptr); str_truncate(buffer, digest->digest_size); if (context->set->policy_hash_truncate > 0) { - /* truncate it to closest byte boundary */ - int bytes = ((context->set->policy_hash_truncate + 7) & -8)/8; - /* remainding bits */ - int bits = bytes*8 - context->set->policy_hash_truncate; - str_truncate(buffer, bytes); - ptr = buffer_get_modifiable_data(buffer, NULL); - /* right shift everything and left-pad with 0 */ - if (bits > 0) { - for(size_t i=bytes-1;i>0;i--) - ptr[i] = (ptr[i]>>(8-bits)) + ((ptr[i-1]&(0xff>>(8-bits)))<>(8-bits); - } + buffer_truncate_rshift_bits(buffer, context->set->policy_hash_truncate); } const char *hashed_password = binary_to_hex(str_data(buffer), str_len(buffer)); str_append_c(context->json, '{');