2N/A/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2N/A/*
2N/A * lib/crypto/prf.c
2N/A *
2N/A * Copyright (C) 2004 by the Massachusetts Institute of Technology.
2N/A * All rights reserved.
2N/A *
2N/A * Export of this software from the United States of America may
2N/A * require a specific license from the United States Government.
2N/A * It is the responsibility of any person or organization contemplating
2N/A * export to obtain such a license before exporting.
2N/A *
2N/A * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
2N/A * distribute this software and its documentation for any purpose and
2N/A * without fee is hereby granted, provided that the above copyright
2N/A * notice appear in all copies and that both that copyright notice and
2N/A * this permission notice appear in supporting documentation, and that
2N/A * the name of M.I.T. not be used in advertising or publicity pertaining
2N/A * to distribution of the software without specific, written prior
2N/A * permission. Furthermore if you modify this software you must label
2N/A * your software as modified software and not distribute it in such a
2N/A * fashion that it might be confused with the original M.I.T. software.
2N/A * M.I.T. makes no representations about the suitability of
2N/A * this software for any purpose. It is provided "as is" without express
2N/A * or implied warranty.
2N/A *
2N/A *
2N/A *
2N/A * This contains the implementation of krb5_c_prf, which will find
2N/A *the enctype-specific PRF and then generate pseudo-random data. This
2N/A *function yields krb5_c_prf_length bytes of output.
2N/A */
2N/A
2N/A
2N/A#include "k5-int.h"
2N/A#include "etypes.h"
2N/A
2N/A#include <assert.h>
2N/A
2N/Akrb5_error_code KRB5_CALLCONV
2N/Akrb5_c_prf_length(krb5_context context, krb5_enctype enctype, size_t *len)
2N/A{
2N/A const struct krb5_keytypes *ktp;
2N/A
2N/A assert(len);
2N/A ktp = find_enctype(enctype);
2N/A if (ktp == NULL)
2N/A return KRB5_BAD_ENCTYPE;
2N/A *len = ktp->prf_length;
2N/A return 0;
2N/A}
2N/A
2N/Akrb5_error_code KRB5_CALLCONV
2N/Akrb5_k_prf(krb5_context context, krb5_key key,
2N/A krb5_data *input, krb5_data *output)
2N/A{
2N/A const struct krb5_keytypes *ktp;
2N/A krb5_error_code ret;
2N/A
2N/A assert(input && output);
2N/A assert(output->data);
2N/A
2N/A ktp = find_enctype(key->keyblock.enctype);
2N/A if (ktp == NULL)
2N/A return KRB5_BAD_ENCTYPE;
2N/A if (ktp->prf == NULL)
2N/A return KRB5_CRYPTO_INTERNAL;
2N/A
2N/A output->magic = KV5M_DATA;
2N/A if (ktp->prf_length != output->length)
2N/A return KRB5_CRYPTO_INTERNAL;
2N/A ret = ktp->prf(ktp, key, input, output);
2N/A return ret;
2N/A}
2N/A
2N/Akrb5_error_code KRB5_CALLCONV
2N/Akrb5_c_prf(krb5_context context, const krb5_keyblock *keyblock,
2N/A krb5_data *input, krb5_data *output)
2N/A{
2N/A krb5_key key;
2N/A krb5_error_code ret;
2N/A
2N/A ret = krb5_k_create_key(context, keyblock, &key);
2N/A if (ret != 0)
2N/A return ret;
2N/A ret = krb5_k_prf(context, key, input, output);
2N/A krb5_k_free_key(context, key);
2N/A return ret;
2N/A}