Highly Reusable Software
#License - #Source code - #Example Use -
#include <librock/target/types.c> #include <librock/data.h> void librock_shs1_Init (librock_SHS1_INFO *pinfo); void librock_shs1_Update (librock_SHS1_INFO *pinfo, const unsigned char *buffer, librock_uint32_t len); void librock_shs1_Final (librock_SHS1_INFO*);
The names in the file were changed to use the librock_ prefix. The necessary definitions from the include files were incorporated. ENDIAN-ness tests are modified. SHS1COUNT() is called by us, not the caller. Removed a global static variable, for MT-safety. To compute the SHA1 Message-Digest, declare a librock_SHS1_INFO (a typedef'ed structure) which is initialized with a call to librock_shs1_Init(). After making one or more calls to librock_shs1_Update(), call librock_shs1_Final() to place the result into the digest member of the librock_SHS1_INFO. To show this buffer as ASCII, use code similar to the example below. The well-known algorithm is described elsewhere The design property that is that the result is unique for unique input, and it is computationally infeasible to create text with a given result. Secure hashes (also known as message digests) are used as a unique "fingerprint" (which can verify the integrity of a file or character sequence without a byte by byte comparison.) They are also used as unique hash values. (The computational load to compute this result is significant compared to CRC32, so it should be used only when the uniqueness of the result for unique input is essential, or protecting against generated input which matches a known result is required.) librock_shs1_Update() may save up to 64 bytes of a buffer in the librock_SHS1_INFO structure in between calls. That memory is zeroed on librock_shs1_Final. But callers may want to use care when working with input which must not be exposed. Typical use: #ifdef librock_TYPICAL_USE_shs1_Update #include <librock/target/types.c> #include <librock/data.h> char buf[8*5+1]; char *str = "This is a test string."; int len = strlen(str); librock_SHS1_INFO shsInfo; librock_shs1_Init( &shsInfo ); librock_shs1_Update( &shsInfo, ( unsigned char * ) str, len ); librock_shs1_Final( &shsInfo ); sprintf(buf,"%08lX%08lX%08lX%08lX%08lX",shsInfo.digest, shsInfo.digest,shsInfo.digest,shsInfo.digest,shsInfo.digest); printf("%s\n",buf); #endif
memset(), memcpy() // Well-behaved in multi-threaded uses.
Verbatim copying and distribution of this generated page is permitted in any medium provided that no changes are made.
(The source of this manual page may be covered by a more permissive license which allows modifications.)
Want to help? We welcome comments, patches. -- Need help? Request paid support.