1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2003 Cluster File Systems, Inc. <info@clusterfs.com>
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * See also lustre_idl.h for wire formats of requests.
29 #define LUSTRE_GKS_NAME "gks"
30 #define LUSTRE_GKT_NAME "gkt"
31 #define LUSTRE_GKC_NAME "gkc"
39 struct crypto_ops_item {
40 struct crypto_helper_ops *cops;
41 struct list_head clist;
45 #define DECRYPT_DATA 0x00000001
46 #define ENCRYPT_DATA 0x00000002
48 struct crypto_key lk_ck;
55 static inline struct lustre_key *
56 lustre_key_get(struct lustre_key *lkey)
59 atomic_inc(&lkey->lk_refcount);
66 lustre_key_release(struct lustre_key *lkey)
68 if (lkey && atomic_dec_and_test(&lkey->lk_refcount))
72 #define SET_CRYPTO_FLAGS(flags, type, offset, width) \
74 flags &= ~(((1 << width) - 1) << offset); \
75 flags |= (type & ((1 << width) - 1)) << offset; \
78 #define CPT_TYPE_OFFSET 0
79 #define CPT_TYPE_WIDTH 2
80 #define GKS_CRYPTO_TYPE 1
81 #define MKS_CRYPTO_TYPE 2
83 #define SET_CRYPTO_TYPE(flags, type) \
84 SET_CRYPTO_FLAGS(flags, type, CPT_TYPE_OFFSET, CPT_TYPE_WIDTH)
86 #define IS_GKS_TYPE(flags) \
87 (((flags >> CPT_TYPE_OFFSET) & ((1 << CPT_TYPE_WIDTH) - 1)) == GKS_CRYPTO_TYPE)
89 #define IS_MKS_TYPE(flags) \
90 (((flags >> CPT_TYPE_OFFSET) & ((1 << CPT_TYPE_WIDTH) - 1)) == MKS_CRYPTO_TYPE)
92 #define CPT_ENCRYPT_OFFSET 2
93 #define CPT_ENCRYPT_WIDTH 1
94 #define ENABLE_ENCRYPT_FLAG 1
95 #define DISABLE_ENCRYPT_FLAG 0
97 #define ENABLE_ENCRYPT(flag) \
98 SET_CRYPTO_FLAGS(flag, ENABLE_ENCRYPT_FLAG, CPT_ENCRYPT_OFFSET, CPT_ENCRYPT_WIDTH)
100 #define DISABLE_ENCRYPT(flag) \
101 SET_CRYPTO_FLAGS(flag, DISABLE_ENCRYPT_FLAG, CPT_ENCRYPT_OFFSET, CPT_ENCRYPT_WIDTH)
103 #define IS_ENABLE_ENCRYPT(flags) \
104 (((flags >> CPT_ENCRYPT_OFFSET) & ((1 << CPT_ENCRYPT_WIDTH) - 1)) \
105 == ENABLE_ENCRYPT_FLAG)
107 #define CPT_DECRYPT_OFFSET 3
108 #define CPT_DECRYPT_WIDTH 1
109 #define ENABLE_DECRYPT_FLAG 1
110 #define DISABLE_DECRYPT_FLAG 2
112 #define ENABLE_DECRYPT(flag) \
113 SET_CRYPTO_FLAGS(flag, ENABLE_DECRYPT_FLAG, CPT_DECRYPT_OFFSET, CPT_DECRYPT_WIDTH)
115 #define DISABLE_DECRYPT(flag) \
116 SET_CRYPTO_FLAGS(flag, DISABLE_DECRYPT_FLAG, CPT_DECRYPT_OFFSET, CPT_DECRYPT_WIDTH)
118 #define IS_ENABLE_DECRYPT(flags) \
119 (((flags >> CPT_DECRYPT_OFFSET) & ((1 << CPT_DECRYPT_WIDTH) - 1)) \
120 == ENABLE_DECRYPT_FLAG)
122 #define CPT_DECRYPTED_OFFSET 4
123 #define CPT_DECRYPTED_WIDTH 1
124 #define DECRYPTED_FLAG 1
125 #define ENCRYPTED_FLAG 0
127 #define SET_DECRYPTED(flag) \
128 SET_CRYPTO_FLAGS(flag, DECRYPTED_FLAG, CPT_DECRYPTED_OFFSET, CPT_DECRYPTED_WIDTH)
130 #define SET_UNDECRYPTED(flag) \
131 SET_CRYPTO_FLAGS(flag, ENCRYPTED_FLAG, CPT_DECRYPTED_OFFSET, CPT_DECRYPTED_WIDTH)
133 #define IS_DECRYPTED(flags) \
134 (((flags >> CPT_DECRYPTED_OFFSET) & ((1 << CPT_DECRYPTED_WIDTH) - 1)) \
139 #define MD_KEY_MAGIC 0x19760218
140 struct crypto_key_md {
141 struct crypto_key md_ck;
146 struct key_context *context;
147 struct key_perm *perm;
152 static inline int crypto_kcontext_size(int acl_count)
154 return (sizeof(struct key_context) + acl_count *
155 sizeof(struct posix_acl_entry));
157 static inline int crypto_kperm_size(int acl_count)
159 return (sizeof(struct key_perm) + acl_count *
160 sizeof(struct posix_acl_entry));
162 #endif /*LUSTRE_GS_H*/