]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lwip.git/commitdiff
PPP, magic, enables building without PPP_MD5_RANDM support
authorSylvain Rochet <gradator@gradator.net>
Sun, 30 Aug 2015 16:41:41 +0000 (18:41 +0200)
committerSylvain Rochet <gradator@gradator.net>
Sun, 30 Aug 2015 19:09:39 +0000 (21:09 +0200)
The only API difference with and without the PPP_MD5_RANDM support is the
availability of the random_bytes() function. Added a random_bytes()
function on top of magic() when PPP_MD5_RANDM support is not enabled,
thus allowing builds for both cases.

PPP_MD5_RANDM is still enabled by default (it was mandatory) if a protocol
using encryption is enabled, such as CHAP, EAP, or L2TP auth support.

src/include/lwip/opt.h
src/include/netif/ppp/magic.h
src/netif/ppp/magic.c

index 52f19b8d7f607cd6d80de4e1b8474fa3e446fb54..359a0c26889c0087b0b60998256cd096c0e44915 100644 (file)
 
 /**
  * PPP_MD5_RANDM==1: Use MD5 for better randomness.
- * Automatically enabled if CHAP or L2TP AUTH support is enabled.
+ * Enabled by default if CHAP, EAP, or L2TP AUTH support is enabled.
  */
 #ifndef PPP_MD5_RANDM
-#define PPP_MD5_RANDM                   0
+#define PPP_MD5_RANDM                   (CHAP_SUPPORT || EAP_SUPPORT || PPPOL2TP_AUTH_SUPPORT)
 #endif
-#if CHAP_SUPPORT || PPPOL2TP_AUTH_SUPPORT
-/*  MD5 Random is required for CHAP and L2TP AUTH */
-#undef PPP_MD5_RANDM
-#define PPP_MD5_RANDM                   1
-#endif /* CHAP_SUPPORT || PPPOL2TP_AUTH_SUPPORT */
 
 /**
  * PolarSSL library, used if necessary and not previously disabled
index 1c9b96d058bb6888155985221777039492c6e226..dd99e48378a097c2eeb62b647244ba06bf671b70 100644 (file)
@@ -100,12 +100,6 @@ void magic_randomize(void);
  */
 u32_t magic(void);     /* Returns the next magic number */
 
-/*
- * Return a new random number between 0 and (2^pow)-1 included.
- */
-u32_t magic_pow(u8_t pow);
-
-#if PPP_MD5_RANDM
 /*
  * Fill buffer with random bytes
  *
@@ -116,8 +110,12 @@ u32_t magic_pow(u8_t pow);
  * least some degree.  Also, it's important to get a good seed before
  * the first use.
  */
-void random_bytes(unsigned char *buf, u32_t len);
-#endif /* PPP_MD5_RANDM */
+void random_bytes(unsigned char *buf, u32_t buf_len);
+
+/*
+ * Return a new random number between 0 and (2^pow)-1 included.
+ */
+u32_t magic_pow(u8_t pow);
 
 #endif /* MAGIC_H */
 
index 66a1c3cd3e2d54d1736ca6f589625991f379497a..591dbbbff95f747f3dcd8fac4756e475556b6c18 100644 (file)
@@ -209,7 +209,7 @@ static u32_t magic_randomseed = 0;      /* Seed used for random number generatio
  * operational.  Thus we call it again on the first random
  * event.
  */
-void magic_init() {
+void magic_init(void) {
   magic_randomseed += sys_jiffies();
 
   /* Initialize the Borland random number generator. */
@@ -249,10 +249,24 @@ void magic_randomize(void) {
  * operator or network events in which case it will be pseudo random
  * seeded by the real time clock.
  */
-u32_t magic() {
+u32_t magic(void) {
   return ((((u32_t)rand() << 16) + rand()) + magic_randomseed);
 }
 
+/*
+ * random_bytes - Fill a buffer with random bytes.
+ */
+void random_bytes(unsigned char *buf, u32_t buf_len) {
+  u32_t new_rand, n;
+
+  while (buf_len > 0) {
+    new_rand = magic();
+    n = LWIP_MIN(buf_len, sizeof(new_rand));
+    MEMCPY(buf, &new_rand, n);
+    buf += n;
+    buf_len -= n;
+  }
+}
 #endif /* PPP_MD5_RANDM */
 
 /*