2 * crypto backend implementation
4 * Copyright (C) 2010-2012, Red Hat, Inc. All rights reserved.
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.
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.
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.
19 #ifndef _CRYPTO_BACKEND_H
20 #define _CRYPTO_BACKEND_H
30 int crypt_backend_init(struct crypt_device *ctx);
32 #define CRYPT_BACKEND_KERNEL (1 << 0) /* Crypto uses kernel part, for benchmark */
34 uint32_t crypt_backend_flags(void);
35 const char *crypt_backend_version(void);
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);
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);
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);
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);
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,
69 unsigned int dkLen,char *DK);
72 uint32_t crypt_crc32(uint32_t seed, const unsigned char *buf, size_t len);
74 #endif /* _CRYPTO_BACKEND_H */