From patchwork Tue Feb 3 16:48:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 44259 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F00442034D for ; Tue, 3 Feb 2015 16:49:05 +0000 (UTC) Received: by mail-la0-f71.google.com with SMTP id s18sf21764564lam.2 for ; Tue, 03 Feb 2015 08:49:04 -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=rEgG8ubUY/6jwFBIdZda6oIDCHbRBIPVpMraqczY2Hk=; b=Cv1E1pQzH1J3XaySqHHpoQJRqJk1/T/+MGbFtNtcao4i4Tkk7JXbz0dhrexQGv8RAX UI/jJ1bNcCR8eXxJX094RjV20XsxuuQx/ndnYnc1BXTJbF8E8jGS/xH9hdBgoGXLEh5t timGy45X9++KMfcppW7VdLDn04J8nSYQAr5fJemzF5YXqPQiGZ9iaJ0RMDNI9+O5DJhn uGaySSwbIWMvidQO3GuxwQAkK2HkL8GvtsZKO3biCDsiylJxaBxHwD/bygaujs0xTYX8 hM7DIG2C4vidNinAhFN2ahFPL/V4ELTkXieV0tpso7hci1dTnz2hkFXEWtj+outrD2jQ +ZyA== X-Gm-Message-State: ALoCoQmh1IPy5QKISUzBsirnTp8/AF1l9uT9U00Dbp/eL2cKtehdM+WkZ+SKiugp+YhS1P9+F6Eh X-Received: by 10.180.108.197 with SMTP id hm5mr2113825wib.4.1422982144839; Tue, 03 Feb 2015 08:49:04 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.3.4 with SMTP id 4ls250726lay.65.gmail; Tue, 03 Feb 2015 08:49:04 -0800 (PST) X-Received: by 10.152.36.162 with SMTP id r2mr12647676laj.9.1422982144674; Tue, 03 Feb 2015 08:49:04 -0800 (PST) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id ry10si17027170lbb.117.2015.02.03.08.49.04 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 03 Feb 2015 08:49:04 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by mail-la0-f46.google.com with SMTP id s18so53526059lam.5 for ; Tue, 03 Feb 2015 08:49:04 -0800 (PST) X-Received: by 10.152.2.41 with SMTP id 9mr4947716lar.59.1422982144562; Tue, 03 Feb 2015 08:49:04 -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 h5csp2058268lbj; Tue, 3 Feb 2015 08:49:03 -0800 (PST) X-Received: by 10.224.160.81 with SMTP id m17mr45553907qax.63.1422982143002; Tue, 03 Feb 2015 08:49:03 -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 e4si29331447qai.92.2015.02.03.08.49.01 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 03 Feb 2015 08:49:02 -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 1YIgeq-00088x-2P; Tue, 03 Feb 2015 16:49:00 +0000 Received: from mail-la0-f53.google.com ([209.85.215.53]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YIgeY-00086d-U9 for lng-odp@lists.linaro.org; Tue, 03 Feb 2015 16:48:43 +0000 Received: by mail-la0-f53.google.com with SMTP id gq15so53376737lab.12 for ; Tue, 03 Feb 2015 08:48:37 -0800 (PST) X-Received: by 10.112.205.68 with SMTP id le4mr25704594lbc.96.1422982117035; Tue, 03 Feb 2015 08:48:37 -0800 (PST) Received: from macmini.lan (78-82-118-111.tn.glocalnet.net. [78.82.118.111]) by mx.google.com with ESMTPSA id y2sm434179lay.23.2015.02.03.08.48.36 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 03 Feb 2015 08:48:36 -0800 (PST) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Tue, 3 Feb 2015 17:48:13 +0100 Message-Id: <1422982108-13813-4-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1422982108-13813-1-git-send-email-ola.liljedahl@linaro.org> References: <1422982108-13813-1-git-send-email-ola.liljedahl@linaro.org> X-Topics: crypto patch Subject: [lng-odp] [PATCHv5 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.46 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..1e15775 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 size 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 size, odp_bool_t use_entropy); /** * @} diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index 46766fa..94ebaeb 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, odp_bool_t 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[] = {