~ubuntu-branches/ubuntu/trusty/linux-linaro-omap/trusty

« back to all changes in this revision

Viewing changes to ubuntu/rtl8192se/rtllib/rtl_crypto.h

  • 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-57i0gl3v99b3lkfg
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
 
#ifndef _LINUX_CRYPTO_H
17
 
#define _LINUX_CRYPTO_H
18
 
 
19
 
#include <linux/module.h>
20
 
#include <linux/kernel.h>
21
 
#include <linux/types.h>
22
 
#include <linux/list.h>
23
 
#include <linux/string.h>
24
 
#include <asm/page.h>
25
 
#include <asm/errno.h>
26
 
 
27
 
#ifdef BUILT_IN_CRYPTO
28
 
#ifdef CONFIG_CRYPTO_HMAC
29
 
#undef CONFIG_CRYPTO_HMAC
30
 
#endif
31
 
 
32
 
#ifdef CONFIG_KMOD
33
 
#undef CONFIG_KMOD
34
 
#endif
35
 
#endif /* BUILT_IN_CRYPTO */
36
 
 
37
 
#define crypto_register_alg crypto_register_alg_rsl
38
 
#define crypto_unregister_alg crypto_unregister_alg_rsl
39
 
#define crypto_alloc_tfm crypto_alloc_tfm_rsl
40
 
#define crypto_free_tfm crypto_free_tfm_rsl
41
 
#define crypto_alg_available crypto_alg_available_rsl
42
 
 
43
 
/*
44
 
 * Algorithm masks and types.
45
 
 */
46
 
#define CRYPTO_ALG_TYPE_MASK            0x000000ff
47
 
#define CRYPTO_ALG_TYPE_CIPHER          0x00000001
48
 
#define CRYPTO_ALG_TYPE_DIGEST          0x00000002
49
 
#define CRYPTO_ALG_TYPE_COMPRESS        0x00000004
50
 
 
51
 
/*
52
 
 * Transform masks and values (for crt_flags).
53
 
 */
54
 
#define CRYPTO_TFM_MODE_MASK            0x000000ff
55
 
#define CRYPTO_TFM_REQ_MASK             0x000fff00
56
 
#define CRYPTO_TFM_RES_MASK             0xfff00000
57
 
 
58
 
#define CRYPTO_TFM_MODE_ECB             0x00000001
59
 
#define CRYPTO_TFM_MODE_CBC             0x00000002
60
 
#define CRYPTO_TFM_MODE_CFB             0x00000004
61
 
#define CRYPTO_TFM_MODE_CTR             0x00000008
62
 
 
63
 
#define CRYPTO_TFM_REQ_WEAK_KEY         0x00000100
64
 
#define CRYPTO_TFM_RES_WEAK_KEY         0x00100000
65
 
#define CRYPTO_TFM_RES_BAD_KEY_LEN      0x00200000
66
 
#define CRYPTO_TFM_RES_BAD_KEY_SCHED    0x00400000
67
 
#define CRYPTO_TFM_RES_BAD_BLOCK_LEN    0x00800000
68
 
#define CRYPTO_TFM_RES_BAD_FLAGS        0x01000000
69
 
 
70
 
/*
71
 
 * Miscellaneous stuff.
72
 
 */
73
 
#define CRYPTO_UNSPEC                   0
74
 
#define CRYPTO_MAX_ALG_NAME             64
75
 
 
76
 
struct scatterlist;
77
 
 
78
 
/*
79
 
 * Algorithms: modular crypto algorithm implementations, managed
80
 
 * via crypto_register_alg() and crypto_unregister_alg().
81
 
 */
82
 
struct cipher_alg {
83
 
        unsigned int cia_min_keysize;
84
 
        unsigned int cia_max_keysize;
85
 
        int (*cia_setkey)(void *ctx, const u8 *key,
86
 
                          unsigned int keylen, u32 *flags);
87
 
        void (*cia_encrypt)(void *ctx, u8 *dst, const u8 *src);
88
 
        void (*cia_decrypt)(void *ctx, u8 *dst, const u8 *src);
89
 
};
90
 
 
91
 
struct digest_alg {
92
 
        unsigned int dia_digestsize;
93
 
        void (*dia_init)(void *ctx);
94
 
        void (*dia_update)(void *ctx, const u8 *data, unsigned int len);
95
 
        void (*dia_final)(void *ctx, u8 *out);
96
 
        int (*dia_setkey)(void *ctx, const u8 *key,
97
 
                          unsigned int keylen, u32 *flags);
98
 
};
99
 
 
100
 
struct compress_alg {
101
 
        int (*coa_init)(void *ctx);
102
 
