mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
Add SHA-224 support
This commit is contained in:
parent
36ce455f15
commit
f0902a6aef
@ -1,3 +1,9 @@
|
||||
2006-04-19 David Shaw <dshaw@jabberwocky.com>
|
||||
|
||||
* sha256.c (sha224_get_info, sha224_init): New init functions for
|
||||
the 224-bit variant of SHA-256.
|
||||
* algorithms.h, md.c (load_digest_module): Call them here.
|
||||
|
||||
2006-03-20 David Shaw <dshaw@jabberwocky.com>
|
||||
|
||||
* blowfish.c, md5.c, rmd160.c, sha1.c, sha256.c, sha512.c: Revert
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* algorithms.h - prototypes for algorithm functions.
|
||||
* Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2002, 2003, 2006 Free Software Foundation, Inc.
|
||||
*
|
||||
* This file is part of GnuPG.
|
||||
*
|
||||
@ -51,6 +51,15 @@ sha1_get_info (int algo, size_t *contextsize,
|
||||
byte *(**r_read)( void *c )
|
||||
);
|
||||
|
||||
const char *
|
||||
sha224_get_info (int algo, size_t *contextsize,
|
||||
byte **r_asnoid, int *r_asnlen, int *r_mdlen,
|
||||
void (**r_init)( void *c ),
|
||||
void (**r_write)( void *c, byte *buf, size_t nbytes ),
|
||||
void (**r_final)( void *c ),
|
||||
byte *(**r_read)( void *c )
|
||||
);
|
||||
|
||||
const char *
|
||||
sha256_get_info (int algo, size_t *contextsize,
|
||||
byte **r_asnoid, int *r_asnlen, int *r_mdlen,
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* md.c - message digest dispatcher
|
||||
* Copyright (C) 1998, 1999, 2002, 2003 Free Software Foundation, Inc.
|
||||
* Copyright (C) 1998, 1999, 2002, 2003, 2006 Free Software Foundation, Inc.
|
||||
*
|
||||
* This file is part of GnuPG.
|
||||
*
|
||||
@ -106,6 +106,8 @@ load_digest_module (void)
|
||||
#ifdef USE_SHA256
|
||||
if (!new_list_item (DIGEST_ALGO_SHA256, sha256_get_info))
|
||||
BUG ();
|
||||
if (!new_list_item (DIGEST_ALGO_SHA224, sha224_get_info))
|
||||
BUG ();
|
||||
#endif
|
||||
if (!new_list_item (DIGEST_ALGO_MD5, md5_get_info))
|
||||
BUG ();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* sha256.c - SHA256 hash function
|
||||
* Copyright (C) 2003 Free Software Foundation, Inc.
|
||||
/* sha256.c - SHA224 and SHA256 hash functions
|
||||
* Copyright (C) 2003, 2006 Free Software Foundation, Inc.
|
||||
*
|
||||
* Please see below for more legal information!
|
||||
*
|
||||
@ -25,12 +25,21 @@
|
||||
/* Test vectors from FIPS-180-2:
|
||||
*
|
||||
* "abc"
|
||||
* 224:
|
||||
* 23097D22 3405D822 8642A477 BDA255B3 2AADBCE4 BDA0B3F7 E36C9DA7
|
||||
* 256:
|
||||
* BA7816BF 8F01CFEA 414140DE 5DAE2223 B00361A3 96177A9C B410FF61 F20015AD
|
||||
*
|
||||
* "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
|
||||
* 224:
|
||||
* 75388B16 512776CC 5DBA5DA1 FD890150 B0C6455C B4F58B19 52522525
|
||||
* 256:
|
||||
* 248D6A61 D20638B8 E5C02693 0C3E6039 A33CE459 64FF2167 F6ECEDD4 19DB06C1
|
||||
*
|
||||
* "a" x 1000000
|
||||
* 224:
|
||||
* 20794655 980C91D8 BBB4C1EA 97618A4B F03F4258 1948B2EE 4EE7AD67
|
||||
* 256:
|
||||
* CDC76E5C 9914FB92 81A1C7E2 84D73E67 F1809A48 A497200E 046D39CC C7112CD0
|
||||
*/
|
||||
|
||||
@ -76,6 +85,22 @@ sha256_init( SHA256_CONTEXT *hd )
|
||||
hd->count = 0;
|
||||
}
|
||||
|
||||
void
|
||||
sha224_init( SHA256_CONTEXT *hd )
|
||||
{
|
||||
hd->h0 = 0xc1059ed8;
|
||||
hd->h1 = 0x367cd507;
|
||||
hd->h2 = 0x3070dd17;
|
||||
hd->h3 = 0xf70e5939;
|
||||
hd->h4 = 0xffc00b31;
|
||||
hd->h5 = 0x68581511;
|
||||
hd->h6 = 0x64f98fa7;
|
||||
hd->h7 = 0xbefa4fa4;
|
||||
|
||||
hd->nblocks = 0;
|
||||
hd->count = 0;
|
||||
}
|
||||
|
||||
|
||||
/****************
|
||||
* Transform the message w which consists of 16 32-bit words
|
||||
@ -207,7 +232,8 @@ sha256_write( SHA256_CONTEXT *hd, byte *inbuf, size_t inlen)
|
||||
* returns the digest.
|
||||
* The handle is prepared for a new cycle, but adding bytes to the
|
||||
* handle will the destroy the returned buffer.
|
||||
* Returns: 32 bytes representing the digest.
|
||||
* Returns: 32 bytes representing the digest. When used for sha224,
|
||||
* we take the leftmost 28 of those bytes.
|
||||
*/
|
||||
|
||||
static void
|
||||
@ -270,6 +296,8 @@ sha256_final(SHA256_CONTEXT *hd)
|
||||
X(4);
|
||||
X(5);
|
||||
X(6);
|
||||
/* Note that this last chunk is included even for SHA224. We just
|
||||
ignore it. */
|
||||
X(7);
|
||||
#undef X
|
||||
}
|
||||
@ -316,3 +344,36 @@ sha256_get_info( int algo, size_t *contextsize,
|
||||
|
||||
return "SHA256";
|
||||
}
|
||||
|
||||
/* SHA224 is really a truncated SHA256 with a different
|
||||
initialization */
|
||||
const char *
|
||||
sha224_get_info( int algo, size_t *contextsize,
|
||||
byte **r_asnoid, int *r_asnlen, int *r_mdlen,
|
||||
void (**r_init)( void *c ),
|
||||
void (**r_write)( void *c, byte *buf, size_t nbytes ),
|
||||
void (**r_final)( void *c ),
|
||||
byte *(**r_read)( void *c )
|
||||
)
|
||||
{
|
||||
static byte asn[] = /* Object ID is 2.16.840.1.101.3.4.2.4 */
|
||||
{
|
||||
0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
|
||||
0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04, 0x05,
|
||||
0x00, 0x04, 0x20
|
||||
};
|
||||
|
||||
if( algo != 11 )
|
||||
return NULL;
|
||||
|
||||
*contextsize = sizeof(SHA256_CONTEXT);
|
||||
*r_asnoid = asn;
|
||||
*r_asnlen = DIM(asn);
|
||||
*r_mdlen = 28;
|
||||
*(void (**)(SHA256_CONTEXT *))r_init = sha224_init;
|
||||
*(void (**)(SHA256_CONTEXT *, byte*, size_t))r_write = sha256_write;
|
||||
*(void (**)(SHA256_CONTEXT *))r_final = sha256_final;
|
||||
*(byte *(**)(SHA256_CONTEXT *))r_read = sha256_read;
|
||||
|
||||
return "SHA224";
|
||||
}
|
||||
|
@ -1,3 +1,7 @@
|
||||
2006-04-19 David Shaw <dshaw@jabberwocky.com>
|
||||
|
||||
* cipher.h: Add SHA-224.
|
||||
|
||||
2006-03-16 David Shaw <dshaw@jabberwocky.com>
|
||||
|
||||
* util.h: Handle the fixed IPGP type with fingerprint.
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* cipher.h
|
||||
* Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004,
|
||||
* 2005 Free Software Foundation, Inc.
|
||||
* Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005,
|
||||
* 2006 Free Software Foundation, Inc.
|
||||
*
|
||||
* This file is part of GNUPG.
|
||||
*
|
||||
@ -60,6 +60,7 @@
|
||||
#define DIGEST_ALGO_SHA256 8
|
||||
#define DIGEST_ALGO_SHA384 9
|
||||
#define DIGEST_ALGO_SHA512 10
|
||||
#define DIGEST_ALGO_SHA224 11
|
||||
|
||||
#define COMPRESS_ALGO_NONE 0
|
||||
#define COMPRESS_ALGO_ZIP 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user