esp.h 1.5 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. u8 *key; /* Key */
  13. int key_len; /* Key length */
  14. int padlen; /* 0..255 */
  15. /* ivlen is offset from enc_data, where encrypted data start.
  16. * It is logically different of crypto_tfm_alg_ivsize(tfm).
  17. * We assume that it is either zero (no ivec), or
  18. * >= crypto_tfm_alg_ivsize(tfm). */
  19. int ivlen;
  20. int ivinitted;
  21. u8 *ivec; /* ivec buffer */
  22. struct crypto_blkcipher *tfm; /* crypto handle */
  23. } conf;
  24. /* Integrity. It is active when icv_full_len != 0 */
  25. struct {
  26. u8 *key; /* Key */
  27. int key_len; /* Length of the key */
  28. u8 *work_icv;
  29. int icv_full_len;
  30. int icv_trunc_len;
  31. void (*icv)(struct esp_data*,
  32. struct sk_buff *skb,
  33. int offset, int len, u8 *icv);
  34. struct crypto_hash *tfm;
  35. } auth;
  36. };
  37. extern void *pskb_put(struct sk_buff *skb, struct sk_buff *tail, int len);
  38. static inline int esp_mac_digest(struct esp_data *esp, struct sk_buff *skb,
  39. int offset, int len)
  40. {
  41. struct hash_desc desc;
  42. int err;
  43. desc.tfm = esp->auth.tfm;
  44. desc.flags = 0;
  45. err = crypto_hash_init(&desc);
  46. if (unlikely(err))
  47. return err;
  48. err = skb_icv_walk(skb, &desc, offset, len, crypto_hash_update);
  49. if (unlikely(err))
  50. return err;
  51. return crypto_hash_final(&desc, esp->auth.work_icv);
  52. }
  53. #endif