xref: /illumos-gate/usr/src/uts/common/gssapi/mechs/krb5/mech/util_seed.c (revision 55fea89dcaa64928bed4327112404dcb3e07b79f)
1 /*
2  * Copyright 1993 by OpenVision Technologies, Inc.
3  *
4  * Permission to use, copy, modify, distribute, and sell this software
5  * and its documentation for any purpose is hereby granted without fee,
6  * provided that the above copyright notice appears in all copies and
7  * that both that copyright notice and this permission notice appear in
8  * supporting documentation, and that the name of OpenVision not be used
9  * in advertising or publicity pertaining to distribution of the software
10  * without specific, written prior permission. OpenVision makes no
11  * representations about the suitability of this software for any
12  * purpose.  It is provided "as is" without express or implied warranty.
13  *
14  * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16  * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
18  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20  * PERFORMANCE OF THIS SOFTWARE.
21  */
22 
23 #include "gssapiP_krb5.h"
24 #ifdef HAVE_MEMORY_H
25 #include <memory.h>
26 #endif
27 
28 static const unsigned char zeros[16] = {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0};
29 
30 krb5_error_code
kg_make_seed(context,key,seed)31 kg_make_seed(context, key, seed)
32      krb5_context context;
33      krb5_keyblock *key;
34      unsigned char *seed;
35 {
36    krb5_error_code code;
37    krb5_keyblock *tmpkey;
38    int i;
39 
40    code = krb5_copy_keyblock(context, key, &tmpkey);
41    if (code)
42       return(code);
43 
44    /* reverse the key bytes, as per spec */
45 
46    for (i=0; i<tmpkey->length; i++)
47       tmpkey->contents[i] = key->contents[key->length - 1 - i];
48 
49    code = kg_encrypt(context, tmpkey, KG_USAGE_SEAL, NULL, zeros, seed, 16);
50 
51    krb5_free_keyblock(context, tmpkey);
52 
53    return(code);
54 }
55