From: Slawomir Mrozowicz <slawomirx.mrozowicz@intel.com>
To: sergio.gonzalez.monroy@intel.com
Cc: dev@dpdk.org, Slawomir Mrozowicz <slawomirx.mrozowicz@intel.com>
Subject: [dpdk-dev] [PATCH] examples/ipsec-secgw: Calling risky function
Date: Tue, 7 Jun 2016 10:58:06 +0200 [thread overview]
Message-ID: <1465289886-14479-1-git-send-email-slawomirx.mrozowicz@intel.com> (raw)
lrand48 should not be used for security related applications,
as linear congruential algorithms are too easy to break.
Used a compliant random number generator /dev/urandom.
Fixes: d299106e8e31 ("examples/ipsec-secgw: add IPsec sample application")
Coverity ID 124558
Signed-off-by: Slawomir Mrozowicz <slawomirx.mrozowicz@intel.com>
---
examples/ipsec-secgw/esp.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/examples/ipsec-secgw/esp.c b/examples/ipsec-secgw/esp.c
index 0f6b33e..f3c4687 100644
--- a/examples/ipsec-secgw/esp.c
+++ b/examples/ipsec-secgw/esp.c
@@ -55,16 +55,17 @@
static inline void
random_iv_u64(uint64_t *buf, uint16_t n)
{
- unsigned left = n & 0x7;
- unsigned i;
+ int res = 0;
+ FILE *fp;
- RTE_ASSERT((n & 0x3) == 0);
-
- for (i = 0; i < (n >> 3); i++)
- buf[i] = rte_rand();
+ fp = fopen("/dev/urandom", "r");
+ if (fp != NULL) {
+ res = fread(buf, 8, n, fp);
+ fclose(fp);
+ }
- if (left)
- *((uint32_t *)&buf[i]) = (uint32_t)lrand48();
+ RTE_ASSERT(res != n);
+ RTE_LOG(DEBUG, IPSEC_ESP, "random_iv_u64 result %d\n", res);
}
/* IPv4 Tunnel */
--
1.9.1
next reply other threads:[~2016-06-07 8:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-07 8:58 Slawomir Mrozowicz [this message]
2016-06-07 8:11 ` Thomas Monjalon
2016-06-07 8:15 ` Sergio Gonzalez Monroy
2016-06-07 13:16 ` Mrozowicz, SlawomirX
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1465289886-14479-1-git-send-email-slawomirx.mrozowicz@intel.com \
--to=slawomirx.mrozowicz@intel.com \
--cc=dev@dpdk.org \
--cc=sergio.gonzalez.monroy@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).