|
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 |
krb5_error_code KRB5_CALLCONV
|
|
Packit |
fd8b60 |
krb5_k_verify_checksum(krb5_context context, krb5_key key,
|
|
Packit |
fd8b60 |
krb5_keyusage usage, const krb5_data *data,
|
|
Packit |
fd8b60 |
const krb5_checksum *cksum, krb5_boolean *valid)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
const struct krb5_cksumtypes *ctp;
|
|
Packit |
fd8b60 |
krb5_cksumtype cksumtype;
|
|
Packit |
fd8b60 |
krb5_crypto_iov iov;
|
|
Packit |
fd8b60 |
krb5_error_code ret;
|
|
Packit |
fd8b60 |
krb5_data cksum_data;
|
|
Packit |
fd8b60 |
krb5_checksum computed;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
iov.flags = KRB5_CRYPTO_TYPE_DATA;
|
|
Packit |
fd8b60 |
iov.data = *data;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* A 0 checksum type means use the mandatory checksum. */
|
|
Packit |
fd8b60 |
cksumtype = cksum->checksum_type;
|
|
Packit |
fd8b60 |
if (cksumtype == 0 && key != NULL) {
|
|
Packit |
fd8b60 |
ret = krb5int_c_mandatory_cksumtype(context, key->keyblock.enctype,
|
|
Packit |
fd8b60 |
&cksumtype);
|
|
Packit |
fd8b60 |
if (ret)
|
|
Packit |
fd8b60 |
return ret;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
ctp = find_cksumtype(cksumtype);
|
|
Packit |
fd8b60 |
if (ctp == NULL)
|
|
Packit |
fd8b60 |
return KRB5_BAD_ENCTYPE;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
ret = verify_key(ctp, key);
|
|
Packit |
fd8b60 |
if (ret != 0)
|
|
Packit |
fd8b60 |
return ret;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* If there's actually a verify function, call it. */
|
|
Packit |
fd8b60 |
cksum_data = make_data(cksum->contents, cksum->length);
|
|
Packit |
fd8b60 |
if (ctp->verify != NULL)
|
|
Packit |
fd8b60 |
return ctp->verify(ctp, key, usage, &iov, 1, &cksum_data, valid);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Otherwise, make the checksum again, and compare. */
|
|
Packit |
fd8b60 |
if (cksum->length != ctp->output_size)
|
|
Packit |
fd8b60 |
return KRB5_BAD_MSIZE;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
ret = krb5_k_make_checksum(context, cksum->checksum_type, key, usage,
|
|
Packit |
fd8b60 |
data, &computed);
|
|
Packit |
fd8b60 |
if (ret)
|
|
Packit |
fd8b60 |
return ret;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
*valid = (k5_bcmp(computed.contents, cksum->contents,
|
|
Packit |
fd8b60 |
ctp->output_size) == 0);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
free(computed.contents);
|
|
Packit |
fd8b60 |
return 0;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
krb5_error_code KRB5_CALLCONV
|
|
Packit |
fd8b60 |
krb5_c_verify_checksum(krb5_context context, const krb5_keyblock *keyblock,
|
|
Packit |
fd8b60 |
krb5_keyusage usage, const krb5_data *data,
|
|
Packit |
fd8b60 |
const krb5_checksum *cksum, krb5_boolean *valid)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
krb5_key key = NULL;
|
|
Packit |
fd8b60 |
krb5_error_code ret;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
if (keyblock != NULL) {
|
|
Packit |
fd8b60 |
ret = krb5_k_create_key(context, keyblock, &key);
|
|
Packit |
fd8b60 |
if (ret != 0)
|
|
Packit |
fd8b60 |
return ret;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
ret = krb5_k_verify_checksum(context, key, usage, data, cksum, valid);
|
|
Packit |
fd8b60 |
krb5_k_free_key(context, key);
|
|
Packit |
fd8b60 |
return ret;
|
|
Packit |
fd8b60 |
}
|