SNMP++  3.3.4
idea.h
Go to the documentation of this file.
1 /*_############################################################################
2  _##
3  _## idea.h
4  _##
5  _## SNMP++ v3.3
6  _## -----------------------------------------------
7  _## Copyright (c) 2001-2013 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  _##########################################################################*/
27 // $Id: idea.h 2359 2013-05-09 20:07:01Z fock $
28 
29 /*
30 
31 idea.h
32 
33 Author: Tatu Ylonen <ylo@cs.hut.fi>
34 
35 Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
36  All rights reserved
37 
38 Created: Sun Jun 25 04:44:30 1995 ylo
39 
40 The IDEA encryption algorithm.
41 
42 */
43 
44 #ifndef IDEA_H
45 #define IDEA_H
46 
47 #include "snmp_pp/config_snmp_pp.h"
48 
49 #ifdef SNMP_PP_NAMESPACE
50 namespace Snmp_pp {
51 #endif
52 
53 #ifdef _USE_IDEA
54 
55 typedef unsigned short word16;
56 typedef unsigned int word32;
57 
58 typedef struct
59 {
60  word16 key_schedule[52];
61 } IDEAContext;
62 
63 /* Sets idea key for encryption. */
64 void idea_set_key(IDEAContext *c, const unsigned char key[16]);
65 
66 /* Destroys any sensitive data in the context. */
67 void idea_destroy_context(IDEAContext *c);
68 
69 /* Performs the IDEA cipher transform on a block of data. */
70 void idea_transform(IDEAContext *c, word32 l, word32 r, word32 *output);
71 
72 /* Encrypts len bytes from src to dest in CFB mode. Len need not be a multiple
73  of 8; if it is not, iv at return will contain garbage.
74  Otherwise, iv will be modified at end to a value suitable for continuing
75  encryption. */
76 void idea_cfb_encrypt(IDEAContext *c, unsigned char *iv, unsigned char *dest,
77  const unsigned char *src, unsigned int len);
78 
79 
80 /* Decrypts len bytes from src to dest in CFB mode. Len need not be a multiple
81  of 8; if it is not, iv at return will contain garbage.
82  Otherwise, iv will be modified at end to a value suitable for continuing
83  decryption. */
84 void idea_cfb_decrypt(IDEAContext *c, unsigned char *iv, unsigned char *dest,
85  const unsigned char *src, unsigned int len);
86 
87 #endif /* IDEA_H */
88 #endif /* _USE_IDEA */
89 
90 #ifdef SNMP_PP_NAMESPACE
91 } // end of namespace Snmp_pp
92 #endif
93 
94 /*
95 
96 getput.h
97 
98 Author: Tatu Ylonen <ylo@cs.hut.fi>
99 
100 Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
101  All rights reserved
102 
103 Created: Wed Jun 28 22:36:30 1995 ylo
104 
105 Macros for storing and retrieving data in msb first and lsb first order.
106 
107 */
108 
109 #ifdef SNMP_PP_NAMESPACE
110 namespace Snmp_pp {
111 #endif
112 
113 #ifndef GETPUT_H
114 #define GETPUT_H
115 
116 #ifdef _USE_IDEA
117 
118 /*------------ macros for storing/extracting msb first words -------------*/
119 
120 #define GET_32BIT(cp) (((unsigned long)(unsigned char)(cp)[0] << 24) | \
121  ((unsigned long)(unsigned char)(cp)[1] << 16) | \
122  ((unsigned long)(unsigned char)(cp)[2] << 8) | \
123  ((unsigned long)(unsigned char)(cp)[3]))
124 
125 #define GET_16BIT(cp) (((unsigned long)(unsigned char)(cp)[0] << 8) | \
126  ((unsigned long)(unsigned char)(cp)[1]))
127 
128 #define PUT_32BIT(cp, value) do { \
129  (cp)[0] = (value) >> 24; \
130  (cp)[1] = (value) >> 16; \
131  (cp)[2] = (value) >> 8; \
132  (cp)[3] = (value); } while (0)
133 
134 #define PUT_16BIT(cp, value) do { \
135  (cp)[0] = (value) >> 8; \
136  (cp)[1] = (value); } while (0)
137 
138 /*------------ macros for storing/extracting lsb first words -------------*/
139 
140 #define GET_32BIT_LSB_FIRST(cp) \
141  (((unsigned long)(unsigned char)(cp)[0]) | \
142  ((unsigned long)(unsigned char)(cp)[1] << 8) | \
143  ((unsigned long)(unsigned char)(cp)[2] << 16) | \
144  ((unsigned long)(unsigned char)(cp)[3] << 24))
145 
146 #define GET_16BIT_LSB_FIRST(cp) \
147  (((unsigned long)(unsigned char)(cp)[0]) | \
148  ((unsigned long)(unsigned char)(cp)[1] << 8))
149 
150 #define PUT_32BIT_LSB_FIRST(cp, value) do { \
151  (cp)[0] = (value); \
152  (cp)[1] = (value) >> 8; \
153  (cp)[2] = (value) >> 16; \
154  (cp)[3] = (value) >> 24; } while (0)
155 
156 #define PUT_16BIT_LSB_FIRST(cp, value) do { \
157  (cp)[0] = (value); \
158  (cp)[1] = (value) >> 8; } while (0)
159 
160 #endif // _USE_IDEA
161 
162 #ifdef SNMP_PP_NAMESPACE
163 } // end of namespace Snmp_pp
164 #endif
165 
166 #endif /* GETPUT_H */
167