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 | { |
| 12 | u8 *key; |
| 13 | int key_len; |
| 14 | u8 *work_icv; |
| 15 | int icv_full_len; |
| 16 | int icv_trunc_len; |
| 17 | |
Herbert Xu | 07d4ee5 | 2006-08-20 14:24:50 +1000 | [diff] [blame] | 18 | struct crypto_hash *tfm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | }; |
| 20 | |
Herbert Xu | 07d4ee5 | 2006-08-20 14:24:50 +1000 | [diff] [blame] | 21 | static inline int ah_mac_digest(struct ah_data *ahp, struct sk_buff *skb, |
| 22 | u8 *auth_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | { |
Herbert Xu | 07d4ee5 | 2006-08-20 14:24:50 +1000 | [diff] [blame] | 24 | struct hash_desc desc; |
| 25 | int err; |
| 26 | |
| 27 | desc.tfm = ahp->tfm; |
| 28 | desc.flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | memset(auth_data, 0, ahp->icv_trunc_len); |
Herbert Xu | 07d4ee5 | 2006-08-20 14:24:50 +1000 | [diff] [blame] | 31 | err = crypto_hash_init(&desc); |
| 32 | if (unlikely(err)) |
| 33 | goto out; |
| 34 | err = skb_icv_walk(skb, &desc, 0, skb->len, crypto_hash_update); |
| 35 | if (unlikely(err)) |
| 36 | goto out; |
| 37 | err = crypto_hash_final(&desc, ahp->work_icv); |
| 38 | |
| 39 | out: |
| 40 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | #endif |