aboutsummaryrefslogtreecommitdiffstats
path: root/package/utils/uencrypt/src/uencrypt.h
blob: a4fe1f337626395656d79703ae6bbf3417c18e53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* SPDX-License-Identifier: GPL-2.0-or-later
 * Copyright (C) 2022-2023 Eneas Ulir de Queiroz
 */

#include <stdio.h>

#define CRYPT_BUF_SIZE 1024

#ifdef USE_MBEDTLS
# include <mbedtls/cipher.h>

# if defined(MBEDTLS_MAX_BLOCK_LENGTH) \
     && MBEDTLS_MAX_BLOCK_LENGTH > CRYPT_BUF_SIZE
#  undef CRYPT_BUF_SIZE
#  define CRYPT_BUF_SIZE MAX_BLOCK_LENGTH
# endif

unsigned char *hexstr2buf(const char* str, long *len);

#else /* USE_MBEDTLS */
# ifdef USE_WOLFSSL
#  include <wolfssl/options.h>
#  include <wolfssl/openssl/evp.h>
# else
#  include <openssl/evp.h>
# endif

# if defined(EVP_MAX_BLOCK_LENGTH) \
     && EVP_MAX_BLOCK_LENGTH > CRYPT_BUF_SIZE
#  undef CRYPT_BUF_SIZE
#  define CRYPT_BUF_SIZE EVP_MAX_BLOCK_LENGTH
# endif

# define hexstr2buf OPENSSL_hexstr2buf

#endif /* USE_MBEDTLS */

typedef void cipher_t;
typedef void ctx_t;

const cipher_t *get_default_cipher(void);
const cipher_t *get_cipher_or_print_error(char *name);
int get_cipher_ivsize(const cipher_t *cipher);
int get_cipher_keysize(const cipher_t *cipher);

ctx_t *create_ctx(const cipher_t *cipher, const unsigned char *key,
		  const unsigned char *iv, int enc, int padding);
int do_crypt(FILE *infile, FILE *outfile, ctx_t *ctx);
void free_ctx(ctx_t *ctx);