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