Take the 2-minute tour ×

I know that SHA256_Update() is implemented in libcrypto under openssl, yet, a simple grep can't find its definition:

$ ack SHA256_Update
76:     SHA256_Update(md_ctx,key,len);
87:    SHA256_Update(md_ctx,pad,SHA256_CBLOCK);
92:    SHA256_Update(o_ctx,pad,SHA256_CBLOCK);
100:    SHA256_Update(o_ctx,buf,sizeof buf);
154:        SHA256_Update(&md_ctx,buf,l);

114:    { return SHA256_Update(ctx->md_data,data,count); }

58:     SHA256_Update(&c,d,n);
71:     SHA256_Update(&c,d,n);
78:{   return SHA256_Update (c,data,len);   }
116:#define     HASH_UPDATE             SHA256_Update

All these instances are where the function gets called, but not its definition. Yet, if I do "nm libcrypto.so |grep SHA256_Update", the entry can be found.


Anyone could shed some light here?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

md32_common.h is a "poor-man's template" for C. It defines the structure of a general update function for any hash algorithm. Each algorithm provides the name for this general structure.

So in md32_common.h you will find this:

int HASH_UPDATE (HASH_CTX *c, const void *data_, size_t len)

And in sha/sha256.c you will find:

#define HASH_UPDATE             SHA256_Update

So that when md32_common.h is included, you get the function SHA256_Update defined.

At the beginning of md32_common.h you will find a more complete explanation with an example.

share|improve this answer
I did see this #define yesterday, but didn't pay enough attention to it. Because usually the usage is something like #define unknown known, for example, #define BUFFER_SIZE 256. So when I saw #define HASH_UPDATE SHA256_Update yesterday, I thought SHA256_Update must be defined/implemented somewhere else. But today, you answer makes me think of the basics of a #define macro. Essentially, it is a textual substitution. With this in mind, it is not that hard to understand the code in crypto. Thank you, Omri! –  Qiang Xu Mar 27 '12 at 14:06
add comment

Your Answer


