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