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