        void (*coa_exit)(void *ctx);
103
 
        int (*coa_compress)(void *ctx, const u8 *src, unsigned int slen,
104
 
                            u8 *dst, unsigned int *dlen);
105
 
        int (*coa_decompress)(void *ctx, const u8 *src, unsigned int slen,
106
 
                              u8 *dst, unsigned int *dlen);
107
 
};
108
 
 
109
 
#define cra_cipher      cra_u.cipher
110
 
#define cra_digest      cra_u.digest
111
 
#define cra_compress    cra_u.compress
112
 
 
113
 
struct crypto_alg {
114
 
        struct list_head cra_list;
115
 
        u32 cra_flags;
116
 
        unsigned int cra_blocksize;
117
 
        unsigned int cra_ctxsize;
118
 
        const char cra_name[CRYPTO_MAX_ALG_NAME];
119
 
 
120
 
        union {
121
 
                struct cipher_alg cipher;
122
 
                struct digest_alg digest;
123
 
                struct compress_alg compress;
124
 
        } cra_u;
125
 
        
126
 
        struct module *cra_module;
127
 
};
128
 
 
129
 
/*
130
 
 * Algorithm registration interface.
131
 
 */
132
 
int crypto_register_alg(struct crypto_alg *alg);
133
 
int crypto_unregister_alg(struct crypto_alg *alg);
134
 
 
135
 
/*
136
 
 * Algorithm query interface.
137
 
 */
138
 
int crypto_alg_available(const char *name, u32 flags);
139
 
 
140
 
/*
141
 
 * Transforms: user-instantiated objects which encapsulate algorithms
142
 
 * and core processing logic.  Managed via crypto_alloc_tfm() and
143
 
 * crypto_free_tfm(), as well as the various helpers below.
144
 
 */
145
 
struct crypto_tfm;
146
 
 
147
 
struct cipher_tfm {
148
 
        void *cit_iv;
149
 
        unsigned int cit_ivsize;
150
 
        u32 cit_mode;
151
 
        int (*cit_setkey)(struct crypto_tfm *tfm,
152
 
                          const u8 *key, unsigned int keylen);
153
 
        int (*cit_encrypt)(struct crypto_tfm *tfm,
154
 
                           struct scatterlist *dst,
155
 
                           struct scatterlist *src,
156
 
                           unsigned int nbytes);
157
 
        int (*cit_encrypt_iv)(struct crypto_tfm *tfm,
158
 
                              struct scatterlist *dst,
159
 
                              struct scatterlist *src,
160
 
                              unsigned int nbytes, u8 *iv);
161
 
        int (*cit_decrypt)(struct crypto_tfm *tfm,
162
 
                           struct scatterlist *dst,
163
 
                           struct scatterlist *src,
164
 
                           unsigned int nbytes);
165
 
        int (*cit_decrypt_iv)(struct crypto_tfm *tfm,
166
 
                           struct scatterlist *dst,
167
 
                           struct scatterlist *src,
168
 
                           unsigned int nbytes, u8 *iv);
169
 
        void (*cit_xor_block)(u8 *dst, const u8 *src);
170
 
};
171
 
 
172
 
struct digest_tfm {
173
 
        void (*dit_init)(struct crypto_tfm *tfm);
174
 
        void (*dit_update)(struct crypto_tfm *tfm,
175
 
                           struct scatterlist *sg, unsigned int nsg);
176
 
        void (*dit_final)(struct crypto_tfm *tfm, u8 *out);
177
 
        void (*dit_digest)(struct crypto_tfm *tfm, struct scatterlist *sg,
178
 
                           unsigned int nsg, u8 *out);
179
 
        int (*dit_setkey)(struct crypto_tfm *tfm,
180
 
                          const u8 *key, unsigned int keylen);
181
 
#ifdef CONFIG_CRYPTO_HMAC
182
 
        void *dit_hmac_block;
183
 
#endif
184
 
};
185
 
 
186
 
struct compress_tfm {
187
 
        int (*cot_compress)(struct crypto_tfm *tfm,
188
 
                            const u8 *src, unsigned int slen,
189
 
                            u8 *dst, unsigned int *dlen);
190
 
        int (*cot_decompress)(struct crypto_tfm *tfm,
191
 
                              const u8 *src, unsigned int slen,
192
 
                              u8 *dst, unsigned int *dlen);
193
 
};
194
 
 
195
 
#define crt_cipher      crt_u.cipher
196
 
#define crt_digest      crt_u.digest
197
 
#define crt_compress    crt_u.compress
198
 
 
199
 
struct crypto_tfm {
200
 
 
201
 
        u32 crt_flags;
202
 
        
203
 
