Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _NET_AH_H |
| 2 | #define _NET_AH_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 | |
| 7 | /* This is the maximum truncated ICV length that we know of. */ |
| 8 | #define MAX_AH_AUTH_LEN 12 |
| 9 | |
| 10 | struct ah_data |
| 11 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | u8 *work_icv; |
| 13 | int icv_full_len; |
| 14 | int icv_trunc_len; |
| 15 | |
Herbert Xu | 07d4ee5 | 2006-08-20 14:24:50 +1000 | [diff] [blame] | 16 | struct crypto_hash *tfm; |
Steffen Klassert | 49cbf95 | 2009-10-07 22:47:16 +0000 | [diff] [blame^] | 17 | struct crypto_ahash *ahash; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | }; |
| 19 | |
Herbert Xu | 07d4ee5 | 2006-08-20 14:24:50 +1000 | [diff] [blame] | 20 | static inline int ah_mac_digest(struct ah_data *ahp, struct sk_buff *skb, |
| 21 | u8 *auth_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | { |
Herbert Xu | 07d4ee5 | 2006-08-20 14:24:50 +1000 | [diff] [blame] | 23 | struct hash_desc desc; |
| 24 | int err; |
| 25 | |
| 26 | desc.tfm = ahp->tfm; |
| 27 | desc.flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
| 29 | memset(auth_data, 0, ahp->icv_trunc_len); |
Herbert Xu | 07d4ee5 | 2006-08-20 14:24:50 +1000 | [diff] [blame] | 30 | err = crypto_hash_init(&desc); |
| 31 | if (unlikely(err)) |
| 32 | goto out; |
| 33 | err = skb_icv_walk(skb, &desc, 0, skb->len, crypto_hash_update); |
| 34 | if (unlikely(err)) |
| 35 | goto out; |
| 36 | err = crypto_hash_final(&desc, ahp->work_icv); |
| 37 | |
| 38 | out: |
| 39 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Herbert Xu | 87bdc48 | 2007-10-10 15:45:25 -0700 | [diff] [blame] | 42 | struct ip_auth_hdr; |
| 43 | |
| 44 | static inline struct ip_auth_hdr *ip_auth_hdr(const struct sk_buff *skb) |
| 45 | { |
| 46 | return (struct ip_auth_hdr *)skb_transport_header(skb); |
| 47 | } |
| 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #endif |