blob: 37aa652ce5ce6f89e4738ac07dd770b8df4a6ac9 [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>
Herbert Xu64baf3c2005-09-01 17:43:05 -070020#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/kmap_types.h>
22
23extern enum km_type crypto_km_types[];
24
25static inline enum km_type crypto_kmap_type(int out)
26{
27 return crypto_km_types[(in_softirq() ? 2 : 0) + out];
28}
29
30static inline void *crypto_kmap(struct page *page, int out)
31{
32 return kmap_atomic(page, crypto_kmap_type(out));
33}
34
35static inline void crypto_kunmap(void *vaddr, int out)
36{
37 kunmap_atomic(vaddr, crypto_kmap_type(out));
38}
39
40static inline void crypto_yield(struct crypto_tfm *tfm)
41{
Herbert Xu64baf3c2005-09-01 17:43:05 -070042 if (tfm->crt_flags & CRYPTO_TFM_REQ_MAY_SLEEP)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 cond_resched();
44}
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#ifdef CONFIG_CRYPTO_HMAC
47int crypto_alloc_hmac_block(struct crypto_tfm *tfm);
48void crypto_free_hmac_block(struct crypto_tfm *tfm);
49#else
50static inline int crypto_alloc_hmac_block(struct crypto_tfm *tfm)
51{
52 return 0;
53}
54
55static inline void crypto_free_hmac_block(struct crypto_tfm *tfm)
56{ }
57#endif
58
59#ifdef CONFIG_PROC_FS
60void __init crypto_init_proc(void);
61#else
62static inline void crypto_init_proc(void)
63{ }
64#endif
65
Herbert Xufbdae9f2005-07-06 13:53:29 -070066static inline unsigned int crypto_digest_ctxsize(struct crypto_alg *alg,
67 int flags)
68{
69 return alg->cra_ctxsize;
70}
71
72static inline unsigned int crypto_cipher_ctxsize(struct crypto_alg *alg,
73 int flags)
74{
75 unsigned int len = alg->cra_ctxsize;
76
77 switch (flags & CRYPTO_TFM_MODE_MASK) {
78 case CRYPTO_TFM_MODE_CBC:
Herbert Xu9d853c32005-07-15 07:41:31 -070079 len = ALIGN(len, (unsigned long)alg->cra_alignmask + 1);
Herbert Xufbdae9f2005-07-06 13:53:29 -070080 len += alg->cra_blocksize;
81 break;
82 }
83
84 return len;
85}
86
87static inline unsigned int crypto_compress_ctxsize(struct crypto_alg *alg,
88 int flags)
89{
90 return alg->cra_ctxsize;
91}
92
Linus Torvalds1da177e2005-04-16 15:20:36 -070093int crypto_init_digest_flags(struct crypto_tfm *tfm, u32 flags);
94int crypto_init_cipher_flags(struct crypto_tfm *tfm, u32 flags);
95int crypto_init_compress_flags(struct crypto_tfm *tfm, u32 flags);
96
97int crypto_init_digest_ops(struct crypto_tfm *tfm);
98int crypto_init_cipher_ops(struct crypto_tfm *tfm);
99int crypto_init_compress_ops(struct crypto_tfm *tfm);
100
101void crypto_exit_digest_ops(struct crypto_tfm *tfm);
102void crypto_exit_cipher_ops(struct crypto_tfm *tfm);
103void crypto_exit_compress_ops(struct crypto_tfm *tfm);
104
105#endif /* _CRYPTO_INTERNAL_H */
106