|
Packit |
fd8b60 |
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
Packit |
fd8b60 |
/* lib/crypto/krb/checksum_hmac_md5.c */
|
|
Packit |
fd8b60 |
/*
|
|
Packit |
fd8b60 |
* Copyright (C) 2009 by the Massachusetts Institute of Technology.
|
|
Packit |
fd8b60 |
* All rights reserved.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* Export of this software from the United States of America may
|
|
Packit |
fd8b60 |
* require a specific license from the United States Government.
|
|
Packit |
fd8b60 |
* It is the responsibility of any person or organization contemplating
|
|
Packit |
fd8b60 |
* export to obtain such a license before exporting.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
|
|
Packit |
fd8b60 |
* distribute this software and its documentation for any purpose and
|
|
Packit |
fd8b60 |
* without fee is hereby granted, provided that the above copyright
|
|
Packit |
fd8b60 |
* notice appear in all copies and that both that copyright notice and
|
|
Packit |
fd8b60 |
* this permission notice appear in supporting documentation, and that
|
|
Packit |
fd8b60 |
* the name of M.I.T. not be used in advertising or publicity pertaining
|
|
Packit |
fd8b60 |
* to distribution of the software without specific, written prior
|
|
Packit |
fd8b60 |
* permission. Furthermore if you modify this software you must label
|
|
Packit |
fd8b60 |
* your software as modified software and not distribute it in such a
|
|
Packit |
fd8b60 |
* fashion that it might be confused with the original M.I.T. software.
|
|
Packit |
fd8b60 |
* M.I.T. makes no representations about the suitability of
|
|
Packit |
fd8b60 |
* this software for any purpose. It is provided "as is" without express
|
|
Packit |
fd8b60 |
* or implied warranty.
|
|
Packit |
fd8b60 |
*/
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/*
|
|
Packit |
fd8b60 |
* Microsoft HMAC-MD5 and MD5-HMAC checksums (see RFC 4757):
|
|
Packit |
fd8b60 |
* HMAC(KS, hash(msusage || input))
|
|
Packit |
fd8b60 |
* KS is HMAC(key, "signaturekey\0") for HMAC-MD5, or just the key for
|
|
Packit |
fd8b60 |
* MD5-HMAC.
|
|
Packit |
fd8b60 |
*/
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#include "crypto_int.h"
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
krb5_error_code krb5int_hmacmd5_checksum(const struct krb5_cksumtypes *ctp,
|
|
Packit |
fd8b60 |
krb5_key key, krb5_keyusage usage,
|
|
Packit |
fd8b60 |
const krb5_crypto_iov *data,
|
|
Packit |
fd8b60 |
size_t num_data,
|
|
Packit |
fd8b60 |
krb5_data *output)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
krb5_keyusage ms_usage;
|
|
Packit |
fd8b60 |
krb5_error_code ret;
|
|
Packit |
fd8b60 |
krb5_keyblock ks, *keyblock;
|
|
Packit |
fd8b60 |
krb5_crypto_iov *hash_iov = NULL, iov;
|
|
Packit |
fd8b60 |
krb5_data ds = empty_data(), hashval = empty_data();
|
|
Packit |
fd8b60 |
char t[4];
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (key == NULL || key->keyblock.length > ctp->hash->blocksize)
|
|
Packit |
fd8b60 |
return KRB5_BAD_ENCTYPE;
|
|
Packit |
fd8b60 |
if (ctp->ctype == CKSUMTYPE_HMAC_MD5_ARCFOUR) {
|
|
Packit |
fd8b60 |
/* Compute HMAC(key, "signaturekey\0") to get the signing key ks. */
|
|
Packit |
fd8b60 |
ret = alloc_data(&ds, ctp->hash->hashsize);
|
|
Packit |
fd8b60 |
if (ret != 0)
|
|
Packit |
fd8b60 |
goto cleanup;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
iov.flags = KRB5_CRYPTO_TYPE_DATA;
|
|
Packit |
fd8b60 |
iov.data = make_data("signaturekey", 13);
|
|
Packit |
fd8b60 |
ret = krb5int_hmac(ctp->hash, key, &iov, 1, &ds);
|
|
Packit |
fd8b60 |
if (ret)
|
|
Packit |
fd8b60 |
goto cleanup;
|
|
Packit |
fd8b60 |
ks.length = ds.length;
|
|
Packit |
fd8b60 |
ks.contents = (krb5_octet *) ds.data;
|
|
Packit |
fd8b60 |
keyblock = &ks;
|
|
Packit |
fd8b60 |
} else /* For md5-hmac, just use the key. */
|
|
Packit |
fd8b60 |
keyblock = &key->keyblock;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Compute the MD5 value of the input. */
|
|
Packit |
fd8b60 |
ms_usage = krb5int_arcfour_translate_usage(usage);
|
|
Packit |
fd8b60 |
store_32_le(ms_usage, t);
|
|
Packit |
fd8b60 |
hash_iov = k5calloc(num_data + 1, sizeof(krb5_crypto_iov), &ret;;
|
|
Packit |
fd8b60 |
if (hash_iov == NULL)
|
|
Packit |
fd8b60 |
goto cleanup;
|
|
Packit |
fd8b60 |
hash_iov[0].flags = KRB5_CRYPTO_TYPE_DATA;
|
|
Packit |
fd8b60 |
hash_iov[0].data = make_data(t, 4);
|
|
Packit |
fd8b60 |
memcpy(hash_iov + 1, data, num_data * sizeof(krb5_crypto_iov));
|
|
Packit |
fd8b60 |
ret = alloc_data(&hashval, ctp->hash->hashsize);
|
|
Packit |
fd8b60 |
if (ret != 0)
|
|
Packit |
fd8b60 |
goto cleanup;
|
|
Packit |
fd8b60 |
ret = ctp->hash->hash(hash_iov, num_data + 1, &hashval);
|
|
Packit |
fd8b60 |
if (ret != 0)
|
|
Packit |
fd8b60 |
goto cleanup;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Compute HMAC(ks, md5value). */
|
|
Packit |
fd8b60 |
iov.flags = KRB5_CRYPTO_TYPE_DATA;
|
|
Packit |
fd8b60 |
iov.data = hashval;
|
|
Packit |
fd8b60 |
ret = krb5int_hmac_keyblock(ctp->hash, keyblock, &iov, 1, output);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
cleanup:
|
|
Packit |
fd8b60 |
zapfree(ds.data, ds.length);
|
|
Packit |
fd8b60 |
zapfree(hashval.data, hashval.length);
|
|
Packit |
fd8b60 |
free(hash_iov);
|
|
Packit |
fd8b60 |
return ret;
|
|
Packit |
fd8b60 |
}
|