xref: /titanic_50/usr/src/lib/gss_mechs/mech_krb5/krb5/krb/enc_helper.c (revision 4a9e65b63d55ba9f286a52fb196b881264a7f533)
1 /*
2  * Copyright (C) 1998 by the FundsXpress, INC.
3  *
4  * All rights reserved.
5  *
6  * Export of this software from the United States of America may require
7  * a specific license from the United States Government.  It is the
8  * responsibility of any person or organization contemplating export to
9  * obtain such a license before exporting.
10  *
11  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
12  * distribute this software and its documentation for any purpose and
13  * without fee is hereby granted, provided that the above copyright
14  * notice appear in all copies and that both that copyright notice and
15  * this permission notice appear in supporting documentation, and that
16  * the name of FundsXpress. not be used in advertising or publicity pertaining
17  * to distribution of the software without specific, written prior
18  * permission.  FundsXpress makes no representations about the suitability of
19  * this software for any purpose.  It is provided "as is" without express
20  * or implied warranty.
21  *
22  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
24  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
25  */
26 
27 #include <k5-int.h>
28 
29 krb5_error_code
krb5_encrypt_helper(krb5_context context,const krb5_keyblock * key,krb5_keyusage usage,const krb5_data * plain,krb5_enc_data * cipher)30 krb5_encrypt_helper(krb5_context context, const krb5_keyblock *key, krb5_keyusage usage, const krb5_data *plain, krb5_enc_data *cipher)
31 {
32     krb5_error_code ret;
33     size_t enclen;
34 
35     if ((ret = krb5_c_encrypt_length(context, key->enctype, plain->length,
36 				     &enclen)))
37 	return(ret);
38 
39     cipher->ciphertext.length = enclen;
40 
41     /* Solaris Kerberos */
42     if ((cipher->ciphertext.data = (char *) malloc(enclen)) == NULL) {
43 	cipher->ciphertext.length = 0;
44 	return(ENOMEM);
45     }
46     ret = krb5_c_encrypt(context, key, usage, 0, plain, cipher);
47     if (ret) {
48 	free(cipher->ciphertext.data);
49 	cipher->ciphertext.data = NULL;
50     }
51 
52     return(ret);
53 }
54 
55