Select Git revision
Forked from
Nettle / nettle
Source project has a limited visibility.
-
Niels Möller authored
Rev: src/nettle/hmac-md5.c:1.1 Rev: src/nettle/hmac.c:1.1 Rev: src/nettle/hmac.h:1.1 Rev: src/nettle/md5-meta.c:1.1 Rev: src/nettle/nettle-meta.h:1.1 Rev: src/nettle/sha1-meta.c:1.1 Rev: src/nettle/sha256-meta.c:1.1
Niels Möller authoredRev: src/nettle/hmac-md5.c:1.1 Rev: src/nettle/hmac.c:1.1 Rev: src/nettle/hmac.h:1.1 Rev: src/nettle/md5-meta.c:1.1 Rev: src/nettle/nettle-meta.h:1.1 Rev: src/nettle/sha1-meta.c:1.1 Rev: src/nettle/sha256-meta.c:1.1
sha1.c 12.68 KiB
/* sha1.h
*
* The sha1 hash function.
*/
/* nettle, low-level cryptographics library
*
* Copyright (C) 2001 Peter Gutmann, Andrew Kuchling, Niels Möller
*
* The nettle library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The nettle library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the nettle library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
/* Here's the first paragraph of Peter Gutmann's posting,
* <30ajo5$oe8@ccu2.auckland.ac.nz>:
*
* The following is my SHA (FIPS 180) code updated to allow use of the "fixed"
* SHA, thanks to Jim Gillogly and an anonymous contributor for the information on
* what's changed in the new version. The fix is a simple change which involves
* adding a single rotate in the initial expansion function. It is unknown
* whether this is an optimal solution to the problem which was discovered in the
* SHA or whether it's simply a bandaid which fixes the problem with a minimum of
* effort (for example the reengineering of a great many Capstone chips).
*/
#include "sha1.h"
#include "macros.h"
#include <assert.h>
#include <string.h>
/* A block, treated as a sequence of 32-bit words. */
#define SHA1_DATA_LENGTH 16
/* The SHA f()-functions. The f1 and f3 functions can be optimized to
save one boolean operation each - thanks to Rich Schroeppel,
rcs@cs.arizona.edu for discovering this */
/* #define f1(x,y,z) ( ( x & y ) | ( ~x & z ) ) Rounds 0-19 */
#define f1(x,y,z) ( z ^ ( x & ( y ^ z ) ) ) /* Rounds 0-19 */
#define f2(x,y,z) ( x ^ y ^ z ) /* Rounds 20-39 */
/* #define f3(x,y,z) ( ( x & y ) | ( x & z ) | ( y & z ) ) Rounds 40-59 */
#define f3(x,y,z) ( ( x & y ) | ( z & ( x | y ) ) ) /* Rounds 40-59 */
#define f4(x,y,z) ( x ^ y ^ z ) /* Rounds 60-79 */
/* The SHA Mysterious Constants */
#define K1 0x5A827999L /* Rounds 0-19 */
#define K2 0x6ED9EBA1L /* Rounds 20-39 */
#define K3 0x8F1BBCDCL /* Rounds 40-59 */
#define K4 0xCA62C1D6L /* Rounds 60-79 */
/* SHA initial values */
#define h0init 0x67452301L
#define h1init 0xEFCDAB89L
#define h2init 0x98BADCFEL