esp.h 1.4 KB

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