Whamcloud - gitweb
land lustre part of b_hd_sec on HEAD.
[fs/lustre-release.git] / lustre / sec / gss / gss_krb5.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Modifications for Lustre
5  * Copyright 2004, Cluster File Systems, Inc.
6  * All rights reserved
7  * Author: Eric Mei <ericm@clusterfs.com>
8  */
9
10 /*
11  *  linux/include/linux/sunrpc/gss_krb5_types.h
12  *
13  *  Adapted from MIT Kerberos 5-1.2.1 lib/include/krb5.h,
14  *  lib/gssapi/krb5/gssapiP_krb5.h, and others
15  *
16  *  Copyright (c) 2000 The Regents of the University of Michigan.
17  *  All rights reserved.
18  *
19  *  Andy Adamson   <andros@umich.edu>
20  *  Bruce Fields   <bfields@umich.edu>
21  */
22
23 /*
24  * Copyright 1995 by the Massachusetts Institute of Technology.
25  * All Rights Reserved.
26  *
27  * Export of this software from the United States of America may
28  *   require a specific license from the United States Government.
29  *   It is the responsibility of any person or organization contemplating
30  *   export to obtain such a license before exporting.
31  *
32  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
33  * distribute this software and its documentation for any purpose and
34  * without fee is hereby granted, provided that the above copyright
35  * notice appear in all copies and that both that copyright notice and
36  * this permission notice appear in supporting documentation, and that
37  * the name of M.I.T. not be used in advertising or publicity pertaining
38  * to distribution of the software without specific, written prior
39  * permission.  Furthermore if you modify this software you must label
40  * your software as modified software and not distribute it in such a
41  * fashion that it might be confused with the original M.I.T. software.
42  * M.I.T. makes no representations about the suitability of
43  * this software for any purpose.  It is provided "as is" without express
44  * or implied warranty.
45  *
46  */
47
48 extern spinlock_t krb5_seq_lock;
49
50 struct krb5_ctx {
51         int                     initiate; /* 1 = initiating, 0 = accepting */
52         int                     seed_init;
53         unsigned char           seed[16];
54         int                     signalg;
55         int                     sealalg;
56         struct crypto_tfm      *enc;
57         struct crypto_tfm      *seq;
58         __s32                   endtime;
59         __u32                   seq_send;
60         rawobj_t                mech_used;
61 };
62
63 #define KG_TOK_MIC_MSG    0x0101
64 #define KG_TOK_WRAP_MSG   0x0201
65
66 enum sgn_alg {
67         SGN_ALG_DES_MAC_MD5 = 0x0000,
68         SGN_ALG_MD2_5 = 0x0001,
69         SGN_ALG_DES_MAC = 0x0002,
70         SGN_ALG_3 = 0x0003,                /* not published */
71         SGN_ALG_HMAC_MD5 = 0x0011,        /* microsoft w2k; no support */
72         SGN_ALG_HMAC_SHA1_DES3_KD = 0x0004
73 };
74 enum seal_alg {
75         SEAL_ALG_NONE = 0xffff,
76         SEAL_ALG_DES = 0x0000,
77         SEAL_ALG_1 = 0x0001,                /* not published */
78         SEAL_ALG_MICROSOFT_RC4 = 0x0010,/* microsoft w2k; no support */
79         SEAL_ALG_DES3KD = 0x0002
80 };
81
82 #define KRB5_CKSUM_LENGTH 8
83
84 #define CKSUMTYPE_CRC32                        0x0001
85 #define CKSUMTYPE_RSA_MD4                0x0002
86 #define CKSUMTYPE_RSA_MD4_DES                0x0003
87 #define CKSUMTYPE_DESCBC                0x0004
88 #define CKSUMTYPE_RSA_MD5                0x0007
89 #define CKSUMTYPE_RSA_MD5_DES                0x0008
90 #define CKSUMTYPE_NIST_SHA                0x0009
91 #define CKSUMTYPE_HMAC_SHA1_DES3        0x000c
92
93 /* from gssapi_err_krb5.h */
94 #define KG_CCACHE_NOMATCH                        (39756032L)
95 #define KG_KEYTAB_NOMATCH                        (39756033L)
96 #define KG_TGT_MISSING                           (39756034L)
97 #define KG_NO_SUBKEY                             (39756035L)
98 #define KG_CONTEXT_ESTABLISHED                   (39756036L)
99 #define KG_BAD_SIGN_TYPE                         (39756037L)
100 #define KG_BAD_LENGTH                            (39756038L)
101 #define KG_CTX_INCOMPLETE                        (39756039L)
102 #define KG_CONTEXT                               (39756040L)
103 #define KG_CRED                                  (39756041L)
104 #define KG_ENC_DESC                              (39756042L)
105 #define KG_BAD_SEQ                               (39756043L)
106 #define KG_EMPTY_CCACHE                          (39756044L)
107 #define KG_NO_CTYPES                             (39756045L)
108
109 /* per Kerberos v5 protocol spec crypto types from the wire. 
110  * these get mapped to linux kernel crypto routines.  
111  */
112 #define ENCTYPE_NULL            0x0000
113 #define ENCTYPE_DES_CBC_CRC     0x0001        /* DES cbc mode with CRC-32 */
114 #define ENCTYPE_DES_CBC_MD4     0x0002        /* DES cbc mode with RSA-MD4 */
115 #define ENCTYPE_DES_CBC_MD5     0x0003        /* DES cbc mode with RSA-MD5 */
116 #define ENCTYPE_DES_CBC_RAW     0x0004        /* DES cbc mode raw */
117 /* XXX deprecated? */
118 #define ENCTYPE_DES3_CBC_SHA    0x0005        /* DES-3 cbc mode with NIST-SHA */
119 #define ENCTYPE_DES3_CBC_RAW    0x0006        /* DES-3 cbc mode raw */
120 #define ENCTYPE_DES_HMAC_SHA1   0x0008
121 #define ENCTYPE_DES3_CBC_SHA1   0x0010
122 #define ENCTYPE_UNKNOWN         0x01ff
123
124 __s32
125 make_checksum(__s32 cksumtype,
126               char *header, int hdrlen,
127               rawobj_t *body,
128               rawobj_t *cksum);
129
130 __u32
131 krb5_make_token(struct krb5_ctx *ctx,
132                 int qop_req,
133                 rawobj_t *text,
134                 rawobj_t *token);
135
136 __u32
137 krb5_read_token(struct krb5_ctx *ctx,
138                 rawobj_t *read_token,
139                 rawobj_t *message_buffer,
140                 int *qop_state);
141
142 __u32
143 krb5_encrypt(struct crypto_tfm *tfm,
144              void * iv,
145              void * in,
146              void * out,
147              int length);
148
149 __u32
150 krb5_decrypt(struct crypto_tfm *tfm,
151              void * iv,
152              void * in,
153              void * out,
154              int length);
155
156 __s32
157 krb5_make_seq_num(struct crypto_tfm *key,
158                   int direction,
159                   __s32 seqnum,
160                   unsigned char *cksum,
161                   unsigned char *buf);
162
163 __s32
164 krb5_get_seq_num(struct crypto_tfm *key,
165                  unsigned char *cksum,
166                  unsigned char *buf,
167                  int *direction,
168                  __s32 *seqnum);
169 int
170 gss_encrypt_rawobj(struct crypto_tfm *tfm,
171                    rawobj_t *inobj,
172                    rawobj_t *outobj,
173                    int enc);
174 __u32
175 gss_wrap_kerberos(struct gss_ctx    *ctx,
176                   __u32              qop,
177                   rawobj_buf_t      *in_token,
178                   rawobj_t          *out_token);
179 __u32
180 gss_unwrap_kerberos(struct gss_ctx  *ctx,
181                     __u32            qop,
182                     rawobj_t        *in_token,
183                     rawobj_t        *out_token);