cipher_internal.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /**
  2. * \file cipher_internal.h
  3. *
  4. * \brief Cipher wrappers.
  5. *
  6. * \author Adriaan de Jong <dejong@fox-it.com>
  7. *
  8. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  9. * SPDX-License-Identifier: GPL-2.0
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License along
  22. * with this program; if not, write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  24. *
  25. * This file is part of mbed TLS (https://tls.mbed.org)
  26. */
  27. #ifndef MBEDTLS_CIPHER_WRAP_H
  28. #define MBEDTLS_CIPHER_WRAP_H
  29. #if !defined(MBEDTLS_CONFIG_FILE)
  30. #include "config.h"
  31. #else
  32. #include MBEDTLS_CONFIG_FILE
  33. #endif
  34. #include "cipher.h"
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /**
  39. * Base cipher information. The non-mode specific functions and values.
  40. */
  41. struct mbedtls_cipher_base_t
  42. {
  43. /** Base Cipher type (e.g. MBEDTLS_CIPHER_ID_AES) */
  44. mbedtls_cipher_id_t cipher;
  45. /** Encrypt using ECB */
  46. int (*ecb_func)( void *ctx, mbedtls_operation_t mode,
  47. const unsigned char *input, unsigned char *output );
  48. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  49. /** Encrypt using CBC */
  50. int (*cbc_func)( void *ctx, mbedtls_operation_t mode, size_t length,
  51. unsigned char *iv, const unsigned char *input,
  52. unsigned char *output );
  53. #endif
  54. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  55. /** Encrypt using CFB (Full length) */
  56. int (*cfb_func)( void *ctx, mbedtls_operation_t mode, size_t length, size_t *iv_off,
  57. unsigned char *iv, const unsigned char *input,
  58. unsigned char *output );
  59. #endif
  60. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  61. /** Encrypt using CTR */
  62. int (*ctr_func)( void *ctx, size_t length, size_t *nc_off,
  63. unsigned char *nonce_counter, unsigned char *stream_block,
  64. const unsigned char *input, unsigned char *output );
  65. #endif
  66. #if defined(MBEDTLS_CIPHER_MODE_STREAM)
  67. /** Encrypt using STREAM */
  68. int (*stream_func)( void *ctx, size_t length,
  69. const unsigned char *input, unsigned char *output );
  70. #endif
  71. /** Set key for encryption purposes */
  72. int (*setkey_enc_func)( void *ctx, const unsigned char *key,
  73. unsigned int key_bitlen );
  74. /** Set key for decryption purposes */
  75. int (*setkey_dec_func)( void *ctx, const unsigned char *key,
  76. unsigned int key_bitlen);
  77. /** Allocate a new context */
  78. void * (*ctx_alloc_func)( void );
  79. /** Free the given context */
  80. void (*ctx_free_func)( void *ctx );
  81. };
  82. typedef struct
  83. {
  84. mbedtls_cipher_type_t type;
  85. const mbedtls_cipher_info_t *info;
  86. } mbedtls_cipher_definition_t;
  87. extern const mbedtls_cipher_definition_t mbedtls_cipher_definitions[];
  88. extern int mbedtls_cipher_supported[];
  89. #ifdef __cplusplus
  90. }
  91. #endif
  92. #endif /* MBEDTLS_CIPHER_WRAP_H */