e_afalg.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #ifndef HEADER_AFALG_H
  10. # define HEADER_AFALG_H
  11. # if defined(__GNUC__) && __GNUC__ >= 4 && \
  12. (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L)
  13. # pragma GCC diagnostic ignored "-Wvariadic-macros"
  14. # endif
  15. # ifdef ALG_DEBUG
  16. # define ALG_DGB(x, ...) fprintf(stderr, "ALG_DBG: " x, __VA_ARGS__)
  17. # define ALG_INFO(x, ...) fprintf(stderr, "ALG_INFO: " x, __VA_ARGS__)
  18. # define ALG_WARN(x, ...) fprintf(stderr, "ALG_WARN: " x, __VA_ARGS__)
  19. # else
  20. # define ALG_DGB(x, ...)
  21. # define ALG_INFO(x, ...)
  22. # define ALG_WARN(x, ...)
  23. # endif
  24. # define ALG_ERR(x, ...) fprintf(stderr, "ALG_ERR: " x, __VA_ARGS__)
  25. # define ALG_PERR(x, ...) \
  26. do { \
  27. fprintf(stderr, "ALG_PERR: " x, __VA_ARGS__); \
  28. perror(NULL); \
  29. } while(0)
  30. # define ALG_PWARN(x, ...) \
  31. do { \
  32. fprintf(stderr, "ALG_PERR: " x, __VA_ARGS__); \
  33. perror(NULL); \
  34. } while(0)
  35. # ifndef AES_BLOCK_SIZE
  36. # define AES_BLOCK_SIZE 16
  37. # endif
  38. # define AES_KEY_SIZE_128 16
  39. # define AES_KEY_SIZE_192 24
  40. # define AES_KEY_SIZE_256 32
  41. # define AES_IV_LEN 16
  42. # define MAX_INFLIGHTS 1
  43. typedef enum {
  44. MODE_UNINIT = 0,
  45. MODE_SYNC,
  46. MODE_ASYNC
  47. } op_mode;
  48. enum {
  49. AES_CBC_128 = 0,
  50. AES_CBC_192,
  51. AES_CBC_256
  52. };
  53. struct cbc_cipher_handles {
  54. int key_size;
  55. EVP_CIPHER *_hidden;
  56. };
  57. typedef struct cbc_cipher_handles cbc_handles;
  58. struct afalg_aio_st {
  59. int efd;
  60. op_mode mode;
  61. aio_context_t aio_ctx;
  62. struct io_event events[MAX_INFLIGHTS];
  63. struct iocb cbt[MAX_INFLIGHTS];
  64. };
  65. typedef struct afalg_aio_st afalg_aio;
  66. /*
  67. * MAGIC Number to identify correct initialisation
  68. * of afalg_ctx.
  69. */
  70. # define MAGIC_INIT_NUM 0x1890671
  71. struct afalg_ctx_st {
  72. int init_done;
  73. int sfd;
  74. int bfd;
  75. # ifdef ALG_ZERO_COPY
  76. int zc_pipe[2];
  77. # endif
  78. afalg_aio aio;
  79. };
  80. typedef struct afalg_ctx_st afalg_ctx;
  81. #endif