xtea.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * \file xtea.h
  3. *
  4. * \brief XTEA block cipher (32-bit)
  5. *
  6. * Copyright (C) 2006-2010, Brainspark B.V.
  7. *
  8. * This file is part of PolarSSL (http://www.polarssl.org)
  9. * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
  10. *
  11. * All rights reserved.
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License along
  24. * with this program; if not, write to the Free Software Foundation, Inc.,
  25. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  26. */
  27. #ifndef POLARSSL_XTEA_H
  28. #define POLARSSL_XTEA_H
  29. #include <string.h>
  30. #ifdef _MSC_VER
  31. #include <basetsd.h>
  32. typedef UINT32 uint32_t;
  33. #else
  34. #include <inttypes.h>
  35. #endif
  36. #define XTEA_ENCRYPT 1
  37. #define XTEA_DECRYPT 0
  38. #define POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH -0x0028 /**< The data input has an invalid length. */
  39. /**
  40. * \brief XTEA context structure
  41. */
  42. typedef struct
  43. {
  44. uint32_t k[4]; /*!< key */
  45. }
  46. xtea_context;
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  50. /**
  51. * \brief XTEA key schedule
  52. *
  53. * \param ctx XTEA context to be initialized
  54. * \param key the secret key
  55. */
  56. void xtea_setup( xtea_context *ctx, unsigned char key[16] );
  57. /**
  58. * \brief XTEA cipher function
  59. *
  60. * \param ctx XTEA context
  61. * \param mode XTEA_ENCRYPT or XTEA_DECRYPT
  62. * \param input 8-byte input block
  63. * \param output 8-byte output block
  64. *
  65. * \return 0 if successful
  66. */
  67. int xtea_crypt_ecb( xtea_context *ctx,
  68. int mode,
  69. unsigned char input[8],
  70. unsigned char output[8] );
  71. /**
  72. * \brief XTEA CBC cipher function
  73. *
  74. * \param ctx XTEA context
  75. * \param mode XTEA_ENCRYPT or XTEA_DECRYPT
  76. * \param length the length of input, multiple of 8
  77. * \param iv initialization vector for CBC mode
  78. * \param input input block
  79. * \param output output block
  80. *
  81. * \return 0 if successful,
  82. * POLARSSL_ERR_XTEA_INVALID_INPUT_LENGTH if the length % 8 != 0
  83. */
  84. int xtea_crypt_cbc( xtea_context *ctx,
  85. int mode,
  86. size_t length,
  87. unsigned char iv[8],
  88. unsigned char *input,
  89. unsigned char *output);
  90. /*
  91. * \brief Checkup routine
  92. *
  93. * \return 0 if successful, or 1 if the test failed
  94. */
  95. int xtea_self_test( int verbose );
  96. #ifdef __cplusplus
  97. }
  98. #endif
  99. #endif /* xtea.h */