1 /*
2  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #pragma ident	"%Z%%M%	%I%	%E% SMI"
7 /*
8  * lib/krb5/krb/copy_cksum.c
9  *
10  * Copyright 1990 by the Massachusetts Institute of Technology.
11  * All Rights Reserved.
12  *
13  * Export of this software from the United States of America may
14  *   require a specific license from the United States Government.
15  *   It is the responsibility of any person or organization contemplating
16  *   export to obtain such a license before exporting.
17  *
18  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
19  * distribute this software and its documentation for any purpose and
20  * without fee is hereby granted, provided that the above copyright
21  * notice appear in all copies and that both that copyright notice and
22  * this permission notice appear in supporting documentation, and that
23  * the name of M.I.T. not be used in advertising or publicity pertaining
24  * to distribution of the software without specific, written prior
25  * permission.  Furthermore if you modify this software you must label
26  * your software as modified software and not distribute it in such a
27  * fashion that it might be confused with the original M.I.T. software.
28  * M.I.T. makes no representations about the suitability of
29  * this software for any purpose.  It is provided "as is" without express
30  * or implied warranty.
31  *
32  *
33  * krb5_copy_checksum()
34  */
35 
36 #include <k5-int.h>
37 
38 /*ARGSUSED*/
39 krb5_error_code KRB5_CALLCONV
40 krb5_copy_checksum(krb5_context context, const krb5_checksum *ckfrom, krb5_checksum **ckto)
41 {
42     krb5_checksum *tempto;
43 
44     if (!(tempto = (krb5_checksum *)MALLOC(sizeof(*tempto))))
45 	return ENOMEM;
46 #ifdef HAVE_C_STRUCTURE_ASSIGNMENT
47     *tempto = *ckfrom;
48 #else
49     (void) memcpy(tempto, ckfrom, sizeof(krb5_checksum));
50 #endif
51 
52     if (!(tempto->contents =
53 	  (krb5_octet *)MALLOC(tempto->length))) {
54 	return ENOMEM;
55     }
56     (void) memcpy((char *) tempto->contents, (char *) ckfrom->contents,
57 	   ckfrom->length);
58 
59     *ckto = tempto;
60     return 0;
61 }
62