blob: 37515beafc8ce44ff501d15d617968248656b59f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Cryptographic API.
3 *
4 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 */
12#ifndef _CRYPTO_INTERNAL_H
13#define _CRYPTO_INTERNAL_H
14#include <linux/crypto.h>
15#include <linux/mm.h>
16#include <linux/highmem.h>
17#include <linux/interrupt.h>
18#include <linux/init.h>
Herbert Xufbdae9f2005-07-06 13:53:29 -070019#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <asm/kmap_types.h>
21
22extern enum km_type crypto_km_types[];
23
24static inline enum km_type crypto_kmap_type(int out)
25{
26 return crypto_km_types[(in_softirq() ? 2 : 0) + out];
27}
28
29static inline void *crypto_kmap(struct page *page, int out)
30{
31 return kmap_atomic(page, crypto_kmap_type(out));
32}
33
34static inline void crypto_kunmap(void *vaddr, int out)
35{
36 kunmap_atomic(vaddr, crypto_kmap_type(out));
37}
38
39static inline void crypto_yield(struct crypto_tfm *tfm)
40{
Herbert Xu15333032005-05-23 12:36:25 -070041 if (!in_atomic())
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 cond_resched();
43}
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#ifdef CONFIG_CRYPTO_HMAC
46int crypto_alloc_hmac_block(struct crypto_tfm *tfm);
47void crypto_free_hmac_block(struct crypto_tfm *tfm);
48#else
49static inline int crypto_alloc_hmac_block(struct crypto_tfm *tfm)
50{
51 return 0;
52}
53
54static inline void crypto_free_hmac_block(struct crypto_tfm *tfm)
55{ }
56#endif
57
58#ifdef CONFIG_PROC_FS
59void __init crypto_init_proc(void);
60#else
61static inline void crypto_init_proc(void)
62{ }
63#endif
64
Herbert Xufbdae9f2005-07-06 13:53:29 -070065static inline unsigned int crypto_digest_ctxsize(struct crypto_alg *alg,
66 int flags)
67{
68 return alg->cra_ctxsize;
69}
70
71static inline unsigned int crypto_cipher_ctxsize(struct crypto_alg *alg,
72 int flags)
73{
74 unsigned int len = alg->cra_ctxsize;
75
76 switch (flags & CRYPTO_TFM_MODE_MASK) {
77 case CRYPTO_TFM_MODE_CBC:
Herbert Xu9d853c32005-07-15 07:41:31 -070078 len = ALIGN(len, (unsigned long)alg->cra_alignmask + 1);
Herbert Xufbdae9f2005-07-06 13:53:29 -070079 len += alg->cra_blocksize;
80 break;
81 }
82
83 return len;
84}
85
86static inline unsigned int crypto_compress_ctxsize(struct crypto_alg *alg,
87 int flags)
88{
89 return alg->cra_ctxsize;
90}
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092int crypto_init_digest_flags(struct crypto_tfm *tfm, u32 flags);
93int crypto_init_cipher_flags(struct crypto_tfm *tfm, u32 flags);
94int crypto_init_compress_flags(struct crypto_tfm *tfm, u32 flags);
95
96int crypto_init_digest_ops(struct crypto_tfm *tfm);
97int crypto_init_cipher_ops(struct crypto_tfm *tfm);
98int crypto_init_compress_ops(struct crypto_tfm *tfm);
99
100void crypto_exit_digest_ops(struct crypto_tfm *tfm);
101void crypto_exit_cipher_ops(struct crypto_tfm *tfm);
102void crypto_exit_compress_ops(struct crypto_tfm *tfm);
103
104#endif /* _CRYPTO_INTERNAL_H */
105