~ubuntu-branches/ubuntu/quantal/linux-linaro-mx51/quantal

« back to all changes in this revision

Viewing changes to ubuntu/rtl8192se/rtllib/api.c

  • Committer: Package Import Robot
  • Author(s): John Rigby, John Rigby
  • Date: 2011-09-26 10:44:23 UTC
  • Revision ID: package-import@ubuntu.com-20110926104423-3o58a3c1bj7x00rs
Tags: 3.0.0-1007.9
[ John Rigby ]

Enable crypto modules and remove crypto-modules from
exclude-module files
LP: #826021

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Scatterlist Cryptographic API.
3
 
 *
4
 
 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
5
 
 * Copyright (c) 2002 David S. Miller (davem@redhat.com)
6
 
 *
7
 
 * Portions derived from Cryptoapi, by Alexander Kjeldaas <astor@fast.no>
8
 
 * and Nettle, by Niels M鰈ler.
9
 
 *
10
 
 * This program is free software; you can redistribute it and/or modify it
11
 
 * under the terms of the GNU General Public License as published by the Free
12
 
 * Software Foundation; either version 2 of the License, or (at your option) 
13
 
 * any later version.
14
 
 *
15
 
 */
16
 
 
17
 
 
18
 
#include <linux/init.h>
19
 
#include <linux/module.h>
20
 
#include "rtl_crypto.h"
21
 
#include <linux/errno.h>
22
 
#include <linux/rwsem.h>
23
 
#include <linux/slab.h>
24
 
#include "internal.h"
25
 
 
26
 
LIST_HEAD(crypto_alg_list);
27
 
DECLARE_RWSEM(crypto_alg_sem);
28
 
 
29
 
static inline int crypto_alg_get(struct crypto_alg *alg)
30
 
{
31
 
#ifdef BUILT_IN_CRYPTO
32
 
        return 1;
33
 
#else
34
 
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
35
 
        return try_module_get(alg->cra_module);
36
 
#else
37
 
        return try_inc_mod_count(alg->cra_module);
38
 
#endif                  
39
 
#endif
40
 
}
41
 
 
42
 
static inline void crypto_alg_put(struct crypto_alg *alg)
43
 
{
44
 
#ifndef BUILT_IN_CRYPTO
45
 
        if (alg->cra_module)
46
 
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)         
47
 
                module_put(alg->cra_module);
48
 
#else
49
 
                __MOD_DEC_USE_COUNT(alg->cra_module);
50
 
#endif          
51
 
#endif
52
 
}
53
 
 
54
 
struct crypto_alg *crypto_alg_lookup(const char *name)
55
 
{
56
 
        struct crypto_alg *q, *alg = NULL;
57
 
 
58
 
        if (!name)
59
 
                return NULL;
60
 
        
61
 
        down_read(&crypto_alg_sem);
62
 
        
63
 
        list_for_each_entry(q, &crypto_alg_list, cra_list) {
64
 
                if (!(strcmp(q->cra_name, name))) {
65
 
                        if (crypto_alg_get(q))
66
 
                                alg = q;
67
 
                        break;
68
 
                }
69
 
        }
70
 
        
71
 
        up_read(&crypto_alg_sem);
72
 
        return alg;
73
 
}
74
 
 
75
 
static int crypto_init_flags(struct crypto_tfm *tfm, u32 flags)
76
 
{
77
 
        tfm->crt_flags = 0;
78
 
        
79
 
        switch (crypto_tfm_alg_type(tfm)) {
80
 
        case CRYPTO_ALG_TYPE_CIPHER:
81
 
                return crypto_init_cipher_flags(tfm, flags);
82
 
                
83
 
        case CRYPTO_ALG_TYPE_DIGEST:
84
 
                return crypto_init_digest_flags(tfm, flags);
85
 
                
86
 
        case CRYPTO_ALG_TYPE_COMPRESS:
87
 
                return crypto_init_compress_flags(tfm, flags);
88
 
        
89
 
        default:
90
 
                break;
91
 
        }
92
 
        
93
 
        BUG();
94
 
        return -EINVAL;
95
 
}
96
 
 
97
 
static int crypto_init_ops(struct crypto_tfm *tfm)
98
 
{
99
 
        switch (crypto_tfm_alg_type(tfm)) {
100
 
        case CRYPTO_ALG_TYPE_CIPHER:
101
 
                return crypto_init_cipher_ops(tfm);
102
 
                
103
 
        case CRYPTO_ALG_TYPE_DIGEST:
104
 
                return crypto_init_digest_ops(tfm);
105
 
                
106
 
        case CRYPTO_ALG_TYPE_COMPRESS:
107
 
                return crypto_init_compress_ops(tfm);
108
 
        
109
 
        default:
110
 
                break;
111
 
        }
112
 
        
113
 
        BUG();
114
 
        return -EINVAL;
115
 
}
116
 
 
117
 
static void crypto_exit_ops(struct crypto_tfm *tfm)
118
 
