6128cd4ea0a9d8bb5c0a2eb1e4b28b028a4a1404
[platform/upstream/cryptsetup.git] / lib / crypto_backend / crypto_backend_internal.h
1 /*
2  * crypto backend implementation
3  *
4  * Copyright (C) 2010-2020 Red Hat, Inc. All rights reserved.
5  * Copyright (C) 2010-2020 Milan Broz
6  *
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.
11  *
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.
16  *
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.
20  */
21 #ifndef _CRYPTO_BACKEND_INTERNAL_H
22 #define _CRYPTO_BACKEND_INTERNAL_H
23
24 #include "crypto_backend.h"
25
26 #if USE_INTERNAL_PBKDF2
27 /* internal PBKDF2 implementation */
28 int pkcs5_pbkdf2(const char *hash,
29                  const char *P, size_t Plen,
30                  const char *S, size_t Slen,
31                  unsigned int c,
32                  unsigned int dkLen, char *DK,
33                  unsigned int hash_block_size);
34 #endif
35
36 /* Argon2 implementation wrapper */
37 int argon2(const char *type, const char *password, size_t password_length,
38            const char *salt, size_t salt_length,
39            char *key, size_t key_length,
40            uint32_t iterations, uint32_t memory, uint32_t parallel);
41
42 /* Block ciphers: fallback to kernel crypto API */
43
44 struct crypt_cipher_kernel {
45         int tfmfd;
46         int opfd;
47 };
48
49 int crypt_cipher_init_kernel(struct crypt_cipher_kernel *ctx, const char *name,
50                              const char *mode, const void *key, size_t key_length);
51 int crypt_cipher_encrypt_kernel(struct crypt_cipher_kernel *ctx,
52                                 const char *in, char *out, size_t length,
53                                 const char *iv, size_t iv_length);
54 int crypt_cipher_decrypt_kernel(struct crypt_cipher_kernel *ctx,
55                                 const char *in, char *out, size_t length,
56                                 const char *iv, size_t iv_length);
57 void crypt_cipher_destroy_kernel(struct crypt_cipher_kernel *ctx);
58 int crypt_bitlk_decrypt_key_kernel(const void *key, size_t key_length,
59                                    const char *in, char *out, size_t length,
60                                    const char *iv, size_t iv_length,
61                                    const char *tag, size_t tag_length);
62
63 #endif /* _CRYPTO_BACKEND_INTERNAL_H */