Hello,

On Fri, 24 May 2002, Stella Power wrote:

> I'm having problems with SHA1() and I'm hoping some of you might be able to
> help me out.
>
> I want to calculate the sha1 checksum of a file which i have mapped into
> memory (char *mapped_encrypted_file;).  I use strlen on that to get its
> length (unsigned long maplength;).

Are you sure that your file contains a terminal zero? If your file doesn't
have any zero byte, then the strlen() will fail.

> I also malloc space for my md (unsigned
> char *md;) as follows:
>       md = (unsigned char*)malloc(BUFSIZE*sizeof(unsigned char));

which could be replaced by:
 md = malloc(BUFSIZE);
 * sizeof(char) and sizeof(unsigned char) is always 1 (defined by the
   standard)
 * malloc() returns a void*, which can be stored in any pointer to data,
   without any cast. That's only valid in C.

> and call SHA1()  by:
>       SHA1((const unsigned char*)mapped_encrypted_file, maplength, md);
> However whenever I print md I just get weird characters - non-alphanumeric
> characters, $/\[ and other letters with accents.

Since the digest will be binary data, then printf()'ing it will surely
display weird values. Try to hexify it or base64-encode it before you
display it.

Please note that the digest is *not* a character string, it's an array or
chars, with no terminal zero, but with a constant and known length
(BUFSIZE).

-- 
Erwann ABALEA <[EMAIL PROTECTED]> - RSA PGP Key ID: 0x2D0EABD5
-----
> - Bientot==> Une rubrique membre avec photos
> - Bientot==> "Un chat on line" pour discuter
Si j'amène la photo de mon membre, je pourai caresser le chat ?
-+- FF in Guide du Neuneu Usenet - Cha chanonchait bien pourtant -+-

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to