ciphercommon_ccm.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (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. #include "ciphercommon_aead.h"
  10. typedef struct prov_ccm_hw_st PROV_CCM_HW;
  11. #if defined(OPENSSL_CPUID_OBJ) && defined(__s390__)
  12. /*-
  13. * KMAC-AES parameter block - begin
  14. * (see z/Architecture Principles of Operation >= SA22-7832-08)
  15. */
  16. typedef struct S390X_kmac_params_st {
  17. union {
  18. unsigned long long g[2];
  19. unsigned char b[16];
  20. } icv;
  21. unsigned char k[32];
  22. } S390X_KMAC_PARAMS;
  23. /* KMAC-AES parameter block - end */
  24. #endif
  25. /* Base structure that is shared by AES & ARIA for CCM MODE */
  26. typedef struct prov_ccm_st {
  27. unsigned int enc : 1;
  28. unsigned int key_set : 1; /* Set if key initialised */
  29. unsigned int iv_set : 1; /* Set if an iv is set */
  30. unsigned int tag_set : 1; /* Set if tag is valid */
  31. unsigned int len_set : 1; /* Set if message length set */
  32. size_t l, m; /* L and M parameters from RFC3610 */
  33. size_t keylen;
  34. size_t tls_aad_len; /* TLS AAD length */
  35. size_t tls_aad_pad_sz;
  36. unsigned char iv[GENERIC_BLOCK_SIZE];
  37. unsigned char buf[GENERIC_BLOCK_SIZE];
  38. CCM128_CONTEXT ccm_ctx;
  39. ccm128_f str;
  40. const PROV_CCM_HW *hw; /* hardware specific methods */
  41. } PROV_CCM_CTX;
  42. PROV_CIPHER_FUNC(int, CCM_cipher, (PROV_CCM_CTX *ctx, unsigned char *out, \
  43. size_t *padlen, const unsigned char *in, \
  44. size_t len));
  45. PROV_CIPHER_FUNC(int, CCM_setkey, (PROV_CCM_CTX *ctx, \
  46. const unsigned char *key, size_t keylen));
  47. PROV_CIPHER_FUNC(int, CCM_setiv, (PROV_CCM_CTX *dat, \
  48. const unsigned char *iv, size_t ivlen, \
  49. size_t mlen));
  50. PROV_CIPHER_FUNC(int, CCM_setaad, (PROV_CCM_CTX *ctx, \
  51. const unsigned char *aad, size_t aadlen));
  52. PROV_CIPHER_FUNC(int, CCM_auth_encrypt, (PROV_CCM_CTX *ctx, \
  53. const unsigned char *in, \
  54. unsigned char *out, size_t len, \
  55. unsigned char *tag, size_t taglen));
  56. PROV_CIPHER_FUNC(int, CCM_auth_decrypt, (PROV_CCM_CTX *ctx, \
  57. const unsigned char *in, \
  58. unsigned char *out, size_t len, \
  59. unsigned char *tag, size_t taglen));
  60. PROV_CIPHER_FUNC(int, CCM_gettag, (PROV_CCM_CTX *ctx, \
  61. unsigned char *tag, size_t taglen));
  62. /*
  63. * CCM Mode internal method table used to handle hardware specific differences,
  64. * (and different algorithms).
  65. */
  66. struct prov_ccm_hw_st {
  67. OSSL_CCM_setkey_fn setkey;
  68. OSSL_CCM_setiv_fn setiv;
  69. OSSL_CCM_setaad_fn setaad;
  70. OSSL_CCM_auth_encrypt_fn auth_encrypt;
  71. OSSL_CCM_auth_decrypt_fn auth_decrypt;
  72. OSSL_CCM_gettag_fn gettag;
  73. };
  74. OSSL_FUNC_cipher_encrypt_init_fn ossl_ccm_einit;
  75. OSSL_FUNC_cipher_decrypt_init_fn ossl_ccm_dinit;
  76. OSSL_FUNC_cipher_get_ctx_params_fn ossl_ccm_get_ctx_params;
  77. OSSL_FUNC_cipher_set_ctx_params_fn ossl_ccm_set_ctx_params;
  78. OSSL_FUNC_cipher_update_fn ossl_ccm_stream_update;
  79. OSSL_FUNC_cipher_final_fn ossl_ccm_stream_final;
  80. OSSL_FUNC_cipher_cipher_fn ossl_ccm_cipher;
  81. void ossl_ccm_initctx(PROV_CCM_CTX *ctx, size_t keybits, const PROV_CCM_HW *hw);
  82. int ossl_ccm_generic_setiv(PROV_CCM_CTX *ctx, const unsigned char *nonce,
  83. size_t nlen, size_t mlen);
  84. int ossl_ccm_generic_setaad(PROV_CCM_CTX *ctx, const unsigned char *aad,
  85. size_t alen);
  86. int ossl_ccm_generic_gettag(PROV_CCM_CTX *ctx, unsigned char *tag, size_t tlen);
  87. int ossl_ccm_generic_auth_encrypt(PROV_CCM_CTX *ctx, const unsigned char *in,
  88. unsigned char *out, size_t len,
  89. unsigned char *tag, size_t taglen);
  90. int ossl_ccm_generic_auth_decrypt(PROV_CCM_CTX *ctx, const unsigned char *in,
  91. unsigned char *out, size_t len,
  92. unsigned char *expected_tag, size_t taglen);