From patchwork Mon May 6 17:33:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163444 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:81:0:0:0:0 with SMTP id l1csp273899ilm; Mon, 6 May 2019 10:55:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqywcV0irmZzOmvOTiF5hJkuMaAGorsnxEXFzBu9ZT2KOj3EYzDRqYbji9VeHioffs7da+B0 X-Received: by 2002:a5d:4707:: with SMTP id y7mr2969755wrq.59.1557165355332; Mon, 06 May 2019 10:55:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557165355; cv=none; d=google.com; s=arc-20160816; b=Spftza3OYLJwDDSVPaaDLZBSVlOSmyZeks/o/ZJK8yATEfW946YuocXKPNI3487jXG TjIi8PcujKsEWlRtTycQks3uElBFErPCaCvxYwBPhmr1cBO3jocTyNXGF9Xo3wQa+Hz9 OFqiDKi9xf1IF+2122AEO94ONaaMMVmmpnBJXKyIlwH0Ky4BTGkBhjTqnGv2ODA9MRHG oFCw1A5QZPR45nX275twoKukgrDTYyt1lggpARv0Jre+DhBEbtwcSe/vqpneQb6GxNJV W6c8GjULFo07gj0XL5vJtnG3eE3Ktlu+GSqG8EIxJEnESSQMHqAee3YbA3bVli7A+js0 Z/+g== 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:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=rV9JIaOzfUN4OkPt3KeztWbx7AsXbIEUWY2EQzqrSHU=; b=JSR3COjxZ9fMMaNsdmlKq4Q5ui6CGH2nfWZX/1KtYHoCHFv9OPkcYwIKP5Ki+0Q26C Yo+7a/vPuO+PkNRk/w6ONPF+NtkmBSRrYBbdGlp9L0dkKRbhpSRNUj1M23O1m6wtR+o6 T1/s9VkvLTimDEpvC4IxrP8D8tScfM7GFUZOITltrTIxaG7Uo2kAsGDTNlJ/DqS6IJ6Y X8kwo6yWQ9UIBXIoUVigsC1OS6EbjCJcSlGDfRolPXjq70gc4BUroJWmUcZCxzwdysS2 tsEAZmjwNXIx35RbHxFZ039GCaSEBp9M1ZO7VgqFea6gP9GoVAsFRl9O6vk4xUy9d6Zh EVGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=JPsVvWSv; 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 x185si7303137wmb.73.2019.05.06.10.55.55 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 10:55:55 -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=JPsVvWSv; 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]:60234 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhqE-0003G3-8B for patch@linaro.org; Mon, 06 May 2019 13:55:54 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40149) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNhVV-0001PA-9i for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNhVU-0001d9-BH for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:29 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:45932) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNhVU-0001Z0-3y for qemu-devel@nongnu.org; Mon, 06 May 2019 13:34:28 -0400 Received: by mail-pf1-x442.google.com with SMTP id e24so7119093pfi.12 for ; Mon, 06 May 2019 10:34:24 -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; bh=rV9JIaOzfUN4OkPt3KeztWbx7AsXbIEUWY2EQzqrSHU=; b=JPsVvWSvgo2Fx1dliry01ZRpiz217ThUX6fAXN8kyJBII2va8k4DXmt24Yts3yATwT TyfORURm+fJVw6aaSM0EH2PvE4NxQEoNbgxUpQXTN5mMtrgk9vBdw2bn0awnSWzrAUdH oaC2pe6y6AibFYC+xs0rSaxXaE+5MJW0sxeytMXd1O1+HymLHnyjMMERVf4iF67D97Ei CJnL0tahD0Zme+M1iB2vzyGqpvSKJVZrlLKvI6sFs4sF6C+J0PmSlMUHuVsfXSzqCG2q PrIWSguquJzYL5vl87osooTd/hH02sjzd3VPW5Lg01Fct0chJr75F4neWIDfH5E6pIjY Ndbw== 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; bh=rV9JIaOzfUN4OkPt3KeztWbx7AsXbIEUWY2EQzqrSHU=; b=jIEJc21amS0Okm6YQ/lh3vlhUlCXc/pPd6vFQxGO0MnHBLxNUDSWmIUlGMrM602ZBM 10Pkv+BYdBXG3Ooi1EMa5EgpbRV1lPkmT1K438s3H1TJAyQhFGeSVV289ScN7TUY5v7A sehzprOm0i71xzgUpSjEuIjJSyPGf7Bqge/4o+XA6xqh+xr0QqE7fydoShuRg6cZkjYF akHFREk3w+zhE+e54/S8jf+i9e5MAurM2954SbZINwN1xb5bK/BhwisLK2J+o3ipyupj 22P/3DeQBV/exX264BTILpkORaz4wMUVovB1ZwrreQLQySZRQxMaa4q1SlNuPzb6pd7x nMAg== X-Gm-Message-State: APjAAAWVmlBchjTiOLyQNOyGskF9WRLNzRmWUldF20pmS/D637RXnnIu jmT7eRBXGwyvQyaHk9GhHdG7nPCOJYA= X-Received: by 2002:aa7:8392:: with SMTP id u18mr35979178pfm.217.1557164063137; Mon, 06 May 2019 10:34:23 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id k9sm2268839pfa.180.2019.05.06.10.34.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 10:34:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 10:33:52 -0700 Message-Id: <20190506173353.32206-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506173353.32206-1-richard.henderson@linaro.org> References: <20190506173353.32206-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 Subject: [Qemu-devel] [PATCH v4 23/24] target/ppc: Use qemu_guest_getrandom for DARN 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" We now have an interface for guest visible random numbers. Acked-by: David Gibson Signed-off-by: Richard Henderson --- target/ppc/int_helper.c | 42 +++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) -- 2.17.1 diff --git a/target/ppc/int_helper.c b/target/ppc/int_helper.c index f6a088ac08..9059e70b9c 100644 --- a/target/ppc/int_helper.c +++ b/target/ppc/int_helper.c @@ -23,6 +23,8 @@ #include "exec/helper-proto.h" #include "crypto/aes.h" #include "fpu/softfloat.h" +#include "qapi/error.h" +#include "qemu/guest-random.h" #include "helper_regs.h" /*****************************************************************************/ @@ -158,25 +160,41 @@ uint32_t helper_cmpeqb(target_ulong ra, target_ulong rb) #undef hasvalue /* - * Return invalid random number. - * - * FIXME: Add rng backend or other mechanism to get cryptographically suitable - * random number + * Return a random number. */ -target_ulong helper_darn32(void) +uint64_t helper_darn32(void) { - return -1; + Error *err = NULL; + uint32_t ret; + + if (qemu_guest_getrandom(&ret, 4, &err) < 0) { + qemu_log_mask(LOG_UNIMP, "darn: Crypto failure: %s", + error_get_pretty(err)); + error_free(err); + return -1; + } + + return ret; } -target_ulong helper_darn64(void) +uint64_t helper_darn64(void) { - return -1; + Error *err = NULL; + uint64_t ret; + + do { + if (qemu_guest_getrandom(&ret, 8, &err) < 0) { + qemu_log_mask(LOG_UNIMP, "darn: Crypto failure: %s", + error_get_pretty(err)); + error_free(err); + return -1; + } + /* Since -1 is the error condition, try again for that case. */ + } while (unlikely(ret == -1)); + + return ret; } -#endif - -#if defined(TARGET_PPC64) - uint64_t helper_bpermd(uint64_t rs, uint64_t rb) { int i;