From nobody Thu Nov 30 17:51:04 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Sh3dj3MC6z52Lxl; Thu, 30 Nov 2023 17:51:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Sh3dj1bgwz4dwm; Thu, 30 Nov 2023 17:51:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1701366665; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=DUkh8g9psFR6qadW+eDkobWAug1IEYwWXVPgniojoF4=; b=ZciOP6OjDnnPvckW1JWRz8iU0IUMVSCk0iZGe+/FsUEjP+dXxgDNHoG9Qahie23V4jE8X6 YR6vySQ25Bmgs8NCSXQcE5RLYlLj9zbRQLQG7c9yEk+l3gvhRu5iN4VvE5s+d/jsw4pYIy YjxS6vlqwJJ9VIqCcV3Lin1haaspRlvW0Iw90RzrG7uYVidaYT2HCb0TPLxLF0QysfoqHB dOQsyTqT2ahNLreV4byzUmXS6cL1Wz/KnnhNwR223os/FKp+LEwwAH+GQSWWNlpRAE9IfL PUHzws1wqTOfr0g2gg9AbLC7comWvkf6rdNfz6HslSBr8qXrBJ/6p8Tt6irKpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1701366665; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=DUkh8g9psFR6qadW+eDkobWAug1IEYwWXVPgniojoF4=; b=sSRStFQ5D3IBk1zvyIAzZrZaH3vd1RSvs24KLmLheST8MckHt2ieVxY8+1GoGSIi3OuSqU zTQqUREe6VOtkdDwrx3HpOqpjV0SoQ6nm6kcO+FsML7IJnopjvy+BDOT8UIqOi7QiN6l1w WO1fhi+WyPvgWBtLHRJ3uB9nuk2MEoiQah6H5b5msAIvXbEDjKw9s8C/TztTsMJ45NSrUR vmbe3EBZlrX7YIl3XoFEC52uBrxNLWp0vzTDQwDHne2kd1mD7vZs+SiykbEcBAcx+0707L grKR+z8dn2B8cOubmL+X1vTCgByjJoaR2asOyajPHFW1j4zub7VhkrQJgS33UQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1701366665; a=rsa-sha256; cv=none; b=DZR+tRp38/gkzMytDZwIf3NXa4tSg1j7t3lk1vTH/kbM7TLAWZlDl0lUYHNEMZIaZykuKl uScRngtJizQnPxb4m1oNcValgptxElguwvyjam0XNpGljaNHYjWbxfCzDgAKszLxCcdMSd s4edBrtAPaYeRDDGNd4cZJMbHT2KLPaVqL1KZo5DNFE+ZQ7CX7pF+ey0Nd1wJ7imZ1ywPa 6/hbvXVDjZpNLCFC3rLFrDf7Djuektg1FngKpzrFvPTvuavefMZTzhqvGLxfOeDkdhmV0k KYfKvKU2WnZCp0uUEBzivXBCXW/lQCqehdrZmATHqkZ0JUEOAUXONeS48bVYHA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Sh3dj0f2Gz10LR; Thu, 30 Nov 2023 17:51:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3AUHp49r081798; Thu, 30 Nov 2023 17:51:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3AUHp41U081795; Thu, 30 Nov 2023 17:51:04 GMT (envelope-from git) Date: Thu, 30 Nov 2023 17:51:04 GMT Message-Id: <202311301751.3AUHp41U081795@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 47d767dab548 - main - ossl: Fix some bugs in the fallback AES-GCM implementation List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 47d767dab54895f3ba8abac6ab2295797394659e Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=47d767dab54895f3ba8abac6ab2295797394659e commit 47d767dab54895f3ba8abac6ab2295797394659e Author: Mark Johnston AuthorDate: 2023-11-29 20:08:12 +0000 Commit: Mark Johnston CommitDate: 2023-11-30 17:49:47 +0000 ossl: Fix some bugs in the fallback AES-GCM implementation gcm_*_aesni() are used when the AVX512 implementation is not available. Fix two bugs which manifest when handling operations spanning multiple segments: - Avoid underflow when the length of the input is smaller than the residual. - In gcm_decrypt_aesni(), ensure that we begin the operation at the right offset into the input and output buffers. Reviewed by: jhb Fixes: 9b1d87286c78 ("ossl: Add a fallback AES-GCM implementation using AES-NI") MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D42838 --- sys/crypto/openssl/amd64/ossl_aes_gcm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sys/crypto/openssl/amd64/ossl_aes_gcm.c b/sys/crypto/openssl/amd64/ossl_aes_gcm.c index 0d205ec3ff90..d08b2ac8a759 100644 --- a/sys/crypto/openssl/amd64/ossl_aes_gcm.c +++ b/sys/crypto/openssl/amd64/ossl_aes_gcm.c @@ -459,7 +459,7 @@ gcm_encrypt_aesni(struct ossl_gcm_context *ctx, const unsigned char *in, size_t bulk = 0, res; int error; - res = (AES_BLOCK_LEN - ctx->gcm.mres) % AES_BLOCK_LEN; + res = MIN(len, (AES_BLOCK_LEN - ctx->gcm.mres) % AES_BLOCK_LEN); if ((error = gcm_encrypt(ctx, in, out, res)) != 0) return error; @@ -621,12 +621,12 @@ gcm_decrypt_aesni(struct ossl_gcm_context *ctx, const unsigned char *in, size_t bulk = 0, res; int error; - res = (AES_BLOCK_LEN - ctx->gcm.mres) % AES_BLOCK_LEN; + res = MIN(len, (AES_BLOCK_LEN - ctx->gcm.mres) % AES_BLOCK_LEN); if ((error = gcm_decrypt(ctx, in, out, res)) != 0) return error; - bulk = aesni_gcm_decrypt(in, out, len, &ctx->aes_ks, ctx->gcm.Yi.c, - ctx->gcm.Xi.u); + bulk = aesni_gcm_decrypt(in + res, out + res, len - res, &ctx->aes_ks, + ctx->gcm.Yi.c, ctx->gcm.Xi.u); ctx->gcm.len.u[1] += bulk; bulk += res;