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

Packit fd8b60
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
Packit fd8b60
/*
Packit fd8b60
 * Copyright (C) 1998 by the FundsXpress, INC.
Packit fd8b60
 *
Packit fd8b60
 * All rights reserved.
Packit fd8b60
 *
Packit fd8b60
 * Export of this software from the United States of America may require
Packit fd8b60
 * a specific license from the United States Government.  It is the
Packit fd8b60
 * responsibility of any person or organization contemplating export to
Packit fd8b60
 * 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 FundsXpress. not be used in advertising or publicity pertaining
Packit fd8b60
 * to distribution of the software without specific, written prior
Packit fd8b60
 * permission.  FundsXpress 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
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
Packit fd8b60
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
Packit fd8b60
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Packit fd8b60
 */
Packit fd8b60
Packit fd8b60
#include "crypto_int.h"
Packit fd8b60
Packit fd8b60
static krb5_boolean
Packit fd8b60
is_keyed_for(const struct krb5_cksumtypes *ctp,
Packit fd8b60
             const struct krb5_keytypes *ktp)
Packit fd8b60
{
Packit fd8b60
    if (ctp->flags & CKSUM_UNKEYED)
Packit fd8b60
        return FALSE;
Packit fd8b60
    return (!ctp->enc || ktp->enc == ctp->enc);
Packit fd8b60
}
Packit fd8b60
Packit fd8b60
krb5_error_code KRB5_CALLCONV
Packit fd8b60
krb5_c_keyed_checksum_types(krb5_context context, krb5_enctype enctype,
Packit fd8b60
                            unsigned int *count, krb5_cksumtype **cksumtypes)
Packit fd8b60
{
Packit fd8b60
    unsigned int i, c, nctypes;
Packit fd8b60
    krb5_cksumtype *ctypes;
Packit fd8b60
    const struct krb5_cksumtypes *ctp;
Packit fd8b60
    const struct krb5_keytypes *ktp;
Packit fd8b60
Packit fd8b60
    *count = 0;
Packit fd8b60
    *cksumtypes = NULL;
Packit fd8b60
Packit fd8b60
    ktp = find_enctype(enctype);
Packit fd8b60
    if (ktp == NULL)
Packit fd8b60
        return KRB5_BAD_ENCTYPE;
Packit fd8b60
Packit fd8b60
    nctypes = 0;
Packit fd8b60
    for (i = 0; i < krb5int_cksumtypes_length; i++) {
Packit fd8b60
        ctp = &krb5int_cksumtypes_list[i];
Packit fd8b60
        if (is_keyed_for(ctp, ktp))
Packit fd8b60
            nctypes++;
Packit fd8b60
    }
Packit fd8b60
Packit fd8b60
    ctypes = malloc(nctypes * sizeof(krb5_cksumtype));
Packit fd8b60
    if (ctypes == NULL)
Packit fd8b60
        return ENOMEM;
Packit fd8b60
Packit fd8b60
    c = 0;
Packit fd8b60
    for (i = 0; i < krb5int_cksumtypes_length; i++) {
Packit fd8b60
        ctp = &krb5int_cksumtypes_list[i];
Packit fd8b60
        if (is_keyed_for(ctp, ktp))
Packit fd8b60
            ctypes[c++] = ctp->ctype;
Packit fd8b60
    }
Packit fd8b60
Packit fd8b60
    *count = nctypes;
Packit fd8b60
    *cksumtypes = ctypes;
Packit fd8b60
    return 0;
Packit fd8b60
}
Packit fd8b60
Packit fd8b60
void KRB5_CALLCONV
Packit fd8b60
krb5_free_cksumtypes(krb5_context context, krb5_cksumtype *val)
Packit fd8b60
{
Packit fd8b60
    free(val);
Packit fd8b60
}