Skip to content
Snippets Groups Projects
Select Git revision
  • a88d88020693b35b272800fe0ded4293a22720e2
  • master default protected
  • Sylvan-SOG
  • hybrid
4 results

sha2.c

Blame
  • sha2.c 31.03 KiB
    /*
     * FILE:	sha2.c
     * AUTHOR:	Aaron D. Gifford - http://www.aarongifford.com/
     * 
     * Copyright (c) 2000-2001, Aaron D. Gifford
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     * 1. Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     * 2. Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     * 3. Neither the name of the copyright holder nor the names of contributors
     *    may be used to endorse or promote products derived from this software
     *    without specific prior written permission.
     * 
     * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND
     * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE
     * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     * SUCH DAMAGE.
     *
     */
    
    #include <string.h>	/* memcpy()/memset() or bcopy()/bzero() */
    #include <assert.h>	/* assert() */
    #include "sha2.h"
    
    /*
     * ASSERT NOTE:
     * Some sanity checking code is included using assert().  On my FreeBSD
     * system, this additional code can be removed by compiling with NDEBUG
     * defined.  Check your own systems manpage on assert() to see how to
     * compile WITHOUT the sanity checking code on your system.
     *
     * UNROLLED TRANSFORM LOOP NOTE:
     * You can define SHA2_UNROLL_TRANSFORM to use the unrolled transform
     * loop version for the hash transform rounds (defined using macros
     * later in this file).  Either define on the command line, for example:
     *
     *   cc -DSHA2_UNROLL_TRANSFORM -o sha2 sha2.c sha2prog.c
     *
     * or define below:
     *
     *   #define SHA2_UNROLL_TRANSFORM
     *
     */
    
    
    /*** SHA-256/384/512 Machine Architecture Definitions *****************/
    /*
     * BYTE_ORDER NOTE:
     *
     * Please make sure that your system defines BYTE_ORDER.  If your
     * architecture is little-endian, make sure it also defines
     * LITTLE_ENDIAN and that the two (BYTE_ORDER and LITTLE_ENDIAN) are
     * equivilent.
     *
     * If your system does not define the above, then you can do so by
     * hand like this:
     *