From patchwork Fri May 10 01:24:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163808 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1732928ilr; Thu, 9 May 2019 18:42:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqz0LKemEY9Ef3xb7+JVSZ3IxQ6ZZdgXZ2xKGeF/WnuVlwCfWA8RWWuCJ5I22Xa06x+hCxGk X-Received: by 2002:a5d:50c7:: with SMTP id f7mr5413750wrt.95.1557452530473; Thu, 09 May 2019 18:42:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557452530; cv=none; d=google.com; s=arc-20160816; b=MCjaJ4IrUAl4JsO7HkgNLJ2JvcJSEgz3AmmEFiZkXid8gw6xV5Nio7tEcH0PGSX0eu hTErL506fXMnA8B0euN4V+rNUILTArxNKyIQewG4FMt+itKADb/EyWXfzDmIPbofSm2u 2MH+tuKpWi9B6tO3aDBae4hFfJ7ucYGPXpAOOmhtjsIZG0IbyaAU+fztcSot5oN1QIrH gJi9kbS+Jv4yq+dbMqGRa4gBDBHx0iEu6DWzqO7s4WeIuE5/hAf8BlLp2Pvg1ERtSD67 yvNvT3lUf0fBrkyCznVwp5KY3/TjHiLs4LlkBxl+zHCqpIqIRIuVWN3Trv1iyZd4H+vG FKEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=WcaPjSSW8mCEGy+vfZffpT+ukMC7uteGhxOw5c2wJXo=; b=WfaX4d1qITjFp6NSx/r8QyZ5+VuJ12iFwK0npRC5fAJe1M/hkFTz0OOy9x4mIUjBef 4CGBF+6KhLWypcGWYhLVLSjoJ6KHl9n0V2vYoUe6H+mdC8yUx0Xlsh+qNG9GMg79EjB1 F/KSa6COv0gfsDNb7x1PKmQz/NCKeWrrruUnBp6o8sufGsg66Ingp9xcMlWuH8iBvxwB 5M/t3OFSGB/dXYp1r5Tds2GjM1tSBSZ2ocQlGOy5kh3iICpvXtc+KGVhTMGRCj1RAUTU vY8sv5GtkiH1HHpLMQyUgjeXqKHwQH6bF8nbuC+s8h05CoATEO877tVQzP//R5E5o3gi UgHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=h0ZEFgoo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k3si2628956wmi.124.2019.05.09.18.42.10 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:42:10 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=h0ZEFgoo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:35235 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuY5-0004XD-H4 for patch@linaro.org; Thu, 09 May 2019 21:42:09 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58695) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHl-0006Jj-Qy for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHj-00015I-O1 for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:17 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:43030) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHj-0000ug-HI for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:15 -0400 Received: by mail-pg1-x541.google.com with SMTP id t22so2116429pgi.10 for ; Thu, 09 May 2019 18:25:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=WcaPjSSW8mCEGy+vfZffpT+ukMC7uteGhxOw5c2wJXo=; b=h0ZEFgooJH5WHwPFZMSTligDsA88+EizQ2Gi+JTj1Gqh2Pky11aDt1EnB3vorhNP4o pRCm091sCUrQ0Xg0L3f79HpVXkJHUo9Kt/bvwi9mDCe3BCojk/1TRvOl+fo4Ed6qAv6d 62hcqB+zRhovSakJfwLyOvkba4xXTFWu/LPDSLHIwgLLzZGLfraXnWiMCZKtr63042vI yECcmWNAaTpjk4ce4Kl8iyM7LUr7d5B+R2nOZRfMsPQxB5sIRHBkRnhWp0U7PsmmxUb6 3zaAaVgy6LRf2jMuS7GYc7otnyGdvGDNjNlHoQ3kBf3uIMnmhAv0Bxm8WpnIfe0tOaQB 7tuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WcaPjSSW8mCEGy+vfZffpT+ukMC7uteGhxOw5c2wJXo=; b=tottwBsIMMJ/sv3OVtfFl4rbZyE5yDEieXhsMuD6VeC0vQywokkMYoMV0+yvBxYETr XLyeeLTRpg9EAj4ih5Ht0yjUmOsh1DLyArKHWVJJPBKj0wSHEq7KQDk11MANHtzQtXA4 iCtRWSEkR94pfa1CFzfVVd46lA8Ui4gwnI7TDWX5C0U1Rhg420Su1O9880mPCOoBASOO TJmYCTNbpxHdDuV5yoF0fkPhAr6W7zCZdUVhulkYVALbCmxxVYRenCsvsXOOPbW8lnyA Ara1VizhBl33Jjz3zWLRhu93CbAaI9AVHL/vqQOKpXsG0gbjnHAGzDMN5dYZHHI0o6Xt jVgA== X-Gm-Message-State: APjAAAVzVNNyAjhtwtc+xLf9Y8cDFPzrX/VAKDcIheuRXolQSutk8zTT AOTIIIgffexhQ5w20JaziYk2TLmo1aA= X-Received: by 2002:aa7:8243:: with SMTP id e3mr9817358pfn.213.1557451504149; Thu, 09 May 2019 18:25:04 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:37 -0700 Message-Id: <20190510012458.22706-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::541 Subject: [Qemu-devel] [PATCH v5 03/24] crypto: Reverse code blocks in random-platform.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use #ifdef _WIN32 instead of #ifndef _WIN32. This will make other tests easier to sequence. Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Daniel P. Berrangé Signed-off-by: Richard Henderson --- crypto/random-platform.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) -- 2.17.1 diff --git a/crypto/random-platform.c b/crypto/random-platform.c index 7541b4cae7..f995fc0ef1 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -32,7 +32,14 @@ static int fd; /* a file handle to either /dev/urandom or /dev/random */ int qcrypto_random_init(Error **errp) { -#ifndef _WIN32 +#ifdef _WIN32 + if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, + CRYPT_SILENT | CRYPT_VERIFYCONTEXT)) { + error_setg_win32(errp, GetLastError(), + "Unable to create cryptographic provider"); + return -1; + } +#else /* TBD perhaps also add support for BSD getentropy / Linux * getrandom syscalls directly */ fd = open("/dev/urandom", O_RDONLY); @@ -44,15 +51,7 @@ int qcrypto_random_init(Error **errp) error_setg(errp, "No /dev/urandom or /dev/random found"); return -1; } -#else - if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, - CRYPT_SILENT | CRYPT_VERIFYCONTEXT)) { - error_setg_win32(errp, GetLastError(), - "Unable to create cryptographic provider"); - return -1; - } #endif - return 0; } @@ -60,7 +59,15 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, size_t buflen G_GNUC_UNUSED, Error **errp) { -#ifndef _WIN32 +#ifdef _WIN32 + if (!CryptGenRandom(hCryptProv, buflen, buf)) { + error_setg_win32(errp, GetLastError(), + "Unable to read random bytes"); + return -1; + } + + return 0; +#else int ret = -1; int got; @@ -82,13 +89,5 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, ret = 0; cleanup: return ret; -#else - if (!CryptGenRandom(hCryptProv, buflen, buf)) { - error_setg_win32(errp, GetLastError(), - "Unable to read random bytes"); - return -1; - } - - return 0; #endif }