idea.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*_############################################################################
  2. _##
  3. _## idea.h
  4. _##
  5. _## SNMP++v3.2.23
  6. _## -----------------------------------------------
  7. _## Copyright (c) 2001-2007 Jochen Katz, Frank Fock
  8. _##
  9. _## This software is based on SNMP++2.6 from Hewlett Packard:
  10. _##
  11. _## Copyright (c) 1996
  12. _## Hewlett-Packard Company
  13. _##
  14. _## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
  15. _## Permission to use, copy, modify, distribute and/or sell this software
  16. _## and/or its documentation is hereby granted without fee. User agrees
  17. _## to display the above copyright notice and this license notice in all
  18. _## copies of the software and any documentation of the software. User
  19. _## agrees to assume all liability for the use of the software;
  20. _## Hewlett-Packard and Jochen Katz make no representations about the
  21. _## suitability of this software for any purpose. It is provided
  22. _## "AS-IS" without warranty of any kind, either express or implied. User
  23. _## hereby grants a royalty-free license to any and all derivatives based
  24. _## upon this software code base.
  25. _##
  26. _## Stuttgart, Germany, Sun Nov 11 15:10:59 CET 2007
  27. _##
  28. _##########################################################################*/
  29. // $Id: idea.h 287 2007-03-22 22:37:09Z katz $
  30. /*
  31. idea.h
  32. Author: Tatu Ylonen <ylo@cs.hut.fi>
  33. Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
  34. All rights reserved
  35. Created: Sun Jun 25 04:44:30 1995 ylo
  36. The IDEA encryption algorithm.
  37. */
  38. #ifndef IDEA_H
  39. #define IDEA_H
  40. #include "snmp_pp/config_snmp_pp.h"
  41. #ifdef SNMP_PP_NAMESPACE
  42. namespace Snmp_pp {
  43. #endif
  44. #ifdef _USE_IDEA
  45. typedef unsigned short word16;
  46. typedef unsigned int word32;
  47. typedef struct
  48. {
  49. word16 key_schedule[52];
  50. } IDEAContext;
  51. /* Sets idea key for encryption. */
  52. void idea_set_key(IDEAContext *c, const unsigned char key[16]);
  53. /* Destroys any sensitive data in the context. */
  54. void idea_destroy_context(IDEAContext *c);
  55. /* Performs the IDEA cipher transform on a block of data. */
  56. void idea_transform(IDEAContext *c, word32 l, word32 r, word32 *output);
  57. /* Encrypts len bytes from src to dest in CFB mode. Len need not be a multiple
  58. of 8; if it is not, iv at return will contain garbage.
  59. Otherwise, iv will be modified at end to a value suitable for continuing
  60. encryption. */
  61. void idea_cfb_encrypt(IDEAContext *c, unsigned char *iv, unsigned char *dest,
  62. const unsigned char *src, unsigned int len);
  63. /* Decrypts len bytes from src to dest in CFB mode. Len need not be a multiple
  64. of 8; if it is not, iv at return will contain garbage.
  65. Otherwise, iv will be modified at end to a value suitable for continuing
  66. decryption. */
  67. void idea_cfb_decrypt(IDEAContext *c, unsigned char *iv, unsigned char *dest,
  68. const unsigned char *src, unsigned int len);
  69. #endif /* IDEA_H */
  70. #endif /* _USE_IDEA */
  71. #ifdef SNMP_PP_NAMESPACE
  72. } // end of namespace Snmp_pp
  73. #endif
  74. /*
  75. getput.h
  76. Author: Tatu Ylonen <ylo@cs.hut.fi>
  77. Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
  78. All rights reserved
  79. Created: Wed Jun 28 22:36:30 1995 ylo
  80. Macros for storing and retrieving data in msb first and lsb first order.
  81. */
  82. #ifdef SNMP_PP_NAMESPACE
  83. namespace Snmp_pp {
  84. #endif
  85. #ifndef GETPUT_H
  86. #define GETPUT_H
  87. /*------------ macros for storing/extracting msb first words -------------*/
  88. #define GET_32BIT(cp) (((unsigned long)(unsigned char)(cp)[0] << 24) | \
  89. ((unsigned long)(unsigned char)(cp)[1] << 16) | \
  90. ((unsigned long)(unsigned char)(cp)[2] << 8) | \
  91. ((unsigned long)(unsigned char)(cp)[3]))
  92. #define GET_16BIT(cp) (((unsigned long)(unsigned char)(cp)[0] << 8) | \
  93. ((unsigned long)(unsigned char)(cp)[1]))
  94. #define PUT_32BIT(cp, value) do { \
  95. (cp)[0] = (value) >> 24; \
  96. (cp)[1] = (value) >> 16; \
  97. (cp)[2] = (value) >> 8; \
  98. (cp)[3] = (value); } while (0)
  99. #define PUT_16BIT(cp, value) do { \
  100. (cp)[0] = (value) >> 8; \
  101. (cp)[1] = (value); } while (0)
  102. /*------------ macros for storing/extracting lsb first words -------------*/
  103. #define GET_32BIT_LSB_FIRST(cp) \
  104. (((unsigned long)(unsigned char)(cp)[0]) | \
  105. ((unsigned long)(unsigned char)(cp)[1] << 8) | \
  106. ((unsigned long)(unsigned char)(cp)[2] << 16) | \
  107. ((unsigned long)(unsigned char)(cp)[3] << 24))
  108. #define GET_16BIT_LSB_FIRST(cp) \
  109. (((unsigned long)(unsigned char)(cp)[0]) | \
  110. ((unsigned long)(unsigned char)(cp)[1] << 8))
  111. #define PUT_32BIT_LSB_FIRST(cp, value) do { \
  112. (cp)[0] = (value); \
  113. (cp)[1] = (value) >> 8; \
  114. (cp)[2] = (value) >> 16; \
  115. (cp)[3] = (value) >> 24; } while (0)
  116. #define PUT_16BIT_LSB_FIRST(cp, value) do { \
  117. (cp)[0] = (value); \
  118. (cp)[1] = (value) >> 8; } while (0)
  119. #ifdef SNMP_PP_NAMESPACE
  120. } // end of namespace Snmp_pp
  121. #endif
  122. #endif /* GETPUT_H */