crypto: hash - prevent using keyed hashes without setting key
[pandora-kernel.git] / include / crypto / hash.h
index 26cb1eb..9fa0f77 100644 (file)
@@ -192,12 +192,22 @@ static inline int crypto_ahash_export(struct ahash_request *req, void *out)
 
 static inline int crypto_ahash_import(struct ahash_request *req, const void *in)
 {
-       return crypto_ahash_reqtfm(req)->import(req, in);
+       struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
+
+       if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
+               return -ENOKEY;
+
+       return tfm->import(req, in);
 }
 
 static inline int crypto_ahash_init(struct ahash_request *req)
 {
-       return crypto_ahash_reqtfm(req)->init(req);
+       struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
+
+       if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
+               return -ENOKEY;
+
+       return tfm->init(req);
 }
 
 static inline int crypto_ahash_update(struct ahash_request *req)
@@ -336,12 +346,22 @@ static inline int crypto_shash_export(struct shash_desc *desc, void *out)
 
 static inline int crypto_shash_import(struct shash_desc *desc, const void *in)
 {
-       return crypto_shash_alg(desc->tfm)->import(desc, in);
+       struct crypto_shash *tfm = desc->tfm;
+
+       if (crypto_shash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
+               return -ENOKEY;
+
+       return crypto_shash_alg(tfm)->import(desc, in);
 }
 
 static inline int crypto_shash_init(struct shash_desc *desc)
 {
-       return crypto_shash_alg(desc->tfm)->init(desc);
+       struct crypto_shash *tfm = desc->tfm;
+
+       if (crypto_shash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
+               return -ENOKEY;
+
+       return crypto_shash_alg(tfm)->init(desc);
 }
 
 int crypto_shash_update(struct shash_desc *desc, const u8 *data,