diff libtomcrypt/src/hashes/rmd128.c @ 1471:6dba84798cd5

Update to libtomcrypt 1.18.1, merged with Dropbear changes
author Matt Johnston <matt@ucc.asn.au>
date Fri, 09 Feb 2018 21:44:05 +0800
parents f849a5ca2efc
children
line wrap: on
line diff
--- a/libtomcrypt/src/hashes/rmd128.c	Thu Feb 08 23:11:40 2018 +0800
+++ b/libtomcrypt/src/hashes/rmd128.c	Fri Feb 09 21:44:05 2018 +0800
@@ -5,15 +5,13 @@
  *
  * The library is free for all purposes without any express
  * guarantee it works.
- *
- * Tom St Denis, [email protected], http://libtom.org
  */
 #include "tomcrypt.h"
 
 /**
    @param rmd128.c
    RMD128 Hash function
-*/   
+*/
 
 /* Implementation of LTC_RIPEMD-128 based on the source by Antoon Bosselaers, ESAT-COSIC
  *
@@ -42,11 +40,11 @@
 };
 
 /* the four basic functions F(), G() and H() */
-#define F(x, y, z)        ((x) ^ (y) ^ (z)) 
-#define G(x, y, z)        (((x) & (y)) | (~(x) & (z))) 
+#define F(x, y, z)        ((x) ^ (y) ^ (z))
+#define G(x, y, z)        (((x) & (y)) | (~(x) & (z)))
 #define H(x, y, z)        (((x) | ~(y)) ^ (z))
-#define I(x, y, z)        (((x) & (z)) | ((y) & ~(z))) 
-  
+#define I(x, y, z)        (((x) & (z)) | ((y) & ~(z)))
+
 /* the eight basic operations FF() through III() */
 #define FF(a, b, c, d, x, s)        \
       (a) += F((b), (c), (d)) + (x);\
@@ -88,7 +86,7 @@
 {
    ulong32 aa,bb,cc,dd,aaa,bbb,ccc,ddd,X[16];
    int i;
-   
+
    /* load words X */
    for (i = 0; i < 16; i++){
       LOAD32L(X[i], buf + (4 * i));
@@ -117,7 +115,7 @@
    FF(dd, aa, bb, cc, X[13],  7);
    FF(cc, dd, aa, bb, X[14],  9);
    FF(bb, cc, dd, aa, X[15],  8);
-                             
+
    /* round 2 */
    GG(aa, bb, cc, dd, X[ 7],  7);
    GG(dd, aa, bb, cc, X[ 4],  6);
@@ -173,7 +171,7 @@
    II(bb, cc, dd, aa, X[ 2], 12);
 
    /* parallel round 1 */
-   III(aaa, bbb, ccc, ddd, X[ 5],  8); 
+   III(aaa, bbb, ccc, ddd, X[ 5],  8);
    III(ddd, aaa, bbb, ccc, X[14],  9);
    III(ccc, ddd, aaa, bbb, X[ 7],  9);
    III(bbb, ccc, ddd, aaa, X[ 0], 11);
@@ -208,7 +206,7 @@
    HHH(ccc, ddd, aaa, bbb, X[ 1], 13);
    HHH(bbb, ccc, ddd, aaa, X[ 2], 11);
 
-   /* parallel round 3 */   
+   /* parallel round 3 */
    GGG(aaa, bbb, ccc, ddd, X[15],  9);
    GGG(ddd, aaa, bbb, ccc, X[ 5],  7);
    GGG(ccc, ddd, aaa, bbb, X[ 1], 15);
@@ -342,21 +340,21 @@
 #ifdef LTC_CLEAN_STACK
     zeromem(md, sizeof(hash_state));
 #endif
-   return CRYPT_OK;  
+   return CRYPT_OK;
 }
 
 /**
   Self-test the hash
   @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
-*/  
+*/
 int rmd128_test(void)
 {
 #ifndef LTC_TEST
    return CRYPT_NOP;
 #else
    static const struct {
-        char *msg;
-        unsigned char md[16];
+        const char *msg;
+        unsigned char hash[16];
    } tests[] = {
    { "",
      { 0xcd, 0xf2, 0x62, 0x13, 0xa1, 0x50, 0xdc, 0x3e,
@@ -383,18 +381,16 @@
        0xae, 0xa4, 0x62, 0x4c, 0x60, 0xc5, 0xc7, 0x02 }
    }
    };
-   int x;
-   unsigned char buf[16];
+
+   int i;
+   unsigned char tmp[16];
    hash_state md;
 
-   for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
+   for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
        rmd128_init(&md);
-       rmd128_process(&md, (unsigned char *)tests[x].msg, strlen(tests[x].msg));
-       rmd128_done(&md, buf);
-       if (XMEMCMP(buf, tests[x].md, 16) != 0) {
-       #if 0
-          printf("Failed test %d\n", x);
-       #endif
+       rmd128_process(&md, (unsigned char *)tests[i].msg, strlen(tests[i].msg));
+       rmd128_done(&md, tmp);
+       if (compare_testvector(tmp, sizeof(tmp), tests[i].hash, sizeof(tests[i].hash), "RIPEMD128", i)) {
           return CRYPT_FAIL_TESTVECTOR;
        }
    }
@@ -405,6 +401,6 @@
 #endif
 
 
-/* $Source$ */
-/* $Revision$ */
-/* $Date$ */
+/* ref:         $Format:%D$ */
+/* git commit:  $Format:%H$ */
+/* commit time: $Format:%ai$ */