Reuse, not rework
Home

License Awareness



Highly Reusable Software

By activity
Professions, Sciences, Humanities, Business, ...

User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...

Text Strings
Conversions, tests, processing, manipulation,...

Math
Integer, Floating point, Matrix, Statistics, Boolean, ...

Processing
Algorithms, Memory, Process control, Debugging, ...

Stored Data
Data storage, Integrity, Encryption, Compression, ...

Communications
Networks, protocols, Interprocess, Remote, Client Server, ...

Hard World
Timing, Calendar and Clock, Audio, Video, Printer, Controls...

File System
Management, Filtering, File & Directory access, Viewers, ...


NAME

librock_shs1 - NIST Secure Hash Standard-1 (SHS1) also known as SHA1
#License - #Source code - #Example Use -

SYNOPSIS

#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*);

DESCRIPTION

This is the NIST Secure Hash Standard-1 (SHS1) also known as SHA1. This comes from Landon Curt Noll's md5_rsa hash package with some changes for librock:
   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[0],
        shsInfo.digest[1],shsInfo.digest[2],shsInfo.digest[3],shsInfo.digest[4]);
    printf("%s\n",buf);
#endif

USES

  memset(), memcpy()
  // Well-behaved in multi-threaded uses.

Source Code

./data/integrity/shs1.c (implementation, plus source of this manual page)

This software is part of Librock

Rapid reuse, without rework. Details
This page copyright (C) 2002-2003 Forrest J. Cavalier III, d-b-a Mib Software, Saylorsburg PA 18353, USA

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.