aboutsummaryrefslogtreecommitdiff
path: root/src/lib/crypto/krb/keyhash_provider/k5_md5des.c
diff options
context:
space:
mode:
authorGreg Hudson <ghudson@mit.edu>2009-12-10 17:10:10 +0000
committerGreg Hudson <ghudson@mit.edu>2009-12-10 17:10:10 +0000
commitbad149c2a94f20df57f9d51810aff23aeb0921a4 (patch)
tree9a023564d65fe8c46bcc330f950b37b919599c03 /src/lib/crypto/krb/keyhash_provider/k5_md5des.c
parent009463e22f989a287835228459487c64dcb0b8b3 (diff)
downloadkrb5-bad149c2a94f20df57f9d51810aff23aeb0921a4.zip
krb5-bad149c2a94f20df57f9d51810aff23aeb0921a4.tar.gz
krb5-bad149c2a94f20df57f9d51810aff23aeb0921a4.tar.bz2
Restructure the crypto checksum implementation to minimize
dependencies on the internals of modules. * Keyhash providers are gone. * The cksumtypes table contains checksum and verify functions, similar to the etypes encrypt and decrypt functions. New checksum functions parallel the old keyhash providers, and there are also functions for unkeyed and derived-key HMAC checksums. * The flags field is now used to indicate whether a checksum is unkeyed, but not whether it is a derived-key HMAC checksum. * The descbc checksum is handled through a new enc_provider function which calculates a CBC MAC. The OpenSSL module does not implement the CBC MAC function (it didn't implement descbc before). builtin/des could probably get rid of f_cksum.c (the old DES CBC routine) with some alterations to string2key.c. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@23462 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib/crypto/krb/keyhash_provider/k5_md5des.c')
-rw-r--r--src/lib/crypto/krb/keyhash_provider/k5_md5des.c204
1 files changed, 0 insertions, 204 deletions
diff --git a/src/lib/crypto/krb/keyhash_provider/k5_md5des.c b/src/lib/crypto/krb/keyhash_provider/k5_md5des.c
deleted file mode 100644
index 25dc61c..0000000
--- a/src/lib/crypto/krb/keyhash_provider/k5_md5des.c
+++ /dev/null
@@ -1,204 +0,0 @@
-/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
-/*
- * 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 "des_int.h"
-#include "rsa-md5.h"
-#include "keyhash_provider.h"
-
-#define CONFLENGTH 8
-
-/* Force acceptance of krb5-beta5 md5des checksum for now. */
-#define KRB5int_MD5DES_BETA5_COMPAT
-
-/* des-cbc(xorkey, conf | rsa-md5(conf | data)) */
-
-extern struct krb5_enc_provider krb5int_enc_des;
-
-/* Derive a key by XOR with 0xF0 bytes. */
-static krb5_error_code
-mk_xorkey(krb5_key origkey, krb5_key *xorkey)
-{
- krb5_error_code retval = 0;
- unsigned char xorbytes[8];
- krb5_keyblock xorkeyblock;
- size_t i = 0;
-
- if (origkey->keyblock.length != sizeof(xorbytes))
- return KRB5_CRYPTO_INTERNAL;
- memcpy(xorbytes, origkey->keyblock.contents, sizeof(xorbytes));
- for (i = 0; i < sizeof(xorbytes); i++)
- xorbytes[i] ^= 0xf0;
-
- /* Do a shallow copy here. */
- xorkeyblock = origkey->keyblock;
- xorkeyblock.contents = xorbytes;
-
- retval = krb5_k_create_key(0, &xorkeyblock, xorkey);
- zap(xorbytes, sizeof(xorbytes));
- return retval;
-}
-
-static krb5_error_code
-k5_md5des_hash(krb5_key key, krb5_keyusage usage, const krb5_data *input,
- krb5_data *output)
-{
- krb5_error_code ret;
- krb5_data data;
- krb5_MD5_CTX ctx;
- unsigned char conf[CONFLENGTH];
- krb5_key xorkey = NULL;
- krb5_crypto_iov iov;
- struct krb5_enc_provider *enc = &krb5int_enc_des;
-
- if (output->length != (CONFLENGTH+RSA_MD5_CKSUM_LENGTH))
- return(KRB5_CRYPTO_INTERNAL);
-
- /* create the confouder */
-
- data.length = CONFLENGTH;
- data.data = (char *) conf;
- if ((ret = krb5_c_random_make_octets(/* XXX */ 0, &data)))
- return(ret);
-
- ret = mk_xorkey(key, &xorkey);
- if (ret)
- return ret;
-
- /* hash the confounder, then the input data */
-
- krb5int_MD5Init(&ctx);
- krb5int_MD5Update(&ctx, conf, CONFLENGTH);
- krb5int_MD5Update(&ctx, (unsigned char *) input->data,
- (unsigned int) input->length);
- krb5int_MD5Final(&ctx);
-
- /* construct the buffer to be encrypted */
-
- memcpy(output->data, conf, CONFLENGTH);
- memcpy(output->data+CONFLENGTH, ctx.digest, RSA_MD5_CKSUM_LENGTH);
-
- iov.flags = KRB5_CRYPTO_TYPE_DATA;
- iov.data = *output;
- ret = enc->encrypt(xorkey, NULL, &iov, 1);
-
- krb5_k_free_key(NULL, xorkey);
-
- return ret;
-
-}
-
-static krb5_error_code
-k5_md5des_verify(krb5_key key, krb5_keyusage usage, const krb5_data *input,
- const krb5_data *hash, krb5_boolean *valid)
-{
- krb5_error_code ret;
- krb5_MD5_CTX ctx;
- unsigned char plaintext[CONFLENGTH+RSA_MD5_CKSUM_LENGTH];
- krb5_key xorkey = NULL;
- int compathash = 0;
- struct krb5_enc_provider *enc = &krb5int_enc_des;
- krb5_data iv;
- krb5_crypto_iov iov;
-
- iv.data = NULL;
- iv.length = 0;
-
- if (key->keyblock.length != 8)
- return(KRB5_BAD_KEYSIZE);
-
- if (hash->length != (CONFLENGTH+RSA_MD5_CKSUM_LENGTH)) {
-#ifdef KRB5int_MD5DES_BETA5_COMPAT
- if (hash->length != RSA_MD5_CKSUM_LENGTH)
- return(KRB5_CRYPTO_INTERNAL);
- else
- compathash = 1;
-#else
- return(KRB5_CRYPTO_INTERNAL);
-#endif
- }
-
- if (compathash) {
- iv.data = malloc(key->keyblock.length);
- if (!iv.data) return ENOMEM;
- iv.length = key->keyblock.length;
- if (key->keyblock.contents)
- memcpy(iv.data, key->keyblock.contents, key->keyblock.length);
- } else {
- ret = mk_xorkey(key, &xorkey);
- if (ret)
- return ret;
- }
-
- /* decrypt it */
- iov.flags = KRB5_CRYPTO_TYPE_DATA;
- iov.data = make_data(plaintext, hash->length);
- memcpy(plaintext, hash->data, hash->length);
-
- if (!compathash) {
- ret = enc->decrypt(xorkey, NULL, &iov, 1);
- krb5_k_free_key(NULL, xorkey);
- } else {
- ret = enc->decrypt(key, &iv, &iov, 1);
- zap(iv.data, iv.length);
- free(iv.data);
- }
-
- if (ret) return(ret);
-
- /* hash the confounder, then the input data */
-
- krb5int_MD5Init(&ctx);
- if (!compathash) {
- krb5int_MD5Update(&ctx, plaintext, CONFLENGTH);
- }
- krb5int_MD5Update(&ctx, (unsigned char *) input->data,
- (unsigned) input->length);
- krb5int_MD5Final(&ctx);
-
- /* compare the decrypted hash to the computed one */
-
- if (!compathash) {
- *valid =
- (memcmp(plaintext+CONFLENGTH, ctx.digest, RSA_MD5_CKSUM_LENGTH)
- == 0);
- } else {
- *valid =
- (memcmp(plaintext, ctx.digest, RSA_MD5_CKSUM_LENGTH) == 0);
- }
- memset(plaintext, 0, sizeof(plaintext));
-
- return(0);
-}
-
-const struct krb5_keyhash_provider krb5int_keyhash_md5des = {
- CONFLENGTH+RSA_MD5_CKSUM_LENGTH,
- k5_md5des_hash,
- k5_md5des_verify,
- NULL,
- NULL
-};