blob: 713d039f4af7a61fc59b97d1d0f7c7c22b375dcd [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _NET_ESP_H
2#define _NET_ESP_H
3
Herbert Xu9409f382006-08-06 19:49:12 +10004#include <linux/crypto.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#include <net/xfrm.h>
6#include <asm/scatterlist.h>
7
8#define ESP_NUM_FAST_SG 4
9
10struct esp_data
11{
12 struct scatterlist sgbuf[ESP_NUM_FAST_SG];
13
14 /* Confidentiality */
15 struct {
16 u8 *key; /* Key */
17 int key_len; /* Key length */
David S. Millere4bec822006-09-22 15:17:35 -070018 int padlen; /* 0..255 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 /* ivlen is offset from enc_data, where encrypted data start.
20 * It is logically different of crypto_tfm_alg_ivsize(tfm).
21 * We assume that it is either zero (no ivec), or
22 * >= crypto_tfm_alg_ivsize(tfm). */
23 int ivlen;
David S. Millere4bec822006-09-22 15:17:35 -070024 int ivinitted;
25 u8 *ivec; /* ivec buffer */
Herbert Xu6b7326c2006-07-30 15:41:01 +100026 struct crypto_blkcipher *tfm; /* crypto handle */
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 } conf;
28
29 /* Integrity. It is active when icv_full_len != 0 */
30 struct {
31 u8 *key; /* Key */
32 int key_len; /* Length of the key */
33 u8 *work_icv;
34 int icv_full_len;
35 int icv_trunc_len;
36 void (*icv)(struct esp_data*,
37 struct sk_buff *skb,
38 int offset, int len, u8 *icv);
Herbert Xu07d4ee52006-08-20 14:24:50 +100039 struct crypto_hash *tfm;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 } auth;
41};
42
43extern int skb_to_sgvec(struct sk_buff *skb, struct scatterlist *sg, int offset, int len);
44extern int skb_cow_data(struct sk_buff *skb, int tailbits, struct sk_buff **trailer);
45extern void *pskb_put(struct sk_buff *skb, struct sk_buff *tail, int len);
46
Herbert Xu07d4ee52006-08-20 14:24:50 +100047static inline int esp_mac_digest(struct esp_data *esp, struct sk_buff *skb,
48 int offset, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
Herbert Xu07d4ee52006-08-20 14:24:50 +100050 struct hash_desc desc;
51 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Herbert Xu07d4ee52006-08-20 14:24:50 +100053 desc.tfm = esp->auth.tfm;
54 desc.flags = 0;
55
56 err = crypto_hash_init(&desc);
57 if (unlikely(err))
58 return err;
59 err = skb_icv_walk(skb, &desc, offset, len, crypto_hash_update);
60 if (unlikely(err))
61 return err;
62 return crypto_hash_final(&desc, esp->auth.work_icv);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063}
64
65#endif