Whamcloud - gitweb
6b46e7e1cec3126dbba61ee5626565ef8f7cc178
[fs/lustre-release.git] / lustre / sec / gss / gss_internal.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Modified from NFSv4 project for Lustre
5  * Copyright 2004, Cluster File Systems, Inc.
6  * All rights reserved
7  * Author: Eric Mei <ericm@clusterfs.com>
8  */
9
10 #ifndef __SEC_GSS_GSS_INTERNAL_H_
11 #define __SEC_GSS_GSS_INTERNAL_H_
12
13 /* remove this mess when libkcrypt is ready --umka */
14 #ifndef __KERNEL__
15 /*
16  * Algorithm masks and types.
17  */
18 #define CRYPTO_ALG_TYPE_MASK            0x000000ff
19 #define CRYPTO_ALG_TYPE_CIPHER          0x00000001
20 #define CRYPTO_ALG_TYPE_DIGEST          0x00000002
21 #define CRYPTO_ALG_TYPE_COMPRESS        0x00000004
22
23 /*
24  * Transform masks and values (for crt_flags).
25  */
26 #define CRYPTO_TFM_MODE_MASK            0x000000ff
27 #define CRYPTO_TFM_REQ_MASK             0x000fff00
28 #define CRYPTO_TFM_RES_MASK             0xfff00000
29
30 #define CRYPTO_TFM_MODE_ECB             0x00000001
31 #define CRYPTO_TFM_MODE_CBC             0x00000002
32 #define CRYPTO_TFM_MODE_CFB             0x00000004
33 #define CRYPTO_TFM_MODE_CTR             0x00000008
34
35 #define CRYPTO_TFM_REQ_WEAK_KEY         0x00000100
36 #define CRYPTO_TFM_RES_WEAK_KEY         0x00100000
37 #define CRYPTO_TFM_RES_BAD_KEY_LEN      0x00200000
38 #define CRYPTO_TFM_RES_BAD_KEY_SCHED    0x00400000
39 #define CRYPTO_TFM_RES_BAD_BLOCK_LEN    0x00800000
40 #define CRYPTO_TFM_RES_BAD_FLAGS        0x01000000
41
42 /*
43  * Miscellaneous stuff.
44  */
45 #define CRYPTO_UNSPEC                   0
46 #define CRYPTO_MAX_ALG_NAME             64
47
48 struct scatterlist {
49     struct page         *page;
50     unsigned int        offset;
51     __u32               dma_address;
52     unsigned int        length;
53 };
54
55 static inline struct crypto_tfm *
56 crypto_alloc_tfm(const char *name, __u32 flags)
57 {
58         return NULL;
59 }
60
61 static inline void 
62 crypto_free_tfm(struct crypto_tfm *tfm)
63 {
64         return;
65 }
66
67 static inline int 
68 crypto_digest_setkey(struct crypto_tfm *tfm,
69                      const __u8 *key, unsigned int keylen)
70 {
71         return -ENOSYS;
72 }
73
74 static inline unsigned int 
75 crypto_tfm_alg_blocksize(struct crypto_tfm *tfm)
76 {
77         return 0;
78 }
79
80 static inline unsigned int 
81 crypto_tfm_alg_ivsize(struct crypto_tfm *tfm)
82 {
83         return 0;
84 }
85
86 #endif /* __KERNEL__ */
87
88 struct ptlrpc_sec;
89 struct ptlrpc_cred;
90
91 typedef struct rawobj_s {
92         __u32           len;
93         __u8           *data;
94 } rawobj_t;
95
96 int rawobj_alloc(rawobj_t *obj, char *buf, int len);
97 void rawobj_free(rawobj_t *obj);
98 int rawobj_equal(rawobj_t *a, rawobj_t *b);
99 int rawobj_dup(rawobj_t *dest, rawobj_t *src);
100 int rawobj_serialize(rawobj_t *obj, __u32 **buf, __u32 *buflen);
101 int rawobj_extract(rawobj_t *obj, __u32 **buf, __u32 *buflen);
102 int rawobj_extract_local(rawobj_t *obj, __u32 **buf, __u32 *buflen);
103
104 typedef struct rawobj_buf_s {
105         __u32           dataoff;
106         __u32           datalen;
107         __u32           buflen;
108         __u8           *buf;
109 } rawobj_buf_t;
110
111 #define MAXSEQ 0x80000000 /* maximum legal sequence number, from rfc 2203 */
112
113 enum rpc_gss_proc {
114         RPC_GSS_PROC_DATA =             0,
115         RPC_GSS_PROC_INIT =             1,
116         RPC_GSS_PROC_CONTINUE_INIT =    2,
117         RPC_GSS_PROC_DESTROY =          3,
118 };
119
120 enum rpc_gss_svc {
121         RPC_GSS_SVC_NONE =              1,
122         RPC_GSS_SVC_INTEGRITY =         2,
123         RPC_GSS_SVC_PRIVACY =           3,
124 };
125
126 /* on-the-wire gss cred: */
127 struct rpc_gss_wire_cred {
128         __u32                   gc_v;           /* version */
129         __u32                   gc_proc;        /* control procedure */
130         __u32                   gc_seq;         /* sequence number */
131         __u32                   gc_svc;         /* service */
132         rawobj_t                gc_ctx;         /* context handle */
133 };
134
135 /* on-the-wire gss verifier: */
136 struct rpc_gss_wire_verf {
137         __u32                   gv_flavor;
138         rawobj_t                gv_verf;
139 };
140
141 struct gss_cl_ctx {
142         atomic_t                gc_refcount;
143         __u32                   gc_proc;
144         __u32                   gc_seq;
145         spinlock_t              gc_seq_lock;
146         struct gss_ctx         *gc_gss_ctx;
147         rawobj_t                gc_wire_ctx;
148         __u32                   gc_win;
149 };
150
151 struct gss_cred {
152         struct ptlrpc_cred      gc_base;
153         ptlrpcs_flavor_t        gc_flavor;
154         struct gss_cl_ctx      *gc_ctx;
155 };
156
157 /*
158  * This only guaranteed be enough for current krb5 des-cbc-crc . We might
159  * adjust this when new enc type or mech added in.
160  */
161 #define GSS_PRIVBUF_PREFIX_LEN         (32)
162 #define GSS_PRIVBUF_SUFFIX_LEN         (32)
163
164 /* This is too coarse. We'll let mech determine it */
165 #define GSS_MAX_AUTH_PAYLOAD    (128)
166
167 /* gss_mech_switch.c */
168 int init_kerberos_module(void);
169 void cleanup_kerberos_module(void);
170
171 /* gss_generic_token.c */
172 int g_token_size(rawobj_t *mech, unsigned int body_size);
173 void g_make_token_header(rawobj_t *mech, int body_size, unsigned char **buf);
174 __u32 g_verify_token_header(rawobj_t *mech, int *body_size,
175                             unsigned char **buf_in, int toksize);
176
177 /* svcsec_gss.c */
178 int gss_svc_init(void);
179 void gss_svc_exit(void);
180
181 #endif /* __SEC_GSS_GSS_INTERNAL_H_ */