From patchwork Tue Feb 3 14:53:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 44231 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7D15A2034D for ; Tue, 3 Feb 2015 14:54:04 +0000 (UTC) Received: by mail-la0-f70.google.com with SMTP id ge10sf21267459lab.1 for ; Tue, 03 Feb 2015 06:54:03 -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=D5qjGTKvEqFQR1VtrfwQ7BnAEyO5sglcrX+rPF58qJ+99AyH0DxgWwg6+xzWkNywR2 y0wI61DMJNkWXtbCJSQ7oln1OgwOsUMoMS38WAw+Tgvs/UtmeGb2DGUHYlqGKR6DZXW/ 1yVm4TFYLS6hjXWbdQDfw1p4GaJQVR1OgCw/b7f/28VwM1WbwGWTVKkuHtB4jgAM0jYR z559uteanKqrA0rAQf0StPMGtueRgN7DFy756sZmA/0fxE846Bh6F0or3oUMuXtvFMJ5 Re6qZz1Qmbo0FbVshsGcG90guJsyVNtNiOzMOQkZLtRF6/cK2Xj3P3MQyWupKfMdtBCd l7Ew== X-Gm-Message-State: ALoCoQkbT/JCm5ODP8ki6Pjm8nRVIsmWcdlTFMDpVsct3HHOsRcpQk9FkYI7BcHQ/H7+iYpo/Pam X-Received: by 10.112.131.106 with SMTP id ol10mr3213945lbb.20.1422975243220; Tue, 03 Feb 2015 06:54:03 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.167 with SMTP id x7ls457299lal.61.gmail; Tue, 03 Feb 2015 06:54:03 -0800 (PST) X-Received: by 10.112.159.195 with SMTP id xe3mr24604208lbb.64.1422975243079; Tue, 03 Feb 2015 06:54:03 -0800 (PST) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id ec7si19376304lbc.32.2015.02.03.06.54.03 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 03 Feb 2015 06:54:03 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by mail-la0-f53.google.com with SMTP id gq15so52482512lab.12 for ; Tue, 03 Feb 2015 06:54:03 -0800 (PST) X-Received: by 10.152.20.169 with SMTP id o9mr25107706lae.50.1422975242976; Tue, 03 Feb 2015 06:54:02 -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 h5csp1987761lbj; Tue, 3 Feb 2015 06:54:02 -0800 (PST) X-Received: by 10.229.114.74 with SMTP id d10mr10059380qcq.5.1422975236274; Tue, 03 Feb 2015 06:53:56 -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 q7si29105653qas.7.2015.02.03.06.53.54 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 03 Feb 2015 06:53:56 -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 1YIerR-0001aJ-AC; Tue, 03 Feb 2015 14:53:53 +0000 Received: from mail-la0-f41.google.com ([209.85.215.41]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YIer9-0001Xo-Ok for lng-odp@lists.linaro.org; Tue, 03 Feb 2015 14:53:35 +0000 Received: by mail-la0-f41.google.com with SMTP id gm9so52583931lab.0 for ; Tue, 03 Feb 2015 06:53:29 -0800 (PST) X-Received: by 10.152.116.43 with SMTP id jt11mr25069251lab.69.1422975209821; Tue, 03 Feb 2015 06:53:29 -0800 (PST) Received: from localhost.localdomain (78-82-118-111.tn.glocalnet.net. [78.82.118.111]) by mx.google.com with ESMTPSA id jf3sm5082572lbc.44.2015.02.03.06.53.29 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 03 Feb 2015 06:53:29 -0800 (PST) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Tue, 3 Feb 2015 15:53:06 +0100 Message-Id: <1422975201-3364-4-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1422975201-3364-1-git-send-email-ola.liljedahl@linaro.org> References: <1422975201-3364-1-git-send-email-ola.liljedahl@linaro.org> X-Topics: crypto patch Subject: [lng-odp] [PATCHv4 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.53 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[] = {