summaryrefslogtreecommitdiffstats
path: root/src/lib/crypto/openssl
diff options
context:
space:
mode:
authorZhanna Tsitkov <tsitkova@mit.edu>2009-09-30 22:33:41 +0000
committerZhanna Tsitkov <tsitkova@mit.edu>2009-09-30 22:33:41 +0000
commitcb1fe7f9bbab7c09c483bac964f4d045b91aec66 (patch)
tree836dab3fde0e3202cf6bc8c7eaba2f18c9bbde49 /src/lib/crypto/openssl
parente9c2e78bdd51ea150e46c9297f7abf5f5590522a (diff)
Crypto modularity proj: SHS_INFO structure is defined differently for crypto impl's. Files hash_sha1.c and yhash.h are affected by this difference. Move hash_provider into the backend
The following bigredbutton is used to suppress svn complains about the trailing spaces in the moved/copied dirs. bigredbutton: whitespace git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@22815 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib/crypto/openssl')
-rw-r--r--src/lib/crypto/openssl/hash_provider/hash_crc32.c56
-rw-r--r--src/lib/crypto/openssl/hash_provider/hash_md4.c56
-rw-r--r--src/lib/crypto/openssl/hash_provider/hash_md5.c56
-rw-r--r--src/lib/crypto/openssl/hash_provider/hash_provider.h32
-rw-r--r--src/lib/crypto/openssl/hash_provider/hash_sha1.c61
-rw-r--r--src/lib/crypto/openssl/hmac.c2
-rw-r--r--src/lib/crypto/openssl/sha1/shs.c18
-rw-r--r--src/lib/crypto/openssl/sha1/shs.h8
-rw-r--r--src/lib/crypto/openssl/yhash.h30
9 files changed, 305 insertions, 14 deletions
diff --git a/src/lib/crypto/openssl/hash_provider/hash_crc32.c b/src/lib/crypto/openssl/hash_provider/hash_crc32.c
new file mode 100644
index 000000000..a3d3028e8
--- /dev/null
+++ b/src/lib/crypto/openssl/hash_provider/hash_crc32.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 1998 by the FundsXpress, INC.
+ *
+ * All rights reserved.
+ *
+ * Export of this software from the United States of America may require
+ * a specific license from the United States Government. It is the
+ * responsibility of any person or organization contemplating export to
+ * obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of FundsXpress. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. FundsXpress makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#include "k5-int.h"
+#include "crc-32.h"
+#include "hash_provider.h"
+
+static krb5_error_code
+k5_crc32_hash(unsigned int icount, const krb5_data *input,
+ krb5_data *output)
+{
+ unsigned long c, cn;
+ unsigned int i;
+
+ if (output->length != CRC32_CKSUM_LENGTH)
+ return(KRB5_CRYPTO_INTERNAL);
+
+ c = 0;
+ for (i=0; i<icount; i++) {
+ mit_crc32(input[i].data, input[i].length, &cn);
+ c ^= cn;
+ }
+
+ store_32_le(c, output->data);
+ return(0);
+}
+
+const struct krb5_hash_provider krb5int_hash_crc32 = {
+ "CRC32",
+ CRC32_CKSUM_LENGTH,
+ 1,
+ k5_crc32_hash
+};
diff --git a/src/lib/crypto/openssl/hash_provider/hash_md4.c b/src/lib/crypto/openssl/hash_provider/hash_md4.c
new file mode 100644
index 000000000..f507aaaf7
--- /dev/null
+++ b/src/lib/crypto/openssl/hash_provider/hash_md4.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 1998 by the FundsXpress, INC.
+ *
+ * All rights reserved.
+ *
+ * Export of this software from the United States of America may require
+ * a specific license from the United States Government. It is the
+ * responsibility of any person or organization contemplating export to
+ * obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of FundsXpress. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. FundsXpress makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#include "k5-int.h"
+#include "rsa-md4.h"
+#include "hash_provider.h"
+
+static krb5_error_code
+k5_md4_hash(unsigned int icount, const krb5_data *input,
+ krb5_data *output)
+{
+ krb5_MD4_CTX ctx;
+ unsigned int i;
+
+ if (output->length != RSA_MD4_CKSUM_LENGTH)
+ return(KRB5_CRYPTO_INTERNAL);
+
+ krb5_MD4Init(&ctx);
+ for (i=0; i<icount; i++)
+ krb5_MD4Update(&ctx, (unsigned char *) input[i].data, input[i].length);
+ krb5_MD4Final(&ctx);
+
+ memcpy(output->data, ctx.digest, RSA_MD4_CKSUM_LENGTH);
+
+ return(0);
+}
+
+const struct krb5_hash_provider krb5int_hash_md4 = {
+ "MD4",
+ RSA_MD4_CKSUM_LENGTH,
+ 64,
+ k5_md4_hash
+};
diff --git a/src/lib/crypto/openssl/hash_provider/hash_md5.c b/src/lib/crypto/openssl/hash_provider/hash_md5.c
new file mode 100644
index 000000000..a6e380ae2
--- /dev/null
+++ b/src/lib/crypto/openssl/hash_provider/hash_md5.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 1998 by the FundsXpress, INC.
+ *
+ * All rights reserved.
+ *
+ * Export of this software from the United States of America may require
+ * a specific license from the United States Government. It is the
+ * responsibility of any person or organization contemplating export to
+ * obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of FundsXpress. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. FundsXpress makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#include "k5-int.h"
+#include "rsa-md5.h"
+#include "hash_provider.h"
+
+static krb5_error_code
+k5_md5_hash(unsigned int icount, const krb5_data *input,
+ krb5_data *output)
+{
+ krb5_MD5_CTX ctx;
+ unsigned int i;
+
+ if (output->length != RSA_MD5_CKSUM_LENGTH)
+ return(KRB5_CRYPTO_INTERNAL);
+
+ krb5_MD5Init(&ctx);
+ for (i=0; i<icount; i++)
+ krb5_MD5Update(&ctx, (unsigned char *) input[i].data, input[i].length);
+ krb5_MD5Final(&ctx);
+
+ memcpy(output->data, ctx.digest, RSA_MD5_CKSUM_LENGTH);
+
+ return(0);
+}
+
+const struct krb5_hash_provider krb5int_hash_md5 = {
+ "MD5",
+ RSA_MD5_CKSUM_LENGTH,
+ 64,
+ k5_md5_hash
+};
diff --git a/src/lib/crypto/openssl/hash_provider/hash_provider.h b/src/lib/crypto/openssl/hash_provider/hash_provider.h
new file mode 100644
index 000000000..4fa46097d
--- /dev/null
+++ b/src/lib/crypto/openssl/hash_provider/hash_provider.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 1998 by the FundsXpress, INC.
+ *
+ * All rights reserved.
+ *
+ * Export of this software from the United States of America may require
+ * a specific license from the United States Government. It is the
+ * responsibility of any person or organization contemplating export to
+ * obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of FundsXpress. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. FundsXpress makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#include "k5-int.h"
+
+extern const struct krb5_hash_provider krb5int_hash_crc32;
+extern const struct krb5_hash_provider krb5int_hash_md4;
+extern const struct krb5_hash_provider krb5int_hash_md5;
+extern const struct krb5_hash_provider krb5int_hash_sha1;
diff --git a/src/lib/crypto/openssl/hash_provider/hash_sha1.c b/src/lib/crypto/openssl/hash_provider/hash_sha1.c
new file mode 100644
index 000000000..d217086e6
--- /dev/null
+++ b/src/lib/crypto/openssl/hash_provider/hash_sha1.c
@@ -0,0 +1,61 @@
+/* lib/crypto/openssl/hash/yhash.h
+ *
+ * Copyright (C) 1998 by the FundsXpress, INC.
+ *
+ * All rights reserved.
+ *
+ * Export of this software from the United States of America may require
+ * a specific license from the United States Government. It is the
+ * responsibility of any person or organization contemplating export to
+ * obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of FundsXpress. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. FundsXpress makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#include "k5-int.h"
+#include "shs.h"
+#include "hash_provider.h"
+
+static krb5_error_code
+k5_sha1_hash(unsigned int icount, const krb5_data *input,
+ krb5_data *output)
+{
+ SHS_INFO ctx;
+ unsigned int i;
+
+ if (output->length != SHS_DIGESTSIZE)
+ return(KRB5_CRYPTO_INTERNAL);
+
+ shsInit(&ctx);
+ for (i=0; i<icount; i++)
+ shsUpdate(&ctx, (unsigned char *) input[i].data, input[i].length);
+ shsFinal(&ctx);
+
+ if (ctx.digestLen > 0 && ctx.digestLen <= output->length){
+ output->length = ctx.digestLen;
+ memcpy(output->data, ctx.digestBuf,ctx.digestLen);
+ }
+
+ return(0);
+}
+
+const struct krb5_hash_provider krb5int_hash_sha1 = {
+ "SHA1",
+ SHS_DIGESTSIZE,
+ SHS_DATASIZE,
+ k5_sha1_hash
+};
+
diff --git a/src/lib/crypto/openssl/hmac.c b/src/lib/crypto/openssl/hmac.c
index a5543c977..e0c8dec79 100644
--- a/src/lib/crypto/openssl/hmac.c
+++ b/src/lib/crypto/openssl/hmac.c
@@ -1,4 +1,4 @@
-/*
+/* lib/crypto/openssl/hmac.c
*/
#include "k5-int.h"
diff --git a/src/lib/crypto/openssl/sha1/shs.c b/src/lib/crypto/openssl/sha1/shs.c
index 9fb60f87c..7cc864bb8 100644
--- a/src/lib/crypto/openssl/sha1/shs.c
+++ b/src/lib/crypto/openssl/sha1/shs.c
@@ -3,12 +3,19 @@
#include <sys/types.h>
#endif
#include <string.h>
+#define h0init 0x67452301L
+#define h1init 0xEFCDAB89L
+#define h2init 0x98BADCFEL
+#define h3init 0x10325476L
+#define h4init 0xC3D2E1F0L
/* Initialize the SHS values */
void shsInit(SHS_INFO *shsInfo)
{
EVP_MD_CTX_init(&shsInfo->ossl_sha1_ctx );
EVP_DigestInit_ex(&shsInfo->ossl_sha1_ctx , EVP_sha1(), NULL);
+ shsInfo->digestLen = 0;
+ memset(shsInfo->digestBuf, 0 , sizeof(shsInfo->digestBuf));
}
/* Update SHS for a block of data */
@@ -22,13 +29,8 @@ void shsUpdate(SHS_INFO *shsInfo, const SHS_BYTE *buffer, unsigned int count)
void shsFinal(SHS_INFO *shsInfo)
{
- unsigned char *digest_buf = NULL;
-
- digest_buf = (unsigned char *)OPENSSL_malloc( sizeof(shsInfo->digest));
-
- EVP_DigestFinal_ex(&shsInfo->ossl_sha1_ctx , digest_buf , &shsInfo->digest_len);
-
- memcpy(shsInfo->digest, digest_buf, shsInfo->digest_len);
- OPENSSL_free(digest_buf);
+ EVP_DigestFinal_ex(&shsInfo->ossl_sha1_ctx ,(unsigned char *)shsInfo->digestBuf , &shsInfo->digestLen);
EVP_MD_CTX_cleanup(&shsInfo->ossl_sha1_ctx );
}
+
+
diff --git a/src/lib/crypto/openssl/sha1/shs.h b/src/lib/crypto/openssl/sha1/shs.h
index 66e91b69b..772c72ac6 100644
--- a/src/lib/crypto/openssl/sha1/shs.h
+++ b/src/lib/crypto/openssl/sha1/shs.h
@@ -22,11 +22,9 @@ typedef krb5_ui_4 SHS_LONG;
/* The structure for storing SHS info */
typedef struct {
- EVP_MD_CTX ossl_sha1_ctx;
- unsigned int digest_len;
- SHS_LONG digest[ 5 ]; /* Message digest */
- SHS_LONG countLo, countHi; /* 64-bit bit count */
- SHS_LONG data[ 16 ]; /* SHS data buffer */
+ EVP_MD_CTX ossl_sha1_ctx;
+ unsigned char digestBuf[SHS_DIGESTSIZE]; /* output */
+ unsigned int digestLen; /* output */
} SHS_INFO;
/* Message digest functions (shs.c) */
diff --git a/src/lib/crypto/openssl/yhash.h b/src/lib/crypto/openssl/yhash.h
new file mode 100644
index 000000000..94c557c64
--- /dev/null
+++ b/src/lib/crypto/openssl/yhash.h
@@ -0,0 +1,30 @@
+/* -*- Mode: C; c-file-style: "bsd" -*- */
+/* lib/crypto/openssl/hash/yhash.h
+ */
+
+#ifndef YHASH_H
+#define YHASH_H
+
+/* hash function interface */
+
+/* default to SHA1 for yarrow 160 */
+
+#include "shs.h"
+
+
+#define HASH_CTX SHS_INFO
+#define HASH_Init(x) shsInit(x)
+#define HASH_Update(x, buf, sz) shsUpdate(x, (const void*)buf, sz)
+
+#define HASH_Final(x, tdigest) do { \
+ int loopvar; \
+ unsigned char *out2 = (void *)(tdigest); \
+ HASH_CTX *ctx = (x); \
+ shsFinal(ctx); \
+ memcpy(out2, ctx->digestBuf, ctx->digestLen); \
+ } while(0)
+
+#define HASH_DIGEST_SIZE SHS_DIGESTSIZE
+
+#endif /* YHASH_H */
+