~ubuntu-branches/ubuntu/quantal/maradns/quantal

« back to all changes in this revision

Viewing changes to libs/MaraHash.c

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2012-01-12 23:35:38 UTC
  • mto: This revision was merged to the branch mainline in revision 26.
  • Revision ID: package-import@ubuntu.com-20120112233538-5jkaqrh9nbqtf1ey
Tags: upstream-2.0.04+really1.4.09
ImportĀ upstreamĀ versionĀ 2.0.04+really1.4.09

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2006 Sam Trenholme
 
1
/* Copyright (c) 2006, 2011 Sam Trenholme
2
2
 *
3
3
 * TERMS
4
4
 *
32
32
#include "JsStr.h"
33
33
#endif
34
34
#include "MaraHash.h"
 
35
#include <stdio.h>
35
36
 
36
37
/* Masks to limit the size of the hash */
37
38
/* These are powers of two, minus one */
41
42
                          16777215, 33554431, 67108863, 134217727,
42
43
                          268435455, 536870911, 1073741823 };
43
44
 
 
45
mhash_offset mhash_secret_add_constant = 7;
 
46
 
44
47
/* Create a new, blank mhash object
45
48
   input: none
46
49
   output: pointer to the object in quesiton on success, NULL (0)
100
103
    /* Simple enough hash */
101
104
    while(point < max) {
102
105
        ret += (mhash_offset)(*point << shift);
 
106
        ret += mhash_secret_add_constant;
103
107
        shift += 7;
104
108
        shift %= hash_bits;
105
109
        point++;
684
688
    return tuple->tuple_list[element];
685
689
    }
686
690
 
 
691
/* Read four bytes from a filename and use that as a secret add constant */
 
692
int mhash_set_add_constant(char *filename) {
 
693
        FILE *read = 0;
 
694
 
 
695
        read = fopen(filename,"rb");
 
696
        if(read == NULL) {
 
697
                return -1;
 
698
        }
 
699
 
 
700
        mhash_secret_add_constant ^= getc(read);
 
701
        mhash_secret_add_constant <<= 8;
 
702
        mhash_secret_add_constant ^= getc(read);
 
703
        mhash_secret_add_constant <<= 8;
 
704
        mhash_secret_add_constant ^= getc(read);
 
705
        mhash_secret_add_constant <<= 7;
 
706
        mhash_secret_add_constant ^= getc(read);
 
707
        fclose(read);
 
708
        return 1;
 
709
}
 
710