1*505d05c7Sgtb /*
2*505d05c7Sgtb * lib/krb5/krb/init_keyblock.c
3*505d05c7Sgtb *
4*505d05c7Sgtb * Copyright (C) 2002 by the Massachusetts Institute of Technology.
5*505d05c7Sgtb * All rights reserved.
6*505d05c7Sgtb *
7*505d05c7Sgtb * Export of this software from the United States of America may
8*505d05c7Sgtb * require a specific license from the United States Government.
9*505d05c7Sgtb * It is the responsibility of any person or organization contemplating
10*505d05c7Sgtb * export to obtain such a license before exporting.
11*505d05c7Sgtb *
12*505d05c7Sgtb * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13*505d05c7Sgtb * distribute this software and its documentation for any purpose and
14*505d05c7Sgtb * without fee is hereby granted, provided that the above copyright
15*505d05c7Sgtb * notice appear in all copies and that both that copyright notice and
16*505d05c7Sgtb * this permission notice appear in supporting documentation, and that
17*505d05c7Sgtb * the name of M.I.T. not be used in advertising or publicity pertaining
18*505d05c7Sgtb * to distribution of the software without specific, written prior
19*505d05c7Sgtb * permission. Furthermore if you modify this software you must label
20*505d05c7Sgtb * your software as modified software and not distribute it in such a
21*505d05c7Sgtb * fashion that it might be confused with the original M.I.T. software.
22*505d05c7Sgtb * M.I.T. makes no representations about the suitability of
23*505d05c7Sgtb * this software for any purpose. It is provided "as is" without express
24*505d05c7Sgtb * or implied warranty.
25*505d05c7Sgtb *
26*505d05c7Sgtb *
27*505d05c7Sgtb *
28*505d05c7Sgtb * krb5_init_keyblock- a function to set up
29*505d05c7Sgtb * an empty keyblock
30*505d05c7Sgtb */
31*505d05c7Sgtb
32*505d05c7Sgtb
33*505d05c7Sgtb #include "k5-int.h"
34*505d05c7Sgtb #include <assert.h>
35*505d05c7Sgtb
krb5_init_keyblock(krb5_context context,krb5_enctype enctype,size_t length,krb5_keyblock ** out)36*505d05c7Sgtb krb5_error_code KRB5_CALLCONV krb5_init_keyblock
37*505d05c7Sgtb (krb5_context context, krb5_enctype enctype,
38*505d05c7Sgtb size_t length, krb5_keyblock **out)
39*505d05c7Sgtb {
40*505d05c7Sgtb krb5_keyblock *kb;
41*505d05c7Sgtb kb = malloc (sizeof(krb5_keyblock));
42*505d05c7Sgtb assert (out);
43*505d05c7Sgtb *out = NULL;
44*505d05c7Sgtb if (!kb) {
45*505d05c7Sgtb return ENOMEM;
46*505d05c7Sgtb }
47*505d05c7Sgtb kb->magic = KV5M_KEYBLOCK;
48*505d05c7Sgtb kb->enctype = enctype;
49*505d05c7Sgtb kb->length = length;
50*505d05c7Sgtb if(length) {
51*505d05c7Sgtb kb->contents = malloc (length);
52*505d05c7Sgtb if(!kb->contents) {
53*505d05c7Sgtb free (kb);
54*505d05c7Sgtb return ENOMEM;
55*505d05c7Sgtb }
56*505d05c7Sgtb } else {
57*505d05c7Sgtb kb->contents = NULL;
58*505d05c7Sgtb }
59*505d05c7Sgtb kb->dk_list = NULL;
60*505d05c7Sgtb #ifdef _KERNEL
61*505d05c7Sgtb kb->kef_key = NULL;
62*505d05c7Sgtb #else
63*505d05c7Sgtb kb->hKey = CK_INVALID_HANDLE;
64*505d05c7Sgtb #endif
65*505d05c7Sgtb
66*505d05c7Sgtb *out = kb;
67*505d05c7Sgtb return 0;
68*505d05c7Sgtb }
69