Annotation of embedaddon/bird/lib/sha1.h, revision 1.1

1.1     ! misho       1: /*
        !             2:  *     BIRD Library -- SHA-1 Hash Function (FIPS 180-1, RFC 3174)
        !             3:  *
        !             4:  *     (c) 2015 CZ.NIC z.s.p.o.
        !             5:  *
        !             6:  *     Based on the code from libucw-6.4
        !             7:  *     (c) 2008--2009 Martin Mares <mj@ucw.cz>
        !             8:  *
        !             9:  *     Based on the code from libgcrypt-1.2.3, which is
        !            10:  *     (c) 1998, 2001, 2002, 2003 Free Software Foundation, Inc.
        !            11:  *
        !            12:  *     Can be freely distributed and used under the terms of the GNU GPL.
        !            13:  */
        !            14: 
        !            15: #ifndef _BIRD_SHA1_H_
        !            16: #define _BIRD_SHA1_H_
        !            17: 
        !            18: #include "nest/bird.h"
        !            19: 
        !            20: 
        !            21: #define SHA1_SIZE              20      /* Size of the SHA1 hash in its binary representation */
        !            22: #define SHA1_HEX_SIZE          41      /* Buffer length for a string containing SHA1 in hexadecimal format. */
        !            23: #define SHA1_BLOCK_SIZE                64      /* SHA1 splits input to blocks of this size. */
        !            24: 
        !            25: 
        !            26: /*
        !            27:  * Internal SHA1 state.
        !            28:  * You should use it just as an opaque handle only.
        !            29:  */
        !            30: struct hash_context;
        !            31: 
        !            32: struct sha1_context {
        !            33:   u32 h0, h1, h2, h3, h4;
        !            34:   byte buf[SHA1_BLOCK_SIZE];
        !            35:   uint nblocks;
        !            36:   uint count;
        !            37: };
        !            38: 
        !            39: void sha1_init(struct hash_context *ctx); /* Initialize new algorithm run in the @ctx context. **/
        !            40: /*
        !            41:  * Push another @len bytes of data pointed to by @buf onto the SHA1 hash
        !            42:  * currently in @ctx. You can call this any times you want on the same hash (and
        !            43:  * you do not need to reinitialize it by @sha1_init()). It has the same effect
        !            44:  * as concatenating all the data together and passing them at once.
        !            45:  */
        !            46: void sha1_update(struct hash_context *ctx, const byte *buf, uint len);
        !            47: /*
        !            48:  * No more @sha1_update() calls will be done. This terminates the hash and
        !            49:  * returns a pointer to it.
        !            50:  *
        !            51:  * Note that the pointer points into data in the @ctx context. If it ceases to
        !            52:  * exist, the pointer becomes invalid.
        !            53:  */
        !            54: byte *sha1_final(struct hash_context *ctx);
        !            55: 
        !            56: /*
        !            57:  * A convenience one-shot function for SHA1 hash. It is equivalent to this
        !            58:  * snippet of code:
        !            59:  *
        !            60:  *  sha1_context ctx;
        !            61:  *  sha1_init(&ctx);
        !            62:  *  sha1_update(&ctx, buffer, length);
        !            63:  *  memcpy(outbuf, sha1_final(&ctx), SHA1_SIZE);
        !            64:  */
        !            65: void sha1_hash_buffer(byte *outbuf, const byte *buffer, uint length);
        !            66: 
        !            67: 
        !            68: #endif /* _BIRD_SHA1_H_ */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>