Blame view

kernel/linux-imx6_3.14.28/fs/btrfs/hash.c 1.11 KB
6b13f685e   김민수   BSP 최초 추가
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  /*
   * 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);
  	if (IS_ERR(tfm))
  		return PTR_ERR(tfm);
  
  	return 0;
  }
  
  void btrfs_hash_exit(void)
  {
  	crypto_free_shash(tfm);
  }
  
  u32 btrfs_crc32c(u32 crc, const void *address, unsigned int length)
  {
  	struct {
  		struct shash_desc shash;
  		char ctx[crypto_shash_descsize(tfm)];
  	} desc;
  	int err;
  
  	desc.shash.tfm = tfm;
  	desc.shash.flags = 0;
  	*(u32 *)desc.ctx = crc;
  
  	err = crypto_shash_update(&desc.shash, address, length);
  	BUG_ON(err);
  
  	return *(u32 *)desc.ctx;
  }