"Fossies" - the Fresh Open Source Software Archive

Member "tin-2.4.1/libcanlock/include/sha1.h" (28 Aug 2013, 1413 Bytes) of archive /linux/misc/tin-2.4.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "sha1.h" see the Fossies "Dox" file reference documentation.

    1 #ifndef _SHA1_H_
    2 #define _SHA1_H_
    3 
    4 #ifdef HAVE_CONFIG_H
    5 #   include "autoconf.h"
    6 #endif /* HAVE_CONFIG_H */
    7 
    8 /* The SHA block size and message digest sizes, in bytes */
    9 
   10 #define SHA_DATASIZE    64
   11 #define SHA_DATALEN     16
   12 #define SHA_DIGESTSIZE  20
   13 #define SHA_DIGESTLEN    5
   14 /* The structure for storing SHA info */
   15 
   16 #ifdef HAVE_STDINT_H
   17 #   include <stdint.h>
   18 #else
   19 #   ifdef HAVE_INTTYPES_H
   20 #       include <inttypes.h>
   21 #   endif /* HAVE_INTTYPES_H */
   22 #endif /* HAVE_STDINT_H */
   23 
   24 typedef struct sha_ctx {
   25   uint32_t digest[SHA_DIGESTLEN];  /* Message digest */
   26   uint32_t count_l, count_h;       /* 64-bit block count */
   27   uint8_t block[SHA_DATASIZE];     /* SHA data buffer */
   28   int index;                             /* index into buffer */
   29   int finalized;
   30 } SHA_CTX;
   31 
   32 int sha_init(struct sha_ctx *ctx);
   33 int sha_update(struct sha_ctx *ctx, const uint8_t *buffer, uint32_t len);
   34 void sha_final(struct sha_ctx *ctx);
   35 int sha_digest(struct sha_ctx *ctx, uint8_t *s);
   36 void sha_copy(struct sha_ctx *dest, struct sha_ctx *src);
   37 
   38 #if 1
   39 
   40 #ifndef EXTRACT_UCHAR
   41 #define EXTRACT_UCHAR(p)  (*(unsigned char *)(p))
   42 #endif
   43 
   44 #define STRING2INT(s) ((((((EXTRACT_UCHAR(s) << 8)    \
   45              | EXTRACT_UCHAR(s+1)) << 8)  \
   46              | EXTRACT_UCHAR(s+2)) << 8)  \
   47              | EXTRACT_UCHAR(s+3))
   48 #else
   49 uint32_t STRING2INT(uint8_t *s)
   50 {
   51   uint32_t r;
   52   int i;
   53   
   54   for (i = 0, r = 0; i < 4; i++, s++)
   55     r = (r << 8) | *s;
   56   return r;
   57 }
   58 #endif
   59 
   60 #endif