From c08ae816a2cb82400f04202803c3558e1db3900f Mon Sep 17 00:00:00 2001 From: Andreas Steffen Date: Thu, 7 May 2009 10:10:42 +0200 Subject: [PATCH] use hash size constants from hasher.h --- src/pluto/constants.c | 2 +- src/pluto/constants.h | 25 +++++-------------------- src/pluto/ocsp.c | 5 +++-- src/pluto/pgp.h | 5 ++++- src/scepclient/scep.c | 5 +++-- 5 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/pluto/constants.c b/src/pluto/constants.c index a8985be8f..810d76bcb 100644 --- a/src/pluto/constants.c +++ b/src/pluto/constants.c @@ -1364,6 +1364,6 @@ void init_constants(void) happy(initsubnet(&ipv6_any, 0, '0', &ipv6_all)); } -u_char secret_of_the_day[SHA1_DIGEST_SIZE]; +u_char secret_of_the_day[HASH_SIZE_SHA1]; diff --git a/src/pluto/constants.h b/src/pluto/constants.h index aa7a75828..56e9321e8 100644 --- a/src/pluto/constants.h +++ b/src/pluto/constants.h @@ -18,6 +18,7 @@ #define _CONSTANTS_H #include +#include extern const char compile_time_interop_options[]; @@ -278,32 +279,16 @@ extern const char sparse_end[]; #define COOKIE_SIZE 8 #define MAX_ISAKMP_SPI_SIZE 16 -#define MD2_DIGEST_SIZE (128 / BITS_PER_BYTE) -#define MD5_DIGEST_SIZE (128 / BITS_PER_BYTE) -#define SHA1_DIGEST_SIZE (160 / BITS_PER_BYTE) -#define SHA2_256_DIGEST_SIZE (256 / BITS_PER_BYTE) -#define SHA2_384_DIGEST_SIZE (384 / BITS_PER_BYTE) -#define SHA2_512_DIGEST_SIZE (512 / BITS_PER_BYTE) - -#define MD5_BLOCK_SIZE (512 / BITS_PER_BYTE) -#define SHA1_BLOCK_SIZE (512 / BITS_PER_BYTE) -#define SHA2_256_BLOCK_SIZE (512 / BITS_PER_BYTE) -#define SHA2_384_BLOCK_SIZE (1024 / BITS_PER_BYTE) -#define SHA2_512_BLOCK_SIZE (1024 / BITS_PER_BYTE) - #define DES_CBC_BLOCK_SIZE (64 / BITS_PER_BYTE) -#define DSS_QBITS 160 /* bits in DSS's "q" (FIPS 186-1) */ - /* Maximum is required for SHA2_512 */ -#define MAX_DIGEST_LEN SHA2_512_DIGEST_SIZE -#define MAX_HASH_BLOCK_SIZE SHA2_512_BLOCK_SIZE +#define MAX_DIGEST_LEN HASH_SIZE_SHA512 /* RFC 2404 "HMAC-SHA-1-96" section 3 */ -#define HMAC_SHA1_KEY_LEN SHA1_DIGEST_SIZE +#define HMAC_SHA1_KEY_LEN HASH_SIZE_SHA1 /* RFC 2403 "HMAC-MD5-96" section 3 */ -#define HMAC_MD5_KEY_LEN MD5_DIGEST_SIZE +#define HMAC_MD5_KEY_LEN HASH_SIZE_MD5 #define IKE_UDP_PORT 500 @@ -1269,6 +1254,6 @@ enum dns_auth_level { extern const char *const natt_type_bitnames[]; /* secret value for responder cookies */ -extern u_char secret_of_the_day[SHA1_DIGEST_SIZE]; +extern u_char secret_of_the_day[HASH_SIZE_SHA1]; #endif /* _CONSTANTS_H */ diff --git a/src/pluto/ocsp.c b/src/pluto/ocsp.c index c2d9b6aa9..6613ef119 100644 --- a/src/pluto/ocsp.c +++ b/src/pluto/ocsp.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "constants.h" #include "defs.h" @@ -293,7 +294,7 @@ static const asn1Object_t singleResponseObjects[] = { */ static bool build_ocsp_location(const x509cert_t *cert, ocsp_location_t *location) { - static u_char digest[SHA1_DIGEST_SIZE]; /* temporary storage */ + static u_char digest[HASH_SIZE_SHA1]; /* temporary storage */ location->uri = cert->accessLocation; @@ -311,7 +312,7 @@ static bool build_ocsp_location(const x509cert_t *cert, ocsp_location_t *locatio } } - location->authNameID = chunk_create(digest, SHA1_DIGEST_SIZE); + location->authNameID = chunk_create(digest, HASH_SIZE_SHA1); compute_digest(cert->issuer, OID_SHA1, &location->authNameID); location->next = NULL; diff --git a/src/pluto/pgp.h b/src/pluto/pgp.h index 418567b25..4519022e4 100644 --- a/src/pluto/pgp.h +++ b/src/pluto/pgp.h @@ -15,11 +15,14 @@ #ifndef _PGP_H #define _PGP_H +#include + #include "pkcs1.h" + /* * Length of PGP V3 fingerprint */ -#define PGP_FINGERPRINT_SIZE MD5_DIGEST_SIZE +#define PGP_FINGERPRINT_SIZE HASH_SIZE_MD5 typedef char fingerprint_t[PGP_FINGERPRINT_SIZE]; diff --git a/src/scepclient/scep.c b/src/scepclient/scep.c index 5fb763169..dd16dff1b 100644 --- a/src/scepclient/scep.c +++ b/src/scepclient/scep.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "../pluto/constants.h" #include "../pluto/defs.h" @@ -267,7 +268,7 @@ end: */ void scep_generate_pkcs10_fingerprint(chunk_t pkcs10, chunk_t *fingerprint) { - char buf[MD5_DIGEST_SIZE]; + char buf[HASH_SIZE_MD5]; chunk_t digest = { buf, sizeof(buf) }; /* the fingerprint is the MD5 hash in hexadecimal format */ @@ -284,7 +285,7 @@ void scep_generate_pkcs10_fingerprint(chunk_t pkcs10, chunk_t *fingerprint) void scep_generate_transaction_id(const RSA_public_key_t *rsak, chunk_t *transID, chunk_t *serialNumber) { - char buf[MD5_DIGEST_SIZE]; + char buf[HASH_SIZE_MD5]; chunk_t digest = { buf, sizeof(buf) }; chunk_t public_key = pkcs1_build_publicKeyInfo(rsak);