From nobody Sat Apr 20 00:37:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1562926758; cv=none; d=zoho.com; s=zohoarc; b=OA3nzE5YHmKUuatH6tny3V8zNfKODp6/07WAk5Jm/Y+aRbaLn25IrZAl8qBduszOkq1E9tM4bTc78HkoQ7L4qdgu4bj+OHavnAlYQyQFjQz6e8JbNnaB7zvFv0Dfs2EI9D+9+pprNMAaiqLgTAFcjLXbyjAFZOXK7IHfgKnOu2w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562926758; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=gvTgqhwYLPVvKYpbFyZpPz2XDifxwgSzeB0L3gQwSa0=; b=JzpoDJOrcba78/HevtJ473+o9NKhcQjzzavLlqhHK9XPJC4RwXy8txtH3ojk3VrbwPP0hTOwbHJDRiH2H+eVOaJG9Yd6wgZcxm6E42AYU4NG9z6wJAaTN+xSNWAFH1ni2kaM3nEHYNhousznAd4VIpvc+pqNzeeH0McypIUxi7E= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1562926758570177.86673107430397; Fri, 12 Jul 2019 03:19:18 -0700 (PDT) Received: from localhost ([::1]:47956 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlse5-0002Ix-D5 for importer@patchew.org; Fri, 12 Jul 2019 06:19:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57409) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlsdm-0001FW-4P for qemu-devel@nongnu.org; Fri, 12 Jul 2019 06:18:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hlsdk-0001PL-Hg for qemu-devel@nongnu.org; Fri, 12 Jul 2019 06:18:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42516) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hlsdk-0001P1-9L for qemu-devel@nongnu.org; Fri, 12 Jul 2019 06:18:56 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9846085543; Fri, 12 Jul 2019 10:18:55 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id E556060BFB; Fri, 12 Jul 2019 10:18:53 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Fri, 12 Jul 2019 11:18:48 +0100 Message-Id: <20190712101849.8993-2-berrange@redhat.com> In-Reply-To: <20190712101849.8993-1-berrange@redhat.com> References: <20190712101849.8993-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 12 Jul 2019 10:18:55 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-4.1 1/2] crypto: switch to modern nettle AES APIs X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Amol Surati , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The aes_ctx struct and aes_* functions have been deprecated in nettle 3.5, in favour of keysize specific functions which were introduced first in nettle 3.0. Switch QEMU code to use the new APIs and add some backcompat defines such that it still builds on nettle 2.7 Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Alex Benn=C3=A9e Tested-by: Alex Benn=C3=A9e --- crypto/cipher-nettle.c | 218 ++++++++++++++++++++++++++++++++++------- 1 file changed, 183 insertions(+), 35 deletions(-) diff --git a/crypto/cipher-nettle.c b/crypto/cipher-nettle.c index 3848cb3b3a..115d16dd7b 100644 --- a/crypto/cipher-nettle.c +++ b/crypto/cipher-nettle.c @@ -42,29 +42,89 @@ typedef void * cipher_ctx_t; typedef unsigned cipher_length_t; =20 #define cast5_set_key cast128_set_key + +#define aes128_ctx aes_ctx +#define aes192_ctx aes_ctx +#define aes256_ctx aes_ctx +#define aes128_set_encrypt_key(c, k) \ + aes_set_encrypt_key(c, 16, k) +#define aes192_set_encrypt_key(c, k) \ + aes_set_encrypt_key(c, 24, k) +#define aes256_set_encrypt_key(c, k) \ + aes_set_encrypt_key(c, 32, k) +#define aes128_set_decrypt_key(c, k) \ + aes_set_decrypt_key(c, 16, k) +#define aes192_set_decrypt_key(c, k) \ + aes_set_decrypt_key(c, 24, k) +#define aes256_set_decrypt_key(c, k) \ + aes_set_decrypt_key(c, 32, k) +#define aes128_encrypt aes_encrypt +#define aes192_encrypt aes_encrypt +#define aes256_encrypt aes_encrypt +#define aes128_decrypt aes_decrypt +#define aes192_decrypt aes_decrypt +#define aes256_decrypt aes_decrypt #else typedef nettle_cipher_func * QCryptoCipherNettleFuncNative; typedef const void * cipher_ctx_t; typedef size_t cipher_length_t; #endif =20 -typedef struct QCryptoNettleAES { - struct aes_ctx enc; - struct aes_ctx dec; -} QCryptoNettleAES; +typedef struct QCryptoNettleAES128 { + struct aes128_ctx enc; + struct aes128_ctx dec; +} QCryptoNettleAES128; + +typedef struct QCryptoNettleAES192 { + struct aes192_ctx enc; + struct aes192_ctx dec; +} QCryptoNettleAES192; + +typedef struct QCryptoNettleAES256 { + struct aes256_ctx enc; + struct aes256_ctx dec; +} QCryptoNettleAES256; + +static void aes128_encrypt_native(cipher_ctx_t ctx, cipher_length_t length, + uint8_t *dst, const uint8_t *src) +{ + const QCryptoNettleAES128 *aesctx =3D ctx; + aes128_encrypt(&aesctx->enc, length, dst, src); +} + +static void aes128_decrypt_native(cipher_ctx_t ctx, cipher_length_t length, + uint8_t *dst, const uint8_t *src) +{ + const QCryptoNettleAES128 *aesctx =3D ctx; + aes128_decrypt(&aesctx->dec, length, dst, src); +} + +static void aes192_encrypt_native(cipher_ctx_t ctx, cipher_length_t length, + uint8_t *dst, const uint8_t *src) +{ + const QCryptoNettleAES192 *aesctx =3D ctx; + aes192_encrypt(&aesctx->enc, length, dst, src); +} + +static void aes192_decrypt_native(cipher_ctx_t ctx, cipher_length_t length, + uint8_t *dst, const uint8_t *src) +{ + const QCryptoNettleAES192 *aesctx =3D ctx; + aes192_decrypt(&aesctx->dec, length, dst, src); +} =20 -static void aes_encrypt_native(cipher_ctx_t ctx, cipher_length_t length, +static void aes256_encrypt_native(cipher_ctx_t ctx, cipher_length_t length, uint8_t *dst, const uint8_t *src) { - const QCryptoNettleAES *aesctx =3D ctx; - aes_encrypt(&aesctx->enc, length, dst, src); + const QCryptoNettleAES256 *aesctx =3D ctx; + aes256_encrypt(&aesctx->enc, length, dst, src); } =20 -static void aes_decrypt_native(cipher_ctx_t ctx, cipher_length_t length, +static void aes256_decrypt_native(cipher_ctx_t ctx, cipher_length_t length, uint8_t *dst, const uint8_t *src) { - const QCryptoNettleAES *aesctx =3D ctx; - aes_decrypt(&aesctx->dec, length, dst, src); + const QCryptoNettleAES256 *aesctx =3D ctx; + aes256_decrypt(&aesctx->dec, length, dst, src); } =20 static void des_encrypt_native(cipher_ctx_t ctx, cipher_length_t length, @@ -127,18 +187,46 @@ static void twofish_decrypt_native(cipher_ctx_t ctx, = cipher_length_t length, twofish_decrypt(ctx, length, dst, src); } =20 -static void aes_encrypt_wrapper(const void *ctx, size_t length, +static void aes128_encrypt_wrapper(const void *ctx, size_t length, + uint8_t *dst, const uint8_t *src) +{ + const QCryptoNettleAES128 *aesctx =3D ctx; + aes128_encrypt(&aesctx->enc, length, dst, src); +} + +static void aes128_decrypt_wrapper(const void *ctx, size_t length, uint8_t *dst, const uint8_t *src) { - const QCryptoNettleAES *aesctx =3D ctx; - aes_encrypt(&aesctx->enc, length, dst, src); + const QCryptoNettleAES128 *aesctx =3D ctx; + aes128_decrypt(&aesctx->dec, length, dst, src); } =20 -static void aes_decrypt_wrapper(const void *ctx, size_t length, +static void aes192_encrypt_wrapper(const void *ctx, size_t length, uint8_t *dst, const uint8_t *src) { - const QCryptoNettleAES *aesctx =3D ctx; - aes_decrypt(&aesctx->dec, length, dst, src); + const QCryptoNettleAES192 *aesctx =3D ctx; + aes192_encrypt(&aesctx->enc, length, dst, src); +} + +static void aes192_decrypt_wrapper(const void *ctx, size_t length, + uint8_t *dst, const uint8_t *src) +{ + const QCryptoNettleAES192 *aesctx =3D ctx; + aes192_decrypt(&aesctx->dec, length, dst, src); +} + +static void aes256_encrypt_wrapper(const void *ctx, size_t length, + uint8_t *dst, const uint8_t *src) +{ + const QCryptoNettleAES256 *aesctx =3D ctx; + aes256_encrypt(&aesctx->enc, length, dst, src); +} + +static void aes256_decrypt_wrapper(const void *ctx, size_t length, + uint8_t *dst, const uint8_t *src) +{ + const QCryptoNettleAES256 *aesctx =3D ctx; + aes256_decrypt(&aesctx->dec, length, dst, src); } =20 static void des_encrypt_wrapper(const void *ctx, size_t length, @@ -319,34 +407,94 @@ static QCryptoCipherNettle *qcrypto_cipher_ctx_new(QC= ryptoCipherAlgorithm alg, break; =20 case QCRYPTO_CIPHER_ALG_AES_128: + ctx->ctx =3D g_new0(QCryptoNettleAES128, 1); + + if (mode =3D=3D QCRYPTO_CIPHER_MODE_XTS) { + ctx->ctx_tweak =3D g_new0(QCryptoNettleAES128, 1); + + nkey /=3D 2; + aes128_set_encrypt_key(&((QCryptoNettleAES128 *)ctx->ctx)->enc, + key); + aes128_set_decrypt_key(&((QCryptoNettleAES128 *)ctx->ctx)->dec, + key); + + aes128_set_encrypt_key(&((QCryptoNettleAES128 *)ctx->ctx_tweak= )-> + enc, key + nkey); + aes128_set_decrypt_key(&((QCryptoNettleAES128 *)ctx->ctx_tweak= )-> + dec, key + nkey); + } else { + aes128_set_encrypt_key(&((QCryptoNettleAES128 *)ctx->ctx)->enc, + key); + aes128_set_decrypt_key(&((QCryptoNettleAES128 *)ctx->ctx)->dec, + key); + } + + ctx->alg_encrypt_native =3D aes128_encrypt_native; + ctx->alg_decrypt_native =3D aes128_decrypt_native; + ctx->alg_encrypt_wrapper =3D aes128_encrypt_wrapper; + ctx->alg_decrypt_wrapper =3D aes128_decrypt_wrapper; + + ctx->blocksize =3D AES_BLOCK_SIZE; + break; + case QCRYPTO_CIPHER_ALG_AES_192: + ctx->ctx =3D g_new0(QCryptoNettleAES192, 1); + + if (mode =3D=3D QCRYPTO_CIPHER_MODE_XTS) { + ctx->ctx_tweak =3D g_new0(QCryptoNettleAES192, 1); + + nkey /=3D 2; + aes192_set_encrypt_key(&((QCryptoNettleAES192 *)ctx->ctx)->enc, + key); + aes192_set_decrypt_key(&((QCryptoNettleAES192 *)ctx->ctx)->dec, + key); + + aes192_set_encrypt_key(&((QCryptoNettleAES192 *)ctx->ctx_tweak= )-> + enc, key + nkey); + aes192_set_decrypt_key(&((QCryptoNettleAES192 *)ctx->ctx_tweak= )-> + dec, key + nkey); + } else { + aes192_set_encrypt_key(&((QCryptoNettleAES192 *)ctx->ctx)->enc, + key); + aes192_set_decrypt_key(&((QCryptoNettleAES192 *)ctx->ctx)->dec, + key); + } + + ctx->alg_encrypt_native =3D aes192_encrypt_native; + ctx->alg_decrypt_native =3D aes192_decrypt_native; + ctx->alg_encrypt_wrapper =3D aes192_encrypt_wrapper; + ctx->alg_decrypt_wrapper =3D aes192_decrypt_wrapper; + + ctx->blocksize =3D AES_BLOCK_SIZE; + break; + case QCRYPTO_CIPHER_ALG_AES_256: - ctx->ctx =3D g_new0(QCryptoNettleAES, 1); + ctx->ctx =3D g_new0(QCryptoNettleAES256, 1); =20 if (mode =3D=3D QCRYPTO_CIPHER_MODE_XTS) { - ctx->ctx_tweak =3D g_new0(QCryptoNettleAES, 1); + ctx->ctx_tweak =3D g_new0(QCryptoNettleAES256, 1); =20 nkey /=3D 2; - aes_set_encrypt_key(&((QCryptoNettleAES *)ctx->ctx)->enc, - nkey, key); - aes_set_decrypt_key(&((QCryptoNettleAES *)ctx->ctx)->dec, - nkey, key); - - aes_set_encrypt_key(&((QCryptoNettleAES *)ctx->ctx_tweak)->enc, - nkey, key + nkey); - aes_set_decrypt_key(&((QCryptoNettleAES *)ctx->ctx_tweak)->dec, - nkey, key + nkey); + aes256_set_encrypt_key(&((QCryptoNettleAES256 *)ctx->ctx)->enc, + key); + aes256_set_decrypt_key(&((QCryptoNettleAES256 *)ctx->ctx)->dec, + key); + + aes256_set_encrypt_key(&((QCryptoNettleAES256 *)ctx->ctx_tweak= )-> + enc, key + nkey); + aes256_set_decrypt_key(&((QCryptoNettleAES256 *)ctx->ctx_tweak= )-> + dec, key + nkey); } else { - aes_set_encrypt_key(&((QCryptoNettleAES *)ctx->ctx)->enc, - nkey, key); - aes_set_decrypt_key(&((QCryptoNettleAES *)ctx->ctx)->dec, - nkey, key); + aes256_set_encrypt_key(&((QCryptoNettleAES256 *)ctx->ctx)->enc, + key); + aes256_set_decrypt_key(&((QCryptoNettleAES256 *)ctx->ctx)->dec, + key); } =20 - ctx->alg_encrypt_native =3D aes_encrypt_native; - ctx->alg_decrypt_native =3D aes_decrypt_native; - ctx->alg_encrypt_wrapper =3D aes_encrypt_wrapper; - ctx->alg_decrypt_wrapper =3D aes_decrypt_wrapper; + ctx->alg_encrypt_native =3D aes256_encrypt_native; + ctx->alg_decrypt_native =3D aes256_decrypt_native; + ctx->alg_encrypt_wrapper =3D aes256_encrypt_wrapper; + ctx->alg_decrypt_wrapper =3D aes256_decrypt_wrapper; =20 ctx->blocksize =3D AES_BLOCK_SIZE; break; --=20 2.21.0 From nobody Sat Apr 20 00:37:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1562926770; cv=none; d=zoho.com; s=zohoarc; b=JYkMFz7C3ycFCHM83gm308u6z3MU6nP+KaVR/D3QnjpIIOdW2BfVE+jSUg9Ix2c0GLzhWpV/TEM+LTnpjImTuFf9FMoSvyLQDAj3Q6leE/TdUo4woLkoeNRLkJyYU4MS2pxrLaEaNuxfX1lE8IN7TUj3eAZgz7DV8uyLOfnIX9g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562926770; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=7x0Fr440hr2j3OwbQ9Mtsb+EJzeSIoEsX4ha2LTyzXA=; b=lkX69Yse3bVIh8KpFlM2YeaRyIs+3fkkZrZLYkSP0dQq7F3SSr2+xTu7IMLnRlho1bu0Nkcm+N7aZ1OUwMIk42uW0SY/+jVVAzAW0fV1h+LErIWQkukDoqejviXsDovZqM+vN6WT3dLGjo8Q0/nkpjEybQgmmTj5oiuv13u6Sdc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1562926770736582.0259426673404; Fri, 12 Jul 2019 03:19:30 -0700 (PDT) Received: from localhost ([::1]:47964 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlseH-0003JU-IO for importer@patchew.org; Fri, 12 Jul 2019 06:19:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57449) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hlsdp-0001S0-75 for qemu-devel@nongnu.org; Fri, 12 Jul 2019 06:19:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hlsdo-0001Sr-4O for qemu-devel@nongnu.org; Fri, 12 Jul 2019 06:19:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34726) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hlsdn-0001Ry-T3 for qemu-devel@nongnu.org; Fri, 12 Jul 2019 06:19:00 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3737A83F40; Fri, 12 Jul 2019 10:18:59 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0851860BFB; Fri, 12 Jul 2019 10:18:55 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Fri, 12 Jul 2019 11:18:49 +0100 Message-Id: <20190712101849.8993-3-berrange@redhat.com> In-Reply-To: <20190712101849.8993-1-berrange@redhat.com> References: <20190712101849.8993-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 12 Jul 2019 10:18:59 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-4.1 2/2] crypto: fix function signatures for nettle 2.7 vs 3 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Amol Surati , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Nettle version 2.7.x used 'unsigned int' instead of 'size_t' for length parameters in functions. Use a local typedef so that we can build with the correct signature depending on nettle version, as we already do in the cipher code. Signed-off-by: Daniel P. Berrang=C3=A9 Reported-by: Amol Surati Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Alex Benn=C3=A9e --- crypto/hash-nettle.c | 12 +++++++++--- crypto/hmac-nettle.c | 17 +++++++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/crypto/hash-nettle.c b/crypto/hash-nettle.c index 96f186f442..6ffb9c3db7 100644 --- a/crypto/hash-nettle.c +++ b/crypto/hash-nettle.c @@ -26,12 +26,18 @@ #include #include =20 +#if CONFIG_NETTLE_VERSION_MAJOR < 3 +typedef unsigned int hash_length_t; +#else +typedef size_t hash_length_t; +#endif + typedef void (*qcrypto_nettle_init)(void *ctx); typedef void (*qcrypto_nettle_write)(void *ctx, - unsigned int len, + hash_length_t len, const uint8_t *buf); typedef void (*qcrypto_nettle_result)(void *ctx, - unsigned int len, + hash_length_t len, uint8_t *buf); =20 union qcrypto_hash_ctx { @@ -112,7 +118,7 @@ qcrypto_nettle_hash_bytesv(QCryptoHashAlgorithm alg, size_t *resultlen, Error **errp) { - int i; + size_t i; union qcrypto_hash_ctx ctx; =20 if (!qcrypto_hash_supports(alg)) { diff --git a/crypto/hmac-nettle.c b/crypto/hmac-nettle.c index ec2d61bdde..1152b741fd 100644 --- a/crypto/hmac-nettle.c +++ b/crypto/hmac-nettle.c @@ -18,14 +18,23 @@ #include "hmacpriv.h" #include =20 +#if CONFIG_NETTLE_VERSION_MAJOR < 3 +typedef unsigned int hmac_length_t; +#else +typedef size_t hmac_length_t; +#endif + typedef void (*qcrypto_nettle_hmac_setkey)(void *ctx, - size_t key_length, const uint8_t *key); + hmac_length_t key_length, + const uint8_t *key); =20 typedef void (*qcrypto_nettle_hmac_update)(void *ctx, - size_t length, const uint8_t *data); + hmac_length_t length, + const uint8_t *data); =20 typedef void (*qcrypto_nettle_hmac_digest)(void *ctx, - size_t length, uint8_t *digest); + hmac_length_t length, + uint8_t *digest); =20 typedef struct QCryptoHmacNettle QCryptoHmacNettle; struct QCryptoHmacNettle { @@ -135,7 +144,7 @@ qcrypto_nettle_hmac_bytesv(QCryptoHmac *hmac, Error **errp) { QCryptoHmacNettle *ctx; - int i; + size_t i; =20 ctx =3D (QCryptoHmacNettle *)hmac->opaque; =20 --=20 2.21.0