Btrfs: Fix misuse of chunk mutex
[deliverable/linux.git] / fs / btrfs / hash.c
CommitLineData
14a958e6
FDBM
1/*
2 * Copyright (C) 2014 Filipe David Borba Manana <fdmanana@gmail.com>
3 *
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.
7 *
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.
12 */
13
14#include <crypto/hash.h>
15#include <linux/err.h>
16#include "hash.h"
17
18static struct crypto_shash *tfm;
19
20int __init btrfs_hash_init(void)
21{
22 tfm = crypto_alloc_shash("crc32c", 0, 0);
14a958e6 23
6f84e236 24 return PTR_ERR_OR_ZERO(tfm);
14a958e6
FDBM
25}
26
27void btrfs_hash_exit(void)
28{
29 crypto_free_shash(tfm);
30}
31
32u32 btrfs_crc32c(u32 crc, const void *address, unsigned int length)
33{
34 struct {
35 struct shash_desc shash;
36 char ctx[crypto_shash_descsize(tfm)];
37 } desc;
38 int err;
39
40 desc.shash.tfm = tfm;
41 desc.shash.flags = 0;
42 *(u32 *)desc.ctx = crc;
43
44 err = crypto_shash_update(&desc.shash, address, length);
45 BUG_ON(err);
46
47 return *(u32 *)desc.ctx;
48}
This page took 0.059778 seconds and 5 git commands to generate.