limit fstBC to 30bp in Python3 ver.
[GalaxyCodeBases.git] / c_cpp / etc / calc / hash.c
blob96f8fda13e5f1a87f255e583294933f5739b2657
1 /*
2 * hash - one-way hash routines
4 * Copyright (C) 1999-2007 Landon Curt Noll
6 * Calc is open software; you can redistribute it and/or modify it under
7 * the terms of the version 2.1 of the GNU Lesser General Public License
8 * as published by the Free Software Foundation.
10 * Calc is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
13 * Public License for more details.
15 * A copy of version 2.1 of the GNU Lesser General Public License is
16 * distributed with calc under the filename COPYING-LGPL. You should have
17 * received a copy with calc; if not, write to Free Software Foundation, Inc.
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * @(#) $Revision: 30.3 $
21 * @(#) $Id: hash.c,v 30.3 2013/08/11 08:41:38 chongo Exp $
22 * @(#) $Source: /usr/local/src/bin/calc/RCS/hash.c,v $
24 * Under source code control: 1995/11/23 05:13:11
25 * File existed as early as: 1995
27 * chongo <was here> /\oo/\ http://www.isthe.com/chongo/
28 * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
32 #include <stdio.h>
33 #include <string.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include "calc.h"
37 #include "value.h"
38 #include "zrand.h"
39 #include "zrandom.h"
40 #include "hash.h"
44 * external hash_setup functions
46 E_FUNC void shs_init_state(HASH*);
47 E_FUNC void sha1_init_state(HASH*);
48 E_FUNC void MD5_init_state(HASH*);
52 * hash_long can deal with BOOL's, int's, FLAGS's and LEN's
54 #define hash_bool(type, val, state) (hash_long((type), (long)(val), (state)))
55 #define hash_int(type, val, state) (hash_long((type), (long)(val), (state)))
56 #define hash_flag(type, val, state) (hash_long((type), (long)(val), (state)))
57 #define hash_len(type, val, state) (hash_long((type), (long)(val), (state)))
61 * hash_setup - setup the hash state for a given hash
63 STATIC struct hash_setup {
64 int type; /* hash type (see XYZ_HASH_TYPE below) */
65 void (*init_state)(HASH*); /* initialize a hash state */
66 } htbl[] = {
67 { SHA1_HASH_TYPE, sha1_init_state }, /* SHA-1 / SHA-1 */
68 { -1, NULL } /* must be last */
73 * hash_init - initialize a hash state
75 * given:
76 * type - hash type (see hash.h)
77 * state - the state to initialize, or NULL to malloc it
79 * returns:
80 * initialized state
82 HASH *
83 hash_init(int type, HASH *state)
85 int i;
88 * malloc if needed
90 if (state == NULL) {
91 state = (HASH *)malloc(sizeof(HASH));
92 if (state == NULL) {
93 math_error("hash_init: cannot malloc HASH");
94 /*NOTREACHED*/
99 * clear hash value
101 memset((void*)state, 0, sizeof(HASH));
102 state->bytes = TRUE;
105 * search for the hash_setup function
107 for (i=0; htbl[i].init_state != NULL; ++i) {
109 /* if we found the state that we were looking for */
110 if (type == htbl[i].type) {
112 /* initialize state and return */
113 (htbl[i].init_state)(state);
115 /* firewall - MAX_CHUNKSIZE must be >= chunksize */
116 if (state->chunksize > MAX_CHUNKSIZE) {
117 math_error(
118 "internal error: MAX_CHUNKSIZE is too small");
119 /*NOTREACHED*/
121 return state;
126 * no such hash state
128 math_error("internal error: hash type not found in htbl[]");
129 return NULL;
134 * hash_free - free the hash state
136 void
137 hash_free(HASH *state)
140 * do nothing if state is NULL
142 if (state == NULL) {
143 return;
147 * free main state and return
149 free(state);
150 return;
155 * hash_copy - copy a hash state
157 * given:
158 * state - the state to copy
160 * returns:
161 * pointer to copy of state
163 HASH *
164 hash_copy(HASH *state)
166 HASH *hnew; /* copy of state */
169 * malloc new state
171 hnew = (HASH *)malloc(sizeof(HASH));
172 if (hnew == NULL) {
173 math_error("hash_init: cannot malloc HASH");
174 /*NOTREACHED*/
178 * duplicate state
180 memcpy((void *)hnew, (void *)state, sizeof(HASH));
181 return hnew;
186 * hash_cmp - compare hash values
188 * given:
189 * a first hash state
190 * b second hash state
192 * returns:
193 * TRUE => hash states are different
194 * FALSE => hash states are the same
197 hash_cmp(HASH *a, HASH *b)
200 * firewall and quick check
202 if (a == b) {
203 /* pointers to the same object */
204 return FALSE;
206 if (a == NULL || b == NULL) {
207 /* one pointer is NULL, so they differ */
208 return TRUE;
210 if (a->cmp == NULL || b->cmp == NULL) {
211 /* one cmp function is NULL, so they differ */
212 return TRUE;
216 * compare hash types
218 if (a->hashtype != b->hashtype) {
219 /* different hash types are different */
220 return TRUE;
224 * perform the hash specific comparison
226 return ((a->cmp)(a,b));
231 * hash_print - print the name and value of a hash
233 * given:
234 * state the hash state to print name and value of
236 void
237 hash_print(HASH *state)
239 /* print the hash */
240 (state->print)(state);
241 return;
246 * hash_final - finalize the state of a hash and return a ZVALUE
248 * given:
249 * state the hash state to finalize
251 * returns:
252 * hash state as a ZVALUE
254 ZVALUE
255 hash_final(HASH *state)
257 /* return the finalized the hash value */
258 return (state->final)(state);
263 * hash_long - note a long value
265 * given:
266 * type - hash type (see hash.h)
267 * longval - a long value
268 * state - the state to hash
270 * returns:
271 * the new state
273 * This function will hash a long value as if it were a 64 bit value.
274 * The input is a long. If a long is smaller than 64 bits, we will
275 * hash a final 32 bits of zeros.
277 * This function is OK to hash BOOL's, unslogned long's, unsigned int's
278 * signed int's as well as FLAG's and LEN's.
280 HASH *
281 hash_long(int type, long longval, HASH *state)
283 long lval[64/LONG_BITS]; /* 64 bits of longs */
286 * initialize if state is NULL
288 if (state == NULL) {
289 state = hash_init(type, NULL);
293 * setup for the hash_long
295 (state->chkpt)(state);
296 state->bytes = FALSE; /* data to be read as words */
299 * catch the zero numeric value special case
301 if (longval == 0) {
302 /* note a zero numeric value and return */
303 (state->note)(HASH_ZERO(state->base), state);
304 return state;
308 * prep for a long value hash
310 (state->note)(state->base, state);
313 * hash as if we have a 64 bit value
315 memset((char *)lval, 0, sizeof(lval));
316 lval[0] = longval;
317 (state->update)(state, (USB8 *)lval, sizeof(lval));
320 * all done
322 return state;
327 * hash_zvalue - hash a ZVALUE
329 * given:
330 * type - hash type (see hash.h)
331 * zval - the ZVALUE
332 * state - the state to hash or NULL
334 * returns:
335 * the new state
337 HASH *
338 hash_zvalue(int type, ZVALUE zval, HASH *state)
341 #if CALC_BYTE_ORDER == BIG_ENDIAN && BASEB == 16
342 int full_lim; /* HALFs in whole chunks in zval */
343 int chunkhalf; /* size of half buffer in HALFs */
344 int i;
345 int j;
346 #endif
347 #if BASEB == 16
348 HALF half[MAX_CHUNKSIZE]; /* For endian reversal */
349 #endif
352 * initialize if state is NULL
354 if (state == NULL) {
355 state = hash_init(type, NULL);
359 * setup for the ZVALUE hash
361 (state->chkpt)(state);
362 state->bytes = FALSE; /* data to be read as words */
365 * catch the zero numeric value special case
367 if (ziszero(zval)) {
368 /* note a zero numeric value and return */
369 (state->note)(HASH_ZERO(state->base), state);
370 return state;
374 * prep for a ZVALUE hash
376 (state->note)(HASH_ZVALUE(state->base), state);
377 /* note if we have a negative value */
378 if (zisneg(zval)) {
379 (state->note)(HASH_NEG(state->base), state);
382 #if CALC_BYTE_ORDER == BIG_ENDIAN && BASEB == 16
385 * hash full chunks
387 * We need to convert the array of HALFs into canonical architectural
388 * independent form -- 32 bit arrays. Because we have 16 bit values
389 * in Big Endian form, we need to swap 16 bit values so that they
390 * appear as 32 bit Big Endian values.
392 chunkhalf = state->chunksize/sizeof(HALF);
393 full_lim = (zval.len / chunkhalf) * chunkhalf;
394 for (i=0; i < full_lim; i += chunkhalf) {
395 /* HALF swap copy a chunk into a data buffer */
396 for (j=0; j < chunkhalf; j += 2) {
397 half[j] = zval.v[i+j+1];
398 half[j+1] = zval.v[i+j];
400 (state->update)(state, (USB8*) half, state->chunksize);
404 * hash the final partial chunk (if any)
406 * We need to convert the array of HALFs into canonical architectural
407 * independent form -- 32 bit arrays. Because we have 16 bit values
408 * in Big Endian form, we need to swap 16 bit values so that they
409 * appear as 32 bit Big Endian values.
411 if (zval.len > full_lim) {
412 for (j=0; j < zval.len-full_lim-1; j += 2) {
413 half[j] = zval.v[full_lim+j+1];
414 half[j+1] = zval.v[full_lim+j];
416 if (j < zval.len-full_lim) {
417 half[j] = (HALF)0;
418 half[j+1] = zval.v[zval.len-1];
419 --full_lim;
421 (state->update)(state, (USB8 *) half,
422 (zval.len-full_lim)*sizeof(HALF));
425 #else
428 * hash the array of HALFs
430 * The array of HALFs is equivalent to the canonical architectural
431 * independent form. We either have 32 bit HALFs (in which case
432 * we do not case the byte order) or we have 16 bit HALFs in Little
433 * Endian order (which happens to be laid out in the same order as
434 * 32 bit values).
436 (state->update)(state, (USB8 *)zval.v, zval.len*sizeof(HALF));
438 #if BASEB == 16
439 if (zval.len & 1) { /* padding to complete word */
440 half[0] = 0;
441 (state->update)(state, (USB8 *) half, 2);
443 #endif
445 #endif
448 * all done
450 return state;
455 * hash_number - hash a NUMBER
457 * given:
458 * type - hash type (see hash.h)
459 * n - the NUMBER
460 * state - the state to hash or NULL
462 * returns:
463 * the new state
465 HASH *
466 hash_number(int type, void *n, HASH *state)
468 NUMBER *number = (NUMBER *)n; /* n as a NUMBER pointer */
469 BOOL sign; /* sign of the denominator */
472 * initialize if state is NULL
474 if (state == NULL) {
475 state = hash_init(type, NULL);
479 * setup for the NUMBER hash
481 (state->chkpt)(state);
482 state->bytes = FALSE;
485 * process the numerator
487 state = hash_zvalue(type, number->num, state);
490 * if the NUMBER is not an integer, process the denominator
492 if (qisfrac(number)) {
494 /* note the division */
495 (state->note)(HASH_DIV(state->base), state);
497 /* hash denominator as positive -- just in case */
498 sign = number->den.sign;
499 number->den.sign = 0;
501 /* hash the denominator */
502 state = hash_zvalue(type, number->den, state);
504 /* restore the sign */
505 number->den.sign = sign;
509 * all done
511 return state;
516 * hash_complex - hash a COMPLEX
518 * given:
519 * type - hash type (see hash.h)
520 * c - the COMPLEX
521 * state - the state to hash or NULL
523 * returns:
524 * the new state
526 HASH *
527 hash_complex(int type, void *c, HASH *state)
529 COMPLEX *complex = (COMPLEX *)c; /* c as a COMPLEX pointer */
532 * initialize if state is NULL
534 if (state == NULL) {
535 state = hash_init(type, NULL);
539 * setup for the COMPLEX hash
541 (state->chkpt)(state);
542 state->bytes = FALSE;
545 * catch the zero special case
547 if (ciszero(complex)) {
548 /* note a zero numeric value and return */
549 (state->note)(HASH_ZERO(state->base), state);
550 return state;
554 * process the real value if not pure imaginary
556 * We will ignore the real part if the value is of the form 0+xi.
558 if (!qiszero(complex->real)) {
559 state = hash_number(type, complex->real, state);
563 * if the NUMBER is not real, process the imaginary value
565 * We will ignore the imaginary part of the value is of the form x+0i.
567 if (!cisreal(complex)) {
569 /* note the sqrt(-1) */
570 (state->note)(HASH_COMPLEX(state->base), state);
572 /* hash the imaginary value */
573 state = hash_number(type, complex->imag, state);
577 * all done
579 return state;
584 * hash_str - hash a null-terminated string
586 * given:
587 * type - hash type (see hash.h)
588 * str - the string
589 * state - the state to hash or NULL
591 * returns:
592 * the new state
594 HASH *
595 hash_str(int type, char *str, HASH *state)
597 size_t len; /* string length */
600 * initialize if state is NULL
602 if (state == NULL) {
603 state = hash_init(type, NULL);
607 * setup for the string hash
609 if (!state->bytes) {
610 (state->chkpt)(state);
611 state->bytes = TRUE;
614 len = strlen(str);
617 * hash the string
619 (state->update)(state, (USB8*)str, len);
622 * all done
624 return state;
629 * hash_STR - hash a STRING
631 * given:
632 * type - hash type (see hash.h)
633 * str - the STRING
634 * state - the state to hash or NULL
636 * returns:
637 * the new state
639 HASH *
640 hash_STR(int type, STRING *str, HASH *state)
643 * initialize if state is NULL
645 if (state == NULL) {
646 state = hash_init(type, NULL);
650 * setup for the string hash
652 if (!state->bytes) {
653 (state->chkpt)(state);
654 state->bytes = TRUE;
658 * hash the string
660 (state->update)(state, (USB8*) str->s_str, (USB32) str->s_len);
663 * all done
665 return state;
670 * hash_usb8 - hash an array of USB8s
672 * given:
673 * type - hash type (see hash.h)
674 * byte - pointer to an array of USB8s
675 * len - number of USB8s to hash
676 * state - the state to hash or NULL
678 * returns:
679 * the new state
681 HASH *
682 hash_usb8(int type, USB8 *byte, int len, HASH *state)
685 * initialize if state is NULL
687 if (state == NULL) {
688 state = hash_init(type, NULL);
692 * setup for the string hash
694 if (!state->bytes) {
695 (state->chkpt)(state);
696 state->bytes = TRUE;
700 * hash the array of octets
702 (state->update)(state, byte, (USB32)len);
705 * all done
707 return state;
712 * hash_value - hash a value
714 * given:
715 * type - hash type (see hash.h)
716 * v - the value
717 * state - the state to hash or NULL
719 * returns:
720 * the new state
722 HASH *
723 hash_value(int type, void *v, HASH *state)
725 LISTELEM *ep; /* list element pointer */
726 ASSOCELEM **assochead; /* association chain head */
727 ASSOCELEM *aep; /* current association value */
728 ASSOCELEM *nextaep; /* next association value */
729 VALUE *value = (VALUE *)v; /* v cast to a VALUE */
730 VALUE *vp; /* pointer to next OBJ table value */
731 ZVALUE fileval; /* size, position, dev, inode of a file */
732 int i;
735 * initialize if state is NULL
737 if (state == NULL) {
738 state = hash_init(type, NULL);
742 * process the value type
744 switch (value->v_type) {
745 case V_NULL:
746 (state->chkpt)(state);
747 state->bytes = TRUE;
748 break;
750 case V_INT:
751 /* setup for the this value type */
752 (state->chkpt)(state);
753 (state->type)(value->v_type, state);
755 /* hash as if we have a 64 bit value */
756 state = hash_int(type, value->v_int, state);
757 break;
759 case V_NUM:
760 /* hash this type */
761 state = hash_number(type, value->v_num, state);
762 break;
764 case V_COM:
765 /* setup for the this value type */
766 (state->chkpt)(state);
767 (state->type)(value->v_type, state);
769 /* hash this type */
770 state = hash_complex(type, value->v_com, state);
771 break;
773 case V_ADDR:
774 /* there is nothing to setup, simply hash what we point at */
775 state = hash_value(type, value->v_addr, state);
776 break;
778 case V_STR:
779 /* strings have no setup */
781 /* hash this type */
782 state = hash_STR(type, value->v_str, state);
783 break;
785 case V_MAT:
786 /* setup for the this value type */
787 (state->chkpt)(state);
788 (state->type)(value->v_type, state);
789 state->bytes = TRUE;
791 /* hash all the elements of the matrix */
792 for (i=0; i < value->v_mat->m_size; ++i) {
794 /* hash the next matrix value */
795 state = hash_value(type,
796 value->v_mat->m_table+i, state);
797 state->bytes = FALSE; /* as if reading words */
799 break;
801 case V_LIST:
802 /* setup for the this value type */
803 (state->chkpt)(state);
804 (state->type)(value->v_type, state);
806 /* hash all the elements of the list */
807 for (i=0, ep = value->v_list->l_first;
808 ep != NULL && i < value->v_list->l_count;
809 ++i, ep = ep->e_next) {
811 /* hash the next list value */
812 state = hash_value(type, &ep->e_value, state);
813 state->bytes = FALSE; /* as if reading words */
815 break;
817 case V_ASSOC:
818 /* setup for the this value type */
819 (state->chkpt)(state);
820 (state->type)(value->v_type, state);
821 state->bytes = TRUE;
823 /* hash the association */
824 assochead = value->v_assoc->a_table;
825 for (i = 0; i < value->v_assoc->a_size; i++) {
826 nextaep = *assochead;
827 while (nextaep) {
828 aep = nextaep;
829 nextaep = aep->e_next;
831 /* hash the next association value */
832 state = hash_value(type, &aep->e_value, state);
833 state->bytes = FALSE; /* as if reading words */
835 assochead++;
837 break;
839 case V_OBJ:
840 /* setup for the this value type */
841 (state->chkpt)(state);
842 (state->type)(value->v_type, state);
843 state->bytes = TRUE; /* reading bytes */
845 /* hash the object name and then the element values */
847 state = hash_str(type, objtypename(
848 value->v_obj->o_actions->oa_index), state);
849 (state->chkpt)(state);
851 for (i=value->v_obj->o_actions->oa_count,
852 vp=value->v_obj->o_table;
853 i-- > 0;
854 vp++) {
856 /* hash the next object value */
857 state = hash_value(type, vp, state);
858 state->bytes = FALSE; /* as if reading words */
860 break;
862 case V_FILE:
863 /* setup for the this value type */
864 (state->chkpt)(state);
865 (state->type)(value->v_type, state);
867 /* hash file length if possible */
868 if (getsize(value->v_file, &fileval) == 0) {
869 state = hash_zvalue(type, fileval, state);
870 zfree(fileval);
871 } else {
872 /* hash -1 for invalid length */
873 state = hash_long(type, (long)-1, state);
875 /* hash the file position if possible */
876 if (getloc(value->v_file, &fileval) == 0) {
877 state = hash_zvalue(type, fileval, state);
878 zfree(fileval);
879 } else {
880 /* hash -1 for invalid location */
881 state = hash_long(type, (long)-1, state);
883 /* hash the file device if possible */
884 if (get_device(value->v_file, &fileval) == 0) {
885 state = hash_zvalue(type, fileval, state);
886 zfree(fileval);
887 } else {
888 /* hash -1 for invalid device */
889 state = hash_long(type, (long)-1, state);
891 /* hash the file inode if possible */
892 if (get_inode(value->v_file, &fileval) == 0) {
893 state = hash_zvalue(type, fileval, state);
894 zfree(fileval);
895 } else {
896 /* hash -1 for invalid inode */
897 state = hash_long(type, (long)-1, state);
899 break;
901 case V_RAND:
902 /* setup for the this value type */
903 (state->chkpt)(state);
904 (state->type)(value->v_type, state);
906 /* hash the RAND state */
907 state = hash_int(type, value->v_rand->seeded, state);
908 state = hash_int(type, value->v_rand->bits, state);
909 (state->update)(state,
910 (USB8 *)value->v_rand->buffer, SLEN*FULL_BITS/8);
911 state = hash_int(type, value->v_rand->j, state);
912 state = hash_int(type, value->v_rand->k, state);
913 state = hash_int(type, value->v_rand->need_to_skip, state);
914 (state->update)(state,
915 (USB8 *)value->v_rand->slot, SCNT*FULL_BITS/8);
916 (state->update)(state,
917 (USB8*)value->v_rand->shuf, SHUFLEN*FULL_BITS/8);
918 state->bytes = FALSE; /* as if reading words */
919 break;
921 case V_RANDOM:
922 /* setup for the this value type */
923 (state->chkpt)(state);
924 (state->type)(value->v_type, state);
926 /* hash the RANDOM state */
927 state = hash_int(type, value->v_random->seeded, state);
928 state = hash_int(type, value->v_random->bits, state);
929 (state->update)(state,
930 (USB8 *)&(value->v_random->buffer), BASEB/8);
931 state = hash_zvalue(type, value->v_random->r, state);
932 state = hash_zvalue(type, value->v_random->n, state);
933 state->bytes = FALSE; /* as if reading words */
934 break;
936 case V_CONFIG:
937 /* setup for the this value type */
938 (state->chkpt)(state);
939 (state->type)(value->v_type, state);
941 /* hash the CONFIG state */
942 state = hash_int(type, value->v_config->outmode, state);
943 state = hash_int(type, value->v_config->outmode2, state);
944 state = hash_long(type,(long)value->v_config->outdigits, state);
945 state = hash_number(type, value->v_config->epsilon, state);
946 state = hash_long(type,
947 (long)value->v_config->epsilonprec, state);
948 state = hash_flag(type, value->v_config->traceflags, state);
949 state = hash_long(type, (long)value->v_config->maxprint, state);
950 state = hash_len(type, value->v_config->mul2, state);
951 state = hash_len(type, value->v_config->sq2, state);
952 state = hash_len(type, value->v_config->pow2, state);
953 state = hash_len(type, value->v_config->redc2, state);
954 state = hash_bool(type, value->v_config->tilde_ok, state);
955 state = hash_bool(type, value->v_config->tab_ok, state);
956 state = hash_long(type, (long)value->v_config->quomod, state);
957 state = hash_long(type, (long)value->v_config->quo, state);
958 state = hash_long(type, (long)value->v_config->mod, state);
959 state = hash_long(type, (long)value->v_config->sqrt, state);
960 state = hash_long(type, (long)value->v_config->appr, state);
961 state = hash_long(type, (long)value->v_config->cfappr, state);
962 state = hash_long(type, (long)value->v_config->cfsim, state);
963 state = hash_long(type, (long)value->v_config->outround, state);
964 state = hash_long(type, (long)value->v_config->round, state);
965 state = hash_bool(type, value->v_config->leadzero, state);
966 state = hash_bool(type, value->v_config->fullzero, state);
967 state = hash_long(type,
968 (long)value->v_config->maxscancount, state);
969 state = hash_str(type, value->v_config->prompt1, state);
970 state->bytes = FALSE; /* as if just read words */
971 state = hash_str(type, value->v_config->prompt2, state);
972 state->bytes = FALSE; /* as if just read words */
973 state = hash_int(type, value->v_config->blkmaxprint, state);
974 state = hash_bool(type, value->v_config->blkverbose, state);
975 state = hash_int(type, value->v_config->blkbase, state);
976 state = hash_int(type, value->v_config->blkfmt, state);
977 state = hash_long(type,
978 (long)value->v_config->resource_debug, state);
979 state = hash_long(type,
980 (long)value->v_config->calc_debug, state);
981 state = hash_long(type,
982 (long)value->v_config->user_debug, state);
983 state = hash_bool(type, value->v_config->verbose_quit, state);
984 state = hash_int(type, value->v_config->ctrl_d, state);
985 state = hash_str(type, value->v_config->program, state);
986 state = hash_str(type, value->v_config->base_name, state);
987 state = hash_bool(type, value->v_config->windows, state);
988 state = hash_bool(type, value->v_config->cygwin, state);
989 state = hash_bool(type, value->v_config->compile_custom, state);
990 if (value->v_config->allow_custom != NULL &&
991 *(value->v_config->allow_custom)) {
992 state = hash_bool(type, TRUE, state);
993 } else {
994 state = hash_bool(type, FALSE, state);
996 state = hash_str(type, value->v_config->version, state);
997 state = hash_int(type, value->v_config->baseb, state);
998 state = hash_bool(type, value->v_config->redecl_warn, state);
999 state = hash_bool(type, value->v_config->dupvar_warn, state);
1000 break;
1002 case V_HASH:
1003 /* setup for the this value type */
1004 (state->chkpt)(state);
1005 (state->type)(value->v_type, state);
1007 /* hash the HASH state */
1008 state = hash_int(type, value->v_hash->type, state);
1009 state = hash_bool(type, value->v_hash->bytes,state);
1010 state = hash_int(type, value->v_hash->base, state);
1011 state = hash_int(type, value->v_hash->chunksize, state);
1012 state = hash_int(type, value->v_hash->unionsize, state);
1013 (state->update)(state,
1014 value->v_hash->h_union.data, state->unionsize);
1015 state->bytes = FALSE; /* as if reading words */
1016 break;
1018 case V_BLOCK:
1019 /* there is no setup for a BLOCK */
1021 /* hash the octets in the BLOCK */
1022 if (value->v_block->datalen > 0) {
1023 state = hash_usb8(type, value->v_block->data,
1024 value->v_block->datalen, state);
1026 break;
1028 case V_OCTET:
1029 /* there is no setup for an OCTET */
1031 /* hash the OCTET */
1032 state = hash_usb8(type, value->v_octet, 1, state);
1033 break;
1035 case V_NBLOCK:
1036 /* there is no setup for a NBLOCK */
1038 /* hash the octets in the NBLOCK */
1039 if (value->v_nblock->blk->datalen > 0) {
1040 state = hash_usb8(type, value->v_nblock->blk->data,
1041 value->v_nblock->blk->datalen,
1042 state);
1044 break;
1046 default:
1047 math_error("hashing an unknown value");
1048 /*NOTREACHED*/
1050 return state;