Blame src/lib/crypto/krb/prf.c

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