{
119
 
        switch (crypto_tfm_alg_type(tfm)) {
120
 
        case CRYPTO_ALG_TYPE_CIPHER:
121
 
                crypto_exit_cipher_ops(tfm);
122
 
                break;
123
 
                
124
 
        case CRYPTO_ALG_TYPE_DIGEST:
125
 
                crypto_exit_digest_ops(tfm);
126
 
                break;
127
 
                
128
 
        case CRYPTO_ALG_TYPE_COMPRESS:
129
 
                crypto_exit_compress_ops(tfm);
130
 
                break;
131
 
        
132
 
        default:
133
 
                BUG();
134
 
                
135
 
        }
136
 
}
137
 
 
138
 
struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags)
139
 
{
140
 
        struct crypto_tfm *tfm = NULL;
141
 
        struct crypto_alg *alg;
142
 
 
143
 
        alg = crypto_alg_mod_lookup(name);
144
 
        if (alg == NULL)
145
 
                goto out;
146
 
        
147
 
        tfm = kmalloc(sizeof(*tfm) + alg->cra_ctxsize, GFP_KERNEL);
148
 
        if (tfm == NULL)
149
 
                goto out_put;
150
 
 
151
 
        memset(tfm, 0, sizeof(*tfm) + alg->cra_ctxsize);
152
 
        
153
 
        tfm->__crt_alg = alg;
154
 
        
155
 
        if (crypto_init_flags(tfm, flags))
156
 
                goto out_free_tfm;
157
 
                
158
 
        if (crypto_init_ops(tfm)) {
159
 
                crypto_exit_ops(tfm);
160
 
                goto out_free_tfm;
161
 
        }
162
 
 
163
 
        goto out;
164
 
 
165
 
out_free_tfm:
166
 
        kfree(tfm);
167
 
        tfm = NULL;
168
 
out_put:
169
 
        crypto_alg_put(alg);
170
 
out:
171
 
        return tfm;
172
 
}
173
 
 
174
 
void crypto_free_tfm(struct crypto_tfm *tfm)
175
 
{
176
 
        struct crypto_alg *alg = tfm->__crt_alg;
177
 
        int size = sizeof(*tfm) + alg->cra_ctxsize;
178
 
 
179
 
        crypto_exit_ops(tfm);
180
 
        crypto_alg_put(alg);
181
 
        memset(tfm, 0, size);
182
 
        kfree(tfm);
183
 
}
184
 
 
185
 
int crypto_register_alg(struct crypto_alg *alg)
186
 
{
187
 
        int ret = 0;
188
 
        struct crypto_alg *q;
189
 
        
190
 
        down_write(&crypto_alg_sem);
191
 
        
192
 
        list_for_each_entry(q, &crypto_alg_list, cra_list) {
193
 
                if (!(strcmp(q->cra_name, alg->cra_name))) {
194
 
                        ret = -EEXIST;
195
 
                        goto out;
196
 
                }
197
 
        }
198
 
        
199
 
        list_add_tail(&alg->cra_list, &crypto_alg_list);
200
 
out:    
201
 
        up_write(&crypto_alg_sem);
202
 
        return ret;
203
 
}
204
 
 
205
 
int crypto_unregister_alg(struct crypto_alg *alg)
206
 
{
207
 
        int ret = -ENOENT;
208
 
        struct crypto_alg *q;
209
 
        
210
 
        BUG_ON(!alg->cra_module);
211
 
        
212
 
        down_write(&crypto_alg_sem);
213
 
        list_for_each_entry(q, &crypto_alg_list, cra_list) {
214
 
                if (alg == q) {
215
 
                        list_del(&alg->cra_list);
216
 
                        ret = 0;
217
 
                        goto out;
218
 
                }
219
 
        }
220
 
out:    
221
 
        up_write(&crypto_alg_sem);
222
 
        return ret;
223
 
}
224
 
 
225
 
int crypto_alg_available(const char *name, u32 flags)
226
 
{
227
 
        int ret = 0;
228
 
        struct crypto_alg *alg = crypto_alg_mod_lookup(name);
229
 
        
230
 
        if (alg) {
231
 
                crypto_alg_put(alg);
232
 
                ret = 1;
233
 
        }
234
 
        
235
 
        return ret;
236
 
}
237
 
 
238
 
#ifndef BUILT_IN_CRYPTO
239
 
static int __init init_crypto(void)
240
 
{
241
 
        printk(KERN_INFO "Initializing Cryptographic API\n");
242
 
        crypto_init_proc();
243
 
        return 0;
244
 
}
245
 
 
246
 
__initcall(init_crypto);
247
 
 
248
 
 
249
 
/*
250
 
EXPORT_SYMBOL_GPL(crypto_register_alg);
251
 
EXPORT_SYMBOL_GPL(crypto_unregister_alg);
252
 
EXPORT_SYMBOL_GPL(crypto_alloc_tfm);
253
 
EXPORT_SYMBOL_GPL(crypto_free_tfm);
254
 
EXPORT_SYMBOL_GPL(crypto_alg_available);
255
 
*/
256
 
EXPORT_SYMBOL_RSL(crypto_register_alg);
257
 
EXPORT_SYMBOL_RSL(crypto_unregister_alg);
258
 
EXPORT_SYMBOL_RSL(crypto_alloc_tfm);
259
 
EXPORT_SYMBOL_RSL(crypto_free_tfm);
260
 
EXPORT_SYMBOL_RSL(crypto_alg_available);
261
 
#endif