History

crypto: provide single place for hash algo information

This patch provides a single place for information about hash algorithms, such as hash sizes and kernel driver names, which will be used by IMA and the public key code. Changelog: - Fix sparse and checkpatch warnings - Move hash algo enums to uapi for userspace signing functions.

Dmitry Kasatkin committed 13 years ago

Commit ee089971 parent 08de59e5 files · +137 −0Browse files

Unified · Split

5 files
  1. crypto/Kconfig +3 −0
  2. crypto/Makefile +1 −0
  3. crypto/hash_info.c +56 −0
  4. include/crypto/hash_info.h +40 −0
  5. include/uapi/linux/hash_info.h +37 −0
crypto/Kconfig+3−0
@@ -1386,6 +1386,9 @@ config CRYPTO_USER_API_SKCIPHER · 1385 unmodified lines
1386 This option enables the user-spaces interface for symmetric1386 This option enables the user-spaces interface for symmetric
1387 key cipher algorithms.1387 key cipher algorithms.
1388 1388
1389config CRYPTO_HASH_INFO
1390 bool
1391
1389source "drivers/crypto/Kconfig"1392source "drivers/crypto/Kconfig"
1390source crypto/asymmetric_keys/Kconfig1393source crypto/asymmetric_keys/Kconfig
1391 1394
crypto/Makefile+1−0
@@ -104,3 +104,4 @@ obj-$(CONFIG_CRYPTO_USER_API_SKCIPHER) += algif_skcipher.o · 103 unmodified lines
104obj-$(CONFIG_XOR_BLOCKS) += xor.o104obj-$(CONFIG_XOR_BLOCKS) += xor.o
105obj-$(CONFIG_ASYNC_CORE) += async_tx/105obj-$(CONFIG_ASYNC_CORE) += async_tx/
106obj-$(CONFIG_ASYMMETRIC_KEY_TYPE) += asymmetric_keys/106obj-$(CONFIG_ASYMMETRIC_KEY_TYPE) += asymmetric_keys/
107obj-$(CONFIG_CRYPTO_HASH_INFO) += hash_info.o
crypto/hash_info.c+56−0
@@ -0,0 +1,56 @@
1/*
2 * Hash Info: Hash algorithms information
3 *
4 * Copyright (c) 2013 Dmitry Kasatkin <d.kasatkin@samsung.com>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 */
12
13#include <linux/export.h>
14#include <crypto/hash_info.h>
15
16const char *const hash_algo_name[HASH_ALGO__LAST] = {
17 [HASH_ALGO_MD4] = "md4",
18 [HASH_ALGO_MD5] = "md5",
19 [HASH_ALGO_SHA1] = "sha1",
20 [HASH_ALGO_RIPE_MD_160] = "rmd160",
21 [HASH_ALGO_SHA256] = "sha256",
22 [HASH_ALGO_SHA384] = "sha384",
23 [HASH_ALGO_SHA512] = "sha512",
24 [HASH_ALGO_SHA224] = "sha224",
25 [HASH_ALGO_RIPE_MD_128] = "rmd128",
26 [HASH_ALGO_RIPE_MD_256] = "rmd256",
27 [HASH_ALGO_RIPE_MD_320] = "rmd320",
28 [HASH_ALGO_WP_256] = "wp256",
29 [HASH_ALGO_WP_384] = "wp384",
30 [HASH_ALGO_WP_512] = "wp512",
31 [HASH_ALGO_TGR_128] = "tgr128",
32 [HASH_ALGO_TGR_160] = "tgr160",
33 [HASH_ALGO_TGR_192] = "tgr192",
34};
35EXPORT_SYMBOL_GPL(hash_algo_name);
36
37const int hash_digest_size[HASH_ALGO__LAST] = {
38 [HASH_ALGO_MD4] = MD5_DIGEST_SIZE,
39 [HASH_ALGO_MD5] = MD5_DIGEST_SIZE,
40 [HASH_ALGO_SHA1] = SHA1_DIGEST_SIZE,
41 [HASH_ALGO_RIPE_MD_160] = RMD160_DIGEST_SIZE,
42 [HASH_ALGO_SHA256] = SHA256_DIGEST_SIZE,
43 [HASH_ALGO_SHA384] = SHA384_DIGEST_SIZE,
44 [HASH_ALGO_SHA512] = SHA512_DIGEST_SIZE,
45 [HASH_ALGO_SHA224] = SHA224_DIGEST_SIZE,
46 [HASH_ALGO_RIPE_MD_128] = RMD128_DIGEST_SIZE,
47 [HASH_ALGO_RIPE_MD_256] = RMD256_DIGEST_SIZE,
48 [HASH_ALGO_RIPE_MD_320] = RMD320_DIGEST_SIZE,
49 [HASH_ALGO_WP_256] = WP256_DIGEST_SIZE,
50 [HASH_ALGO_WP_384] = WP384_DIGEST_SIZE,
51 [HASH_ALGO_WP_512] = WP512_DIGEST_SIZE,
52 [HASH_ALGO_TGR_128] = TGR128_DIGEST_SIZE,
53 [HASH_ALGO_TGR_160] = TGR160_DIGEST_SIZE,
54 [HASH_ALGO_TGR_192] = TGR192_DIGEST_SIZE,
55};
56EXPORT_SYMBOL_GPL(hash_digest_size);
include/crypto/hash_info.h+40−0
@@ -0,0 +1,40 @@
1/*
2 * Hash Info: Hash algorithms information
3 *
4 * Copyright (c) 2013 Dmitry Kasatkin <d.kasatkin@samsung.com>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 */
12
13#ifndef _CRYPTO_HASH_INFO_H
14#define _CRYPTO_HASH_INFO_H
15
16#include <crypto/sha.h>
17#include <crypto/md5.h>
18
19#include <uapi/linux/hash_info.h>
20
21/* not defined in include/crypto/ */
22#define RMD128_DIGEST_SIZE 16
23#define RMD160_DIGEST_SIZE 20
24#define RMD256_DIGEST_SIZE 32
25#define RMD320_DIGEST_SIZE 40
26
27/* not defined in include/crypto/ */
28#define WP512_DIGEST_SIZE 64
29#define WP384_DIGEST_SIZE 48
30#define WP256_DIGEST_SIZE 32
31
32/* not defined in include/crypto/ */
33#define TGR128_DIGEST_SIZE 16
34#define TGR160_DIGEST_SIZE 20
35#define TGR192_DIGEST_SIZE 24
36
37extern const char *const hash_algo_name[HASH_ALGO__LAST];
38extern const int hash_digest_size[HASH_ALGO__LAST];
39
40#endif /* _CRYPTO_HASH_INFO_H */
include/uapi/linux/hash_info.h+37−0
@@ -0,0 +1,37 @@
1/*
2 * Hash Info: Hash algorithms information
3 *
4 * Copyright (c) 2013 Dmitry Kasatkin <d.kasatkin@samsung.com>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 */
12
13#ifndef _UAPI_LINUX_HASH_INFO_H
14#define _UAPI_LINUX_HASH_INFO_H
15
16enum hash_algo {
17 HASH_ALGO_MD4,
18 HASH_ALGO_MD5,
19 HASH_ALGO_SHA1,
20 HASH_ALGO_RIPE_MD_160,
21 HASH_ALGO_SHA256,
22 HASH_ALGO_SHA384,
23 HASH_ALGO_SHA512,
24 HASH_ALGO_SHA224,
25 HASH_ALGO_RIPE_MD_128,
26 HASH_ALGO_RIPE_MD_256,
27 HASH_ALGO_RIPE_MD_320,
28 HASH_ALGO_WP_256,
29 HASH_ALGO_WP_384,
30 HASH_ALGO_WP_512,
31 HASH_ALGO_TGR_128,
32 HASH_ALGO_TGR_160,
33 HASH_ALGO_TGR_192,
34 HASH_ALGO__LAST
35};
36
37#endif /* _UAPI_LINUX_HASH_INFO_H */