1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3 * Copyright (C) 1998 by the FundsXpress, INC.
4 *
5 * All rights reserved.
6 *
7 * Export of this software from the United States of America may require
8 * a specific license from the United States Government. It is the
9 * responsibility of any person or organization contemplating export to
10 * obtain such a license before exporting.
11 *
12 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13 * distribute this software and its documentation for any purpose and
14 * without fee is hereby granted, provided that the above copyright
15 * notice appear in all copies and that both that copyright notice and
16 * this permission notice appear in supporting documentation, and that
17 * the name of FundsXpress. not be used in advertising or publicity pertaining
18 * to distribution of the software without specific, written prior
19 * permission. FundsXpress makes no representations about the suitability of
20 * this software for any purpose. It is provided "as is" without express
21 * or implied warranty.
22 *
23 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
25 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26 */
27
28 #include "crypto_int.h"
29 #include "shs.h"
30
31 #ifdef K5_BUILTIN_SHA1
32
33 static krb5_error_code
k5_sha1_hash(const krb5_crypto_iov * data,size_t num_data,krb5_data * output)34 k5_sha1_hash(const krb5_crypto_iov *data, size_t num_data, krb5_data *output)
35 {
36 SHS_INFO ctx;
37 unsigned int i;
38
39 if (output->length != SHS_DIGESTSIZE)
40 return KRB5_CRYPTO_INTERNAL;
41
42 shsInit(&ctx);
43 for (i = 0; i < num_data; i++) {
44 const krb5_crypto_iov *iov = &data[i];
45
46 if (SIGN_IOV(iov)) {
47 shsUpdate(&ctx, (unsigned char *) iov->data.data,
48 iov->data.length);
49 }
50 }
51 shsFinal(&ctx);
52
53 for (i = 0; i < sizeof(ctx.digest) / sizeof(ctx.digest[0]); i++)
54 store_32_be(ctx.digest[i], &output->data[i*4]);
55
56 return 0;
57 }
58
59 const struct krb5_hash_provider krb5int_hash_sha1 = {
60 "SHA1",
61 SHS_DIGESTSIZE,
62 SHS_DATASIZE,
63 k5_sha1_hash
64 };
65
66 #endif /* K5_BUILTIN_SHA1 */
67