        union {
204
 
                struct cipher_tfm cipher;
205
 
                struct digest_tfm digest;
206
 
                struct compress_tfm compress;
207
 
        } crt_u;
208
 
        
209
 
        struct crypto_alg *__crt_alg;
210
 
};
211
 
 
212
 
/* 
213
 
 * Transform user interface.
214
 
 */
215
 
 
216
 
/*
217
 
 * crypto_alloc_tfm() will first attempt to locate an already loaded algorithm.
218
 
 * If that fails and the kernel supports dynamically loadable modules, it
219
 
 * will then attempt to load a module of the same name or alias.  A refcount
220
 
 * is grabbed on the algorithm which is then associated with the new transform.
221
 
 *
222
 
 * crypto_free_tfm() frees up the transform and any associated resources,
223
 
 * then drops the refcount on the associated algorithm.
224
 
 */
225
 
struct crypto_tfm *crypto_alloc_tfm(const char *alg_name, u32 tfm_flags);
226
 
void crypto_free_tfm(struct crypto_tfm *tfm);
227
 
 
228
 
/*
229
 
 * Transform helpers which query the underlying algorithm.
230
 
 */
231
 
static inline const char *crypto_tfm_alg_name(struct crypto_tfm *tfm)
232
 
{
233
 
        return tfm->__crt_alg->cra_name;
234
 
}
235
 
 
236
 
static inline const char *crypto_tfm_alg_modname(struct crypto_tfm *tfm)
237
 
{
238
 
        struct crypto_alg *alg = tfm->__crt_alg;
239
 
        
240
 
        if (alg->cra_module)
241
 
                return alg->cra_module->name;
242
 
        else
243
 
                return NULL;
244
 
}
245
 
 
246
 
static inline u32 crypto_tfm_alg_type(struct crypto_tfm *tfm)
247
 
{
248
 
        return tfm->__crt_alg->cra_flags & CRYPTO_ALG_TYPE_MASK;
249
 
}
250
 
 
251
 
static inline unsigned int crypto_tfm_alg_min_keysize(struct crypto_tfm *tfm)
252
 
{
253
 
        BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
254
 
        return tfm->__crt_alg->cra_cipher.cia_min_keysize;
255
 
}
256
 
 
257
 
static inline unsigned int crypto_tfm_alg_max_keysize(struct crypto_tfm *tfm)
258
 
{
259
 
        BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
260
 
        return tfm->__crt_alg->cra_cipher.cia_max_keysize;
261
 
}
262
 
 
263
 
static inline unsigned int crypto_tfm_alg_ivsize(struct crypto_tfm *tfm)
264
 
{
265
 
        BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
266
 
        return tfm->crt_cipher.cit_ivsize;
267
 
}
268
 
 
269
 
static inline unsigned int crypto_tfm_alg_blocksize(struct crypto_tfm *tfm)
270
 
{
271
 
        return tfm->__crt_alg->cra_blocksize;
272
 
}
273
 
 
274
 
static inline unsigned int crypto_tfm_alg_digestsize(struct crypto_tfm *tfm)
275
 
{
276
 
        BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
277
 
        return tfm->__crt_alg->cra_digest.dia_digestsize;
278
 
}
279
 
 
280
 
/*
281
 
 * API wrappers.
282
 
 */
283
 
static inline void crypto_digest_init(struct crypto_tfm *tfm)
284
 
{
285
 
        BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
286
 
        tfm->crt_digest.dit_init(tfm);
287
 
}
288
 
 
289
 
static inline void crypto_digest_update(struct crypto_tfm *tfm,
290
 
                                        struct scatterlist *sg,
291
 
                                        unsigned int nsg)
292
 
{
293
 
        BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
294
 
        tfm->crt_digest.dit_update(tfm, sg, nsg);
295
 
}
296
 
 
297
 
static inline void crypto_digest_final(struct crypto_tfm *tfm, u8 *out)
298
 
{
299
 
        BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
300
 
        tfm->crt_digest.dit_final(tfm, out);
301
 
}
302
 
 
303
 
static inline void crypto_digest_digest(struct crypto_tfm *tfm,
304
 
                                        struct scatterlist *sg,
305
 
                                        unsigned int nsg, u8 *out)
306
 
{
307
 
        BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
308
 
        tfm->crt_digest.dit_digest(tfm, sg, nsg, out);
309
 
}
310
 
 
311
 
static inline int crypto_digest_setkey(struct crypto_tfm *tfm,
312
 
                                       const u8 *key, unsigned int keylen)
313
 
