crypto: hash - prevent using keyed hashes without setting key
[pandora-kernel.git] / include / crypto / hash.h
index c8c7987..9fa0f77 100644 (file)
@@ -94,7 +94,6 @@ struct crypto_ahash {
                      unsigned int keylen);
 
        unsigned int reqsize;
-       bool has_setkey;
        struct crypto_tfm base;
 };
 
@@ -182,11 +181,6 @@ static inline void *ahash_request_ctx(struct ahash_request *req)
 
 int crypto_ahash_setkey(struct crypto_ahash *tfm, const u8 *key,
                        unsigned int keylen);
-static inline bool crypto_ahash_has_setkey(struct crypto_ahash *tfm)
-{
-       return tfm->has_setkey;
-}
-
 int crypto_ahash_finup(struct ahash_request *req);
 int crypto_ahash_final(struct ahash_request *req);
 int crypto_ahash_digest(struct ahash_request *req);
@@ -198,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)
@@ -342,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,