Question on SHA1 Functions

2011-01-10 Thread Stan Joyner
Hi,

I am a newbie to openssl and have run into what is probably a stupid
question. I am using openssl-1.0.0c.

So here it goes.

I wanted to look at how openssl implemented the following functions which
are defined in the openssl crypto library in openssl/crytpo/sha.h:

int SHA1_Init(SHA_CTX *c);
int SHA1_Update(SHA_CTX *c, const void *data, size_t len);
int SHA1_Final(unsigned char *md, SHA_CTX *c);
unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md);

In file sha1.c I only see the function implementation for SHA1 which is a
wrapper function that invokes SHA1_init, SHA1_Update, and SHA1_Final. I was
expecting to see the implementations for all four of these functions in file
sha1_one.c. But I only see the implementation for the wrapper function SHA1
in that file.

Where are these functions suppose to be implemented?

[u...@centos sha]$ pwd
/home/user/OPENSSLTEST/openssl-1.0.0c/crypto/sha
[u...@centos sha]$ grep SHA1_Final *
sha1.c: SHA1_Final((md[0]),c);
sha1_one.c: SHA1_Final(md,c);
sha.h:int SHA1_Final(unsigned char *md, SHA_CTX *c);
sha_locl.h:# define HASH_FINAL  SHA1_Final

For instance above I see calls to SHA1_Final; but I don't see the actual
implementation of that function.

By comparison for the SHA512 case I do see all of the following functions in
sha512.c in this same directory:

SHA512_Init. SHA512_Update, SHA512_Final,  and of course the wrapper
function SHA512 implementations can all be found in sha512.c.

For example:

[u...@centos sha]$ grep SHA512_Final *
*sha512.c:int SHA512_Final (unsigned char *md, SHA512_CTX *c)*
sha512.c:{   return SHA512_Final (md,c);   }
sha512.c:   SHA512_Final(md,c);
sha512.c:   SHA512_Final(md,c);
sha.h:int SHA512_Final(unsigned char *md, SHA512_CTX *c);

I don't understand how this works obviously. Any information would be
appreciated. I want to use this in an embedded application.

I also noticed macros in sha_locl.h for SHA. Is this where the SHA1
functions are implemented?


Thanks,

Stan Joyner


Re: Question on SHA1 Functions

2011-01-10 Thread Mounir IDRASSI


Hi,

SHA1_Init is indeed defined in sha_locl.h as HASH_INIT, whereas 
SHA1_Update and SHA1_Final are defined in md32_common.h (under crypto 
folder) as HASH_UPDATE and HASH_FINAL respectively.


Happy hacking,
--
Mounir IDRASSI
IDRIX
http://www.idrix.fr

On 1/10/2011 4:40 PM, Stan Joyner wrote:

Hi,

I am a newbie to openssl and have run into what is probably a stupid 
question. I am using openssl-1.0.0c.


So here it goes.

I wanted to look at how openssl implemented the following functions 
which are defined in the openssl crypto library in openssl/crytpo/sha.h:


int SHA1_Init(SHA_CTX *c);
int SHA1_Update(SHA_CTX *c, const void *data, size_t len);
int SHA1_Final(unsigned char *md, SHA_CTX *c);
unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md);

In file sha1.c I only see the function implementation for SHA1 which 
is a wrapper function that invokes SHA1_init, SHA1_Update, and 
SHA1_Final. I was expecting to see the implementations for all four of 
these functions in file sha1_one.c. But I only see the implementation 
for the wrapper function SHA1 in that file.


Where are these functions suppose to be implemented?

[u...@centos sha]$ pwd
/home/user/OPENSSLTEST/openssl-1.0.0c/crypto/sha
[u...@centos sha]$ grep SHA1_Final *
sha1.c: SHA1_Final((md[0]),c);
sha1_one.c: SHA1_Final(md,c);
sha.h:int SHA1_Final(unsigned char *md, SHA_CTX *c);
sha_locl.h:# define HASH_FINAL  SHA1_Final

For instance above I see calls to SHA1_Final; but I don't see the 
actual implementation of that function.


By comparison for the SHA512 case I do see all of the following 
functions in sha512.c in this same directory:


SHA512_Init. SHA512_Update, SHA512_Final,  and of course the wrapper 
function SHA512 implementations can all be found in sha512.c.


For example:

[u...@centos sha]$ grep SHA512_Final *
*sha512.c:int SHA512_Final (unsigned char *md, SHA512_CTX *c)*
sha512.c:{   return SHA512_Final (md,c);   }
sha512.c:   SHA512_Final(md,c);
sha512.c:   SHA512_Final(md,c);
sha.h:int SHA512_Final(unsigned char *md, SHA512_CTX *c);

I don't understand how this works obviously. Any information would be 
appreciated. I want to use this in an embedded application.


I also noticed macros in sha_locl.h for SHA. Is this where the SHA1 
functions are implemented?



Thanks,

Stan Joyner




__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   majord...@openssl.org