From patchwork Mon Dec 5 01:15:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 86474 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp1258290qgi; Sun, 4 Dec 2016 17:17:28 -0800 (PST) X-Received: by 10.237.60.11 with SMTP id t11mr49328101qte.227.1480900648452; Sun, 04 Dec 2016 17:17:28 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id p58si7819091qta.237.2016.12.04.17.17.27; Sun, 04 Dec 2016 17:17:28 -0800 (PST) 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 DD37C63621; Mon, 5 Dec 2016 01:17:27 +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=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, 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 6359963627; Mon, 5 Dec 2016 01:15:51 +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 46AB763609; Mon, 5 Dec 2016 01:15:30 +0000 (UTC) Received: from mail-oi0-f46.google.com (mail-oi0-f46.google.com [209.85.218.46]) by lists.linaro.org (Postfix) with ESMTPS id 416CF63608 for ; Mon, 5 Dec 2016 01:15:27 +0000 (UTC) Received: by mail-oi0-f46.google.com with SMTP id v84so323259308oie.3 for ; Sun, 04 Dec 2016 17:15:27 -0800 (PST) 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=hL2mzNZdc74xAkqUS1xUk/SjTEgRmcx7u8879nUSi9I=; b=gVTeV9rjonbDExA2SWHTMjSz89YU07uQ1fW3XKfKV8C7dq4MshunoqrQLoUZRhJvZ2 25MEMsYRc9o+yDbNXXgDddR0XW4Kz18iRnzF2UeO/qAdzm9SbeQ7KM9ajl4DQg9Mbtl5 M8tGn7rvoq4VRp7m5s9l+SXNS7QvTmpjow9O3aR5EkHpUjFivagjOGjAQ0W3j+VPX3u+ x+/YyAJFzg5G7I2X5mmepjzNYyO9LFTIBIInTmTcymkUjbG66BhF3X7gP6InnhWYqYph pAoPyRec9W4pkm3GZauPF9r4sBmXDI95dLPa2wcDKP15MqkQP5BUpTa0GIoBuX5N/Lk7 ii5A== X-Gm-Message-State: AKaTC00q542cdtOvJ2kJRlk5C7Y38IVwr6CanBT7QmZivJjjA31cAUV3XZq7HZY75dP+Y4uvMT0= X-Received: by 10.157.47.250 with SMTP id b55mr31409564otd.236.1480900526762; Sun, 04 Dec 2016 17:15:26 -0800 (PST) Received: from localhost.localdomain (cpe-70-121-83-241.austin.res.rr.com. [70.121.83.241]) by smtp.gmail.com with ESMTPSA id t43sm5378971otd.27.2016.12.04.17.15.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 04 Dec 2016 17:15:26 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Sun, 4 Dec 2016 19:15:17 -0600 Message-Id: <1480900520-21989-4-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1480900520-21989-1-git-send-email-bill.fischofer@linaro.org> References: <1480900520-21989-1-git-send-email-bill.fischofer@linaro.org> Subject: [lng-odp] [API-NEXT PATCHv5 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 7e686ff..8d1eea8 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 @@ -620,6 +622,8 @@ int odp_crypto_capability(odp_crypto_capability_t *capa) capa->max_sessions = MAX_SESSIONS; + capa->max_random_kind = ODP_RANDOM_CRYPTO; + return 0; } @@ -877,12 +881,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)