5edcb6b8c9b90971c578736f51db78bd6d45e4ce
[platform/upstream/cryptsetup.git] / lib / crypto_backend / crypto_backend.h
1 /*
2  * crypto backend implementation
3  *
4  * Copyright (C) 2010-2012, Red Hat, Inc. All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * version 2 as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 #ifndef _CRYPTO_BACKEND_H
20 #define _CRYPTO_BACKEND_H
21
22 #include <stdint.h>
23 #include <string.h>
24 #include "config.h"
25
26 struct crypt_device;
27 struct crypt_hash;
28 struct crypt_hmac;
29
30 int crypt_backend_init(struct crypt_device *ctx);
31
32 #define CRYPT_BACKEND_KERNEL (1 << 0)   /* Crypto uses kernel part, for benchmark */
33
34 uint32_t crypt_backend_flags(void);
35 const char *crypt_backend_version(void);
36
37 /* HASH */
38 int crypt_hash_size(const char *name);
39 int crypt_hash_init(struct crypt_hash **ctx, const char *name);
40 int crypt_hash_write(struct crypt_hash *ctx, const char *buffer, size_t length);
41 int crypt_hash_final(struct crypt_hash *ctx, char *buffer, size_t length);
42 int crypt_hash_destroy(struct crypt_hash *ctx);
43
44 /* HMAC */
45 int crypt_hmac_size(const char *name);
46 int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
47                     const void *buffer, size_t length);
48 int crypt_hmac_write(struct crypt_hmac *ctx, const char *buffer, size_t length);
49 int crypt_hmac_final(struct crypt_hmac *ctx, char *buffer, size_t length);
50 int crypt_hmac_destroy(struct crypt_hmac *ctx);
51
52 /* RNG (if fips paramater set, must provide FIPS compliance) */
53 enum { CRYPT_RND_NORMAL = 0, CRYPT_RND_KEY = 1, CRYPT_RND_SALT = 2 };
54 int crypt_backend_rng(char *buffer, size_t length, int quality, int fips);
55
56 /* PBKDF*/
57 int crypt_pbkdf_check(const char *kdf, const char *hash, uint64_t *iter_secs);
58 int crypt_pbkdf(const char *kdf, const char *hash,
59                 const char *password, size_t password_length,
60                 const char *salt, size_t salt_length,
61                 char *key, size_t key_length,
62                 unsigned int iterations);
63
64 /* internal PBKDF2 implementation */
65 int pkcs5_pbkdf2(const char *hash,
66                  const char *P, size_t Plen,
67                  const char *S, size_t Slen,
68                  unsigned int c,
69                  unsigned int dkLen,char *DK);
70
71 /* CRC32 */
72 uint32_t crypt_crc32(uint32_t seed, const unsigned char *buf, size_t len);
73
74 #endif /* _CRYPTO_BACKEND_H */