Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
The memory management of dirname is stupid, so be brutal
[simgrid.git] / src / xbt / xbt_sha.c
index 12fa575..d6223e2 100644 (file)
@@ -1,15 +1,18 @@
-/* $Id$ */
 /* xbt_sha.c - SHA1 hash function */
 
-/* Initial version part of iksemel (XML parser for Jabber)
- *   Copyright (C) 2000-2003 Gurer Ozen <madcat@e-kolay.net>. All right reserved. */
-
-/* Adapted to fit into SimGrid by Martin Quinson.
-     Copyright (c) 2008 Martin Quinson. All rights reserved. */
+/* Copyright (c) 2008-2014. The SimGrid Team.
+ * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
+/* Initial version part of iksemel (XML parser for Jabber)
+ *   Copyright (C) 2000-2003 Gurer Ozen <madcat@e-kolay.net>. All right reserved.
+ *   Distributed under LGPL v2.1, February 1999.
+ */
+
+/* Later adapted to fit into SimGrid. Distributed under LGPL v2.1, Feb 1999.*/
+
 #include "xbt/sysdep.h"
 #include "xbt/hash.h"
 
@@ -55,7 +58,7 @@ void xbt_sha_reset(xbt_sha_t sha)
 /* @brief Add some more data to the buffer */
 void xbt_sha_feed(xbt_sha_t sha, const unsigned char *data, size_t len)
 {
-  int i;
+  unsigned int i;
 
   for (i = 0; i < len; i++) {
     sha->buf[sha->blen / 4] <<= 8;
@@ -97,7 +100,7 @@ static void xbt_sha_finalize(xbt_sha_t sha)
 /** @brief returns the sha hash into a newly allocated buffer (+ reset sha object) */
 char *xbt_sha_read(xbt_sha_t sha)
 {
-  char *res = xbt_malloc(40);
+  char *res = xbt_malloc(41);
   xbt_sha_print(sha, res);
   return res;
 }
@@ -148,8 +151,8 @@ static void sha_calculate(xbt_sha_t sha)
 
   for (i = 16; i < 80; i++)
     sha->buf[i] =
-      SRL(sha->buf[i - 3] ^ sha->buf[i - 8] ^ sha->
-          buf[i - 14] ^ sha->buf[i - 16], 1);
+        SRL(sha->buf[i - 3] ^ sha->buf[i - 8] ^ sha->
+            buf[i - 14] ^ sha->buf[i - 16], 1);
 
   A = sha->hash[0];
   B = sha->hash[1];
@@ -174,7 +177,7 @@ static void sha_calculate(xbt_sha_t sha)
 /* ************* */
 #ifdef SIMGRID_TEST
 #include "xbt/hash.h"
-#include "portable.h"           /* hexa_str */
+#include "src/portable.h"           /* hexa_str */
 
 static char *mycmp(const char *p1, const char *p2, size_t n)
 {
@@ -193,16 +196,13 @@ static void test_sha(const char *clear, const char *hashed)
   char hash[41];
   xbt_sha(clear, hash);
 
-  xbt_test_add1("==== Test with '%s'", clear);
-  xbt_test_assert3(!memcmp(hash, hashed, 40), "Wrong sha: %40s!=%40s (%s)",
+  xbt_test_add("==== Test with '%s'", clear);
+  xbt_test_assert(!memcmp(hash, hashed, 40), "Wrong sha: %40s!=%40s (%s)",
                    hash, hashed, mycmp(hash, hashed, 40));
 }
 
 XBT_TEST_SUITE("hash", "Various hash functions");
 
-XBT_LOG_NEW_DEFAULT_CATEGORY(hash, "Tests of various hash functions ");
-
-
 XBT_TEST_UNIT("sha", test_crypto_sha, "Test of the sha algorithm")
 {
   /* Empty string as test vector */
@@ -217,4 +217,4 @@ XBT_TEST_UNIT("sha", test_crypto_sha, "Test of the sha algorithm")
            "373ba8be29d4d95708bf7cd43038f4e409dcb439");
 
 }
-#endif /* SIMGRID_TEST */
+#endif                          /* SIMGRID_TEST */