xref: /third_party/openssl/engines/e_afalg.h (revision e1051a39)
1e1051a39Sopenharmony_ci/*
2e1051a39Sopenharmony_ci * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
3e1051a39Sopenharmony_ci *
4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License").  You may not use
5e1051a39Sopenharmony_ci * this file except in compliance with the License.  You can obtain a copy
6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at
7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html
8e1051a39Sopenharmony_ci */
9e1051a39Sopenharmony_ci
10e1051a39Sopenharmony_ci#ifndef OSSL_ENGINES_E_AFALG_H
11e1051a39Sopenharmony_ci# define OSSL_ENGINES_E_AFALG_H
12e1051a39Sopenharmony_ci
13e1051a39Sopenharmony_ci# if defined(__GNUC__) && __GNUC__ >= 4 && \
14e1051a39Sopenharmony_ci     (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L)
15e1051a39Sopenharmony_ci#  pragma GCC diagnostic ignored "-Wvariadic-macros"
16e1051a39Sopenharmony_ci# endif
17e1051a39Sopenharmony_ci
18e1051a39Sopenharmony_ci# ifdef ALG_DEBUG
19e1051a39Sopenharmony_ci#  define ALG_DGB(x, ...) fprintf(stderr, "ALG_DBG: " x, __VA_ARGS__)
20e1051a39Sopenharmony_ci#  define ALG_INFO(x, ...) fprintf(stderr, "ALG_INFO: " x, __VA_ARGS__)
21e1051a39Sopenharmony_ci#  define ALG_WARN(x, ...) fprintf(stderr, "ALG_WARN: " x, __VA_ARGS__)
22e1051a39Sopenharmony_ci# else
23e1051a39Sopenharmony_ci#  define ALG_DGB(x, ...)
24e1051a39Sopenharmony_ci#  define ALG_INFO(x, ...)
25e1051a39Sopenharmony_ci#  define ALG_WARN(x, ...)
26e1051a39Sopenharmony_ci# endif
27e1051a39Sopenharmony_ci
28e1051a39Sopenharmony_ci# define ALG_ERR(x, ...) fprintf(stderr, "ALG_ERR: " x, __VA_ARGS__)
29e1051a39Sopenharmony_ci# define ALG_PERR(x, ...) \
30e1051a39Sopenharmony_ci                do { \
31e1051a39Sopenharmony_ci                    fprintf(stderr, "ALG_PERR: " x, __VA_ARGS__); \
32e1051a39Sopenharmony_ci                    perror(NULL); \
33e1051a39Sopenharmony_ci                } while(0)
34e1051a39Sopenharmony_ci# define ALG_PWARN(x, ...) \
35e1051a39Sopenharmony_ci                do { \
36e1051a39Sopenharmony_ci                    fprintf(stderr, "ALG_PERR: " x, __VA_ARGS__); \
37e1051a39Sopenharmony_ci                    perror(NULL); \
38e1051a39Sopenharmony_ci                } while(0)
39e1051a39Sopenharmony_ci
40e1051a39Sopenharmony_ci# ifndef AES_BLOCK_SIZE
41e1051a39Sopenharmony_ci#  define AES_BLOCK_SIZE   16
42e1051a39Sopenharmony_ci# endif
43e1051a39Sopenharmony_ci# define AES_KEY_SIZE_128 16
44e1051a39Sopenharmony_ci# define AES_KEY_SIZE_192 24
45e1051a39Sopenharmony_ci# define AES_KEY_SIZE_256 32
46e1051a39Sopenharmony_ci# define AES_IV_LEN       16
47e1051a39Sopenharmony_ci
48e1051a39Sopenharmony_ci# define MAX_INFLIGHTS 1
49e1051a39Sopenharmony_ci
50e1051a39Sopenharmony_citypedef enum {
51e1051a39Sopenharmony_ci    MODE_UNINIT = 0,
52e1051a39Sopenharmony_ci    MODE_SYNC,
53e1051a39Sopenharmony_ci    MODE_ASYNC
54e1051a39Sopenharmony_ci} op_mode;
55e1051a39Sopenharmony_ci
56e1051a39Sopenharmony_cienum {
57e1051a39Sopenharmony_ci    AES_CBC_128 = 0,
58e1051a39Sopenharmony_ci    AES_CBC_192,
59e1051a39Sopenharmony_ci    AES_CBC_256
60e1051a39Sopenharmony_ci};
61e1051a39Sopenharmony_ci
62e1051a39Sopenharmony_cistruct cbc_cipher_handles {
63e1051a39Sopenharmony_ci    int key_size;
64e1051a39Sopenharmony_ci    EVP_CIPHER *_hidden;
65e1051a39Sopenharmony_ci};
66e1051a39Sopenharmony_ci
67e1051a39Sopenharmony_citypedef struct cbc_cipher_handles cbc_handles;
68e1051a39Sopenharmony_ci
69e1051a39Sopenharmony_cistruct afalg_aio_st {
70e1051a39Sopenharmony_ci    int efd;
71e1051a39Sopenharmony_ci    op_mode mode;
72e1051a39Sopenharmony_ci    aio_context_t aio_ctx;
73e1051a39Sopenharmony_ci    struct io_event events[MAX_INFLIGHTS];
74e1051a39Sopenharmony_ci    struct iocb cbt[MAX_INFLIGHTS];
75e1051a39Sopenharmony_ci};
76e1051a39Sopenharmony_citypedef struct afalg_aio_st afalg_aio;
77e1051a39Sopenharmony_ci
78e1051a39Sopenharmony_ci/*
79e1051a39Sopenharmony_ci * MAGIC Number to identify correct initialisation
80e1051a39Sopenharmony_ci * of afalg_ctx.
81e1051a39Sopenharmony_ci */
82e1051a39Sopenharmony_ci# define MAGIC_INIT_NUM 0x1890671
83e1051a39Sopenharmony_ci
84e1051a39Sopenharmony_cistruct afalg_ctx_st {
85e1051a39Sopenharmony_ci    int init_done;
86e1051a39Sopenharmony_ci    int sfd;
87e1051a39Sopenharmony_ci    int bfd;
88e1051a39Sopenharmony_ci# ifdef ALG_ZERO_COPY
89e1051a39Sopenharmony_ci    int zc_pipe[2];
90e1051a39Sopenharmony_ci# endif
91e1051a39Sopenharmony_ci    afalg_aio aio;
92e1051a39Sopenharmony_ci};
93e1051a39Sopenharmony_ci
94e1051a39Sopenharmony_citypedef struct afalg_ctx_st afalg_ctx;
95e1051a39Sopenharmony_ci#endif
96