2 * Copyright (C) 2014 Filipe David Borba Manana <fdmanana@gmail.com>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
14 #include <crypto/hash.h>
15 #include <linux/err.h>
18 static struct crypto_shash
*tfm
;
20 int __init
btrfs_hash_init(void)
22 tfm
= crypto_alloc_shash("crc32c", 0, 0);
29 void btrfs_hash_exit(void)
31 crypto_free_shash(tfm
);
34 u32
btrfs_crc32c(u32 crc
, const void *address
, unsigned int length
)
37 struct shash_desc shash
;
38 char ctx
[crypto_shash_descsize(tfm
)];
44 *(u32
*)desc
.ctx
= crc
;
46 err
= crypto_shash_update(&desc
.shash
, address
, length
);
49 return *(u32
*)desc
.ctx
;