From patchwork Mon Feb 2 15:42:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 44150 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f198.google.com (mail-we0-f198.google.com [74.125.82.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7EB462034D for ; Mon, 2 Feb 2015 15:42:58 +0000 (UTC) Received: by mail-we0-f198.google.com with SMTP id q59sf16865479wes.1 for ; Mon, 02 Feb 2015 07:42:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=L8NvCLD4FRf6W9lDI4dHjUBgZOS9SFqteN3YjpA4wrU=; b=gGV1fharI86k44DfeagIzNiyaAs/yEKBx74Vcst/r76hEPNNiz5s8YnlHhYlOoduxg HN/CkdDyZY/XNy9kjxnCJFJhDCJuLgvsQEEPbuAVHAjQu/sE99VNmMPamNdOlJxre3la y9xsokVsnwJLDAk3jMKgrOvDxnubjyFQzh5a5k5tzPECcF1TeCzPznyiu7fGw/Mf1k+8 FFlVI52CxTjohqiphh0rr4np+ZBVjQWg/GlJUhAgNeyhdzTfEy92grrd3aN3nkfKrPIR zenUqY6ZIeRswWl1GenDgN7Knc+ckX6PsdTpMpiDvw0a15AwM/eAwU5Y8XprsPzJ8vZk E/Fg== X-Gm-Message-State: ALoCoQkZXGEI78e5fCMASOjYNDdSrdGKJjf1MJSRyNaX6MRiDpWNLuQLjX9/ebEYXSwt5nxMJ4Ih X-Received: by 10.194.221.65 with SMTP id qc1mr2466723wjc.7.1422891777450; Mon, 02 Feb 2015 07:42:57 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.45.6 with SMTP id i6ls632507lam.10.gmail; Mon, 02 Feb 2015 07:42:57 -0800 (PST) X-Received: by 10.112.144.164 with SMTP id sn4mr14973706lbb.2.1422891777210; Mon, 02 Feb 2015 07:42:57 -0800 (PST) Received: from mail-la0-f50.google.com (mail-la0-f50.google.com. [209.85.215.50]) by mx.google.com with ESMTPS id r10si3367254lar.126.2015.02.02.07.42.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 02 Feb 2015 07:42:57 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) client-ip=209.85.215.50; Received: by mail-la0-f50.google.com with SMTP id hs14so42002534lab.9 for ; Mon, 02 Feb 2015 07:42:57 -0800 (PST) X-Received: by 10.152.7.229 with SMTP id m5mr20371125laa.80.1422891777103; Mon, 02 Feb 2015 07:42:57 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp1371613lbj; Mon, 2 Feb 2015 07:42:56 -0800 (PST) X-Received: by 10.224.80.135 with SMTP id t7mr42583118qak.65.1422891774904; Mon, 02 Feb 2015 07:42:54 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id c6si25451475qan.67.2015.02.02.07.42.53 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 02 Feb 2015 07:42:54 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YIJ9H-0001m0-Gk; Mon, 02 Feb 2015 15:42:51 +0000 Received: from mail-la0-f52.google.com ([209.85.215.52]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YIJ91-0001kY-2i for lng-odp@lists.linaro.org; Mon, 02 Feb 2015 15:42:35 +0000 Received: by mail-la0-f52.google.com with SMTP id ge10so42173742lab.11 for ; Mon, 02 Feb 2015 07:42:29 -0800 (PST) X-Received: by 10.152.5.2 with SMTP id o2mr20278718lao.5.1422891749273; Mon, 02 Feb 2015 07:42:29 -0800 (PST) Received: from macmini.lan (78-82-118-111.tn.glocalnet.net. [78.82.118.111]) by mx.google.com with ESMTPSA id w1sm4461682lal.49.2015.02.02.07.42.28 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Feb 2015 07:42:28 -0800 (PST) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Mon, 2 Feb 2015 16:42:14 +0100 Message-Id: <1422891740-5347-4-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1422891740-5347-1-git-send-email-ola.liljedahl@linaro.org> References: <1422891740-5347-1-git-send-email-ola.liljedahl@linaro.org> X-Topics: crypto patch Subject: [lng-odp] [PATCHv3 03/18] api: odp_crypto.h: odp_hw_random_get(): return number of bytes written X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ola.liljedahl@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 odp_hw_random_get() takes output buffer size as input and returns number of bytes written (on success), <0 on failure. Updated the implementation. Updated all usages in example and test programs. Signed-off-by: Ola Liljedahl --- (This document/code contribution attached is provided under the terms of agreement LES-LTM-21309) example/ipsec/odp_ipsec_cache.c | 6 ++++-- include/odp/api/crypto.h | 17 ++++++++++------- platform/linux-generic/odp_crypto.c | 8 ++++---- test/validation/crypto/odp_crypto_test_rng.c | 6 ++---- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/example/ipsec/odp_ipsec_cache.c b/example/ipsec/odp_ipsec_cache.c index 904e7b6..ab05829 100644 --- a/example/ipsec/odp_ipsec_cache.c +++ b/example/ipsec/odp_ipsec_cache.c @@ -96,9 +96,11 @@ int create_ipsec_cache_entry(sa_db_entry_t *cipher_sa, /* Generate an IV */ if (params.iv.length) { - size_t size = params.iv.length; + ssize_t size = params.iv.length; - odp_hw_random_get(params.iv.data, &size, 1); + ssize_t ret = odp_hw_random_get(params.iv.data, size, 1); + if (ret != size) + return -1; } /* Synchronous session create for now */ diff --git a/include/odp/api/crypto.h b/include/odp/api/crypto.h index 545c1a5..e9530a3 100644 --- a/include/odp/api/crypto.h +++ b/include/odp/api/crypto.h @@ -18,6 +18,8 @@ extern "C" { #endif +#include + /** @defgroup odp_crypto ODP CRYPTO * Macros, enums, types and operations to utilise crypto. * @{ @@ -330,18 +332,19 @@ odp_crypto_compl_result(odp_crypto_compl_t completion_event, odp_crypto_op_result_t *result); /** - * Generate random byte string + * Generate random byte data * - * @param buf Pointer to store result - * @param len Pointer to input length value as well as return value - * @param use_entropy Use entropy + * @param[out] buf Output buffer + * @param bufsz Size of output buffer + * @param use_entropy Use entropy * * @todo Define the implication of the use_entropy parameter * - * @return 0 if succesful + * @return Number of bytes written + * @retval <0 on failure */ -int -odp_hw_random_get(uint8_t *buf, size_t *len, odp_bool_t use_entropy); +ssize_t +odp_hw_random_get(uint8_t *buf, ssize_t bufsz, bool use_entropy); /** * @} diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index 46766fa..b553306 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -446,12 +446,12 @@ odp_crypto_init_global(void) return 0; } -int -odp_hw_random_get(uint8_t *buf, size_t *len, odp_bool_t use_entropy ODP_UNUSED) +ssize_t +odp_hw_random_get(uint8_t *buf, ssize_t len, bool use_entropy ODP_UNUSED) { int rc; - rc = RAND_bytes(buf, *len); - return ((1 == rc) ? 0 : -1); + rc = RAND_bytes(buf, len); + return (1 == rc) ? len /*success*/: -1 /*failure*/; } odp_crypto_compl_t odp_crypto_compl_from_event(odp_event_t ev) diff --git a/test/validation/crypto/odp_crypto_test_rng.c b/test/validation/crypto/odp_crypto_test_rng.c index 458f908..a9de5b9 100644 --- a/test/validation/crypto/odp_crypto_test_rng.c +++ b/test/validation/crypto/odp_crypto_test_rng.c @@ -16,12 +16,10 @@ static void rng_get_size(void) { int ret; - size_t len = TDES_CBC_IV_LEN; uint8_t buf[TDES_CBC_IV_LEN]; - ret = odp_hw_random_get(buf, &len, false); - CU_ASSERT(!ret); - CU_ASSERT(len == TDES_CBC_IV_LEN); + ret = odp_hw_random_get(buf, sizeof(buf), false); + CU_ASSERT(ret == TDES_CBC_IV_LEN); } CU_TestInfo test_rng[] = {