morus640_glue.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * The MORUS-640 Authenticated-Encryption Algorithm
  4. * Common glue skeleton -- header file
  5. *
  6. * Copyright (c) 2016-2018 Ondrej Mosnacek <omosnacek@gmail.com>
  7. * Copyright (C) 2017-2018 Red Hat, Inc. All rights reserved.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the Free
  11. * Software Foundation; either version 2 of the License, or (at your option)
  12. * any later version.
  13. */
  14. #ifndef _CRYPTO_MORUS640_GLUE_H
  15. #define _CRYPTO_MORUS640_GLUE_H
  16. #include <linux/module.h>
  17. #include <linux/types.h>
  18. #include <crypto/algapi.h>
  19. #include <crypto/aead.h>
  20. #include <crypto/morus_common.h>
  21. #define MORUS640_WORD_SIZE 4
  22. #define MORUS640_BLOCK_SIZE (MORUS_BLOCK_WORDS * MORUS640_WORD_SIZE)
  23. struct morus640_block {
  24. u8 bytes[MORUS640_BLOCK_SIZE];
  25. };
  26. struct morus640_glue_ops {
  27. void (*init)(void *state, const void *key, const void *iv);
  28. void (*ad)(void *state, const void *data, unsigned int length);
  29. void (*enc)(void *state, const void *src, void *dst, unsigned int length);
  30. void (*dec)(void *state, const void *src, void *dst, unsigned int length);
  31. void (*enc_tail)(void *state, const void *src, void *dst, unsigned int length);
  32. void (*dec_tail)(void *state, const void *src, void *dst, unsigned int length);
  33. void (*final)(void *state, void *tag_xor, u64 assoclen, u64 cryptlen);
  34. };
  35. struct morus640_ctx {
  36. const struct morus640_glue_ops *ops;
  37. struct morus640_block key;
  38. };
  39. void crypto_morus640_glue_init_ops(struct crypto_aead *aead,
  40. const struct morus640_glue_ops *ops);
  41. int crypto_morus640_glue_setkey(struct crypto_aead *aead, const u8 *key,
  42. unsigned int keylen);
  43. int crypto_morus640_glue_setauthsize(struct crypto_aead *tfm,
  44. unsigned int authsize);
  45. int crypto_morus640_glue_encrypt(struct aead_request *req);
  46. int crypto_morus640_glue_decrypt(struct aead_request *req);
  47. int cryptd_morus640_glue_setkey(struct crypto_aead *aead, const u8 *key,
  48. unsigned int keylen);
  49. int cryptd_morus640_glue_setauthsize(struct crypto_aead *aead,
  50. unsigned int authsize);
  51. int cryptd_morus640_glue_encrypt(struct aead_request *req);
  52. int cryptd_morus640_glue_decrypt(struct aead_request *req);
  53. int cryptd_morus640_glue_init_tfm(struct crypto_aead *aead);
  54. void cryptd_morus640_glue_exit_tfm(struct crypto_aead *aead);
  55. #define MORUS640_DECLARE_ALGS(id, driver_name, priority) \
  56. static const struct morus640_glue_ops crypto_morus640_##id##_ops = {\
  57. .init = crypto_morus640_##id##_init, \
  58. .ad = crypto_morus640_##id##_ad, \
  59. .enc = crypto_morus640_##id##_enc, \
  60. .enc_tail = crypto_morus640_##id##_enc_tail, \
  61. .dec = crypto_morus640_##id##_dec, \
  62. .dec_tail = crypto_morus640_##id##_dec_tail, \
  63. .final = crypto_morus640_##id##_final, \
  64. }; \
  65. \
  66. static int crypto_morus640_##id##_init_tfm(struct crypto_aead *tfm) \
  67. { \
  68. crypto_morus640_glue_init_ops(tfm, &crypto_morus640_##id##_ops); \
  69. return 0; \
  70. } \
  71. \
  72. static void crypto_morus640_##id##_exit_tfm(struct crypto_aead *tfm) \
  73. { \
  74. } \
  75. \
  76. struct aead_alg crypto_morus640_##id##_algs[] = {\
  77. { \
  78. .setkey = crypto_morus640_glue_setkey, \
  79. .setauthsize = crypto_morus640_glue_setauthsize, \
  80. .encrypt = crypto_morus640_glue_encrypt, \
  81. .decrypt = crypto_morus640_glue_decrypt, \
  82. .init = crypto_morus640_##id##_init_tfm, \
  83. .exit = crypto_morus640_##id##_exit_tfm, \
  84. \
  85. .ivsize = MORUS_NONCE_SIZE, \
  86. .maxauthsize = MORUS_MAX_AUTH_SIZE, \
  87. .chunksize = MORUS640_BLOCK_SIZE, \
  88. \
  89. .base = { \
  90. .cra_flags = CRYPTO_ALG_INTERNAL, \
  91. .cra_blocksize = 1, \
  92. .cra_ctxsize = sizeof(struct morus640_ctx), \
  93. .cra_alignmask = 0, \
  94. \
  95. .cra_name = "__morus640", \
  96. .cra_driver_name = "__"driver_name, \
  97. \
  98. .cra_module = THIS_MODULE, \
  99. } \
  100. }, { \
  101. .setkey = cryptd_morus640_glue_setkey, \
  102. .setauthsize = cryptd_morus640_glue_setauthsize, \
  103. .encrypt = cryptd_morus640_glue_encrypt, \
  104. .decrypt = cryptd_morus640_glue_decrypt, \
  105. .init = cryptd_morus640_glue_init_tfm, \
  106. .exit = cryptd_morus640_glue_exit_tfm, \
  107. \
  108. .ivsize = MORUS_NONCE_SIZE, \
  109. .maxauthsize = MORUS_MAX_AUTH_SIZE, \
  110. .chunksize = MORUS640_BLOCK_SIZE, \
  111. \
  112. .base = { \
  113. .cra_flags = CRYPTO_ALG_ASYNC, \
  114. .cra_blocksize = 1, \
  115. .cra_ctxsize = sizeof(struct crypto_aead *), \
  116. .cra_alignmask = 0, \
  117. \
  118. .cra_priority = priority, \
  119. \
  120. .cra_name = "morus640", \
  121. .cra_driver_name = driver_name, \
  122. \
  123. .cra_module = THIS_MODULE, \
  124. } \
  125. } \
  126. }
  127. #endif /* _CRYPTO_MORUS640_GLUE_H */