You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/04/17 02:40:00 UTC
[incubator-nuttx-apps] 02/04: Fix nxstyle issue for Juha patch
This is an automated email from the ASF dual-hosted git repository.
gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit d10eb2ae3a85c06e9489c7b72804851c7ff12291
Author: Alan C. Assis <en...@siam.ind.br>
AuthorDate: Thu Apr 16 10:28:12 2020 -0300
Fix nxstyle issue for Juha patch
---
include/netutils/md5.h | 17 +++++++-------
netutils/codecs/Kconfig | 5 ++--
netutils/codecs/md5.c | 62 ++++++++++++++++++++++++++-----------------------
nshlib/nsh_codeccmd.c | 14 ++++++-----
4 files changed, 52 insertions(+), 46 deletions(-)
diff --git a/include/netutils/md5.h b/include/netutils/md5.h
index bb75e6d..d5bd3e3 100644
--- a/include/netutils/md5.h
+++ b/include/netutils/md5.h
@@ -10,7 +10,6 @@
*
* This code implements the MD5 message-digest algorithm.
* The algorithm is due to Ron Rivest. This code was
- * written by Colin Plumb in 1993, no copyright is claimed.
* This code is in the public domain; do with it what you wish.
*
* Equivalent code is available from RSA Data Security, Inc.
@@ -19,8 +18,8 @@
* with every copy.
*
* To compute the message digest of a chunk of bytes, declare an
- * MD5Context structure, pass it to MD5Init, call MD5Update as
- * needed on buffers full of bytes, and then call MD5Final, which
+ * md5_context_s structure, pass it to md5_init, call md5_update as
+ * needed on buffers full of bytes, and then call md5_final, which
* will fill a supplied 16-byte array with the digest.
*
* See README and COPYING for more details.
@@ -74,24 +73,24 @@ extern "C"
* Public Types
****************************************************************************/
-struct MD5Context
+struct md5_context_s
{
uint32_t buf[4];
uint32_t bits[2];
uint8_t in[64];
};
-typedef struct MD5Context MD5_CTX;
+typedef struct md5_context_s MD5_CTX;
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
-void MD5Init(struct MD5Context *context);
-void MD5Update(struct MD5Context *context, unsigned char const *buf,
+void md5_init(struct md5_context_s *context);
+void md5_update(struct md5_context_s *context, unsigned char const *buf,
unsigned len);
-void MD5Final(unsigned char digest[16], struct MD5Context *context);
-void MD5Transform(uint32_t buf[4], uint32_t const in[16]);
+void md5_final(unsigned char digest[16], struct md5_context_s *context);
+void md5_transform(uint32_t buf[4], uint32_t const in[16]);
void md5_sum(const uint8_t *addr, const size_t len, uint8_t *mac);
char *md5_hash(const uint8_t *addr, const size_t len);
diff --git a/netutils/codecs/Kconfig b/netutils/codecs/Kconfig
index 096b732..baa88bb 100644
--- a/netutils/codecs/Kconfig
+++ b/netutils/codecs/Kconfig
@@ -24,8 +24,9 @@ config CODECS_HASH_MD5
bool "MD5 Support"
default n
---help---
- Enables support for the following interfaces: MD5Init(),
- MD5Update(), MD5Final(), MD5Transform(), md5_sum() and md5_hash()
+ Enables support for the following interfaces: md5_init(),
+ md5_update(), md5_final(), md5_transform(), md5_sum() and
+ md5_hash()
Contributed NuttX by Darcy Gong.
diff --git a/netutils/codecs/md5.c b/netutils/codecs/md5.c
index 2d5d136..132b8bd 100644
--- a/netutils/codecs/md5.c
+++ b/netutils/codecs/md5.c
@@ -19,8 +19,8 @@
* with every copy.
*
* To compute the message digest of a chunk of bytes, declare an
- * MD5Context structure, pass it to MD5Init, call MD5Update as
- * needed on buffers full of bytes, and then call MD5Final, which
+ * md5_context_s structure, pass it to md5_init, call md5_update as
+ * needed on buffers full of bytes, and then call md5_final, which
* will fill a supplied 16-byte array with the digest.
*
* See README and COPYING for more details.
@@ -91,13 +91,13 @@
****************************************************************************/
/****************************************************************************
- * Name: byteReverse
+ * Name: byte_reverse
****************************************************************************/
#ifndef CONFIG_ENDIAN_BIG
-# define byteReverse(buf, len)
+# define byte_reverse(buf, len)
#else
-static void byteReverse(FAR unsigned char *buf, unsigned longs)
+static void byte_reverse(FAR unsigned char *buf, unsigned longs)
{
uint32_t t;
do
@@ -107,7 +107,7 @@ static void byteReverse(FAR unsigned char *buf, unsigned longs)
((uint32_t)buf[1] << 8) |
(uint32_t)buf[0];
- *(uint32_t*)buf = t;
+ *(uint32_t *)buf = t;
buf += 4;
}
while (--longs);
@@ -119,7 +119,7 @@ static void byteReverse(FAR unsigned char *buf, unsigned longs)
****************************************************************************/
/****************************************************************************
- * Name: MD5Init
+ * Name: md5_init
*
* Description:
* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
@@ -127,7 +127,7 @@ static void byteReverse(FAR unsigned char *buf, unsigned longs)
*
****************************************************************************/
-void MD5Init(struct MD5Context *ctx)
+void md5_init(struct md5_context_s *ctx)
{
ctx->buf[0] = 0x67452301;
ctx->buf[1] = 0xefcdab89;
@@ -139,7 +139,7 @@ void MD5Init(struct MD5Context *ctx)
}
/****************************************************************************
- * Name: MD5Update
+ * Name: md5_update
*
* Description:
* Update context to reflect the concatenation of another buffer full
@@ -147,7 +147,8 @@ void MD5Init(struct MD5Context *ctx)
*
****************************************************************************/
-void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
+void md5_update(struct md5_context_s *ctx, unsigned char const *buf,
+ unsigned len)
{
uint32_t t;
@@ -181,8 +182,8 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
}
memcpy(p, buf, t);
- byteReverse(ctx->in, 16);
- MD5Transform(ctx->buf, (uint32_t *) ctx->in);
+ byte_reverse(ctx->in, 16);
+ md5_transform(ctx->buf, (uint32_t *) ctx->in);
buf += t;
len -= t;
}
@@ -192,8 +193,8 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
while (len >= 64)
{
memcpy(ctx->in, buf, 64);
- byteReverse(ctx->in, 16);
- MD5Transform(ctx->buf, (uint32_t *) ctx->in);
+ byte_reverse(ctx->in, 16);
+ md5_transform(ctx->buf, (uint32_t *) ctx->in);
buf += 64;
len -= 64;
}
@@ -204,7 +205,7 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
}
/****************************************************************************
- * Name: MD5Final
+ * Name: md5_final
*
* Description:
* Final wrapup - pad to 64-byte boundary with the bit pattern
@@ -212,7 +213,7 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
*
****************************************************************************/
-void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
+void md5_final(unsigned char digest[16], struct md5_context_s *ctx)
{
unsigned count;
unsigned char *p;
@@ -239,8 +240,8 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
/* Two lots of padding: Pad the first block to 64 bytes */
memset(p, 0, count);
- byteReverse(ctx->in, 16);
- MD5Transform(ctx->buf, (uint32_t *) ctx->in);
+ byte_reverse(ctx->in, 16);
+ md5_transform(ctx->buf, (uint32_t *) ctx->in);
/* Now fill the next block with 56 bytes */
@@ -253,32 +254,35 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
memset(p, 0, count - 8);
}
- byteReverse(ctx->in, 14);
+ byte_reverse(ctx->in, 14);
/* Append length in bits and transform */
((uint32_t *)ctx->in)[14] = ctx->bits[0];
((uint32_t *)ctx->in)[15] = ctx->bits[1];
- MD5Transform(ctx->buf, (uint32_t *) ctx->in);
- byteReverse((unsigned char *)ctx->buf, 4);
+ md5_transform(ctx->buf, (uint32_t *) ctx->in);
+ byte_reverse((unsigned char *)ctx->buf, 4);
memcpy(digest, ctx->buf, 16);
- memset(ctx, 0, sizeof(struct MD5Context)); /* In case it's sensitive */
+ memset(ctx, 0, sizeof(struct md5_context_s)); /* In case it's sensitive */
}
/****************************************************************************
- * Name: MD5Transform
+ * Name: md5_transform
*
* Description:
* The core of the MD5 algorithm, this alters an existing MD5 hash to
- * reflect the addition of 16 longwords of new data. MD5Update blocks
+ * reflect the addition of 16 longwords of new data. md5_update blocks
* the data and converts bytes into longwords for this routine.
*
****************************************************************************/
-void MD5Transform(uint32_t buf[4], uint32_t const in[16])
+void md5_transform(uint32_t buf[4], uint32_t const in[16])
{
- register uint32_t a, b, c, d;
+ register uint32_t a;
+ register uint32_t b;
+ register uint32_t c;
+ register uint32_t d;
a = buf[0];
b = buf[1];
@@ -376,9 +380,9 @@ void md5_sum(const uint8_t * addr, const size_t len, uint8_t * mac)
{
MD5_CTX ctx;
- MD5Init(&ctx);
- MD5Update(&ctx, addr, len);
- MD5Final(mac, &ctx);
+ md5_init(&ctx);
+ md5_update(&ctx, addr, len);
+ md5_final(mac, &ctx);
}
/****************************************************************************
diff --git a/nshlib/nsh_codeccmd.c b/nshlib/nsh_codeccmd.c
index a2ed61a..fe6ea6f 100644
--- a/nshlib/nsh_codeccmd.c
+++ b/nshlib/nsh_codeccmd.c
@@ -197,7 +197,7 @@ static void b64dec_cb(FAR char *src, int srclen, FAR char *dest,
else
{
base64w_decode((unsigned char *)src, srclen,
- (unsigned char *)dest,(size_t *)destlen);
+ (unsigned char *)dest, (size_t *)destlen);
}
}
#endif
@@ -210,7 +210,7 @@ static void b64dec_cb(FAR char *src, int srclen, FAR char *dest,
static void md5_cb(FAR char *src, int srclen, FAR char *dest,
FAR int *destlen, int mode)
{
- MD5Update((MD5_CTX *)dest, (unsigned char *)src, srclen);
+ md5_update((MD5_CTX *)dest, (unsigned char *)src, srclen);
}
#endif
@@ -317,7 +317,7 @@ static int cmd_codecs_proc(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv,
/* There should be exactly on parameter left on the command-line */
- if (optind == argc-1)
+ if (optind == argc - 1)
{
sdata = argv[optind];
}
@@ -335,7 +335,7 @@ static int cmd_codecs_proc(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv,
#ifdef HAVE_CODECS_HASH_MD5
if (mode == CODEC_MODE_HASH_MD5)
{
- MD5Init(&ctx);
+ md5_init(&ctx);
}
#endif
@@ -412,6 +412,7 @@ static int cmd_codecs_proc(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv,
ret += read(fd, &srcbuf[srclen], 1);
}
}
+
#endif
memset(destbuf, 0, buflen);
if (func)
@@ -437,7 +438,7 @@ static int cmd_codecs_proc(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv,
{
int i;
- MD5Final(mac, &ctx);
+ md5_final(mac, &ctx);
src = (FAR char *)&mac;
dest = destbuf;
for (i = 0; i < 16; i++, src++)
@@ -449,6 +450,7 @@ static int cmd_codecs_proc(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv,
*dest = '\0';
nsh_output(vtbl, "%s\n", destbuf);
}
+
#endif
ret = OK;
goto exit;
@@ -474,7 +476,7 @@ static int cmd_codecs_proc(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv,
int i;
func(srcbuf, srclen, (char *)&ctx, &buflen, 0);
- MD5Final(mac, &ctx);
+ md5_final(mac, &ctx);
src = (char *)&mac;
dest = destbuf;
for (i = 0; i < 16; i++, src++)