Blame view
fs/btrfs/hash.c
1.14 KB
14a958e67
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
/* * Copyright (C) 2014 Filipe David Borba Manana <fdmanana@gmail.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License v2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. */ #include <crypto/hash.h> #include <linux/err.h> #include "hash.h" static struct crypto_shash *tfm; int __init btrfs_hash_init(void) { tfm = crypto_alloc_shash("crc32c", 0, 0); |
14a958e67
|
23 |
|
6f84e2364
|
24 |
return PTR_ERR_OR_ZERO(tfm); |
14a958e67
|
25 |
} |
5f9e1059d
|
26 27 28 29 |
const char* btrfs_crc32c_impl(void) { return crypto_tfm_alg_driver_name(crypto_shash_tfm(tfm)); } |
14a958e67
|
30 31 32 33 34 35 36 |
void btrfs_hash_exit(void) { crypto_free_shash(tfm); } u32 btrfs_crc32c(u32 crc, const void *address, unsigned int length) { |
0458a953d
|
37 38 |
SHASH_DESC_ON_STACK(shash, tfm); u32 *ctx = (u32 *)shash_desc_ctx(shash); |
14a958e67
|
39 |
int err; |
0458a953d
|
40 41 42 |
shash->tfm = tfm; shash->flags = 0; *ctx = crc; |
14a958e67
|
43 |
|
0458a953d
|
44 |
err = crypto_shash_update(shash, address, length); |
14a958e67
|
45 |
BUG_ON(err); |
0458a953d
|
46 |
return *ctx; |
14a958e67
|
47 |
} |