Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _NET_ESP_H |
| 2 | #define _NET_ESP_H |
| 3 | |
Herbert Xu | 9409f38 | 2006-08-06 19:49:12 +1000 | [diff] [blame] | 4 | #include <linux/crypto.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | #include <net/xfrm.h> |
| 6 | #include <asm/scatterlist.h> |
| 7 | |
| 8 | #define ESP_NUM_FAST_SG 4 |
| 9 | |
| 10 | struct esp_data |
| 11 | { |
| 12 | struct scatterlist sgbuf[ESP_NUM_FAST_SG]; |
| 13 | |
| 14 | /* Confidentiality */ |
| 15 | struct { |
David S. Miller | e4bec82 | 2006-09-22 15:17:35 -0700 | [diff] [blame] | 16 | int padlen; /* 0..255 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | /* ivlen is offset from enc_data, where encrypted data start. |
| 18 | * It is logically different of crypto_tfm_alg_ivsize(tfm). |
| 19 | * We assume that it is either zero (no ivec), or |
| 20 | * >= crypto_tfm_alg_ivsize(tfm). */ |
| 21 | int ivlen; |
David S. Miller | e4bec82 | 2006-09-22 15:17:35 -0700 | [diff] [blame] | 22 | int ivinitted; |
| 23 | u8 *ivec; /* ivec buffer */ |
Herbert Xu | 6b7326c | 2006-07-30 15:41:01 +1000 | [diff] [blame] | 24 | struct crypto_blkcipher *tfm; /* crypto handle */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | } conf; |
| 26 | |
| 27 | /* Integrity. It is active when icv_full_len != 0 */ |
| 28 | struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | u8 *work_icv; |
| 30 | int icv_full_len; |
| 31 | int icv_trunc_len; |
Herbert Xu | 07d4ee5 | 2006-08-20 14:24:50 +1000 | [diff] [blame] | 32 | struct crypto_hash *tfm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | } auth; |
| 34 | }; |
| 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | extern void *pskb_put(struct sk_buff *skb, struct sk_buff *tail, int len); |
| 37 | |
Herbert Xu | 07d4ee5 | 2006-08-20 14:24:50 +1000 | [diff] [blame] | 38 | static inline int esp_mac_digest(struct esp_data *esp, struct sk_buff *skb, |
| 39 | int offset, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | { |
Herbert Xu | 07d4ee5 | 2006-08-20 14:24:50 +1000 | [diff] [blame] | 41 | struct hash_desc desc; |
| 42 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Herbert Xu | 07d4ee5 | 2006-08-20 14:24:50 +1000 | [diff] [blame] | 44 | desc.tfm = esp->auth.tfm; |
| 45 | desc.flags = 0; |
| 46 | |
| 47 | err = crypto_hash_init(&desc); |
| 48 | if (unlikely(err)) |
| 49 | return err; |
| 50 | err = skb_icv_walk(skb, &desc, offset, len, crypto_hash_update); |
| 51 | if (unlikely(err)) |
| 52 | return err; |
| 53 | return crypto_hash_final(&desc, esp->auth.work_icv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | #endif |