diff libtomcrypt/src/hashes/chc/chc.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/chc/chc.c	Thu Feb 08 23:11:40 2018 +0800
+++ b/libtomcrypt/src/hashes/chc/chc.c	Fri Feb 09 21:44:05 2018 +0800
@@ -5,8 +5,6 @@
  *
  * The library is free for all purposes without any express
  * guarantee it works.
- *
- * Tom St Denis, [email protected], http://libtom.org
  */
 
 #include "tomcrypt.h"
@@ -35,8 +33,8 @@
 };
 
 /**
-  Initialize the CHC state with a given cipher 
-  @param cipher  The index of the cipher you wish to bind 
+  Initialize the CHC state with a given cipher
+  @param cipher  The index of the cipher you wish to bind
   @return CRYPT_OK if successful
 */
 int chc_register(int cipher)
@@ -70,7 +68,7 @@
    }
 
    /* store into descriptor */
-   hash_descriptor[idx].hashsize  = 
+   hash_descriptor[idx].hashsize  =
    hash_descriptor[idx].blocksize = cipher_descriptor[cipher].block_length;
 
    /* store the idx and block size */
@@ -89,7 +87,7 @@
    symmetric_key *key;
    unsigned char  buf[MAXBLOCKSIZE];
    int            err;
- 
+
    LTC_ARGCHK(md != NULL);
 
    /* is the cipher valid? */
@@ -105,7 +103,7 @@
       return CRYPT_MEM;
    }
 
-   /* zero key and what not */   
+   /* zero key and what not */
    zeromem(buf, cipher_blocksize);
    if ((err = cipher_descriptor[cipher_idx].setup(buf, cipher_blocksize, 0, key)) != CRYPT_OK) {
       XFREE(key);
@@ -123,7 +121,7 @@
    return CRYPT_OK;
 }
 
-/* 
+/*
    key    <= state
    T0,T1  <= block
    T0     <= encrypt T0
@@ -147,17 +145,23 @@
    for (x = 0; x < cipher_blocksize; x++) {
        md->chc.state[x] ^= T[0][x] ^ T[1][x];
    }
-   XFREE(key);
 #ifdef LTC_CLEAN_STACK
    zeromem(T, sizeof(T));
-   zeromem(&key, sizeof(key));
+   zeromem(key, sizeof(*key));
 #endif
+   XFREE(key);
    return CRYPT_OK;
 }
 
-/* function for processing blocks */
-int _chc_process(hash_state * md, const unsigned char *buf, unsigned long len);
-HASH_PROCESS(_chc_process, chc_compress, chc, (unsigned long)cipher_blocksize)
+/**
+   Function for processing blocks
+   @param md   The hash state
+   @param buf  The data to hash
+   @param len  The length of the data (octets)
+   @return CRYPT_OK if successful
+*/
+static int _chc_process(hash_state * md, const unsigned char *buf, unsigned long len);
+static HASH_PROCESS(_chc_process, chc_compress, chc, (unsigned long)cipher_blocksize)
 
 /**
    Process a block of memory though the hash
@@ -248,23 +252,26 @@
 /**
   Self-test the hash
   @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled
-*/  
+*/
 int chc_test(void)
 {
+#ifndef LTC_TEST
+   return CRYPT_NOP;
+#else
    static const struct {
       unsigned char *msg,
-                     md[MAXBLOCKSIZE];
+                     hash[MAXBLOCKSIZE];
       int            len;
    } tests[] = {
 {
    (unsigned char *)"hello world",
-   { 0xcf, 0x57, 0x9d, 0xc3, 0x0a, 0x0e, 0xea, 0x61, 
+   { 0xcf, 0x57, 0x9d, 0xc3, 0x0a, 0x0e, 0xea, 0x61,
      0x0d, 0x54, 0x47, 0xc4, 0x3c, 0x06, 0xf5, 0x4e },
    16
 }
 };
-   int x, oldhashidx, idx;
-   unsigned char out[MAXBLOCKSIZE];
+   int i, oldhashidx, idx;
+   unsigned char tmp[MAXBLOCKSIZE];
    hash_state md;
 
    /* AES can be under rijndael or aes... try to find it */
@@ -276,11 +283,11 @@
    oldhashidx = cipher_idx;
    chc_register(idx);
 
-   for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
+   for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
        chc_init(&md);
-       chc_process(&md, tests[x].msg, strlen((char *)tests[x].msg));
-       chc_done(&md, out);
-       if (XMEMCMP(out, tests[x].md, tests[x].len)) {
+       chc_process(&md, tests[i].msg, strlen((char *)tests[i].msg));
+       chc_done(&md, tmp);
+       if (compare_testvector(tmp, tests[i].len, tests[i].hash, tests[i].len, "CHC", i)) {
           return CRYPT_FAIL_TESTVECTOR;
        }
    }
@@ -289,10 +296,11 @@
    }
 
    return CRYPT_OK;
+#endif
 }
 
 #endif
 
-/* $Source$ */
-/* $Revision$ */
-/* $Date$ */
+/* ref:         $Format:%D$ */
+/* git commit:  $Format:%H$ */
+/* commit time: $Format:%ai$ */