2 * crypto backend implementation
4 * Copyright (C) 2010-2012, Red Hat, Inc. All rights reserved.
5 * Copyright (C) 2010-2012, Milan Broz
7 * This file is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This file is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this file; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #ifndef _CRYPTO_BACKEND_H
22 #define _CRYPTO_BACKEND_H
32 int crypt_backend_init(struct crypt_device *ctx);
34 #define CRYPT_BACKEND_KERNEL (1 << 0) /* Crypto uses kernel part, for benchmark */
36 uint32_t crypt_backend_flags(void);
37 const char *crypt_backend_version(void);
40 int crypt_hash_size(const char *name);
41 int crypt_hash_init(struct crypt_hash **ctx, const char *name);
42 int crypt_hash_write(struct crypt_hash *ctx, const char *buffer, size_t length);
43 int crypt_hash_final(struct crypt_hash *ctx, char *buffer, size_t length);
44 int crypt_hash_destroy(struct crypt_hash *ctx);
47 int crypt_hmac_size(const char *name);
48 int crypt_hmac_init(struct crypt_hmac **ctx, const char *name,
49 const void *buffer, size_t length);
50 int crypt_hmac_write(struct crypt_hmac *ctx, const char *buffer, size_t length);
51 int crypt_hmac_final(struct crypt_hmac *ctx, char *buffer, size_t length);
52 int crypt_hmac_destroy(struct crypt_hmac *ctx);
54 /* RNG (if fips paramater set, must provide FIPS compliance) */
55 enum { CRYPT_RND_NORMAL = 0, CRYPT_RND_KEY = 1, CRYPT_RND_SALT = 2 };
56 int crypt_backend_rng(char *buffer, size_t length, int quality, int fips);
59 int crypt_pbkdf_check(const char *kdf, const char *hash,
60 const char *password, size_t password_size,
61 const char *salt, size_t salt_size,
63 int crypt_pbkdf(const char *kdf, const char *hash,
64 const char *password, size_t password_length,
65 const char *salt, size_t salt_length,
66 char *key, size_t key_length,
67 unsigned int iterations);
69 #if USE_INTERNAL_PBKDF2
70 /* internal PBKDF2 implementation */
71 int pkcs5_pbkdf2(const char *hash,
72 const char *P, size_t Plen,
73 const char *S, size_t Slen,
75 unsigned int dkLen,char *DK);
79 uint32_t crypt_crc32(uint32_t seed, const unsigned char *buf, size_t len);
82 int crypt_cipher_init(struct crypt_cipher **ctx, const char *name,
83 const char *mode, const void *buffer, size_t length);
84 int crypt_cipher_destroy(struct crypt_cipher *ctx);
85 int crypt_cipher_encrypt(struct crypt_cipher *ctx,
86 const char *in, char *out, size_t length,
87 const char *iv, size_t iv_length);
88 int crypt_cipher_decrypt(struct crypt_cipher *ctx,
89 const char *in, char *out, size_t length,
90 const char *iv, size_t iv_length);
92 #endif /* _CRYPTO_BACKEND_H */