From patchwork Fri Jan 30 09:28:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 44022 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D45B22410D for ; Fri, 30 Jan 2015 09:29:37 +0000 (UTC) Received: by mail-lb0-f199.google.com with SMTP id f15sf7406361lbj.2 for ; Fri, 30 Jan 2015 01:29:31 -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=acylfAtwX6RUKVBLYDHQLNduGhLACgJXXusWtpESvlA=; b=imyzYNuPAnAkCaZMgpCk6n+q1XRTtd3ycFziojwcnUAB1n1RNZoqqpaeW6dX01p4tb hy0XkyYCTeaoBqT0h3mxNp3gonjtsDaSYe8vzjOyGznKrmffCVdDC2E1pGNtF5LoWt9c lX3heMOMKZV5y6kSU8dNhVgqw/8yIsUIQxEfHwlXcWFMOrY7LKWiIETuXvEvXyDtZVzD 9FdH9KloLZ8IjyM9rmgILzbqOXYHiNpbpzRnG0/F/p/u2i7t7+CKWY3l+Ru8ww1VnKww 6a+NY9Eg4eIoOqplBcv/yu7ZPZHwqmDDeedwwsMdODZVb/fg6fxZzWTQ8Ef6eKY9AnLW kcjA== X-Gm-Message-State: ALoCoQkRu2gdZexRznOYrBZGuh5N64IF3VEPcdgcC+un9oB1m1pjnM4C7c+550w1JhEHFGA9VPnZ X-Received: by 10.152.3.234 with SMTP id f10mr672213laf.1.1422610170767; Fri, 30 Jan 2015 01:29:30 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.37.137 with SMTP id y9ls447365laj.59.gmail; Fri, 30 Jan 2015 01:29:30 -0800 (PST) X-Received: by 10.152.19.194 with SMTP id h2mr5275066lae.77.1422610170549; Fri, 30 Jan 2015 01:29:30 -0800 (PST) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id qn4si9711812lbb.56.2015.01.30.01.29.30 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 30 Jan 2015 01:29:30 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by mail-la0-f51.google.com with SMTP id ge10so22705432lab.10 for ; Fri, 30 Jan 2015 01:29:30 -0800 (PST) X-Received: by 10.152.245.44 with SMTP id xl12mr5392565lac.81.1422610170419; Fri, 30 Jan 2015 01:29:30 -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 h5csp220595lbj; Fri, 30 Jan 2015 01:29:29 -0800 (PST) X-Received: by 10.52.183.34 with SMTP id ej2mr2344329vdc.9.1422610167345; Fri, 30 Jan 2015 01:29:27 -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 n13si4842307vci.49.2015.01.30.01.29.25 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 30 Jan 2015 01:29:27 -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 1YH7tD-0004E1-Tf; Fri, 30 Jan 2015 09:29:23 +0000 Received: from mail-la0-f48.google.com ([209.85.215.48]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YH7sv-0004AY-Uk for lng-odp@lists.linaro.org; Fri, 30 Jan 2015 09:29:06 +0000 Received: by mail-la0-f48.google.com with SMTP id pv20so22564108lab.7 for ; Fri, 30 Jan 2015 01:29:00 -0800 (PST) X-Received: by 10.152.183.196 with SMTP id eo4mr5656882lac.0.1422610140240; Fri, 30 Jan 2015 01:29:00 -0800 (PST) Received: from macmini.lan (78-82-118-111.tn.glocalnet.net. [78.82.118.111]) by mx.google.com with ESMTPSA id p5sm2614383laj.0.2015.01.30.01.28.59 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 30 Jan 2015 01:28:59 -0800 (PST) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Fri, 30 Jan 2015 10:28:47 +0100 Message-Id: <1422610133-20756-4-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1422610133-20756-1-git-send-email-ola.liljedahl@linaro.org> References: <1422610133-20756-1-git-send-email-ola.liljedahl@linaro.org> X-Topics: crypto patch Subject: [lng-odp] [PATCHv2 03/16] 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.51 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() returns number of bytes written (on success), return <0 on failure. Output buffer size pass by value, not reference, as it is no longer written to. Updated some doxygen descriptions, particularly the @return/@retval descriptions. No other changes of implementation necessary. 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 ++++-- platform/linux-generic/include/api/odp_crypto.h | 24 ++++++++++++++---------- platform/linux-generic/odp_crypto.c | 8 ++++---- test/validation/crypto/odp_crypto_test_rng.c | 6 ++---- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/example/ipsec/odp_ipsec_cache.c b/example/ipsec/odp_ipsec_cache.c index 15180f2..332fb81 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/platform/linux-generic/include/api/odp_crypto.h b/platform/linux-generic/include/api/odp_crypto.h index da6041c..f5a8801 100644 --- a/platform/linux-generic/include/api/odp_crypto.h +++ b/platform/linux-generic/include/api/odp_crypto.h @@ -18,6 +18,7 @@ extern "C" { #endif +#include #include #include #include @@ -218,7 +219,8 @@ typedef struct odp_crypto_compl_status { * @param session Created session else ODP_CRYPTO_SESSION_INVALID * @param status Failure code if unsuccessful * - * @return 0 if successful else -1 + * @retval 0 on success + * @retval <0 on failure */ int odp_crypto_session_create(odp_crypto_session_params_t *params, @@ -242,7 +244,8 @@ odp_crypto_session_create(odp_crypto_session_params_t *params, * @param posted Pointer to return posted, TRUE for async operation * @param completion_event Event by which the operation results are delivered. * - * @return 0 if successful else -1 + * @retval 0 on success + * @retval <0 on failure */ int odp_crypto_operation(odp_crypto_op_params_t *params, @@ -281,7 +284,7 @@ odp_crypto_get_operation_compl_status(odp_event_t completion_event, * * @param completion_event Event containing operation results * - * @return Packet structure where data now resides + * @return Handle for packet where data now resides */ odp_packet_t odp_crypto_get_operation_compl_packet(odp_event_t completion_event); @@ -297,18 +300,19 @@ void * odp_crypto_get_operation_compl_ctx(odp_event_t completion_event); /** - * 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 + * @retval Number of bytes written + * @retval <0 on failure */ -int -odp_hw_random_get(uint8_t *buf, size_t *len, bool 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 4436a0c..b329756 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -428,12 +428,12 @@ odp_crypto_init_global(void) return 0; } -int -odp_hw_random_get(uint8_t *buf, size_t *len, bool 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*/; } void 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[] = {