From patchwork Thu Nov 3 00:41:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 80569 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp397056qge; Wed, 2 Nov 2016 17:44:23 -0700 (PDT) X-Received: by 10.176.84.2 with SMTP id n2mr5262578uaa.29.1478133863541; Wed, 02 Nov 2016 17:44:23 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id d138si1506018vke.181.2016.11.02.17.44.23; Wed, 02 Nov 2016 17:44:23 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 3134D6083A; Thu, 3 Nov 2016 00:44:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 016F5608F8; Thu, 3 Nov 2016 00:43:29 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 050BB60891; Thu, 3 Nov 2016 00:43:20 +0000 (UTC) Received: from mail-oi0-f42.google.com (mail-oi0-f42.google.com [209.85.218.42]) by lists.linaro.org (Postfix) with ESMTPS id 1E19F60F3A for ; Thu, 3 Nov 2016 00:42:11 +0000 (UTC) Received: by mail-oi0-f42.google.com with SMTP id x4so49731659oix.2 for ; Wed, 02 Nov 2016 17:42:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=spEwhwtBmNInyNTeFBdd9PWCLA48VLNwJEZ+AVjEvb8=; b=Y7XfwoGRVW0OV1ipEi3XT4Yf42FatwYu85uMyCHs9n4SwK82Pn+SrDmBbs3ptUzOc9 AgUnY0lswHIW1ZD+NCkre79yqaFY2shOr9KDtEhemRiTShGUHn5FRtEjpvS6m216VBwj 7fF/YgCjN5l0eb46N2ezVUS1cVzgnBUWiCZqHIHbatbxzKh+x1hoHn818Vv/vW0LVEpu BSrUYGpziBJCqFXayTpEtSYlr87ktRSmiizGcOeeBaBUHSpj3aE6A8y6C4DHLwldp5EL u0npWq6dEezyd5ShkQCV20TAuJot6dg285NKPlyLOq0tMkyFwI1AK/xszMKVUrkZRYOq kW3w== X-Gm-Message-State: ABUngvfjm4KCKXJlV68cWBwgk6jFellzZeyWj3g5W56fcbx6RfgbcyBX4rfk5KGGQeOF9bLygbE= X-Received: by 10.202.52.198 with SMTP id b189mr5369187oia.41.1478133730361; Wed, 02 Nov 2016 17:42:10 -0700 (PDT) Received: from localhost.localdomain (cpe-70-121-83-241.austin.res.rr.com. [70.121.83.241]) by smtp.gmail.com with ESMTPSA id p82sm1352229oia.25.2016.11.02.17.42.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 02 Nov 2016 17:42:05 -0700 (PDT) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Wed, 2 Nov 2016 19:41:56 -0500 Message-Id: <1478133719-10981-4-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1478133719-10981-1-git-send-email-bill.fischofer@linaro.org> References: <1478133719-10981-1-git-send-email-bill.fischofer@linaro.org> X-Topics: crypto patch Subject: [lng-odp] [API-NEXT PATCHv4 4/7] linux-generic: crypto: implement crypto capabilities and random kind X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Add random kind related values to odp_crypto_capability() and implement this selector field in odp_random_data(). Since odp-linux uses the OpenSSL RAND_bytes() API, the highest kind of random data supported by this implementation is ODP_RANDOM_CRYPTO. Signed-off-by: Bill Fischofer --- platform/linux-generic/odp_crypto.c | 47 +++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index c7431e6..46d137b 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-3-Clause */ +#include #include #include #include @@ -19,6 +20,7 @@ #include #include +#include #include #include @@ -618,6 +620,8 @@ int odp_crypto_capability(odp_crypto_capability_t *capa) capa->max_sessions = MAX_SESSIONS; + capa->max_random_kind = ODP_RANDOM_CRYPTO; + return 0; } @@ -871,12 +875,45 @@ int odp_crypto_term_global(void) return rc; } -int32_t -odp_random_data(uint8_t *buf, int32_t len, odp_bool_t use_entropy ODP_UNUSED) +int odp_random_data(uint8_t *buf, uint32_t len, odp_random_kind_t kind) { - int32_t rc; - rc = RAND_bytes(buf, len); - return (1 == rc) ? len /*success*/: -1 /*failure*/; + int rc; + + switch (kind) { + case ODP_RANDOM_BASIC: + RAND_pseudo_bytes(buf, len); + return len; + + case ODP_RANDOM_CRYPTO: + rc = RAND_bytes(buf, len); + return (1 == rc) ? (int)len /*success*/: -1 /*failure*/; + + case ODP_RANDOM_TRUE: + default: + return -1; + } +} + +int odp_random_seeded_data(uint8_t *buf, uint32_t len, + odp_random_kind_t kind, uint32_t *seed) +{ + union { + uint32_t rand_word; + uint8_t rand_byte[4]; + } u; + uint32_t i = 0, j; + + if (kind != ODP_RANDOM_BASIC) + return -1; + + while (i < len) { + u.rand_word = rand_r(seed); + + for (j = 0; j < 4 && i < len; j++, i++) + *buf++ = u.rand_byte[j]; + } + + return len; } odp_crypto_compl_t odp_crypto_compl_from_event(odp_event_t ev)