haval.h 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Modified version of the HAVAL hash algorithm implementation
  2. * by Calyptix Security Corporation.
  3. * Use freely.
  4. *
  5. * Changes to the original version:
  6. * - Renamed some function and constants
  7. * - Added new include file to the haval.h header file
  8. * - Removed config.h from include directives
  9. */
  10. /* $Id: haval.h,v 1.2 2003/01/20 05:44:48 lteo Exp $ */
  11. /*
  12. * haval.h: specifies the interface to the HAVAL (V.1) hashing library.
  13. *
  14. * Copyright (c) 2003 Calyptix Security Corporation
  15. * All rights reserved.
  16. *
  17. * This code is derived from software contributed to Calyptix Security
  18. * Corporation by Yuliang Zheng.
  19. *
  20. * Redistribution and use in source and binary forms, with or without
  21. * modification, are permitted provided that the following conditions
  22. * are met:
  23. * 1. Redistributions of source code must retain the above copyright
  24. * notice, this list of conditions and the following disclaimer.
  25. * 2. Redistributions in binary form must reproduce the above
  26. * copyright notice, this list of conditions and the following
  27. * disclaimer in the documentation and/or other materials provided
  28. * with the distribution.
  29. * 3. Neither the name of Calyptix Security Corporation nor the
  30. * names of its contributors may be used to endorse or promote
  31. * products derived from this software without specific prior
  32. * written permission.
  33. *
  34. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  35. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  36. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  37. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  38. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  39. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  40. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  41. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  42. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  43. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  44. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  45. * POSSIBILITY OF SUCH DAMAGE.
  46. *
  47. * -------------------------------------------------------------------
  48. *
  49. * HAVAL is a one-way hashing algorithm with the following
  50. * collision-resistant property:
  51. * It is computationally infeasible to find two or more
  52. * messages that are hashed into the same fingerprint.
  53. *
  54. * Reference:
  55. * Y. Zheng, J. Pieprzyk and J. Seberry:
  56. * ``HAVAL --- a one-way hashing algorithm with variable
  57. * length of output'', Advances in Cryptology --- AUSCRYPT'92,
  58. * Lecture Notes in Computer Science, Vol.718, pp.83-104,
  59. * Springer-Verlag, 1993.
  60. *
  61. * This library provides routines to hash
  62. * - a string,
  63. * - a file,
  64. * - input from the standard input device,
  65. * - a 32-word block, and
  66. * - a string of specified length.
  67. *
  68. * Authors: Yuliang Zheng and Lawrence Teo
  69. * Calyptix Security Corporation
  70. * P.O. Box 561508, Charlotte, NC 28213, USA
  71. * Email: info@calyptix.com
  72. * URL: http://www.calyptix.com/
  73. * Voice: +1 704 806 8635
  74. *
  75. * For a list of changes, see the ChangeLog file.
  76. */
  77. #include "../rhsyscfg.h" /* Endian, hash function passes and fptlen */
  78. typedef unsigned long int haval_word; /* a HAVAL word = 32 bits */
  79. typedef struct {
  80. haval_word count[2]; /* number of bits in a message */
  81. haval_word fingerprint[8]; /* current state of fingerprint */
  82. haval_word block[32]; /* buffer for a 32-word block */
  83. unsigned char remainder[32*4]; /* unhashed chars (No.<128) */
  84. } haval_state;
  85. void haval_string (char *, unsigned char *); /* hash a string */
  86. int haval_file (char *, unsigned char *); /* hash a file */
  87. void haval_stdin (void); /* filter -- hash input from stdin */
  88. void haval_start (haval_state *); /* initialization */
  89. void haval_hash (haval_state *, unsigned char *,
  90. unsigned int); /* updating routine */
  91. void haval_end (haval_state *, unsigned char *); /* finalization */
  92. void haval_hash_block (haval_state *); /* hash a 32-word block */