/[mldonkey]/mldonkey/src/daemon/common/commonHasher_c.c
ViewVC logotype

Diff of /mldonkey/src/daemon/common/commonHasher_c.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by mldonkey, Mon Nov 1 11:22:59 2004 UTC revision 1.7 by spiralvoice, Sun Aug 28 10:47:39 2005 UTC
# Line 50  static unsigned char local_hash_buffer[H Line 50  static unsigned char local_hash_buffer[H
50    
51    
52  #define COMPLETE_HASH(HASH_NAME,HASH_CONTEXT,HASH_INIT,HASH_APPEND,HASH_FINISH) \  #define COMPLETE_HASH(HASH_NAME,HASH_CONTEXT,HASH_INIT,HASH_APPEND,HASH_FINISH) \
53  static void HASH_NAME##_unsafe64_fd_direct (OS_FD fd, off_t pos, long len, \  static void HASH_NAME##_unsafe64_fd_direct (OS_FD fd, OFF_T pos, OFF_T len, \
54    unsigned char *digest) \    unsigned char *digest) \
55  { \  { \
56    HASH_CONTEXT context; \    HASH_CONTEXT context; \
57    int nread; \    ssize_t nread; \
58   \   \
59    HASH_INIT (&context); \    HASH_INIT (&context); \
60    os_lseek(fd, pos, SEEK_SET); \    os_lseek(fd, pos, SEEK_SET); \
61   \   \
62    while (len!=0){ \    while (len!=0){ \
63      int max_nread = HASH_BUFFER_LEN > len ? len : HASH_BUFFER_LEN; \      size_t max_nread = HASH_BUFFER_LEN > len ? len : HASH_BUFFER_LEN; \
64   \   \
65      nread = os_read (fd, local_hash_buffer, max_nread); \      nread = os_read (fd, local_hash_buffer, max_nread); \
66   \   \
# Line 83  COMPLETE_HASH(sha1,SHA1_CTX,sha1_begin,s Line 83  COMPLETE_HASH(sha1,SHA1_CTX,sha1_begin,s
83  COMPLETE_HASH(md5,md5_state_t,md5_init,md5_append,md5_finish)  COMPLETE_HASH(md5,md5_state_t,md5_init,md5_append,md5_finish)
84  COMPLETE_HASH(md4,MD4_CTX,MD4Init,MD4Update,md4_finish)  COMPLETE_HASH(md4,MD4_CTX,MD4Init,MD4Update,md4_finish)
85    
86  static void tiger_tree_fd(OS_FD fd, long len, off_t pos,  static void tiger_tree_fd(OS_FD fd, size_t len, OFF_T pos,
87    int block_size, char *digest)    size_t block_size, char *digest)
88  {  {
89    static char tiger_buffer[BLOCK_SIZE+1];    static char tiger_buffer[BLOCK_SIZE+1];
90    
91    if(block_size == BLOCK_SIZE){    if(block_size == BLOCK_SIZE){
92      int length = (len - pos > BLOCK_SIZE) ? BLOCK_SIZE : len - pos;      size_t length = (len - pos > BLOCK_SIZE) ? BLOCK_SIZE : len - pos;
93      char *s = tiger_buffer+1;      char *s = tiger_buffer+1;
94      int toread = length;      size_t toread = length;
95      char *curs = s;      char *curs = s;
96    
97        while (toread>0){        while (toread>0){
98        int max_nread = toread;        size_t max_nread = toread;
99  /* HASH_BUFFER_LEN > toread ? toread : HASH_BUFFER_LEN; */  /* HASH_BUFFER_LEN > toread ? toread : HASH_BUFFER_LEN; */
100    
101        int nread = os_read (fd, curs, max_nread);        ssize_t nread = os_read (fd, curs, max_nread);
102    
103          if(nread <= 0) {          if(nread <= 0) {
104          unix_error(errno, "tiger_safe_fd: Read", Nothing);          unix_error(errno, "tiger_safe_fd: Read", Nothing);
# Line 126  static void tiger_tree_fd(OS_FD fd, long Line 126  static void tiger_tree_fd(OS_FD fd, long
126    
127  #define MAX_CHUNK_SIZE 1000000  #define MAX_CHUNK_SIZE 1000000
128  static OS_FD job_fd;  static OS_FD job_fd;
129  static off_t job_pos;  static OFF_T job_pos;
130  static long job_len;  static OFF_T job_len;
131  static value job_finished = 1;  static value job_finished = 1;
132    
133    
# Line 140  computations of MAX_CHUNK_SIZE(1 Mo) byt Line 140  computations of MAX_CHUNK_SIZE(1 Mo) byt
140  #define PARTIAL_HASH(HASH_NAME,HASH_CONTEXT,HASH_INIT,HASH_APPEND,HASH_FINISH) \  #define PARTIAL_HASH(HASH_NAME,HASH_CONTEXT,HASH_INIT,HASH_APPEND,HASH_FINISH) \
141  value HASH_NAME##_step(value job_v) \  value HASH_NAME##_step(value job_v) \
142  { \  { \
143    int nread; \    ssize_t nread; \
144    int ndone = 0; \    size_t ndone = 0; \
145    static int timer = 0; \    static int timer = 0; \
146    static  HASH_CONTEXT context; \    static  HASH_CONTEXT context; \
147    if(job_v == Val_unit) { \    if(job_v == Val_unit) { \
# Line 150  value HASH_NAME##_step(value job_v) \ Line 150  value HASH_NAME##_step(value job_v) \
150    } \    } \
151    if(--timer > 0) return Val_false; \    if(--timer > 0) return Val_false; \
152    while (job_len>0 && ndone< MAX_CHUNK_SIZE){ \    while (job_len>0 && ndone< MAX_CHUNK_SIZE){ \
153      int max_nread = HASH_BUFFER_LEN > job_len ? job_len : HASH_BUFFER_LEN; \      size_t max_nread = HASH_BUFFER_LEN > job_len ? job_len : HASH_BUFFER_LEN; \
154       \       \
155      nread = os_read (job_fd, local_hash_buffer, max_nread); \      nread = os_read (job_fd, local_hash_buffer, max_nread); \
156       \       \
# Line 275  static int volatile  job_done = 1; Line 275  static int volatile  job_done = 1;
275  /* We use these variables for thread communication */  /* We use these variables for thread communication */
276  static char volatile job_result[64];  static char volatile job_result[64];
277  static OS_FD volatile  job_fd = 0;  static OS_FD volatile  job_fd = 0;
278  static off_t volatile job_begin_pos = 0;  static OFF_T volatile job_begin_pos = 0;
279  static long volatile job_len = 0;  static long volatile job_len = 0;
280  static int volatile job_method = 0;  static int volatile job_method = 0;
281    
# Line 336  static void * hasher_thread(void * arg) Line 336  static void * hasher_thread(void * arg)
336              sha1_unsafe64_fd_direct(job_fd, job_begin_pos, job_len, job_result);              sha1_unsafe64_fd_direct(job_fd, job_begin_pos, job_len, job_result);
337            else            else
338              if( job_method == METHOD_TIGER){              if( job_method == METHOD_TIGER){
339                int bsize = tiger_block_size(job_len);                long bsize = tiger_block_size(job_len);
340                tiger_tree_fd(job_fd, job_len, 0, bsize, job_result);                tiger_tree_fd(job_fd, job_len, 0, bsize, job_result);
341              } else {              } else {
342                printf("commonHasher_c.c: method sha1 not implemented\n");                printf("commonHasher_c.c: method sha1 not implemented\n");

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26