]> err.no Git - linux-2.6/blobdiff - include/net/esp.h
[IPSEC]: Use HMAC template and hash interface
[linux-2.6] / include / net / esp.h
index 90cd94fad7d9cbbc286caa2d7b9674b924f61877..064366d66eead993061d9752958b2d4ee739e3c1 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef _NET_ESP_H
 #define _NET_ESP_H
 
+#include <linux/crypto.h>
 #include <net/xfrm.h>
 #include <asm/scatterlist.h>
 
@@ -21,7 +22,7 @@ struct esp_data
                 * >= crypto_tfm_alg_ivsize(tfm). */
                int                     ivlen;
                int                     padlen;         /* 0..255 */
-               struct crypto_tfm       *tfm;           /* crypto handle */
+               struct crypto_blkcipher *tfm;           /* crypto handle */
        } conf;
 
        /* Integrity. It is active when icv_full_len != 0 */
@@ -34,7 +35,7 @@ struct esp_data
                void                    (*icv)(struct esp_data*,
                                               struct sk_buff *skb,
                                               int offset, int len, u8 *icv);
-               struct crypto_tfm       *tfm;
+               struct crypto_hash      *tfm;
        } auth;
 };
 
@@ -42,18 +43,22 @@ extern int skb_to_sgvec(struct sk_buff *skb, struct scatterlist *sg, int offset,
 extern int skb_cow_data(struct sk_buff *skb, int tailbits, struct sk_buff **trailer);
 extern void *pskb_put(struct sk_buff *skb, struct sk_buff *tail, int len);
 
-static inline void
-esp_hmac_digest(struct esp_data *esp, struct sk_buff *skb, int offset,
-                int len, u8 *auth_data)
+static inline int esp_mac_digest(struct esp_data *esp, struct sk_buff *skb,
+                                int offset, int len)
 {
-       struct crypto_tfm *tfm = esp->auth.tfm;
-       char *icv = esp->auth.work_icv;
-
-       memset(auth_data, 0, esp->auth.icv_trunc_len);
-       crypto_hmac_init(tfm, esp->auth.key, &esp->auth.key_len);
-       skb_icv_walk(skb, tfm, offset, len, crypto_hmac_update);
-       crypto_hmac_final(tfm, esp->auth.key, &esp->auth.key_len, icv);
-       memcpy(auth_data, icv, esp->auth.icv_trunc_len);
+       struct hash_desc desc;
+       int err;
+
+       desc.tfm = esp->auth.tfm;
+       desc.flags = 0;
+
+       err = crypto_hash_init(&desc);
+       if (unlikely(err))
+               return err;
+       err = skb_icv_walk(skb, &desc, offset, len, crypto_hash_update);
+       if (unlikely(err))
+               return err;
+       return crypto_hash_final(&desc, esp->auth.work_icv);
 }
 
 #endif