10Sstevel@tonic-gate /*
2*7934SMark.Phalan@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
30Sstevel@tonic-gate * Use is subject to license terms.
40Sstevel@tonic-gate */
50Sstevel@tonic-gate
60Sstevel@tonic-gate /*
70Sstevel@tonic-gate * lib/crypto/state.c
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * Copyright (C) 2001 by the Massachusetts Institute of Technology.
100Sstevel@tonic-gate * All rights reserved.
110Sstevel@tonic-gate *
120Sstevel@tonic-gate * Export of this software from the United States of America may
130Sstevel@tonic-gate * require a specific license from the United States Government.
140Sstevel@tonic-gate * It is the responsibility of any person or organization contemplating
150Sstevel@tonic-gate * export to obtain such a license before exporting.
160Sstevel@tonic-gate *
170Sstevel@tonic-gate * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
180Sstevel@tonic-gate * distribute this software and its documentation for any purpose and
190Sstevel@tonic-gate * without fee is hereby granted, provided that the above copyright
200Sstevel@tonic-gate * notice appear in all copies and that both that copyright notice and
210Sstevel@tonic-gate * this permission notice appear in supporting documentation, and that
220Sstevel@tonic-gate * the name of M.I.T. not be used in advertising or publicity pertaining
230Sstevel@tonic-gate * to distribution of the software without specific, written prior
240Sstevel@tonic-gate * permission. Furthermore if you modify this software you must label
250Sstevel@tonic-gate * your software as modified software and not distribute it in such a
260Sstevel@tonic-gate * fashion that it might be confused with the original M.I.T. software.
270Sstevel@tonic-gate * M.I.T. makes no representations about the suitability of
280Sstevel@tonic-gate * this software for any purpose. It is provided "as is" without express
290Sstevel@tonic-gate
300Sstevel@tonic-gate *
310Sstevel@tonic-gate *
320Sstevel@tonic-gate *
330Sstevel@tonic-gate * * Section 6 (Encryption) of the Kerberos revisions document defines
340Sstevel@tonic-gate * cipher states to be used to chain encryptions and decryptions
350Sstevel@tonic-gate * together. Examples of cipher states include initialization vectors
360Sstevel@tonic-gate * for CBC encription. This file contains implementations of
370Sstevel@tonic-gate * krb5_c_init_state and krb5_c_free_state used by clients of the
380Sstevel@tonic-gate * Kerberos crypto library.
390Sstevel@tonic-gate */
40*7934SMark.Phalan@Sun.COM #include "k5-int.h"
41*7934SMark.Phalan@Sun.COM #include "etypes.h"
420Sstevel@tonic-gate
430Sstevel@tonic-gate krb5_error_code KRB5_CALLCONV
krb5_c_init_state(krb5_context context,const krb5_keyblock * key,krb5_keyusage keyusage,krb5_data * new_state)440Sstevel@tonic-gate krb5_c_init_state (krb5_context context, const krb5_keyblock *key,
450Sstevel@tonic-gate krb5_keyusage keyusage, krb5_data *new_state)
460Sstevel@tonic-gate {
470Sstevel@tonic-gate int i;
480Sstevel@tonic-gate
490Sstevel@tonic-gate for (i=0; i<krb5_enctypes_length; i++) {
500Sstevel@tonic-gate if (krb5_enctypes_list[i].etype == key->enctype)
510Sstevel@tonic-gate break;
520Sstevel@tonic-gate }
530Sstevel@tonic-gate
540Sstevel@tonic-gate if (i == krb5_enctypes_length)
550Sstevel@tonic-gate return(KRB5_BAD_ENCTYPE);
560Sstevel@tonic-gate
57*7934SMark.Phalan@Sun.COM /* Solaris Kerberos */
580Sstevel@tonic-gate return (*(krb5_enctypes_list[i].enc->init_state))
590Sstevel@tonic-gate (context, key, keyusage, new_state);
600Sstevel@tonic-gate }
610Sstevel@tonic-gate
620Sstevel@tonic-gate krb5_error_code KRB5_CALLCONV
krb5_c_free_state(krb5_context context,const krb5_keyblock * key,krb5_data * state)630Sstevel@tonic-gate krb5_c_free_state (krb5_context context, const krb5_keyblock *key,
640Sstevel@tonic-gate krb5_data *state)
650Sstevel@tonic-gate {
660Sstevel@tonic-gate int i;
670Sstevel@tonic-gate
680Sstevel@tonic-gate for (i=0; i<krb5_enctypes_length; i++) {
690Sstevel@tonic-gate if (krb5_enctypes_list[i].etype == key->enctype)
700Sstevel@tonic-gate break;
710Sstevel@tonic-gate }
720Sstevel@tonic-gate
730Sstevel@tonic-gate if (i == krb5_enctypes_length)
740Sstevel@tonic-gate return(KRB5_BAD_ENCTYPE);
750Sstevel@tonic-gate
76*7934SMark.Phalan@Sun.COM /* Solaris Kerberos */
77*7934SMark.Phalan@Sun.COM return (*(krb5_enctypes_list[i].enc->free_state))
780Sstevel@tonic-gate (context, state);
790Sstevel@tonic-gate }
80