Debug output disabled by default.
[mx3r.git] / plugin-hash-lines.c
blob34308171b88d0e3adffba06c69709a8730064361
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
5 #include <gcrypt.h>
6 #include <ctype.h>
8 #define HASH_TYPE GCRY_MD_SHA1
10 #define MAX_LINE 255
12 #define BASE 0
13 #define LOCAL 1
14 #define REMOTE 2
16 char *buffer[3];
17 int basefsize[3];
19 void init()
21 int i;
22 for (i=0;i<3;i++)
24 buffer[i]=NULL;
25 basefsize[i]=0;
29 int loadbuffer(char *buff, int size, int nfile)
31 if (nfile<0 || nfile>2) return 0;
32 buffer[nfile]=buff;
33 basefsize[nfile]=size;
34 return 1;
37 unsigned int hash(int nfile,int from, int size)
39 if (size<=0) return 0;
40 char *txt=malloc(size);
41 if (!txt) {
42 fprintf(stderr,"hash(nfile:%d,from:%d,size:%d) > malloc failed! ",nfile,from, size);
43 return 0;
45 // memcpy(txt,&buffer[nfile][from],size);
47 int i;
48 char ch;
49 int txt_size=0;
50 for (i=0;i<size;i++)
52 ch=buffer[nfile][from+i];
53 if (ch>='a' && ch<='z') ch-='a'-'A';
55 if (ch>='A' && ch<='Z')
57 txt[txt_size]=ch;
58 txt_size++;
62 // Longitud del hash resultante - gcry_md_get_algo_dlen
63 // devuelve la longitud del resumen hash para un algoritmo
64 int hash_len = gcry_md_get_algo_dlen( HASH_TYPE );
66 // Salida del hash SHA1 - esto serán datos binarios
67 unsigned char hash[ hash_len ];
69 // Calcular el resumen SHA1. Esto es una especie de función-atajo,
70 // ya que la mayoría de funciones gcrypt requieren
71 // la creación de un handle, etc.
72 gcry_md_hash_buffer( HASH_TYPE, hash, txt, txt_size );
74 // unsigned int ihash=*((unsigned int *)hash);
75 return *((unsigned int *)hash);