{
314
 
        BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
315
 
        if (tfm->crt_digest.dit_setkey == NULL)
316
 
                return -ENOSYS;
317
 
        return tfm->crt_digest.dit_setkey(tfm, key, keylen);
318
 
}
319
 
 
320
 
static inline int crypto_cipher_setkey(struct crypto_tfm *tfm,
321
 
                                       const u8 *key, unsigned int keylen)
322
 
{
323
 
        BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
324
 
        return tfm->crt_cipher.cit_setkey(tfm, key, keylen);
325
 
}
326
 
 
327
 
static inline int crypto_cipher_encrypt(struct crypto_tfm *tfm,
328
 
                                        struct scatterlist *dst,
329
 
                                        struct scatterlist *src,
330
 
                                        unsigned int nbytes)
331
 
{
332
 
        BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
333
 
        return tfm->crt_cipher.cit_encrypt(tfm, dst, src, nbytes);
334
 
}                                        
335
 
 
336
 
static inline int crypto_cipher_encrypt_iv(struct crypto_tfm *tfm,
337
 
                                           struct scatterlist *dst,
338
 
                                           struct scatterlist *src,
339
 
                                           unsigned int nbytes, u8 *iv)
340
 
{
341
 
        BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
342
 
        BUG_ON(tfm->crt_cipher.cit_mode == CRYPTO_TFM_MODE_ECB);
343
 
        return tfm->crt_cipher.cit_encrypt_iv(tfm, dst, src, nbytes, iv);
344
 
}                                        
345
 
 
346
 
static inline int crypto_cipher_decrypt(struct crypto_tfm *tfm,
347
 
                                        struct scatterlist *dst,
348
 
                                        struct scatterlist *src,
349
 
                                        unsigned int nbytes)
350
 
{
351
 
        BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
352
 
        return tfm->crt_cipher.cit_decrypt(tfm, dst, src, nbytes);
353
 
}
354
 
 
355
 
static inline int crypto_cipher_decrypt_iv(struct crypto_tfm *tfm,
356
 
                                           struct scatterlist *dst,
357
 
                                           struct scatterlist *src,
358
 
                                           unsigned int nbytes, u8 *iv)
359
 
{
360
 
        BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
361
 
        BUG_ON(tfm->crt_cipher.cit_mode == CRYPTO_TFM_MODE_ECB);
362
 
        return tfm->crt_cipher.cit_decrypt_iv(tfm, dst, src, nbytes, iv);
363
 
}
364
 
 
365
 
static inline void crypto_cipher_set_iv(struct crypto_tfm *tfm,
366
 
                                        const u8 *src, unsigned int len)
367
 
{
368
 
        BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
369
 
        memcpy(tfm->crt_cipher.cit_iv, src, len);
370
 
}
371
 
 
372
 
static inline void crypto_cipher_get_iv(struct crypto_tfm *tfm,
373
 
                                        u8 *dst, unsigned int len)
374
 
{
375
 
        BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
376
 
        memcpy(dst, tfm->crt_cipher.cit_iv, len);
377
 
}
378
 
 
379
 
static inline int crypto_comp_compress(struct crypto_tfm *tfm,
380
 
                                       const u8 *src, unsigned int slen,
381
 
                                       u8 *dst, unsigned int *dlen)
382
 
{
383
 
        BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_COMPRESS);
384
 
        return tfm->crt_compress.cot_compress(tfm, src, slen, dst, dlen);
385
 
}
386
 
 
387
 
static inline int crypto_comp_decompress(struct crypto_tfm *tfm,
388
 
                                         const u8 *src, unsigned int slen,
389
 
                                         u8 *dst, unsigned int *dlen)
390
 
{
391
 
        BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_COMPRESS);
392
 
        return tfm->crt_compress.cot_decompress(tfm, src, slen, dst, dlen);
393
 
}
394
 
 
395
 
/*
396
 
 * HMAC support.
397
 
 */
398
 
#ifdef CONFIG_CRYPTO_HMAC
399
 
void crypto_hmac_init(struct crypto_tfm *tfm, u8 *key, unsigned int *keylen);
400
 
void crypto_hmac_update(struct crypto_tfm *tfm,
401
 
                        struct scatterlist *sg, unsigned int nsg);
402
 
void crypto_hmac_final(struct crypto_tfm *tfm, u8 *key,
403
 
                       unsigned int *keylen, u8 *out);
404
 
void crypto_hmac(struct crypto_tfm *tfm, u8 *key, unsigned int *keylen,
405
 
                 struct scatterlist *sg, unsigned int nsg, u8 *out);
406
 
#endif  /* CONFIG_CRYPTO_HMAC */
407
 
 
408
 
#endif  /* _LINUX_CRYPTO_H */
409