arcfour.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* arcfour.h */
  2. /*
  3. This file is part of the ARM-Crypto-Lib.
  4. Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. /*
  17. * File: arcfour.h
  18. * Author: Daniel Otte
  19. * Date: 2006-06-07
  20. * License: GPLv3+
  21. * Description: Implementation of the ARCFOUR (RC4 compatible) stream cipher algorithm.
  22. */
  23. /**
  24. * \file arcfour.h
  25. * \author Daniel Otte
  26. * \date 2006-06-07
  27. * \license GPLv3+
  28. * \brief Implementation of the ARCFOUR (RC4 compatible) stream cipher algorithm.
  29. *
  30. * This header file defines the interface of the ARCFOUR cipher implementation.
  31. *
  32. * This implementation aims to be compatible with the ARCFOUR description
  33. * available at
  34. * http://www.mozilla.org/projects/security/pki/nss/draft-kaukonen-cipher-arcfour-03.txt
  35. */
  36. #ifndef ARCFOUR_H_
  37. #define ARCFOUR_H_
  38. #include <stdint.h>
  39. /** \typedef arcfour_ctx_t
  40. * \brief type for arcfour context
  41. *
  42. * A variable of this type may contain a complete ARCFOUR context.
  43. * The context is used to store the state of the cipher and gets
  44. * created by the arcfour_init(arcfour_ctx_t *c, uint8_t *key, uint8_t length_B)
  45. * function. The context is of the fixed size of 258 bytes
  46. */
  47. /** \struct arcfour_ctx_st
  48. * \brief base for ::arcfour_ctx_t
  49. *
  50. * The struct holds the two indices and the S-Box
  51. */
  52. typedef struct arcfour_ctx_st {
  53. uint8_t i,j;
  54. uint8_t s[256];
  55. } arcfour_ctx_t;
  56. /** \fn void arcfour_init(const void *key, uint8_t length_B, arcfour_ctx_t *ctx)
  57. * \brief setup a context with a key
  58. *
  59. * This function sets up a ::arcfour_ctx_t context using
  60. * the supplied key of the given length.
  61. * \param ctx pointer to the context
  62. * \param key pointer to the key
  63. * \param length_b length of the key in bits
  64. */
  65. void arcfour_init(const void *key, uint16_t length_b, arcfour_ctx_t *ctx);
  66. /** \fn uint8_t arcfour_gen(arcfour_ctx_t *ctx)
  67. * \brief generates a byte of keystream
  68. *
  69. * This function generates the next byte of keystream
  70. * from the supplied ::arcfour_ctx_t context which is updated accordingly
  71. *
  72. * \param ctx pointer to the context
  73. * \return byte of keystream
  74. */
  75. uint8_t arcfour_gen(arcfour_ctx_t *ctx);
  76. #endif