|
Packit |
fd8b60 |
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
Packit |
fd8b60 |
/* lib/crypto/krb/prf_dk.c - RFC 3961 simplified profile PRF */
|
|
Packit |
fd8b60 |
/*
|
|
Packit |
fd8b60 |
* Copyright (C) 2004 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 |
#include "crypto_int.h"
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
krb5_error_code
|
|
Packit |
fd8b60 |
krb5int_dk_prf(const struct krb5_keytypes *ktp, krb5_key key,
|
|
Packit |
fd8b60 |
const krb5_data *in, krb5_data *out)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
const struct krb5_enc_provider *enc = ktp->enc;
|
|
Packit |
fd8b60 |
const struct krb5_hash_provider *hash = ktp->hash;
|
|
Packit |
fd8b60 |
krb5_crypto_iov iov;
|
|
Packit |
fd8b60 |
krb5_data cksum = empty_data(), prfconst = make_data("prf", 3);
|
|
Packit |
fd8b60 |
krb5_key kp = NULL;
|
|
Packit |
fd8b60 |
krb5_error_code ret;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Hash the input data into an allocated buffer. */
|
|
Packit |
fd8b60 |
ret = alloc_data(&cksum, hash->hashsize);
|
|
Packit |
fd8b60 |
if (ret != 0)
|
|
Packit |
fd8b60 |
goto cleanup;
|
|
Packit |
fd8b60 |
iov.flags = KRB5_CRYPTO_TYPE_DATA;
|
|
Packit |
fd8b60 |
iov.data = *in;
|
|
Packit |
fd8b60 |
ret = hash->hash(&iov, 1, &cksum);
|
|
Packit |
fd8b60 |
if (ret != 0)
|
|
Packit |
fd8b60 |
goto cleanup;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Derive a key using the PRF constant. */
|
|
Packit |
fd8b60 |
ret = krb5int_derive_key(ktp->enc, NULL, key, &kp, &prfconst,
|
|
Packit |
fd8b60 |
DERIVE_RFC3961);
|
|
Packit |
fd8b60 |
if (ret != 0)
|
|
Packit |
fd8b60 |
goto cleanup;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Truncate the hash to the closest multiple of the block size. */
|
|
Packit |
fd8b60 |
iov.data.data = cksum.data;
|
|
Packit |
fd8b60 |
iov.data.length = (hash->hashsize / enc->block_size) * enc->block_size;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Encrypt the truncated hash in the derived key to get the output. */
|
|
Packit |
fd8b60 |
ret = ktp->enc->encrypt(kp, NULL, &iov, 1);
|
|
Packit |
fd8b60 |
if (ret != 0)
|
|
Packit |
fd8b60 |
goto cleanup;
|
|
Packit |
fd8b60 |
memcpy(out->data, iov.data.data, out->length);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
cleanup:
|
|
Packit |
fd8b60 |
zapfree(cksum.data, hash->hashsize);
|
|
Packit |
fd8b60 |
krb5_k_free_key(NULL, kp);
|
|
Packit |
fd8b60 |
return ret;
|
|
Packit |
fd8b60 |
}
|