diff options
author | Jay Threeth | 2011-04-04 11:48:26 -0700 |
---|---|---|
committer | Jay Threeth | 2011-04-04 11:48:26 -0700 |
commit | 3c9cc506f741b980565ff5b3b001cd8b6ee36b12 (patch) | |
tree | cb862c57b3d5f74177cde3bd962a53fc377166f6 /linden/indra/libotr/libotr-3.2.0/toolkit | |
parent | build fixes, might build on linux now (diff) | |
download | meta-impy-3c9cc506f741b980565ff5b3b001cd8b6ee36b12.zip meta-impy-3c9cc506f741b980565ff5b3b001cd8b6ee36b12.tar.gz meta-impy-3c9cc506f741b980565ff5b3b001cd8b6ee36b12.tar.bz2 meta-impy-3c9cc506f741b980565ff5b3b001cd8b6ee36b12.tar.xz |
add source to libraries, and cruft for building under windows
Diffstat (limited to 'linden/indra/libotr/libotr-3.2.0/toolkit')
21 files changed, 3520 insertions, 0 deletions
diff --git a/linden/indra/libotr/libotr-3.2.0/toolkit/Makefile.am b/linden/indra/libotr/libotr-3.2.0/toolkit/Makefile.am new file mode 100755 index 0000000..1cdb37b --- /dev/null +++ b/linden/indra/libotr/libotr-3.2.0/toolkit/Makefile.am | |||
@@ -0,0 +1,44 @@ | |||
1 | INCLUDES = -I$(includedir) -I../src @LIBGCRYPT_CFLAGS@ | ||
2 | |||
3 | noinst_HEADERS = aes.h ctrmode.h parse.h sesskeys.h readotr.h sha1hmac.h | ||
4 | |||
5 | bin_PROGRAMS = otr_parse otr_sesskeys otr_mackey otr_readforge \ | ||
6 | otr_modify otr_remac | ||
7 | |||
8 | COMMON_S = parse.c sha1hmac.c | ||
9 | COMMON_LD = ../src/libotr.la @LIBS@ @LIBGCRYPT_LIBS@ | ||
10 | |||
11 | otr_parse_SOURCES = otr_parse.c readotr.c $(COMMON_S) | ||
12 | otr_parse_LDADD = $(COMMON_LD) | ||
13 | |||
14 | otr_sesskeys_SOURCES = otr_sesskeys.c sesskeys.c $(COMMON_S) | ||
15 | otr_sesskeys_LDADD = $(COMMON_LD) | ||
16 | |||
17 | otr_mackey_SOURCES = otr_mackey.c sesskeys.c $(COMMON_S) | ||
18 | otr_mackey_LDADD = $(COMMON_LD) | ||
19 | |||
20 | otr_readforge_SOURCES = otr_readforge.c readotr.c sesskeys.c \ | ||
21 | aes.c ctrmode.c $(COMMON_S) | ||
22 | otr_readforge_LDADD = $(COMMON_LD) | ||
23 | |||
24 | otr_modify_SOURCES = otr_modify.c readotr.c $(COMMON_S) | ||
25 | otr_modify_LDADD = $(COMMON_LD) | ||
26 | |||
27 | otr_remac_SOURCES = otr_remac.c $(COMMON_S) | ||
28 | otr_remac_LDADD = $(COMMON_LD) | ||
29 | |||
30 | |||
31 | man_MANS = otr_toolkit.1 | ||
32 | EXTRA_DIST = otr_toolkit.1 | ||
33 | |||
34 | MANLINKS = otr_parse.1 otr_sesskeys.1 otr_mackey.1 otr_readforge.1 \ | ||
35 | otr_modify.1 otr_remac.1 | ||
36 | |||
37 | install-data-local: | ||
38 | -mkdir -p $(DESTDIR)$(man1dir) | ||
39 | (cd $(DESTDIR)$(man1dir) && \ | ||
40 | for f in $(MANLINKS); do ln -sf otr_toolkit.1 $$f; done) | ||
41 | |||
42 | uninstall-local: | ||
43 | (cd $(DESTDIR)$(man1dir) && \ | ||
44 | for f in $(MANLINKS); do rm -f $$f; done) | ||
diff --git a/linden/indra/libotr/libotr-3.2.0/toolkit/Makefile.in b/linden/indra/libotr/libotr-3.2.0/toolkit/Makefile.in new file mode 100755 index 0000000..e7fc920 --- /dev/null +++ b/linden/indra/libotr/libotr-3.2.0/toolkit/Makefile.in | |||
@@ -0,0 +1,587 @@ | |||
1 | # Makefile.in generated by automake 1.9.6 from Makefile.am. | ||
2 | # @configure_input@ | ||
3 | |||
4 | # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, | ||
5 | # 2003, 2004, 2005 Free Software Foundation, Inc. | ||
6 | # This Makefile.in is free software; the Free Software Foundation | ||
7 | # gives unlimited permission to copy and/or distribute it, | ||
8 | # with or without modifications, as long as this notice is preserved. | ||
9 | |||
10 | # This program is distributed in the hope that it will be useful, | ||
11 | # but WITHOUT ANY WARRANTY, to the extent permitted by law; without | ||
12 | # even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
13 | # PARTICULAR PURPOSE. | ||
14 | |||
15 | @SET_MAKE@ | ||
16 | |||
17 | |||
18 | srcdir = @srcdir@ | ||
19 | top_srcdir = @top_srcdir@ | ||
20 | VPATH = @srcdir@ | ||
21 | pkgdatadir = $(datadir)/@PACKAGE@ | ||
22 | pkglibdir = $(libdir)/@PACKAGE@ | ||
23 | pkgincludedir = $(includedir)/@PACKAGE@ | ||
24 | top_builddir = .. | ||
25 | am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd | ||
26 | INSTALL = @INSTALL@ | ||
27 | install_sh_DATA = $(install_sh) -c -m 644 | ||
28 | install_sh_PROGRAM = $(install_sh) -c | ||
29 | install_sh_SCRIPT = $(install_sh) -c | ||
30 | INSTALL_HEADER = $(INSTALL_DATA) | ||
31 | transform = $(program_transform_name) | ||
32 | NORMAL_INSTALL = : | ||
33 | PRE_INSTALL = : | ||
34 | POST_INSTALL = : | ||
35 | NORMAL_UNINSTALL = : | ||
36 | PRE_UNINSTALL = : | ||
37 | POST_UNINSTALL = : | ||
38 | build_triplet = @build@ | ||
39 | host_triplet = @host@ | ||
40 | bin_PROGRAMS = otr_parse$(EXEEXT) otr_sesskeys$(EXEEXT) \ | ||
41 | otr_mackey$(EXEEXT) otr_readforge$(EXEEXT) otr_modify$(EXEEXT) \ | ||
42 | otr_remac$(EXEEXT) | ||
43 | subdir = toolkit | ||
44 | DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \ | ||
45 | $(srcdir)/Makefile.in | ||
46 | ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 | ||
47 | am__aclocal_m4_deps = $(top_srcdir)/configure.ac | ||
48 | am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ | ||
49 | $(ACLOCAL_M4) | ||
50 | mkinstalldirs = $(install_sh) -d | ||
51 | CONFIG_HEADER = $(top_builddir)/config.h | ||
52 | CONFIG_CLEAN_FILES = | ||
53 | am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)" | ||
54 | binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) | ||
55 | PROGRAMS = $(bin_PROGRAMS) | ||
56 | am__objects_1 = parse.$(OBJEXT) sha1hmac.$(OBJEXT) | ||
57 | am_otr_mackey_OBJECTS = otr_mackey.$(OBJEXT) sesskeys.$(OBJEXT) \ | ||
58 | $(am__objects_1) | ||
59 | otr_mackey_OBJECTS = $(am_otr_mackey_OBJECTS) | ||
60 | am__DEPENDENCIES_1 = ../src/libotr.la | ||
61 | otr_mackey_DEPENDENCIES = $(am__DEPENDENCIES_1) | ||
62 | am_otr_modify_OBJECTS = otr_modify.$(OBJEXT) readotr.$(OBJEXT) \ | ||
63 | $(am__objects_1) | ||
64 | otr_modify_OBJECTS = $(am_otr_modify_OBJECTS) | ||
65 | otr_modify_DEPENDENCIES = $(am__DEPENDENCIES_1) | ||
66 | am_otr_parse_OBJECTS = otr_parse.$(OBJEXT) readotr.$(OBJEXT) \ | ||
67 | $(am__objects_1) | ||
68 | otr_parse_OBJECTS = $(am_otr_parse_OBJECTS) | ||
69 | otr_parse_DEPENDENCIES = $(am__DEPENDENCIES_1) | ||
70 | am_otr_readforge_OBJECTS = otr_readforge.$(OBJEXT) readotr.$(OBJEXT) \ | ||
71 | sesskeys.$(OBJEXT) aes.$(OBJEXT) ctrmode.$(OBJEXT) \ | ||
72 | $(am__objects_1) | ||
73 | otr_readforge_OBJECTS = $(am_otr_readforge_OBJECTS) | ||
74 | otr_readforge_DEPENDENCIES = $(am__DEPENDENCIES_1) | ||
75 | am_otr_remac_OBJECTS = otr_remac.$(OBJEXT) $(am__objects_1) | ||
76 | otr_remac_OBJECTS = $(am_otr_remac_OBJECTS) | ||
77 | otr_remac_DEPENDENCIES = $(am__DEPENDENCIES_1) | ||
78 | am_otr_sesskeys_OBJECTS = otr_sesskeys.$(OBJEXT) sesskeys.$(OBJEXT) \ | ||
79 | $(am__objects_1) | ||
80 | otr_sesskeys_OBJECTS = $(am_otr_sesskeys_OBJECTS) | ||
81 | otr_sesskeys_DEPENDENCIES = $(am__DEPENDENCIES_1) | ||
82 | DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) | ||
83 | depcomp = $(SHELL) $(top_srcdir)/depcomp | ||
84 | am__depfiles_maybe = depfiles | ||
85 | COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ | ||
86 | $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) | ||
87 | LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \ | ||
88 | $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ | ||
89 | $(AM_CFLAGS) $(CFLAGS) | ||
90 | CCLD = $(CC) | ||
91 | LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ | ||
92 | $(AM_LDFLAGS) $(LDFLAGS) -o $@ | ||
93 | SOURCES = $(otr_mackey_SOURCES) $(otr_modify_SOURCES) \ | ||
94 | $(otr_parse_SOURCES) $(otr_readforge_SOURCES) \ | ||
95 | $(otr_remac_SOURCES) $(otr_sesskeys_SOURCES) | ||
96 | DIST_SOURCES = $(otr_mackey_SOURCES) $(otr_modify_SOURCES) \ | ||
97 | $(otr_parse_SOURCES) $(otr_readforge_SOURCES) \ | ||
98 | $(otr_remac_SOURCES) $(otr_sesskeys_SOURCES) | ||
99 | man1dir = $(mandir)/man1 | ||
100 | NROFF = nroff | ||
101 | MANS = $(man_MANS) | ||
102 | HEADERS = $(noinst_HEADERS) | ||
103 | ETAGS = etags | ||
104 | CTAGS = ctags | ||
105 | DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) | ||
106 | ACLOCAL = @ACLOCAL@ | ||
107 | AMDEP_FALSE = @AMDEP_FALSE@ | ||
108 | AMDEP_TRUE = @AMDEP_TRUE@ | ||
109 | AMTAR = @AMTAR@ | ||
110 | AR = @AR@ | ||
111 | AUTOCONF = @AUTOCONF@ | ||
112 | AUTOHEADER = @AUTOHEADER@ | ||
113 | AUTOMAKE = @AUTOMAKE@ | ||
114 | AWK = @AWK@ | ||
115 | CC = @CC@ | ||
116 | CCDEPMODE = @CCDEPMODE@ | ||
117 | CFLAGS = @CFLAGS@ | ||
118 | CPP = @CPP@ | ||
119 | CPPFLAGS = @CPPFLAGS@ | ||
120 | CXX = @CXX@ | ||
121 | CXXCPP = @CXXCPP@ | ||
122 | CXXDEPMODE = @CXXDEPMODE@ | ||
123 | CXXFLAGS = @CXXFLAGS@ | ||
124 | CYGPATH_W = @CYGPATH_W@ | ||
125 | DEFS = @DEFS@ | ||
126 | DEPDIR = @DEPDIR@ | ||
127 | ECHO = @ECHO@ | ||
128 | ECHO_C = @ECHO_C@ | ||
129 | ECHO_N = @ECHO_N@ | ||
130 | ECHO_T = @ECHO_T@ | ||
131 | EGREP = @EGREP@ | ||
132 | EXEEXT = @EXEEXT@ | ||
133 | F77 = @F77@ | ||
134 | FFLAGS = @FFLAGS@ | ||
135 | INSTALL_DATA = @INSTALL_DATA@ | ||
136 | INSTALL_PROGRAM = @INSTALL_PROGRAM@ | ||
137 | INSTALL_SCRIPT = @INSTALL_SCRIPT@ | ||
138 | INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ | ||
139 | LDFLAGS = @LDFLAGS@ | ||
140 | LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ | ||
141 | LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ | ||
142 | LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ | ||
143 | LIBOBJS = @LIBOBJS@ | ||
144 | LIBOTR_LIBTOOL_VERSION = @LIBOTR_LIBTOOL_VERSION@ | ||
145 | LIBS = @LIBS@ | ||
146 | LIBTOOL = @LIBTOOL@ | ||
147 | LN_S = @LN_S@ | ||
148 | LTLIBOBJS = @LTLIBOBJS@ | ||
149 | MAKEINFO = @MAKEINFO@ | ||
150 | OBJEXT = @OBJEXT@ | ||
151 | PACKAGE = @PACKAGE@ | ||
152 | PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ | ||
153 | PACKAGE_NAME = @PACKAGE_NAME@ | ||
154 | PACKAGE_STRING = @PACKAGE_STRING@ | ||
155 | PACKAGE_TARNAME = @PACKAGE_TARNAME@ | ||
156 | PACKAGE_VERSION = @PACKAGE_VERSION@ | ||
157 | PATH_SEPARATOR = @PATH_SEPARATOR@ | ||
158 | RANLIB = @RANLIB@ | ||
159 | SET_MAKE = @SET_MAKE@ | ||
160 | SHELL = @SHELL@ | ||
161 | STRIP = @STRIP@ | ||
162 | VERSION = @VERSION@ | ||
163 | ac_ct_AR = @ac_ct_AR@ | ||
164 | ac_ct_CC = @ac_ct_CC@ | ||
165 | ac_ct_CXX = @ac_ct_CXX@ | ||
166 | ac_ct_F77 = @ac_ct_F77@ | ||
167 | ac_ct_RANLIB = @ac_ct_RANLIB@ | ||
168 | ac_ct_STRIP = @ac_ct_STRIP@ | ||
169 | am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ | ||
170 | am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ | ||
171 | am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ | ||
172 | am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ | ||
173 | am__include = @am__include@ | ||
174 | am__leading_dot = @am__leading_dot@ | ||
175 | am__quote = @am__quote@ | ||
176 | am__tar = @am__tar@ | ||
177 | am__untar = @am__untar@ | ||
178 | bindir = @bindir@ | ||
179 | build = @build@ | ||
180 | build_alias = @build_alias@ | ||
181 | build_cpu = @build_cpu@ | ||
182 | build_os = @build_os@ | ||
183 | build_vendor = @build_vendor@ | ||
184 | datadir = @datadir@ | ||
185 | exec_prefix = @exec_prefix@ | ||
186 | host = @host@ | ||
187 | host_alias = @host_alias@ | ||
188 | host_cpu = @host_cpu@ | ||
189 | host_os = @host_os@ | ||
190 | host_vendor = @host_vendor@ | ||
191 | includedir = @includedir@ | ||
192 | infodir = @infodir@ | ||
193 | install_sh = @install_sh@ | ||
194 | libdir = @libdir@ | ||
195 | libexecdir = @libexecdir@ | ||
196 | localstatedir = @localstatedir@ | ||
197 | mandir = @mandir@ | ||
198 | mkdir_p = @mkdir_p@ | ||
199 | oldincludedir = @oldincludedir@ | ||
200 | prefix = @prefix@ | ||
201 | program_transform_name = @program_transform_name@ | ||
202 | sbindir = @sbindir@ | ||
203 | sharedstatedir = @sharedstatedir@ | ||
204 | sysconfdir = @sysconfdir@ | ||
205 | target_alias = @target_alias@ | ||
206 | INCLUDES = -I$(includedir) -I../src @LIBGCRYPT_CFLAGS@ | ||
207 | noinst_HEADERS = aes.h ctrmode.h parse.h sesskeys.h readotr.h sha1hmac.h | ||
208 | COMMON_S = parse.c sha1hmac.c | ||
209 | COMMON_LD = ../src/libotr.la @LIBS@ @LIBGCRYPT_LIBS@ | ||
210 | otr_parse_SOURCES = otr_parse.c readotr.c $(COMMON_S) | ||
211 | otr_parse_LDADD = $(COMMON_LD) | ||
212 | otr_sesskeys_SOURCES = otr_sesskeys.c sesskeys.c $(COMMON_S) | ||
213 | otr_sesskeys_LDADD = $(COMMON_LD) | ||
214 | otr_mackey_SOURCES = otr_mackey.c sesskeys.c $(COMMON_S) | ||
215 | otr_mackey_LDADD = $(COMMON_LD) | ||
216 | otr_readforge_SOURCES = otr_readforge.c readotr.c sesskeys.c \ | ||
217 | aes.c ctrmode.c $(COMMON_S) | ||
218 | |||
219 | otr_readforge_LDADD = $(COMMON_LD) | ||
220 | otr_modify_SOURCES = otr_modify.c readotr.c $(COMMON_S) | ||
221 | otr_modify_LDADD = $(COMMON_LD) | ||
222 | otr_remac_SOURCES = otr_remac.c $(COMMON_S) | ||
223 | otr_remac_LDADD = $(COMMON_LD) | ||
224 | man_MANS = otr_toolkit.1 | ||
225 | EXTRA_DIST = otr_toolkit.1 | ||
226 | MANLINKS = otr_parse.1 otr_sesskeys.1 otr_mackey.1 otr_readforge.1 \ | ||
227 | otr_modify.1 otr_remac.1 | ||
228 | |||
229 | all: all-am | ||
230 | |||
231 | .SUFFIXES: | ||
232 | .SUFFIXES: .c .lo .o .obj | ||
233 | $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) | ||
234 | @for dep in $?; do \ | ||
235 | case '$(am__configure_deps)' in \ | ||
236 | *$$dep*) \ | ||
237 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ | ||
238 | && exit 0; \ | ||
239 | exit 1;; \ | ||
240 | esac; \ | ||
241 | done; \ | ||
242 | echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu toolkit/Makefile'; \ | ||
243 | cd $(top_srcdir) && \ | ||
244 | $(AUTOMAKE) --gnu toolkit/Makefile | ||
245 | .PRECIOUS: Makefile | ||
246 | Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status | ||
247 | @case '$?' in \ | ||
248 | *config.status*) \ | ||
249 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ | ||
250 | *) \ | ||
251 | echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ | ||
252 | cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ | ||
253 | esac; | ||
254 | |||
255 | $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) | ||
256 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh | ||
257 | |||
258 | $(top_srcdir)/configure: $(am__configure_deps) | ||
259 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh | ||
260 | $(ACLOCAL_M4): $(am__aclocal_m4_deps) | ||
261 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh | ||
262 | install-binPROGRAMS: $(bin_PROGRAMS) | ||
263 | @$(NORMAL_INSTALL) | ||
264 | test -z "$(bindir)" || $(mkdir_p) "$(DESTDIR)$(bindir)" | ||
265 | @list='$(bin_PROGRAMS)'; for p in $$list; do \ | ||
266 | p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ | ||
267 | if test -f $$p \ | ||
268 | || test -f $$p1 \ | ||
269 | ; then \ | ||
270 | f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \ | ||
271 | echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \ | ||
272 | $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \ | ||
273 | else :; fi; \ | ||
274 | done | ||
275 | |||
276 | uninstall-binPROGRAMS: | ||
277 | @$(NORMAL_UNINSTALL) | ||
278 | @list='$(bin_PROGRAMS)'; for p in $$list; do \ | ||
279 | f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \ | ||
280 | echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \ | ||
281 | rm -f "$(DESTDIR)$(bindir)/$$f"; \ | ||
282 | done | ||
283 | |||
284 | clean-binPROGRAMS: | ||
285 | @list='$(bin_PROGRAMS)'; for p in $$list; do \ | ||
286 | f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ | ||
287 | echo " rm -f $$p $$f"; \ | ||
288 | rm -f $$p $$f ; \ | ||
289 | done | ||
290 | otr_mackey$(EXEEXT): $(otr_mackey_OBJECTS) $(otr_mackey_DEPENDENCIES) | ||
291 | @rm -f otr_mackey$(EXEEXT) | ||
292 | $(LINK) $(otr_mackey_LDFLAGS) $(otr_mackey_OBJECTS) $(otr_mackey_LDADD) $(LIBS) | ||
293 | otr_modify$(EXEEXT): $(otr_modify_OBJECTS) $(otr_modify_DEPENDENCIES) | ||
294 | @rm -f otr_modify$(EXEEXT) | ||
295 | $(LINK) $(otr_modify_LDFLAGS) $(otr_modify_OBJECTS) $(otr_modify_LDADD) $(LIBS) | ||
296 | otr_parse$(EXEEXT): $(otr_parse_OBJECTS) $(otr_parse_DEPENDENCIES) | ||
297 | @rm -f otr_parse$(EXEEXT) | ||
298 | $(LINK) $(otr_parse_LDFLAGS) $(otr_parse_OBJECTS) $(otr_parse_LDADD) $(LIBS) | ||
299 | otr_readforge$(EXEEXT): $(otr_readforge_OBJECTS) $(otr_readforge_DEPENDENCIES) | ||
300 | @rm -f otr_readforge$(EXEEXT) | ||
301 | $(LINK) $(otr_readforge_LDFLAGS) $(otr_readforge_OBJECTS) $(otr_readforge_LDADD) $(LIBS) | ||
302 | otr_remac$(EXEEXT): $(otr_remac_OBJECTS) $(otr_remac_DEPENDENCIES) | ||
303 | @rm -f otr_remac$(EXEEXT) | ||
304 | $(LINK) $(otr_remac_LDFLAGS) $(otr_remac_OBJECTS) $(otr_remac_LDADD) $(LIBS) | ||
305 | otr_sesskeys$(EXEEXT): $(otr_sesskeys_OBJECTS) $(otr_sesskeys_DEPENDENCIES) | ||
306 | @rm -f otr_sesskeys$(EXEEXT) | ||
307 | $(LINK) $(otr_sesskeys_LDFLAGS) $(otr_sesskeys_OBJECTS) $(otr_sesskeys_LDADD) $(LIBS) | ||
308 | |||
309 | mostlyclean-compile: | ||
310 | -rm -f *.$(OBJEXT) | ||
311 | |||
312 | distclean-compile: | ||
313 | -rm -f *.tab.c | ||
314 | |||
315 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/aes.Po@am__quote@ | ||
316 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ctrmode.Po@am__quote@ | ||
317 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/otr_mackey.Po@am__quote@ | ||
318 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/otr_modify.Po@am__quote@ | ||
319 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/otr_parse.Po@am__quote@ | ||
320 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/otr_readforge.Po@am__quote@ | ||
321 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/otr_remac.Po@am__quote@ | ||
322 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/otr_sesskeys.Po@am__quote@ | ||
323 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parse.Po@am__quote@ | ||
324 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readotr.Po@am__quote@ | ||
325 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sesskeys.Po@am__quote@ | ||
326 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sha1hmac.Po@am__quote@ | ||
327 | |||
328 | .c.o: | ||
329 | @am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ | ||
330 | @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi | ||
331 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ | ||
332 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | ||
333 | @am__fastdepCC_FALSE@ $(COMPILE) -c $< | ||
334 | |||
335 | .c.obj: | ||
336 | @am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \ | ||
337 | @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi | ||
338 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ | ||
339 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | ||
340 | @am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` | ||
341 | |||
342 | .c.lo: | ||
343 | @am__fastdepCC_TRUE@ if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ | ||
344 | @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi | ||
345 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ | ||
346 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ | ||
347 | @am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< | ||
348 | |||
349 | mostlyclean-libtool: | ||
350 | -rm -f *.lo | ||
351 | |||
352 | clean-libtool: | ||
353 | -rm -rf .libs _libs | ||
354 | |||
355 | distclean-libtool: | ||
356 | -rm -f libtool | ||
357 | uninstall-info-am: | ||
358 | install-man1: $(man1_MANS) $(man_MANS) | ||
359 | @$(NORMAL_INSTALL) | ||
360 | test -z "$(man1dir)" || $(mkdir_p) "$(DESTDIR)$(man1dir)" | ||
361 | @list='$(man1_MANS) $(dist_man1_MANS) $(nodist_man1_MANS)'; \ | ||
362 | l2='$(man_MANS) $(dist_man_MANS) $(nodist_man_MANS)'; \ | ||
363 | for i in $$l2; do \ | ||
364 | case "$$i" in \ | ||
365 | *.1*) list="$$list $$i" ;; \ | ||
366 | esac; \ | ||
367 | done; \ | ||
368 | for i in $$list; do \ | ||
369 | if test -f $(srcdir)/$$i; then file=$(srcdir)/$$i; \ | ||
370 | else file=$$i; fi; \ | ||
371 | ext=`echo $$i | sed -e 's/^.*\\.//'`; \ | ||
372 | case "$$ext" in \ | ||
373 | 1*) ;; \ | ||
374 | *) ext='1' ;; \ | ||
375 | esac; \ | ||
376 | inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \ | ||
377 | inst=`echo $$inst | sed -e 's/^.*\///'`; \ | ||
378 | inst=`echo $$inst | sed '$(transform)'`.$$ext; \ | ||
379 | echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man1dir)/$$inst'"; \ | ||
380 | $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man1dir)/$$inst"; \ | ||
381 | done | ||
382 | uninstall-man1: | ||
383 | @$(NORMAL_UNINSTALL) | ||
384 | @list='$(man1_MANS) $(dist_man1_MANS) $(nodist_man1_MANS)'; \ | ||
385 | l2='$(man_MANS) $(dist_man_MANS) $(nodist_man_MANS)'; \ | ||
386 | for i in $$l2; do \ | ||
387 | case "$$i" in \ | ||
388 | *.1*) list="$$list $$i" ;; \ | ||
389 | esac; \ | ||
390 | done; \ | ||
391 | for i in $$list; do \ | ||
392 | ext=`echo $$i | sed -e 's/^.*\\.//'`; \ | ||
393 | case "$$ext" in \ | ||
394 | 1*) ;; \ | ||
395 | *) ext='1' ;; \ | ||
396 | esac; \ | ||
397 | inst=`echo $$i | sed -e 's/\\.[0-9a-z]*$$//'`; \ | ||
398 | inst=`echo $$inst | sed -e 's/^.*\///'`; \ | ||
399 | inst=`echo $$inst | sed '$(transform)'`.$$ext; \ | ||
400 | echo " rm -f '$(DESTDIR)$(man1dir)/$$inst'"; \ | ||
401 | rm -f "$(DESTDIR)$(man1dir)/$$inst"; \ | ||
402 | done | ||
403 | |||
404 | ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) | ||
405 | list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ | ||
406 | unique=`for i in $$list; do \ | ||
407 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ | ||
408 | done | \ | ||
409 | $(AWK) ' { files[$$0] = 1; } \ | ||
410 | END { for (i in files) print i; }'`; \ | ||
411 | mkid -fID $$unique | ||
412 | tags: TAGS | ||
413 | |||
414 | TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ | ||
415 | $(TAGS_FILES) $(LISP) | ||
416 | tags=; \ | ||
417 | here=`pwd`; \ | ||
418 | list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ | ||
419 | unique=`for i in $$list; do \ | ||
420 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ | ||
421 | done | \ | ||
422 | $(AWK) ' { files[$$0] = 1; } \ | ||
423 | END { for (i in files) print i; }'`; \ | ||
424 | if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ | ||
425 | test -n "$$unique" || unique=$$empty_fix; \ | ||
426 | $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ | ||
427 | $$tags $$unique; \ | ||
428 | fi | ||
429 | ctags: CTAGS | ||
430 | CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ | ||
431 | $(TAGS_FILES) $(LISP) | ||
432 | tags=; \ | ||
433 | here=`pwd`; \ | ||
434 | list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ | ||
435 | unique=`for i in $$list; do \ | ||
436 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ | ||
437 | done | \ | ||
438 | $(AWK) ' { files[$$0] = 1; } \ | ||
439 | END { for (i in files) print i; }'`; \ | ||
440 | test -z "$(CTAGS_ARGS)$$tags$$unique" \ | ||
441 | || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ | ||
442 | $$tags $$unique | ||
443 | |||
444 | GTAGS: | ||
445 | here=`$(am__cd) $(top_builddir) && pwd` \ | ||
446 | && cd $(top_srcdir) \ | ||
447 | && gtags -i $(GTAGS_ARGS) $$here | ||
448 | |||
449 | distclean-tags: | ||
450 | -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags | ||
451 | |||
452 | distdir: $(DISTFILES) | ||
453 | @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ | ||
454 | topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ | ||
455 | list='$(DISTFILES)'; for file in $$list; do \ | ||
456 | case $$file in \ | ||
457 | $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ | ||
458 | $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ | ||
459 | esac; \ | ||
460 | if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ | ||
461 | dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ | ||
462 | if test "$$dir" != "$$file" && test "$$dir" != "."; then \ | ||
463 | dir="/$$dir"; \ | ||
464 | $(mkdir_p) "$(distdir)$$dir"; \ | ||
465 | else \ | ||
466 | dir=''; \ | ||
467 | fi; \ | ||
468 | if test -d $$d/$$file; then \ | ||
469 | if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ | ||
470 | cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ | ||
471 | fi; \ | ||
472 | cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ | ||
473 | else \ | ||
474 | test -f $(distdir)/$$file \ | ||
475 | || cp -p $$d/$$file $(distdir)/$$file \ | ||
476 | || exit 1; \ | ||
477 | fi; \ | ||
478 | done | ||
479 | check-am: all-am | ||
480 | check: check-am | ||
481 | all-am: Makefile $(PROGRAMS) $(MANS) $(HEADERS) | ||
482 | installdirs: | ||
483 | for dir in "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)"; do \ | ||
484 | test -z "$$dir" || $(mkdir_p) "$$dir"; \ | ||
485 | done | ||
486 | install: install-am | ||
487 | install-exec: install-exec-am | ||
488 | install-data: install-data-am | ||
489 | uninstall: uninstall-am | ||
490 | |||
491 | install-am: all-am | ||
492 | @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am | ||
493 | |||
494 | installcheck: installcheck-am | ||
495 | install-strip: | ||
496 | $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ | ||
497 | install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ | ||
498 | `test -z '$(STRIP)' || \ | ||
499 | echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install | ||
500 | mostlyclean-generic: | ||
501 | |||
502 | clean-generic: | ||
503 | |||
504 | distclean-generic: | ||
505 | -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) | ||
506 | |||
507 | maintainer-clean-generic: | ||
508 | @echo "This command is intended for maintainers to use" | ||
509 | @echo "it deletes files that may require special tools to rebuild." | ||
510 | clean: clean-am | ||
511 | |||
512 | clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am | ||
513 | |||
514 | distclean: distclean-am | ||
515 | -rm -rf ./$(DEPDIR) | ||
516 | -rm -f Makefile | ||
517 | distclean-am: clean-am distclean-compile distclean-generic \ | ||
518 | distclean-libtool distclean-tags | ||
519 | |||
520 | dvi: dvi-am | ||
521 | |||
522 | dvi-am: | ||
523 | |||
524 | html: html-am | ||
525 | |||
526 | info: info-am | ||
527 | |||
528 | info-am: | ||
529 | |||
530 | install-data-am: install-data-local install-man | ||
531 | |||
532 | install-exec-am: install-binPROGRAMS | ||
533 | |||
534 | install-info: install-info-am | ||
535 | |||
536 | install-man: install-man1 | ||
537 | |||
538 | installcheck-am: | ||
539 | |||
540 | maintainer-clean: maintainer-clean-am | ||
541 | -rm -rf ./$(DEPDIR) | ||
542 | -rm -f Makefile | ||
543 | maintainer-clean-am: distclean-am maintainer-clean-generic | ||
544 | |||
545 | mostlyclean: mostlyclean-am | ||
546 | |||
547 | mostlyclean-am: mostlyclean-compile mostlyclean-generic \ | ||
548 | mostlyclean-libtool | ||
549 | |||
550 | pdf: pdf-am | ||
551 | |||
552 | pdf-am: | ||
553 | |||
554 | ps: ps-am | ||
555 | |||
556 | ps-am: | ||
557 | |||
558 | uninstall-am: uninstall-binPROGRAMS uninstall-info-am uninstall-local \ | ||
559 | uninstall-man | ||
560 | |||
561 | uninstall-man: uninstall-man1 | ||
562 | |||
563 | .PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \ | ||
564 | clean-generic clean-libtool ctags distclean distclean-compile \ | ||
565 | distclean-generic distclean-libtool distclean-tags distdir dvi \ | ||
566 | dvi-am html html-am info info-am install install-am \ | ||
567 | install-binPROGRAMS install-data install-data-am \ | ||
568 | install-data-local install-exec install-exec-am install-info \ | ||
569 | install-info-am install-man install-man1 install-strip \ | ||
570 | installcheck installcheck-am installdirs maintainer-clean \ | ||
571 | maintainer-clean-generic mostlyclean mostlyclean-compile \ | ||
572 | mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ | ||
573 | tags uninstall uninstall-am uninstall-binPROGRAMS \ | ||
574 | uninstall-info-am uninstall-local uninstall-man uninstall-man1 | ||
575 | |||
576 | |||
577 | install-data-local: | ||
578 | -mkdir -p $(DESTDIR)$(man1dir) | ||
579 | (cd $(DESTDIR)$(man1dir) && \ | ||
580 | for f in $(MANLINKS); do ln -sf otr_toolkit.1 $$f; done) | ||
581 | |||
582 | uninstall-local: | ||
583 | (cd $(DESTDIR)$(man1dir) && \ | ||
584 | for f in $(MANLINKS); do rm -f $$f; done) | ||
585 | # Tell versions [3.59,3.63) of GNU make to not export all variables. | ||
586 | # Otherwise a system limit (for SysV at least) may be exceeded. | ||
587 | .NOEXPORT: | ||
diff --git a/linden/indra/libotr/libotr-3.2.0/toolkit/aes.c b/linden/indra/libotr/libotr-3.2.0/toolkit/aes.c new file mode 100755 index 0000000..24b9b56 --- /dev/null +++ b/linden/indra/libotr/libotr-3.2.0/toolkit/aes.c | |||
@@ -0,0 +1,866 @@ | |||
1 | /* Retrieved from http://www.cr0.net:8040/code/crypto/aes/aes.c */ | ||
2 | |||
3 | /* | ||
4 | * FIPS-197 compliant AES implementation | ||
5 | * | ||
6 | * Copyright (C) 2001-2004 Christophe Devine | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | */ | ||
22 | |||
23 | #include "aes.h" | ||
24 | |||
25 | /* uncomment the following line to run the test suite */ | ||
26 | |||
27 | /* #define TEST */ | ||
28 | |||
29 | /* uncomment the following line to use pre-computed tables */ | ||
30 | /* otherwise the tables will be generated at the first run */ | ||
31 | |||
32 | /* #define FIXED_TABLES */ | ||
33 | |||
34 | #ifndef FIXED_TABLES | ||
35 | |||
36 | /* forward S-box & tables */ | ||
37 | |||
38 | uint32 FSb[256]; | ||
39 | uint32 FT0[256]; | ||
40 | uint32 FT1[256]; | ||
41 | uint32 FT2[256]; | ||
42 | uint32 FT3[256]; | ||
43 | |||
44 | /* reverse S-box & tables */ | ||
45 | |||
46 | uint32 RSb[256]; | ||
47 | uint32 RT0[256]; | ||
48 | uint32 RT1[256]; | ||
49 | uint32 RT2[256]; | ||
50 | uint32 RT3[256]; | ||
51 | |||
52 | /* round constants */ | ||
53 | |||
54 | uint32 RCON[10]; | ||
55 | |||
56 | /* tables generation flag */ | ||
57 | |||
58 | int do_init = 1; | ||
59 | |||
60 | /* tables generation routine */ | ||
61 | |||
62 | #define ROTR8(x) ( ( ( x << 24 ) & 0xFFFFFFFF ) | \ | ||
63 | ( ( x & 0xFFFFFFFF ) >> 8 ) ) | ||
64 | |||
65 | #define XTIME(x) ( ( x << 1 ) ^ ( ( x & 0x80 ) ? 0x1B : 0x00 ) ) | ||
66 | #define MUL(x,y) ( ( x && y ) ? pow[(log[x] + log[y]) % 255] : 0 ) | ||
67 | |||
68 | void aes_gen_tables( void ) | ||
69 | { | ||
70 | int i; | ||
71 | uint8 x, y; | ||
72 | uint8 pow[256]; | ||
73 | uint8 log[256]; | ||
74 | |||
75 | /* compute pow and log tables over GF(2^8) */ | ||
76 | |||
77 | for( i = 0, x = 1; i < 256; i++, x ^= XTIME( x ) ) | ||
78 | { | ||
79 | pow[i] = x; | ||
80 | log[x] = i; | ||
81 | } | ||
82 | |||
83 | /* calculate the round constants */ | ||
84 | |||
85 | for( i = 0, x = 1; i < 10; i++, x = XTIME( x ) ) | ||
86 | { | ||
87 | RCON[i] = (uint32) x << 24; | ||
88 | } | ||
89 | |||
90 | /* generate the forward and reverse S-boxes */ | ||
91 | |||
92 | FSb[0x00] = 0x63; | ||
93 | RSb[0x63] = 0x00; | ||
94 | |||
95 | for( i = 1; i < 256; i++ ) | ||
96 | { | ||
97 | x = pow[255 - log[i]]; | ||
98 | |||
99 | y = x; y = ( y << 1 ) | ( y >> 7 ); | ||
100 | x ^= y; y = ( y << 1 ) | ( y >> 7 ); | ||
101 | x ^= y; y = ( y << 1 ) | ( y >> 7 ); | ||
102 | x ^= y; y = ( y << 1 ) | ( y >> 7 ); | ||
103 | x ^= y ^ 0x63; | ||
104 | |||
105 | FSb[i] = x; | ||
106 | RSb[x] = i; | ||
107 | } | ||
108 | |||
109 | /* generate the forward and reverse tables */ | ||
110 | |||
111 | for( i = 0; i < 256; i++ ) | ||
112 | { | ||
113 | x = (unsigned char) FSb[i]; y = XTIME( x ); | ||
114 | |||
115 | FT0[i] = (uint32) ( x ^ y ) ^ | ||
116 | ( (uint32) x << 8 ) ^ | ||
117 | ( (uint32) x << 16 ) ^ | ||
118 | ( (uint32) y << 24 ); | ||
119 | |||
120 | FT0[i] &= 0xFFFFFFFF; | ||
121 | |||
122 | FT1[i] = ROTR8( FT0[i] ); | ||
123 | FT2[i] = ROTR8( FT1[i] ); | ||
124 | FT3[i] = ROTR8( FT2[i] ); | ||
125 | |||
126 | y = (unsigned char) RSb[i]; | ||
127 | |||
128 | RT0[i] = ( (uint32) MUL( 0x0B, y ) ) ^ | ||
129 | ( (uint32) MUL( 0x0D, y ) << 8 ) ^ | ||
130 | ( (uint32) MUL( 0x09, y ) << 16 ) ^ | ||
131 | ( (uint32) MUL( 0x0E, y ) << 24 ); | ||
132 | |||
133 | RT0[i] &= 0xFFFFFFFF; | ||
134 | |||
135 | RT1[i] = ROTR8( RT0[i] ); | ||
136 | RT2[i] = ROTR8( RT1[i] ); | ||
137 | RT3[i] = ROTR8( RT2[i] ); | ||
138 | } | ||
139 | } | ||
140 | |||
141 | #else | ||
142 | |||
143 | /* forward S-box */ | ||
144 | |||
145 | static const uint32 FSb[256] = | ||
146 | { | ||
147 | 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, | ||
148 | 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76, | ||
149 | 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, | ||
150 | 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0, | ||
151 | 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, | ||
152 | 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15, | ||
153 | 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, | ||
154 | 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75, | ||
155 | 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0, | ||
156 | 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84, | ||
157 | 0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B, | ||
158 | 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF, | ||
159 | 0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85, | ||
160 | 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8, | ||
161 | 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5, | ||
162 | 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2, | ||
163 | 0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17, | ||
164 | 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73, | ||
165 | 0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88, | ||
166 | 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB, | ||
167 | 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C, | ||
168 | 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79, | ||
169 | 0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9, | ||
170 | 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08, | ||
171 | 0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6, | ||
172 | 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A, | ||
173 | 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, | ||
174 | 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E, | ||
175 | 0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94, | ||
176 | 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF, | ||
177 | 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, | ||
178 | 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16 | ||
179 | }; | ||
180 | |||
181 | /* forward tables */ | ||
182 | |||
183 | #define FT \ | ||
184 | \ | ||
185 | V(C6,63,63,A5), V(F8,7C,7C,84), V(EE,77,77,99), V(F6,7B,7B,8D), \ | ||
186 | V(FF,F2,F2,0D), V(D6,6B,6B,BD), V(DE,6F,6F,B1), V(91,C5,C5,54), \ | ||
187 | V(60,30,30,50), V(02,01,01,03), V(CE,67,67,A9), V(56,2B,2B,7D), \ | ||
188 | V(E7,FE,FE,19), V(B5,D7,D7,62), V(4D,AB,AB,E6), V(EC,76,76,9A), \ | ||
189 | V(8F,CA,CA,45), V(1F,82,82,9D), V(89,C9,C9,40), V(FA,7D,7D,87), \ | ||
190 | V(EF,FA,FA,15), V(B2,59,59,EB), V(8E,47,47,C9), V(FB,F0,F0,0B), \ | ||
191 | V(41,AD,AD,EC), V(B3,D4,D4,67), V(5F,A2,A2,FD), V(45,AF,AF,EA), \ | ||
192 | V(23,9C,9C,BF), V(53,A4,A4,F7), V(E4,72,72,96), V(9B,C0,C0,5B), \ | ||
193 | V(75,B7,B7,C2), V(E1,FD,FD,1C), V(3D,93,93,AE), V(4C,26,26,6A), \ | ||
194 | V(6C,36,36,5A), V(7E,3F,3F,41), V(F5,F7,F7,02), V(83,CC,CC,4F), \ | ||
195 | V(68,34,34,5C), V(51,A5,A5,F4), V(D1,E5,E5,34), V(F9,F1,F1,08), \ | ||
196 | V(E2,71,71,93), V(AB,D8,D8,73), V(62,31,31,53), V(2A,15,15,3F), \ | ||
197 | V(08,04,04,0C), V(95,C7,C7,52), V(46,23,23,65), V(9D,C3,C3,5E), \ | ||
198 | V(30,18,18,28), V(37,96,96,A1), V(0A,05,05,0F), V(2F,9A,9A,B5), \ | ||
199 | V(0E,07,07,09), V(24,12,12,36), V(1B,80,80,9B), V(DF,E2,E2,3D), \ | ||
200 | V(CD,EB,EB,26), V(4E,27,27,69), V(7F,B2,B2,CD), V(EA,75,75,9F), \ | ||
201 | V(12,09,09,1B), V(1D,83,83,9E), V(58,2C,2C,74), V(34,1A,1A,2E), \ | ||
202 | V(36,1B,1B,2D), V(DC,6E,6E,B2), V(B4,5A,5A,EE), V(5B,A0,A0,FB), \ | ||
203 | V(A4,52,52,F6), V(76,3B,3B,4D), V(B7,D6,D6,61), V(7D,B3,B3,CE), \ | ||
204 | V(52,29,29,7B), V(DD,E3,E3,3E), V(5E,2F,2F,71), V(13,84,84,97), \ | ||
205 | V(A6,53,53,F5), V(B9,D1,D1,68), V(00,00,00,00), V(C1,ED,ED,2C), \ | ||
206 | V(40,20,20,60), V(E3,FC,FC,1F), V(79,B1,B1,C8), V(B6,5B,5B,ED), \ | ||
207 | V(D4,6A,6A,BE), V(8D,CB,CB,46), V(67,BE,BE,D9), V(72,39,39,4B), \ | ||
208 | V(94,4A,4A,DE), V(98,4C,4C,D4), V(B0,58,58,E8), V(85,CF,CF,4A), \ | ||
209 | V(BB,D0,D0,6B), V(C5,EF,EF,2A), V(4F,AA,AA,E5), V(ED,FB,FB,16), \ | ||
210 | V(86,43,43,C5), V(9A,4D,4D,D7), V(66,33,33,55), V(11,85,85,94), \ | ||
211 | V(8A,45,45,CF), V(E9,F9,F9,10), V(04,02,02,06), V(FE,7F,7F,81), \ | ||
212 | V(A0,50,50,F0), V(78,3C,3C,44), V(25,9F,9F,BA), V(4B,A8,A8,E3), \ | ||
213 | V(A2,51,51,F3), V(5D,A3,A3,FE), V(80,40,40,C0), V(05,8F,8F,8A), \ | ||
214 | V(3F,92,92,AD), V(21,9D,9D,BC), V(70,38,38,48), V(F1,F5,F5,04), \ | ||
215 | V(63,BC,BC,DF), V(77,B6,B6,C1), V(AF,DA,DA,75), V(42,21,21,63), \ | ||
216 | V(20,10,10,30), V(E5,FF,FF,1A), V(FD,F3,F3,0E), V(BF,D2,D2,6D), \ | ||
217 | V(81,CD,CD,4C), V(18,0C,0C,14), V(26,13,13,35), V(C3,EC,EC,2F), \ | ||
218 | V(BE,5F,5F,E1), V(35,97,97,A2), V(88,44,44,CC), V(2E,17,17,39), \ | ||
219 | V(93,C4,C4,57), V(55,A7,A7,F2), V(FC,7E,7E,82), V(7A,3D,3D,47), \ | ||
220 | V(C8,64,64,AC), V(BA,5D,5D,E7), V(32,19,19,2B), V(E6,73,73,95), \ | ||
221 | V(C0,60,60,A0), V(19,81,81,98), V(9E,4F,4F,D1), V(A3,DC,DC,7F), \ | ||
222 | V(44,22,22,66), V(54,2A,2A,7E), V(3B,90,90,AB), V(0B,88,88,83), \ | ||
223 | V(8C,46,46,CA), V(C7,EE,EE,29), V(6B,B8,B8,D3), V(28,14,14,3C), \ | ||
224 | V(A7,DE,DE,79), V(BC,5E,5E,E2), V(16,0B,0B,1D), V(AD,DB,DB,76), \ | ||
225 | V(DB,E0,E0,3B), V(64,32,32,56), V(74,3A,3A,4E), V(14,0A,0A,1E), \ | ||
226 | V(92,49,49,DB), V(0C,06,06,0A), V(48,24,24,6C), V(B8,5C,5C,E4), \ | ||
227 | V(9F,C2,C2,5D), V(BD,D3,D3,6E), V(43,AC,AC,EF), V(C4,62,62,A6), \ | ||
228 | V(39,91,91,A8), V(31,95,95,A4), V(D3,E4,E4,37), V(F2,79,79,8B), \ | ||
229 | V(D5,E7,E7,32), V(8B,C8,C8,43), V(6E,37,37,59), V(DA,6D,6D,B7), \ | ||
230 | V(01,8D,8D,8C), V(B1,D5,D5,64), V(9C,4E,4E,D2), V(49,A9,A9,E0), \ | ||
231 | V(D8,6C,6C,B4), V(AC,56,56,FA), V(F3,F4,F4,07), V(CF,EA,EA,25), \ | ||
232 | V(CA,65,65,AF), V(F4,7A,7A,8E), V(47,AE,AE,E9), V(10,08,08,18), \ | ||
233 | V(6F,BA,BA,D5), V(F0,78,78,88), V(4A,25,25,6F), V(5C,2E,2E,72), \ | ||
234 | V(38,1C,1C,24), V(57,A6,A6,F1), V(73,B4,B4,C7), V(97,C6,C6,51), \ | ||
235 | V(CB,E8,E8,23), V(A1,DD,DD,7C), V(E8,74,74,9C), V(3E,1F,1F,21), \ | ||
236 | V(96,4B,4B,DD), V(61,BD,BD,DC), V(0D,8B,8B,86), V(0F,8A,8A,85), \ | ||
237 | V(E0,70,70,90), V(7C,3E,3E,42), V(71,B5,B5,C4), V(CC,66,66,AA), \ | ||
238 | V(90,48,48,D8), V(06,03,03,05), V(F7,F6,F6,01), V(1C,0E,0E,12), \ | ||
239 | V(C2,61,61,A3), V(6A,35,35,5F), V(AE,57,57,F9), V(69,B9,B9,D0), \ | ||
240 | V(17,86,86,91), V(99,C1,C1,58), V(3A,1D,1D,27), V(27,9E,9E,B9), \ | ||
241 | V(D9,E1,E1,38), V(EB,F8,F8,13), V(2B,98,98,B3), V(22,11,11,33), \ | ||
242 | V(D2,69,69,BB), V(A9,D9,D9,70), V(07,8E,8E,89), V(33,94,94,A7), \ | ||
243 | V(2D,9B,9B,B6), V(3C,1E,1E,22), V(15,87,87,92), V(C9,E9,E9,20), \ | ||
244 | V(87,CE,CE,49), V(AA,55,55,FF), V(50,28,28,78), V(A5,DF,DF,7A), \ | ||
245 | V(03,8C,8C,8F), V(59,A1,A1,F8), V(09,89,89,80), V(1A,0D,0D,17), \ | ||
246 | V(65,BF,BF,DA), V(D7,E6,E6,31), V(84,42,42,C6), V(D0,68,68,B8), \ | ||
247 | V(82,41,41,C3), V(29,99,99,B0), V(5A,2D,2D,77), V(1E,0F,0F,11), \ | ||
248 | V(7B,B0,B0,CB), V(A8,54,54,FC), V(6D,BB,BB,D6), V(2C,16,16,3A) | ||
249 | |||
250 | #define V(a,b,c,d) 0x##a##b##c##d | ||
251 | static const uint32 FT0[256] = { FT }; | ||
252 | #undef V | ||
253 | |||
254 | #define V(a,b,c,d) 0x##d##a##b##c | ||
255 | static const uint32 FT1[256] = { FT }; | ||
256 | #undef V | ||
257 | |||
258 | #define V(a,b,c,d) 0x##c##d##a##b | ||
259 | static const uint32 FT2[256] = { FT }; | ||
260 | #undef V | ||
261 | |||
262 | #define V(a,b,c,d) 0x##b##c##d##a | ||
263 | static const uint32 FT3[256] = { FT }; | ||
264 | #undef V | ||
265 | |||
266 | #undef FT | ||
267 | |||
268 | /* reverse S-box */ | ||
269 | |||
270 | static const uint32 RSb[256] = | ||
271 | { | ||
272 | 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, | ||
273 | 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB, | ||
274 | 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, | ||
275 | 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB, | ||
276 | 0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D, | ||
277 | 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E, | ||
278 | 0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2, | ||
279 | 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25, | ||
280 | 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16, | ||
281 | 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92, | ||
282 | 0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA, | ||
283 | 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84, | ||
284 | 0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A, | ||
285 | 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06, | ||
286 | 0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02, | ||
287 | 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B, | ||
288 | 0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA, | ||
289 | 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73, | ||
290 | 0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85, | ||
291 | 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E, | ||
292 | 0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89, | ||
293 | 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B, | ||
294 | 0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20, | ||
295 | 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4, | ||
296 | 0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, | ||
297 | 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F, | ||
298 | 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, | ||
299 | 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF, | ||
300 | 0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0, | ||
301 | 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61, | ||
302 | 0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, | ||
303 | 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D | ||
304 | }; | ||
305 | |||
306 | /* reverse tables */ | ||
307 | |||
308 | #define RT \ | ||
309 | \ | ||
310 | V(51,F4,A7,50), V(7E,41,65,53), V(1A,17,A4,C3), V(3A,27,5E,96), \ | ||
311 | V(3B,AB,6B,CB), V(1F,9D,45,F1), V(AC,FA,58,AB), V(4B,E3,03,93), \ | ||
312 | V(20,30,FA,55), V(AD,76,6D,F6), V(88,CC,76,91), V(F5,02,4C,25), \ | ||
313 | V(4F,E5,D7,FC), V(C5,2A,CB,D7), V(26,35,44,80), V(B5,62,A3,8F), \ | ||
314 | V(DE,B1,5A,49), V(25,BA,1B,67), V(45,EA,0E,98), V(5D,FE,C0,E1), \ | ||
315 | V(C3,2F,75,02), V(81,4C,F0,12), V(8D,46,97,A3), V(6B,D3,F9,C6), \ | ||
316 | V(03,8F,5F,E7), V(15,92,9C,95), V(BF,6D,7A,EB), V(95,52,59,DA), \ | ||
317 | V(D4,BE,83,2D), V(58,74,21,D3), V(49,E0,69,29), V(8E,C9,C8,44), \ | ||
318 | V(75,C2,89,6A), V(F4,8E,79,78), V(99,58,3E,6B), V(27,B9,71,DD), \ | ||
319 | V(BE,E1,4F,B6), V(F0,88,AD,17), V(C9,20,AC,66), V(7D,CE,3A,B4), \ | ||
320 | V(63,DF,4A,18), V(E5,1A,31,82), V(97,51,33,60), V(62,53,7F,45), \ | ||
321 | V(B1,64,77,E0), V(BB,6B,AE,84), V(FE,81,A0,1C), V(F9,08,2B,94), \ | ||
322 | V(70,48,68,58), V(8F,45,FD,19), V(94,DE,6C,87), V(52,7B,F8,B7), \ | ||
323 | V(AB,73,D3,23), V(72,4B,02,E2), V(E3,1F,8F,57), V(66,55,AB,2A), \ | ||
324 | V(B2,EB,28,07), V(2F,B5,C2,03), V(86,C5,7B,9A), V(D3,37,08,A5), \ | ||
325 | V(30,28,87,F2), V(23,BF,A5,B2), V(02,03,6A,BA), V(ED,16,82,5C), \ | ||
326 | V(8A,CF,1C,2B), V(A7,79,B4,92), V(F3,07,F2,F0), V(4E,69,E2,A1), \ | ||
327 | V(65,DA,F4,CD), V(06,05,BE,D5), V(D1,34,62,1F), V(C4,A6,FE,8A), \ | ||
328 | V(34,2E,53,9D), V(A2,F3,55,A0), V(05,8A,E1,32), V(A4,F6,EB,75), \ | ||
329 | V(0B,83,EC,39), V(40,60,EF,AA), V(5E,71,9F,06), V(BD,6E,10,51), \ | ||
330 | V(3E,21,8A,F9), V(96,DD,06,3D), V(DD,3E,05,AE), V(4D,E6,BD,46), \ | ||
331 | V(91,54,8D,B5), V(71,C4,5D,05), V(04,06,D4,6F), V(60,50,15,FF), \ | ||
332 | V(19,98,FB,24), V(D6,BD,E9,97), V(89,40,43,CC), V(67,D9,9E,77), \ | ||
333 | V(B0,E8,42,BD), V(07,89,8B,88), V(E7,19,5B,38), V(79,C8,EE,DB), \ | ||
334 | V(A1,7C,0A,47), V(7C,42,0F,E9), V(F8,84,1E,C9), V(00,00,00,00), \ | ||
335 | V(09,80,86,83), V(32,2B,ED,48), V(1E,11,70,AC), V(6C,5A,72,4E), \ | ||
336 | V(FD,0E,FF,FB), V(0F,85,38,56), V(3D,AE,D5,1E), V(36,2D,39,27), \ | ||
337 | V(0A,0F,D9,64), V(68,5C,A6,21), V(9B,5B,54,D1), V(24,36,2E,3A), \ | ||
338 | V(0C,0A,67,B1), V(93,57,E7,0F), V(B4,EE,96,D2), V(1B,9B,91,9E), \ | ||
339 | V(80,C0,C5,4F), V(61,DC,20,A2), V(5A,77,4B,69), V(1C,12,1A,16), \ | ||
340 | V(E2,93,BA,0A), V(C0,A0,2A,E5), V(3C,22,E0,43), V(12,1B,17,1D), \ | ||
341 | V(0E,09,0D,0B), V(F2,8B,C7,AD), V(2D,B6,A8,B9), V(14,1E,A9,C8), \ | ||
342 | V(57,F1,19,85), V(AF,75,07,4C), V(EE,99,DD,BB), V(A3,7F,60,FD), \ | ||
343 | V(F7,01,26,9F), V(5C,72,F5,BC), V(44,66,3B,C5), V(5B,FB,7E,34), \ | ||
344 | V(8B,43,29,76), V(CB,23,C6,DC), V(B6,ED,FC,68), V(B8,E4,F1,63), \ | ||
345 | V(D7,31,DC,CA), V(42,63,85,10), V(13,97,22,40), V(84,C6,11,20), \ | ||
346 | V(85,4A,24,7D), V(D2,BB,3D,F8), V(AE,F9,32,11), V(C7,29,A1,6D), \ | ||
347 | V(1D,9E,2F,4B), V(DC,B2,30,F3), V(0D,86,52,EC), V(77,C1,E3,D0), \ | ||
348 | V(2B,B3,16,6C), V(A9,70,B9,99), V(11,94,48,FA), V(47,E9,64,22), \ | ||
349 | V(A8,FC,8C,C4), V(A0,F0,3F,1A), V(56,7D,2C,D8), V(22,33,90,EF), \ | ||
350 | V(87,49,4E,C7), V(D9,38,D1,C1), V(8C,CA,A2,FE), V(98,D4,0B,36), \ | ||
351 | V(A6,F5,81,CF), V(A5,7A,DE,28), V(DA,B7,8E,26), V(3F,AD,BF,A4), \ | ||
352 | V(2C,3A,9D,E4), V(50,78,92,0D), V(6A,5F,CC,9B), V(54,7E,46,62), \ | ||
353 | V(F6,8D,13,C2), V(90,D8,B8,E8), V(2E,39,F7,5E), V(82,C3,AF,F5), \ | ||
354 | V(9F,5D,80,BE), V(69,D0,93,7C), V(6F,D5,2D,A9), V(CF,25,12,B3), \ | ||
355 | V(C8,AC,99,3B), V(10,18,7D,A7), V(E8,9C,63,6E), V(DB,3B,BB,7B), \ | ||
356 | V(CD,26,78,09), V(6E,59,18,F4), V(EC,9A,B7,01), V(83,4F,9A,A8), \ | ||
357 | V(E6,95,6E,65), V(AA,FF,E6,7E), V(21,BC,CF,08), V(EF,15,E8,E6), \ | ||
358 | V(BA,E7,9B,D9), V(4A,6F,36,CE), V(EA,9F,09,D4), V(29,B0,7C,D6), \ | ||
359 | V(31,A4,B2,AF), V(2A,3F,23,31), V(C6,A5,94,30), V(35,A2,66,C0), \ | ||
360 | V(74,4E,BC,37), V(FC,82,CA,A6), V(E0,90,D0,B0), V(33,A7,D8,15), \ | ||
361 | V(F1,04,98,4A), V(41,EC,DA,F7), V(7F,CD,50,0E), V(17,91,F6,2F), \ | ||
362 | V(76,4D,D6,8D), V(43,EF,B0,4D), V(CC,AA,4D,54), V(E4,96,04,DF), \ | ||
363 | V(9E,D1,B5,E3), V(4C,6A,88,1B), V(C1,2C,1F,B8), V(46,65,51,7F), \ | ||
364 | V(9D,5E,EA,04), V(01,8C,35,5D), V(FA,87,74,73), V(FB,0B,41,2E), \ | ||
365 | V(B3,67,1D,5A), V(92,DB,D2,52), V(E9,10,56,33), V(6D,D6,47,13), \ | ||
366 | V(9A,D7,61,8C), V(37,A1,0C,7A), V(59,F8,14,8E), V(EB,13,3C,89), \ | ||
367 | V(CE,A9,27,EE), V(B7,61,C9,35), V(E1,1C,E5,ED), V(7A,47,B1,3C), \ | ||
368 | V(9C,D2,DF,59), V(55,F2,73,3F), V(18,14,CE,79), V(73,C7,37,BF), \ | ||
369 | V(53,F7,CD,EA), V(5F,FD,AA,5B), V(DF,3D,6F,14), V(78,44,DB,86), \ | ||
370 | V(CA,AF,F3,81), V(B9,68,C4,3E), V(38,24,34,2C), V(C2,A3,40,5F), \ | ||
371 | V(16,1D,C3,72), V(BC,E2,25,0C), V(28,3C,49,8B), V(FF,0D,95,41), \ | ||
372 | V(39,A8,01,71), V(08,0C,B3,DE), V(D8,B4,E4,9C), V(64,56,C1,90), \ | ||
373 | V(7B,CB,84,61), V(D5,32,B6,70), V(48,6C,5C,74), V(D0,B8,57,42) | ||
374 | |||
375 | #define V(a,b,c,d) 0x##a##b##c##d | ||
376 | static const uint32 RT0[256] = { RT }; | ||
377 | #undef V | ||
378 | |||
379 | #define V(a,b,c,d) 0x##d##a##b##c | ||
380 | static const uint32 RT1[256] = { RT }; | ||
381 | #undef V | ||
382 | |||
383 | #define V(a,b,c,d) 0x##c##d##a##b | ||
384 | static const uint32 RT2[256] = { RT }; | ||
385 | #undef V | ||
386 | |||
387 | #define V(a,b,c,d) 0x##b##c##d##a | ||
388 | static const uint32 RT3[256] = { RT }; | ||
389 | #undef V | ||
390 | |||
391 | #undef RT | ||
392 | |||
393 | /* round constants */ | ||
394 | |||
395 | static const uint32 RCON[10] = | ||
396 | { | ||
397 | 0x01000000, 0x02000000, 0x04000000, 0x08000000, | ||
398 | 0x10000000, 0x20000000, 0x40000000, 0x80000000, | ||
399 | 0x1B000000, 0x36000000 | ||
400 | }; | ||
401 | |||
402 | int do_init = 0; | ||
403 | |||
404 | void aes_gen_tables( void ) | ||
405 | { | ||
406 | } | ||
407 | |||
408 | #endif | ||
409 | |||
410 | /* platform-independant 32-bit integer manipulation macros */ | ||
411 | |||
412 | #define GET_UINT32(n,b,i) \ | ||
413 | { \ | ||
414 | (n) = ( (uint32) (b)[(i) ] << 24 ) \ | ||
415 | | ( (uint32) (b)[(i) + 1] << 16 ) \ | ||
416 | | ( (uint32) (b)[(i) + 2] << 8 ) \ | ||
417 | | ( (uint32) (b)[(i) + 3] ); \ | ||
418 | } | ||
419 | |||
420 | #define PUT_UINT32(n,b,i) \ | ||
421 | { \ | ||
422 | (b)[(i) ] = (uint8) ( (n) >> 24 ); \ | ||
423 | (b)[(i) + 1] = (uint8) ( (n) >> 16 ); \ | ||
424 | (b)[(i) + 2] = (uint8) ( (n) >> 8 ); \ | ||
425 | (b)[(i) + 3] = (uint8) ( (n) ); \ | ||
426 | } | ||
427 | |||
428 | /* decryption key schedule tables */ | ||
429 | |||
430 | int KT_init = 1; | ||
431 | |||
432 | uint32 KT0[256]; | ||
433 | uint32 KT1[256]; | ||
434 | uint32 KT2[256]; | ||
435 | uint32 KT3[256]; | ||
436 | |||
437 | /* AES key scheduling routine */ | ||
438 | |||
439 | int aes_set_key( aes_context *ctx, uint8 *key, int nbits ) | ||
440 | { | ||
441 | int i; | ||
442 | uint32 *RK, *SK; | ||
443 | |||
444 | if( do_init ) | ||
445 | { | ||
446 | aes_gen_tables(); | ||
447 | |||
448 | do_init = 0; | ||
449 | } | ||
450 | |||
451 | switch( nbits ) | ||
452 | { | ||
453 | case 128: ctx->nr = 10; break; | ||
454 | case 192: ctx->nr = 12; break; | ||
455 | case 256: ctx->nr = 14; break; | ||
456 | default : return( 1 ); | ||
457 | } | ||
458 | |||
459 | RK = ctx->erk; | ||
460 | |||
461 | for( i = 0; i < (nbits >> 5); i++ ) | ||
462 | { | ||
463 | GET_UINT32( RK[i], key, i * 4 ); | ||
464 | } | ||
465 | |||
466 | /* setup encryption round keys */ | ||
467 | |||
468 | switch( nbits ) | ||
469 | { | ||
470 | case 128: | ||
471 | |||
472 | for( i = 0; i < 10; i++, RK += 4 ) | ||
473 | { | ||
474 | RK[4] = RK[0] ^ RCON[i] ^ | ||
475 | ( FSb[ (uint8) ( RK[3] >> 16 ) ] << 24 ) ^ | ||
476 | ( FSb[ (uint8) ( RK[3] >> 8 ) ] << 16 ) ^ | ||
477 | ( FSb[ (uint8) ( RK[3] ) ] << 8 ) ^ | ||
478 | ( FSb[ (uint8) ( RK[3] >> 24 ) ] ); | ||
479 | |||
480 | RK[5] = RK[1] ^ RK[4]; | ||
481 | RK[6] = RK[2] ^ RK[5]; | ||
482 | RK[7] = RK[3] ^ RK[6]; | ||
483 | } | ||
484 | break; | ||
485 | |||
486 | case 192: | ||
487 | |||
488 | for( i = 0; i < 8; i++, RK += 6 ) | ||
489 | { | ||
490 | RK[6] = RK[0] ^ RCON[i] ^ | ||
491 | ( FSb[ (uint8) ( RK[5] >> 16 ) ] << 24 ) ^ | ||
492 | ( FSb[ (uint8) ( RK[5] >> 8 ) ] << 16 ) ^ | ||
493 | ( FSb[ (uint8) ( RK[5] ) ] << 8 ) ^ | ||
494 | ( FSb[ (uint8) ( RK[5] >> 24 ) ] ); | ||
495 | |||
496 | RK[7] = RK[1] ^ RK[6]; | ||
497 | RK[8] = RK[2] ^ RK[7]; | ||
498 | RK[9] = RK[3] ^ RK[8]; | ||
499 | RK[10] = RK[4] ^ RK[9]; | ||
500 | RK[11] = RK[5] ^ RK[10]; | ||
501 | } | ||
502 | break; | ||
503 | |||
504 | case 256: | ||
505 | |||
506 | for( i = 0; i < 7; i++, RK += 8 ) | ||
507 | { | ||
508 | RK[8] = RK[0] ^ RCON[i] ^ | ||
509 | ( FSb[ (uint8) ( RK[7] >> 16 ) ] << 24 ) ^ | ||
510 | ( FSb[ (uint8) ( RK[7] >> 8 ) ] << 16 ) ^ | ||
511 | ( FSb[ (uint8) ( RK[7] ) ] << 8 ) ^ | ||
512 | ( FSb[ (uint8) ( RK[7] >> 24 ) ] ); | ||
513 | |||
514 | RK[9] = RK[1] ^ RK[8]; | ||
515 | RK[10] = RK[2] ^ RK[9]; | ||
516 | RK[11] = RK[3] ^ RK[10]; | ||
517 | |||
518 | RK[12] = RK[4] ^ | ||
519 | ( FSb[ (uint8) ( RK[11] >> 24 ) ] << 24 ) ^ | ||
520 | ( FSb[ (uint8) ( RK[11] >> 16 ) ] << 16 ) ^ | ||
521 | ( FSb[ (uint8) ( RK[11] >> 8 ) ] << 8 ) ^ | ||
522 | ( FSb[ (uint8) ( RK[11] ) ] ); | ||
523 | |||
524 | RK[13] = RK[5] ^ RK[12]; | ||
525 | RK[14] = RK[6] ^ RK[13]; | ||
526 | RK[15] = RK[7] ^ RK[14]; | ||
527 | } | ||
528 | break; | ||
529 | } | ||
530 | |||
531 | /* setup decryption round keys */ | ||
532 | |||
533 | if( KT_init ) | ||
534 | { | ||
535 | for( i = 0; i < 256; i++ ) | ||
536 | { | ||
537 | KT0[i] = RT0[ FSb[i] ]; | ||
538 | KT1[i] = RT1[ FSb[i] ]; | ||
539 | KT2[i] = RT2[ FSb[i] ]; | ||
540 | KT3[i] = RT3[ FSb[i] ]; | ||
541 | } | ||
542 | |||
543 | KT_init = 0; | ||
544 | } | ||
545 | |||
546 | SK = ctx->drk; | ||
547 | |||
548 | *SK++ = *RK++; | ||
549 | *SK++ = *RK++; | ||
550 | *SK++ = *RK++; | ||
551 | *SK++ = *RK++; | ||
552 | |||
553 | for( i = 1; i < ctx->nr; i++ ) | ||
554 | { | ||
555 | RK -= 8; | ||
556 | |||
557 | *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^ | ||
558 | KT1[ (uint8) ( *RK >> 16 ) ] ^ | ||
559 | KT2[ (uint8) ( *RK >> 8 ) ] ^ | ||
560 | KT3[ (uint8) ( *RK ) ]; RK++; | ||
561 | |||
562 | *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^ | ||
563 | KT1[ (uint8) ( *RK >> 16 ) ] ^ | ||
564 | KT2[ (uint8) ( *RK >> 8 ) ] ^ | ||
565 | KT3[ (uint8) ( *RK ) ]; RK++; | ||
566 | |||
567 | *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^ | ||
568 | KT1[ (uint8) ( *RK >> 16 ) ] ^ | ||
569 | KT2[ (uint8) ( *RK >> 8 ) ] ^ | ||
570 | KT3[ (uint8) ( *RK ) ]; RK++; | ||
571 | |||
572 | *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^ | ||
573 | KT1[ (uint8) ( *RK >> 16 ) ] ^ | ||
574 | KT2[ (uint8) ( *RK >> 8 ) ] ^ | ||
575 | KT3[ (uint8) ( *RK ) ]; RK++; | ||
576 | } | ||
577 | |||
578 | RK -= 8; | ||
579 | |||
580 | *SK++ = *RK++; | ||
581 | *SK++ = *RK++; | ||
582 | *SK++ = *RK++; | ||
583 | *SK++ = *RK++; | ||
584 | |||
585 | return( 0 ); | ||
586 | } | ||
587 | |||
588 | /* AES 128-bit block encryption routine */ | ||
589 | |||
590 | void aes_encrypt( aes_context *ctx, uint8 input[16], uint8 output[16] ) | ||
591 | { | ||
592 | uint32 *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3; | ||
593 | |||
594 | RK = ctx->erk; | ||
595 | |||
596 | GET_UINT32( X0, input, 0 ); X0 ^= RK[0]; | ||
597 | GET_UINT32( X1, input, 4 ); X1 ^= RK[1]; | ||
598 | GET_UINT32( X2, input, 8 ); X2 ^= RK[2]; | ||
599 | GET_UINT32( X3, input, 12 ); X3 ^= RK[3]; | ||
600 | |||
601 | #define AES_FROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \ | ||
602 | { \ | ||
603 | RK += 4; \ | ||
604 | \ | ||
605 | X0 = RK[0] ^ FT0[ (uint8) ( Y0 >> 24 ) ] ^ \ | ||
606 | FT1[ (uint8) ( Y1 >> 16 ) ] ^ \ | ||
607 | FT2[ (uint8) ( Y2 >> 8 ) ] ^ \ | ||
608 | FT3[ (uint8) ( Y3 ) ]; \ | ||
609 | \ | ||
610 | X1 = RK[1] ^ FT0[ (uint8) ( Y1 >> 24 ) ] ^ \ | ||
611 | FT1[ (uint8) ( Y2 >> 16 ) ] ^ \ | ||
612 | FT2[ (uint8) ( Y3 >> 8 ) ] ^ \ | ||
613 | FT3[ (uint8) ( Y0 ) ]; \ | ||
614 | \ | ||
615 | X2 = RK[2] ^ FT0[ (uint8) ( Y2 >> 24 ) ] ^ \ | ||
616 | FT1[ (uint8) ( Y3 >> 16 ) ] ^ \ | ||
617 | FT2[ (uint8) ( Y0 >> 8 ) ] ^ \ | ||
618 | FT3[ (uint8) ( Y1 ) ]; \ | ||
619 | \ | ||
620 | X3 = RK[3] ^ FT0[ (uint8) ( Y3 >> 24 ) ] ^ \ | ||
621 | FT1[ (uint8) ( Y0 >> 16 ) ] ^ \ | ||
622 | FT2[ (uint8) ( Y1 >> 8 ) ] ^ \ | ||
623 | FT3[ (uint8) ( Y2 ) ]; \ | ||
624 | } | ||
625 | |||
626 | AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 1 */ | ||
627 | AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 2 */ | ||
628 | AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 3 */ | ||
629 | AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 4 */ | ||
630 | AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 5 */ | ||
631 | AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 6 */ | ||
632 | AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 7 */ | ||
633 | AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 8 */ | ||
634 | AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 9 */ | ||
635 | |||
636 | if( ctx->nr > 10 ) | ||
637 | { | ||
638 | AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 10 */ | ||
639 | AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 11 */ | ||
640 | } | ||
641 | |||
642 | if( ctx->nr > 12 ) | ||
643 | { | ||
644 | AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 12 */ | ||
645 | AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 13 */ | ||
646 | } | ||
647 | |||
648 | /* last round */ | ||
649 | |||
650 | RK += 4; | ||
651 | |||
652 | X0 = RK[0] ^ ( FSb[ (uint8) ( Y0 >> 24 ) ] << 24 ) ^ | ||
653 | ( FSb[ (uint8) ( Y1 >> 16 ) ] << 16 ) ^ | ||
654 | ( FSb[ (uint8) ( Y2 >> 8 ) ] << 8 ) ^ | ||
655 | ( FSb[ (uint8) ( Y3 ) ] ); | ||
656 | |||
657 | X1 = RK[1] ^ ( FSb[ (uint8) ( Y1 >> 24 ) ] << 24 ) ^ | ||
658 | ( FSb[ (uint8) ( Y2 >> 16 ) ] << 16 ) ^ | ||
659 | ( FSb[ (uint8) ( Y3 >> 8 ) ] << 8 ) ^ | ||
660 | ( FSb[ (uint8) ( Y0 ) ] ); | ||
661 | |||
662 | X2 = RK[2] ^ ( FSb[ (uint8) ( Y2 >> 24 ) ] << 24 ) ^ | ||
663 | ( FSb[ (uint8) ( Y3 >> 16 ) ] << 16 ) ^ | ||
664 | ( FSb[ (uint8) ( Y0 >> 8 ) ] << 8 ) ^ | ||
665 | ( FSb[ (uint8) ( Y1 ) ] ); | ||
666 | |||
667 | X3 = RK[3] ^ ( FSb[ (uint8) ( Y3 >> 24 ) ] << 24 ) ^ | ||
668 | ( FSb[ (uint8) ( Y0 >> 16 ) ] << 16 ) ^ | ||
669 | ( FSb[ (uint8) ( Y1 >> 8 ) ] << 8 ) ^ | ||
670 | ( FSb[ (uint8) ( Y2 ) ] ); | ||
671 | |||
672 | PUT_UINT32( X0, output, 0 ); | ||
673 | PUT_UINT32( X1, output, 4 ); | ||
674 | PUT_UINT32( X2, output, 8 ); | ||
675 | PUT_UINT32( X3, output, 12 ); | ||
676 | } | ||
677 | |||
678 | /* AES 128-bit block decryption routine */ | ||
679 | |||
680 | void aes_decrypt( aes_context *ctx, uint8 input[16], uint8 output[16] ) | ||
681 | { | ||
682 | uint32 *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3; | ||
683 | |||
684 | RK = ctx->drk; | ||
685 | |||
686 | GET_UINT32( X0, input, 0 ); X0 ^= RK[0]; | ||
687 | GET_UINT32( X1, input, 4 ); X1 ^= RK[1]; | ||
688 | GET_UINT32( X2, input, 8 ); X2 ^= RK[2]; | ||
689 | GET_UINT32( X3, input, 12 ); X3 ^= RK[3]; | ||
690 | |||
691 | #define AES_RROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \ | ||
692 | { \ | ||
693 | RK += 4; \ | ||
694 | \ | ||
695 | X0 = RK[0] ^ RT0[ (uint8) ( Y0 >> 24 ) ] ^ \ | ||
696 | RT1[ (uint8) ( Y3 >> 16 ) ] ^ \ | ||
697 | RT2[ (uint8) ( Y2 >> 8 ) ] ^ \ | ||
698 | RT3[ (uint8) ( Y1 ) ]; \ | ||
699 | \ | ||
700 | X1 = RK[1] ^ RT0[ (uint8) ( Y1 >> 24 ) ] ^ \ | ||
701 | RT1[ (uint8) ( Y0 >> 16 ) ] ^ \ | ||
702 | RT2[ (uint8) ( Y3 >> 8 ) ] ^ \ | ||
703 | RT3[ (uint8) ( Y2 ) ]; \ | ||
704 | \ | ||
705 | X2 = RK[2] ^ RT0[ (uint8) ( Y2 >> 24 ) ] ^ \ | ||
706 | RT1[ (uint8) ( Y1 >> 16 ) ] ^ \ | ||
707 | RT2[ (uint8) ( Y0 >> 8 ) ] ^ \ | ||
708 | RT3[ (uint8) ( Y3 ) ]; \ | ||
709 | \ | ||
710 | X3 = RK[3] ^ RT0[ (uint8) ( Y3 >> 24 ) ] ^ \ | ||
711 | RT1[ (uint8) ( Y2 >> 16 ) ] ^ \ | ||
712 | RT2[ (uint8) ( Y1 >> 8 ) ] ^ \ | ||
713 | RT3[ (uint8) ( Y0 ) ]; \ | ||
714 | } | ||
715 | |||
716 | AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 1 */ | ||
717 | AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 2 */ | ||
718 | AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 3 */ | ||
719 | AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 4 */ | ||
720 | AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 5 */ | ||
721 | AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 6 */ | ||
722 | AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 7 */ | ||
723 | AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 8 */ | ||
724 | AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 9 */ | ||
725 | |||
726 | if( ctx->nr > 10 ) | ||
727 | { | ||
728 | AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 10 */ | ||
729 | AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 11 */ | ||
730 | } | ||
731 | |||
732 | if( ctx->nr > 12 ) | ||
733 | { | ||
734 | AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); /* round 12 */ | ||
735 | AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); /* round 13 */ | ||
736 | } | ||
737 | |||
738 | /* last round */ | ||
739 | |||
740 | RK += 4; | ||
741 | |||
742 | X0 = RK[0] ^ ( RSb[ (uint8) ( Y0 >> 24 ) ] << 24 ) ^ | ||
743 | ( RSb[ (uint8) ( Y3 >> 16 ) ] << 16 ) ^ | ||
744 | ( RSb[ (uint8) ( Y2 >> 8 ) ] << 8 ) ^ | ||
745 | ( RSb[ (uint8) ( Y1 ) ] ); | ||
746 | |||
747 | X1 = RK[1] ^ ( RSb[ (uint8) ( Y1 >> 24 ) ] << 24 ) ^ | ||
748 | ( RSb[ (uint8) ( Y0 >> 16 ) ] << 16 ) ^ | ||
749 | ( RSb[ (uint8) ( Y3 >> 8 ) ] << 8 ) ^ | ||
750 | ( RSb[ (uint8) ( Y2 ) ] ); | ||
751 | |||
752 | X2 = RK[2] ^ ( RSb[ (uint8) ( Y2 >> 24 ) ] << 24 ) ^ | ||
753 | ( RSb[ (uint8) ( Y1 >> 16 ) ] << 16 ) ^ | ||
754 | ( RSb[ (uint8) ( Y0 >> 8 ) ] << 8 ) ^ | ||
755 | ( RSb[ (uint8) ( Y3 ) ] ); | ||
756 | |||
757 | X3 = RK[3] ^ ( RSb[ (uint8) ( Y3 >> 24 ) ] << 24 ) ^ | ||
758 | ( RSb[ (uint8) ( Y2 >> 16 ) ] << 16 ) ^ | ||
759 | ( RSb[ (uint8) ( Y1 >> 8 ) ] << 8 ) ^ | ||
760 | ( RSb[ (uint8) ( Y0 ) ] ); | ||
761 | |||
762 | PUT_UINT32( X0, output, 0 ); | ||
763 | PUT_UINT32( X1, output, 4 ); | ||
764 | PUT_UINT32( X2, output, 8 ); | ||
765 | PUT_UINT32( X3, output, 12 ); | ||
766 | } | ||
767 | |||
768 | #ifdef TEST | ||
769 | |||
770 | #include <string.h> | ||
771 | #include <stdio.h> | ||
772 | |||
773 | /* | ||
774 | * Rijndael Monte Carlo Test: ECB mode | ||
775 | * source: NIST - rijndael-vals.zip | ||
776 | */ | ||
777 | |||
778 | static unsigned char AES_enc_test[3][16] = | ||
779 | { | ||
780 | { 0xA0, 0x43, 0x77, 0xAB, 0xE2, 0x59, 0xB0, 0xD0, | ||
781 | 0xB5, 0xBA, 0x2D, 0x40, 0xA5, 0x01, 0x97, 0x1B }, | ||
782 | { 0x4E, 0x46, 0xF8, 0xC5, 0x09, 0x2B, 0x29, 0xE2, | ||
783 | 0x9A, 0x97, 0x1A, 0x0C, 0xD1, 0xF6, 0x10, 0xFB }, | ||
784 | { 0x1F, 0x67, 0x63, 0xDF, 0x80, 0x7A, 0x7E, 0x70, | ||
785 | 0x96, 0x0D, 0x4C, 0xD3, 0x11, 0x8E, 0x60, 0x1A } | ||
786 | }; | ||
787 | |||
788 | static unsigned char AES_dec_test[3][16] = | ||
789 | { | ||
790 | { 0xF5, 0xBF, 0x8B, 0x37, 0x13, 0x6F, 0x2E, 0x1F, | ||
791 | 0x6B, 0xEC, 0x6F, 0x57, 0x20, 0x21, 0xE3, 0xBA }, | ||
792 | { 0xF1, 0xA8, 0x1B, 0x68, 0xF6, 0xE5, 0xA6, 0x27, | ||
793 | 0x1A, 0x8C, 0xB2, 0x4E, 0x7D, 0x94, 0x91, 0xEF }, | ||
794 | { 0x4D, 0xE0, 0xC6, 0xDF, 0x7C, 0xB1, 0x69, 0x72, | ||
795 | 0x84, 0x60, 0x4D, 0x60, 0x27, 0x1B, 0xC5, 0x9A } | ||
796 | }; | ||
797 | |||
798 | int main( void ) | ||
799 | { | ||
800 | int m, n, i, j; | ||
801 | aes_context ctx; | ||
802 | unsigned char buf[16]; | ||
803 | unsigned char key[32]; | ||
804 | |||
805 | for( m = 0; m < 2; m++ ) | ||
806 | { | ||
807 | printf( "\n Rijndael Monte Carlo Test (ECB mode) - " ); | ||
808 | |||
809 | if( m == 0 ) printf( "encryption\n\n" ); | ||
810 | if( m == 1 ) printf( "decryption\n\n" ); | ||
811 | |||
812 | for( n = 0; n < 3; n++ ) | ||
813 | { | ||
814 | printf( " Test %d, key size = %3d bits: ", | ||
815 | n + 1, 128 + n * 64 ); | ||
816 | |||
817 | fflush( stdout ); | ||
818 | |||
819 | memset( buf, 0, 16 ); | ||
820 | memset( key, 0, 16 + n * 8 ); | ||
821 | |||
822 | for( i = 0; i < 400; i++ ) | ||
823 | { | ||
824 | aes_set_key( &ctx, key, 128 + n * 64 ); | ||
825 | |||
826 | for( j = 0; j < 9999; j++ ) | ||
827 | { | ||
828 | if( m == 0 ) aes_encrypt( &ctx, buf, buf ); | ||
829 | if( m == 1 ) aes_decrypt( &ctx, buf, buf ); | ||
830 | } | ||
831 | |||
832 | if( n > 0 ) | ||
833 | { | ||
834 | for( j = 0; j < (n << 3); j++ ) | ||
835 | { | ||
836 | key[j] ^= buf[j + 16 - (n << 3)]; | ||
837 | } | ||
838 | } | ||
839 | |||
840 | if( m == 0 ) aes_encrypt( &ctx, buf, buf ); | ||
841 | if( m == 1 ) aes_decrypt( &ctx, buf, buf ); | ||
842 | |||
843 | for( j = 0; j < 16; j++ ) | ||
844 | { | ||
845 | key[j + (n << 3)] ^= buf[j]; | ||
846 | } | ||
847 | } | ||
848 | |||
849 | if( ( m == 0 && memcmp( buf, AES_enc_test[n], 16 ) != 0 ) || | ||
850 | ( m == 1 && memcmp( buf, AES_dec_test[n], 16 ) != 0 ) ) | ||
851 | { | ||
852 | printf( "failed!\n" ); | ||
853 | return( 1 ); | ||
854 | } | ||
855 | |||
856 | printf( "passed.\n" ); | ||
857 | } | ||
858 | } | ||
859 | |||
860 | printf( "\n" ); | ||
861 | |||
862 | return( 0 ); | ||
863 | } | ||
864 | |||
865 | #endif | ||
866 | |||
diff --git a/linden/indra/libotr/libotr-3.2.0/toolkit/aes.h b/linden/indra/libotr/libotr-3.2.0/toolkit/aes.h new file mode 100755 index 0000000..67bd423 --- /dev/null +++ b/linden/indra/libotr/libotr-3.2.0/toolkit/aes.h | |||
@@ -0,0 +1,26 @@ | |||
1 | /* Retrieved from http://www.cr0.net:8040/code/crypto/aes/aes.h */ | ||
2 | |||
3 | #ifndef _AES_H | ||
4 | #define _AES_H | ||
5 | |||
6 | #ifndef uint8 | ||
7 | #define uint8 unsigned char | ||
8 | #endif | ||
9 | |||
10 | #ifndef uint32 | ||
11 | #define uint32 unsigned long int | ||
12 | #endif | ||
13 | |||
14 | typedef struct | ||
15 | { | ||
16 | uint32 erk[64]; /* encryption round keys */ | ||
17 | uint32 drk[64]; /* decryption round keys */ | ||
18 | int nr; /* number of rounds */ | ||
19 | } | ||
20 | aes_context; | ||
21 | |||
22 | int aes_set_key( aes_context *ctx, uint8 *key, int nbits ); | ||
23 | void aes_encrypt( aes_context *ctx, uint8 input[16], uint8 output[16] ); | ||
24 | void aes_decrypt( aes_context *ctx, uint8 input[16], uint8 output[16] ); | ||
25 | |||
26 | #endif /* aes.h */ | ||
diff --git a/linden/indra/libotr/libotr-3.2.0/toolkit/ctrmode.c b/linden/indra/libotr/libotr-3.2.0/toolkit/ctrmode.c new file mode 100755 index 0000000..f89cfbd --- /dev/null +++ b/linden/indra/libotr/libotr-3.2.0/toolkit/ctrmode.c | |||
@@ -0,0 +1,60 @@ | |||
1 | /* | ||
2 | * Off-the-Record Messaging Toolkit | ||
3 | * Copyright (C) 2004-2008 Ian Goldberg, Chris Alexander, Nikita Borisov | ||
4 | * <otr@cypherpunks.ca> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of version 2 of the GNU General Public License as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | /* system headers */ | ||
21 | #include <stdlib.h> | ||
22 | #include <string.h> | ||
23 | |||
24 | /* toolkit headers */ | ||
25 | #include "aes.h" | ||
26 | |||
27 | /* Encrypt or decrypt data in AES-CTR mode. (The operations are the | ||
28 | * same.) We roll our own here just to double-check that the calls | ||
29 | * libotr makes to libgcrypt are doing the right thing. */ | ||
30 | void aes_ctr_crypt(unsigned char *out, const unsigned char *in, size_t len, | ||
31 | unsigned char key[16], unsigned char ctrtop[8]) | ||
32 | { | ||
33 | unsigned char ctr[16], encctr[16]; | ||
34 | aes_context aesc; | ||
35 | |||
36 | aes_set_key(&aesc, key, 128); | ||
37 | |||
38 | memmove(ctr, ctrtop, 8); | ||
39 | memset(ctr+8, 0, 8); | ||
40 | |||
41 | while(len > 0) { | ||
42 | /* How much to do at a time? */ | ||
43 | size_t i; | ||
44 | size_t amt = len; | ||
45 | if (amt > 16) amt = 16; | ||
46 | aes_encrypt(&aesc, ctr, encctr); | ||
47 | for(i=0;i<amt;++i) { | ||
48 | out[i] = in[i] ^ encctr[i]; | ||
49 | } | ||
50 | |||
51 | /* Increment the counter */ | ||
52 | for (i=16;i>0;--i) { | ||
53 | if (++ctr[i-1] != 0) break; | ||
54 | } | ||
55 | |||
56 | out += amt; | ||
57 | in += amt; | ||
58 | len -= amt; | ||
59 | } | ||
60 | } | ||
diff --git a/linden/indra/libotr/libotr-3.2.0/toolkit/ctrmode.h b/linden/indra/libotr/libotr-3.2.0/toolkit/ctrmode.h new file mode 100755 index 0000000..a1e049e --- /dev/null +++ b/linden/indra/libotr/libotr-3.2.0/toolkit/ctrmode.h | |||
@@ -0,0 +1,29 @@ | |||
1 | /* | ||
2 | * Off-the-Record Messaging Toolkit | ||
3 | * Copyright (C) 2004-2008 Ian Goldberg, Chris Alexander, Nikita Borisov | ||
4 | * <otr@cypherpunks.ca> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of version 2 of the GNU General Public License as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | #ifndef __CTRMODE_H__ | ||
21 | #define __CTRMODE_H__ | ||
22 | |||
23 | /* Encrypt or decrypt data in AES-CTR mode. (The operations are the | ||
24 | * same.) We roll our own here just to double-check that the calls | ||
25 | * libotr makes to libgcrypt are doing the right thing. */ | ||
26 | void aes_ctr_crypt(unsigned char *out, const unsigned char *in, size_t len, | ||
27 | unsigned char key[16], unsigned char ctrtop[8]); | ||
28 | |||
29 | #endif | ||
diff --git a/linden/indra/libotr/libotr-3.2.0/toolkit/otr_mackey.c b/linden/indra/libotr/libotr-3.2.0/toolkit/otr_mackey.c new file mode 100755 index 0000000..214d59b --- /dev/null +++ b/linden/indra/libotr/libotr-3.2.0/toolkit/otr_mackey.c | |||
@@ -0,0 +1,65 @@ | |||
1 | /* | ||
2 | * Off-the-Record Messaging Toolkit | ||
3 | * Copyright (C) 2004-2008 Ian Goldberg, Chris Alexander, Nikita Borisov | ||
4 | * <otr@cypherpunks.ca> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of version 2 of the GNU General Public License as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | /* system headers */ | ||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | |||
24 | /* toolkit headers */ | ||
25 | #include "parse.h" | ||
26 | #include "sesskeys.h" | ||
27 | |||
28 | static void usage(const char *progname) | ||
29 | { | ||
30 | fprintf(stderr, "Usage: %s aeskey\n" | ||
31 | "Calculate and display the MAC key derived from a given AES key.\n", | ||
32 | progname); | ||
33 | exit(1); | ||
34 | } | ||
35 | |||
36 | int main(int argc, char **argv) | ||
37 | { | ||
38 | unsigned char *argbuf; | ||
39 | size_t argbuflen; | ||
40 | unsigned char mackey[20]; | ||
41 | |||
42 | if (argc != 2) { | ||
43 | usage(argv[0]); | ||
44 | } | ||
45 | |||
46 | argv_to_buf(&argbuf, &argbuflen, argv[1]); | ||
47 | /* AES keys are 128 bits long, so check for that */ | ||
48 | if (!argbuf) { | ||
49 | usage(argv[0]); | ||
50 | } | ||
51 | |||
52 | if (argbuflen != 16) { | ||
53 | fprintf(stderr, "The AES key must be 32 hex chars long.\n"); | ||
54 | usage(argv[0]); | ||
55 | } | ||
56 | |||
57 | sesskeys_make_mac(mackey, argbuf); | ||
58 | |||
59 | dump_data(stdout, "AES key", argbuf, 16); | ||
60 | dump_data(stdout, "MAC key", mackey, 20); | ||
61 | |||
62 | free(argbuf); | ||
63 | fflush(stdout); | ||
64 | return 0; | ||
65 | } | ||
diff --git a/linden/indra/libotr/libotr-3.2.0/toolkit/otr_modify.c b/linden/indra/libotr/libotr-3.2.0/toolkit/otr_modify.c new file mode 100755 index 0000000..c6d045f --- /dev/null +++ b/linden/indra/libotr/libotr-3.2.0/toolkit/otr_modify.c | |||
@@ -0,0 +1,126 @@ | |||
1 | /* | ||
2 | * Off-the-Record Messaging Toolkit | ||
3 | * Copyright (C) 2004-2008 Ian Goldberg, Chris Alexander, Nikita Borisov | ||
4 | * <otr@cypherpunks.ca> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of version 2 of the GNU General Public License as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | /* system headers */ | ||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | |||
24 | /* libotr headers */ | ||
25 | #include "proto.h" | ||
26 | |||
27 | /* toolkit headers */ | ||
28 | #include "readotr.h" | ||
29 | #include "parse.h" | ||
30 | #include "sha1hmac.h" | ||
31 | |||
32 | static void usage(const char *progname) | ||
33 | { | ||
34 | fprintf(stderr, "Usage: %s mackey old_text new_text offset\n" | ||
35 | "Read an OTR Data Message from stdin. Even if we can't read the\n" | ||
36 | "data because we don't know either the AES key or the DH privkey,\n" | ||
37 | "but we can make a good guess that the substring \"old_text\"\n" | ||
38 | "appears at the given offset in the message, replace the old_text\n" | ||
39 | "with the new_text (which must be of the same length), recalculate\n" | ||
40 | "the MAC with the given mackey, and output the resulting Data message.\n", | ||
41 | progname); | ||
42 | exit(1); | ||
43 | } | ||
44 | |||
45 | int main(int argc, char **argv) | ||
46 | { | ||
47 | unsigned char *mackey; | ||
48 | size_t mackeylen; | ||
49 | unsigned char macval[20]; | ||
50 | char *otrmsg = NULL; | ||
51 | DataMsg datamsg; | ||
52 | size_t textlen; | ||
53 | unsigned int offset; | ||
54 | const unsigned char *old_text, *new_text; | ||
55 | char *newdatamsg; | ||
56 | size_t i; | ||
57 | |||
58 | if (argc != 5) { | ||
59 | usage(argv[0]); | ||
60 | } | ||
61 | |||
62 | argv_to_buf(&mackey, &mackeylen, argv[1]); | ||
63 | if (!mackey) { | ||
64 | usage(argv[0]); | ||
65 | } | ||
66 | |||
67 | if (mackeylen != 20) { | ||
68 | fprintf(stderr, "The MAC key must be 40 hex chars long.\n"); | ||
69 | usage(argv[0]); | ||
70 | } | ||
71 | |||
72 | textlen = strlen(argv[2]); | ||
73 | if (textlen != strlen(argv[3])) { | ||
74 | fprintf(stderr, "The old_text and new_text must be of the same " | ||
75 | "length.\n"); | ||
76 | usage(argv[0]); | ||
77 | } | ||
78 | old_text = (const unsigned char *)argv[2]; | ||
79 | new_text = (const unsigned char *)argv[3]; | ||
80 | |||
81 | if (sscanf(argv[4], "%u", &offset) != 1) { | ||
82 | fprintf(stderr, "Unparseable offset given.\n"); | ||
83 | usage(argv[0]); | ||
84 | } | ||
85 | |||
86 | otrmsg = readotr(stdin); | ||
87 | if (otrmsg == NULL) { | ||
88 | fprintf(stderr, "No OTR Data Message found on stdin.\n"); | ||
89 | exit(1); | ||
90 | } | ||
91 | |||
92 | if (otrl_proto_message_type(otrmsg) != OTRL_MSGTYPE_DATA) { | ||
93 | fprintf(stderr, "OTR Non-Data Message found on stdin.\n"); | ||
94 | exit(1); | ||
95 | } | ||
96 | |||
97 | datamsg = parse_datamsg(otrmsg); | ||
98 | free(otrmsg); | ||
99 | if (datamsg == NULL) { | ||
100 | fprintf(stderr, "Invalid OTR Data Message found on stdin.\n"); | ||
101 | exit(1); | ||
102 | } | ||
103 | |||
104 | /* Check the MAC */ | ||
105 | sha1hmac(macval, mackey, datamsg->macstart, | ||
106 | datamsg->macend - datamsg->macstart); | ||
107 | if (memcmp(macval, datamsg->mac, 20)) { | ||
108 | fprintf(stderr, "MAC does not verify: wrong MAC key?\n"); | ||
109 | exit(1); | ||
110 | } | ||
111 | |||
112 | /* Modify the ciphertext */ | ||
113 | for(i=0; i<textlen && offset+i < datamsg->encmsglen; ++i) { | ||
114 | datamsg->encmsg[offset+i] ^= (old_text[i] ^ new_text[i]); | ||
115 | } | ||
116 | |||
117 | /* Recalculate the MAC */ | ||
118 | newdatamsg = remac_datamsg(datamsg, mackey); | ||
119 | printf("%s\n", newdatamsg); | ||
120 | free(newdatamsg); | ||
121 | |||
122 | free_datamsg(datamsg); | ||
123 | free(mackey); | ||
124 | fflush(stdout); | ||
125 | return 0; | ||
126 | } | ||
diff --git a/linden/indra/libotr/libotr-3.2.0/toolkit/otr_parse.c b/linden/indra/libotr/libotr-3.2.0/toolkit/otr_parse.c new file mode 100755 index 0000000..f3bcee4 --- /dev/null +++ b/linden/indra/libotr/libotr-3.2.0/toolkit/otr_parse.c | |||
@@ -0,0 +1,188 @@ | |||
1 | /* | ||
2 | * Off-the-Record Messaging Toolkit | ||
3 | * Copyright (C) 2004-2008 Ian Goldberg, Chris Alexander, Nikita Borisov | ||
4 | * <otr@cypherpunks.ca> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of version 2 of the GNU General Public License as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | /* system headers */ | ||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | |||
24 | /* libotr headers */ | ||
25 | #include "proto.h" | ||
26 | |||
27 | /* toolkit headers */ | ||
28 | #include "readotr.h" | ||
29 | #include "parse.h" | ||
30 | |||
31 | static void parse(const char *msg) | ||
32 | { | ||
33 | OtrlMessageType mtype = otrl_proto_message_type(msg); | ||
34 | CommitMsg cmsg; | ||
35 | KeyMsg kmsg; | ||
36 | RevealSigMsg rmsg; | ||
37 | SignatureMsg smsg; | ||
38 | KeyExchMsg keyexch; | ||
39 | DataMsg datamsg; | ||
40 | |||
41 | switch(mtype) { | ||
42 | case OTRL_MSGTYPE_QUERY: | ||
43 | printf("OTR Query:\n\t%s\n\n", msg); | ||
44 | break; | ||
45 | case OTRL_MSGTYPE_DH_COMMIT: | ||
46 | cmsg = parse_commit(msg); | ||
47 | if (!cmsg) { | ||
48 | printf("Invalid D-H Commit Message\n\n"); | ||
49 | break; | ||
50 | } | ||
51 | printf("D-H Commit Message:\n"); | ||
52 | dump_data(stdout, "\tEncrypted Key", cmsg->enckey, | ||
53 | cmsg->enckeylen); | ||
54 | dump_data(stdout, "\tHashed Key", cmsg->hashkey, | ||
55 | cmsg->hashkeylen); | ||
56 | printf("\n"); | ||
57 | free_commit(cmsg); | ||
58 | break; | ||
59 | case OTRL_MSGTYPE_DH_KEY: | ||
60 | kmsg = parse_key(msg); | ||
61 | if (!kmsg) { | ||
62 | printf("Invalid D-H Key Message\n\n"); | ||
63 | break; | ||
64 | } | ||
65 | printf("D-H Key Message:\n"); | ||
66 | dump_mpi(stdout, "\tD-H Key", kmsg->y); | ||
67 | printf("\n"); | ||
68 | free_key(kmsg); | ||
69 | break; | ||
70 | case OTRL_MSGTYPE_REVEALSIG: | ||
71 | rmsg = parse_revealsig(msg); | ||
72 | if (!rmsg) { | ||
73 | printf("Invalid Reveal Signature Message\n\n"); | ||
74 | break; | ||
75 | } | ||
76 | printf("Reveal Signature Message:\n"); | ||
77 | dump_data(stdout, "\tKey", rmsg->key, rmsg->keylen); | ||
78 | dump_data(stdout, "\tEncrypted Signature", | ||
79 | rmsg->encsig, rmsg->encsiglen); | ||
80 | dump_data(stdout, "\tMAC", rmsg->mac, 20); | ||
81 | printf("\n"); | ||
82 | free_revealsig(rmsg); | ||
83 | break; | ||
84 | case OTRL_MSGTYPE_SIGNATURE: | ||
85 | smsg = parse_signature(msg); | ||
86 | if (!smsg) { | ||
87 | printf("Invalid Signature Message\n\n"); | ||
88 | break; | ||
89 | } | ||
90 | printf("Signature Message:\n"); | ||
91 | dump_data(stdout, "\tEncrypted Signature", | ||
92 | smsg->encsig, smsg->encsiglen); | ||
93 | dump_data(stdout, "\tMAC", smsg->mac, 20); | ||
94 | printf("\n"); | ||
95 | free_signature(smsg); | ||
96 | break; | ||
97 | case OTRL_MSGTYPE_V1_KEYEXCH: | ||
98 | keyexch = parse_keyexch(msg); | ||
99 | if (!keyexch) { | ||
100 | printf("Invalid Key Exchange Message\n\n"); | ||
101 | break; | ||
102 | } | ||
103 | printf("Key Exchange Message:\n"); | ||
104 | dump_int(stdout, "\tReply", keyexch->reply); | ||
105 | dump_mpi(stdout, "\tDSA p", keyexch->p); | ||
106 | dump_mpi(stdout, "\tDSA q", keyexch->q); | ||
107 | dump_mpi(stdout, "\tDSA g", keyexch->g); | ||
108 | dump_mpi(stdout, "\tDSA e", keyexch->e); | ||
109 | dump_int(stdout, "\tKeyID", keyexch->keyid); | ||
110 | dump_mpi(stdout, "\tDH y", keyexch->y); | ||
111 | dump_mpi(stdout, "\tSIG r", keyexch->r); | ||
112 | dump_mpi(stdout, "\tSIG s", keyexch->s); | ||
113 | printf("\n"); | ||
114 | free_keyexch(keyexch); | ||
115 | break; | ||
116 | case OTRL_MSGTYPE_DATA: | ||
117 | datamsg = parse_datamsg(msg); | ||
118 | if (!datamsg) { | ||
119 | printf("Invalid Data Message\n\n"); | ||
120 | break; | ||
121 | } | ||
122 | printf("Data Message:\n"); | ||
123 | if (datamsg->flags >= 0) { | ||
124 | dump_int(stdout, "\tFlags", datamsg->flags); | ||
125 | } | ||
126 | dump_int(stdout, "\tSender keyid", datamsg->sender_keyid); | ||
127 | dump_int(stdout, "\tRcpt keyid", datamsg->rcpt_keyid); | ||
128 | dump_mpi(stdout, "\tDH y", datamsg->y); | ||
129 | dump_data(stdout, "\tCounter", datamsg->ctr, 8); | ||
130 | dump_data(stdout, "\tEncrypted message", datamsg->encmsg, | ||
131 | datamsg->encmsglen); | ||
132 | dump_data(stdout, "\tMAC", datamsg->mac, 20); | ||
133 | if (datamsg->mackeyslen > 0) { | ||
134 | size_t len = datamsg->mackeyslen; | ||
135 | unsigned char *mks = datamsg->mackeys; | ||
136 | unsigned int i = 0; | ||
137 | printf("\tRevealed MAC keys:\n"); | ||
138 | |||
139 | while(len > 19) { | ||
140 | char title[20]; | ||
141 | sprintf(title, "\t\tKey %u", ++i); | ||
142 | dump_data(stdout, title, mks, 20); | ||
143 | mks += 20; len -= 20; | ||
144 | } | ||
145 | } | ||
146 | |||
147 | printf("\n"); | ||
148 | free_datamsg(datamsg); | ||
149 | break; | ||
150 | case OTRL_MSGTYPE_ERROR: | ||
151 | printf("OTR Error:\n\t%s\n\n", msg); | ||
152 | break; | ||
153 | case OTRL_MSGTYPE_TAGGEDPLAINTEXT: | ||
154 | printf("Tagged plaintext message:\n\t%s\n\n", msg); | ||
155 | break; | ||
156 | case OTRL_MSGTYPE_NOTOTR: | ||
157 | printf("Not an OTR message:\n\t%s\n\n", msg); | ||
158 | break; | ||
159 | case OTRL_MSGTYPE_UNKNOWN: | ||
160 | printf("Unrecognized OTR message:\n\t%s\n\n", msg); | ||
161 | break; | ||
162 | } | ||
163 | fflush(stdout); | ||
164 | } | ||
165 | |||
166 | static void usage(const char *progname) | ||
167 | { | ||
168 | fprintf(stderr, "Usage: %s\n" | ||
169 | "Read Off-the-Record (OTR) Key Exchange and/or Data messages from stdin\n" | ||
170 | "and display their contents in a more readable format.\n", progname); | ||
171 | exit(1); | ||
172 | } | ||
173 | |||
174 | int main(int argc, char **argv) | ||
175 | { | ||
176 | char *otrmsg = NULL; | ||
177 | |||
178 | if (argc != 1) { | ||
179 | usage(argv[0]); | ||
180 | } | ||
181 | |||
182 | while ((otrmsg = readotr(stdin)) != NULL) { | ||
183 | parse(otrmsg); | ||
184 | free(otrmsg); | ||
185 | } | ||
186 | |||
187 | return 0; | ||
188 | } | ||
diff --git a/linden/indra/libotr/libotr-3.2.0/toolkit/otr_readforge.c b/linden/indra/libotr/libotr-3.2.0/toolkit/otr_readforge.c new file mode 100755 index 0000000..203001c --- /dev/null +++ b/linden/indra/libotr/libotr-3.2.0/toolkit/otr_readforge.c | |||
@@ -0,0 +1,133 @@ | |||
1 | /* | ||
2 | * Off-the-Record Messaging Toolkit | ||
3 | * Copyright (C) 2004-2008 Ian Goldberg, Chris Alexander, Nikita Borisov | ||
4 | * <otr@cypherpunks.ca> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of version 2 of the GNU General Public License as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | /* system headers */ | ||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | |||
24 | /* libotr headers */ | ||
25 | #include "proto.h" | ||
26 | |||
27 | /* toolkit headers */ | ||
28 | #include "readotr.h" | ||
29 | #include "parse.h" | ||
30 | #include "sesskeys.h" | ||
31 | #include "sha1hmac.h" | ||
32 | #include "ctrmode.h" | ||
33 | |||
34 | static void usage(const char *progname) | ||
35 | { | ||
36 | fprintf(stderr, "Usage: %s aeskey [new_message]\n" | ||
37 | "Read an OTR Data Message from stdin. Use the given AES key to\n" | ||
38 | "verify its MAC and decrypt the message to stdout. If new_message\n" | ||
39 | "is given, output a new OTR Data Message with the same fields as the\n" | ||
40 | "original, but with the message replaced by new_message\n", progname); | ||
41 | exit(1); | ||
42 | } | ||
43 | |||
44 | int main(int argc, char **argv) | ||
45 | { | ||
46 | unsigned char *aeskey; | ||
47 | unsigned char mackey[20]; | ||
48 | unsigned char macval[20]; | ||
49 | size_t aeskeylen; | ||
50 | unsigned char *plaintext, *ciphertext; | ||
51 | char *otrmsg = NULL; | ||
52 | DataMsg datamsg; | ||
53 | |||
54 | if (argc != 2 && argc != 3) { | ||
55 | usage(argv[0]); | ||
56 | } | ||
57 | |||
58 | argv_to_buf(&aeskey, &aeskeylen, argv[1]); | ||
59 | if (!aeskey) { | ||
60 | usage(argv[0]); | ||
61 | } | ||
62 | |||
63 | if (aeskeylen != 16) { | ||
64 | fprintf(stderr, "The AES key must be 32 hex chars long.\n"); | ||
65 | usage(argv[0]); | ||
66 | } | ||
67 | |||
68 | otrmsg = readotr(stdin); | ||
69 | if (otrmsg == NULL) { | ||
70 | fprintf(stderr, "No OTR Data Message found on stdin.\n"); | ||
71 | exit(1); | ||
72 | } | ||
73 | |||
74 | if (otrl_proto_message_type(otrmsg) != OTRL_MSGTYPE_DATA) { | ||
75 | fprintf(stderr, "OTR Non-Data Message found on stdin.\n"); | ||
76 | exit(1); | ||
77 | } | ||
78 | |||
79 | datamsg = parse_datamsg(otrmsg); | ||
80 | free(otrmsg); | ||
81 | if (datamsg == NULL) { | ||
82 | fprintf(stderr, "Invalid OTR Data Message found on stdin.\n"); | ||
83 | exit(1); | ||
84 | } | ||
85 | |||
86 | /* Create the MAC key */ | ||
87 | sesskeys_make_mac(mackey, aeskey); | ||
88 | |||
89 | /* Check the MAC */ | ||
90 | sha1hmac(macval, mackey, datamsg->macstart, | ||
91 | datamsg->macend - datamsg->macstart); | ||
92 | if (memcmp(macval, datamsg->mac, 20)) { | ||
93 | fprintf(stderr, "MAC does not verify: wrong AES key?\n"); | ||
94 | } else { | ||
95 | /* Decrypt the message */ | ||
96 | plaintext = malloc(datamsg->encmsglen+1); | ||
97 | if (!plaintext) { | ||
98 | fprintf(stderr, "Out of memory!\n"); | ||
99 | exit(1); | ||
100 | } | ||
101 | aes_ctr_crypt(plaintext, datamsg->encmsg, datamsg->encmsglen, | ||
102 | aeskey, datamsg->ctr); | ||
103 | plaintext[datamsg->encmsglen] = '\0'; | ||
104 | printf("Plaintext: ``%s''\n", plaintext); | ||
105 | free(plaintext); | ||
106 | } | ||
107 | |||
108 | /* Do we want to forge a message? */ | ||
109 | if (argv[2] != NULL) { | ||
110 | char *newdatamsg; | ||
111 | size_t newlen = strlen(argv[2]); | ||
112 | ciphertext = malloc(newlen); | ||
113 | if (!ciphertext && newlen > 0) { | ||
114 | fprintf(stderr, "Out of memory!\n"); | ||
115 | exit(1); | ||
116 | } | ||
117 | aes_ctr_crypt(ciphertext, (const unsigned char *)argv[2], newlen, | ||
118 | aeskey, datamsg->ctr); | ||
119 | free(datamsg->encmsg); | ||
120 | datamsg->encmsg = ciphertext; | ||
121 | datamsg->encmsglen = newlen; | ||
122 | |||
123 | newdatamsg = remac_datamsg(datamsg, mackey); | ||
124 | |||
125 | printf("%s\n", newdatamsg); | ||
126 | free(newdatamsg); | ||
127 | } | ||
128 | |||
129 | free_datamsg(datamsg); | ||
130 | free(aeskey); | ||
131 | fflush(stdout); | ||
132 | return 0; | ||
133 | } | ||
diff --git a/linden/indra/libotr/libotr-3.2.0/toolkit/otr_remac.c b/linden/indra/libotr/libotr-3.2.0/toolkit/otr_remac.c new file mode 100755 index 0000000..4ae04fc --- /dev/null +++ b/linden/indra/libotr/libotr-3.2.0/toolkit/otr_remac.c | |||
@@ -0,0 +1,127 @@ | |||
1 | /* | ||
2 | * Off-the-Record Messaging Toolkit | ||
3 | * Copyright (C) 2004-2008 Ian Goldberg, Chris Alexander, Nikita Borisov | ||
4 | * <otr@cypherpunks.ca> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of version 2 of the GNU General Public License as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | /* system headers */ | ||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | |||
24 | /* libgcrypt headers */ | ||
25 | #include <gcrypt.h> | ||
26 | |||
27 | /* toolkit headers */ | ||
28 | #include "parse.h" | ||
29 | #include "sha1hmac.h" | ||
30 | |||
31 | static void usage(const char *progname) | ||
32 | { | ||
33 | fprintf(stderr, "Usage: %s mackey flags snd_keyid rcp_keyid pubkey " | ||
34 | "counter encdata revealed_mackeys\n" | ||
35 | "Make a new Data message, with the given pieces (note that the\n" | ||
36 | "data part is already encrypted). MAC it with the given mackey.\n" | ||
37 | "mackey, pubkey, counter, encdata, and revealed_mackeys are given\n" | ||
38 | "as strings of hex chars. snd_keyid and rcp_keyid are decimal integers.\n", progname); | ||
39 | exit(1); | ||
40 | } | ||
41 | |||
42 | int main(int argc, char **argv) | ||
43 | { | ||
44 | unsigned char *mackey; | ||
45 | size_t mackeylen; | ||
46 | unsigned int snd_keyid, rcp_keyid; | ||
47 | int flags; | ||
48 | unsigned char *pubkey; | ||
49 | size_t pubkeylen; | ||
50 | gcry_mpi_t pubv; | ||
51 | unsigned char *ctr; | ||
52 | size_t ctrlen; | ||
53 | unsigned char *encdata; | ||
54 | size_t encdatalen; | ||
55 | unsigned char *mackeys; | ||
56 | size_t mackeyslen; | ||
57 | char *newdatamsg; | ||
58 | |||
59 | if (argc != 9) { | ||
60 | usage(argv[0]); | ||
61 | } | ||
62 | |||
63 | argv_to_buf(&mackey, &mackeylen, argv[1]); | ||
64 | if (!mackey) { | ||
65 | usage(argv[0]); | ||
66 | } | ||
67 | |||
68 | if (mackeylen != 20) { | ||
69 | fprintf(stderr, "The MAC key must be 40 hex chars long.\n"); | ||
70 | usage(argv[0]); | ||
71 | } | ||
72 | |||
73 | if (sscanf(argv[2], "%d", &flags) != 1) { | ||
74 | fprintf(stderr, "Unparseable flags given.\n"); | ||
75 | usage(argv[0]); | ||
76 | } | ||
77 | |||
78 | if (sscanf(argv[3], "%u", &snd_keyid) != 1) { | ||
79 | fprintf(stderr, "Unparseable snd_keyid given.\n"); | ||
80 | usage(argv[0]); | ||
81 | } | ||
82 | |||
83 | if (sscanf(argv[4], "%u", &rcp_keyid) != 1) { | ||
84 | fprintf(stderr, "Unparseable rcp_keyid given.\n"); | ||
85 | usage(argv[0]); | ||
86 | } | ||
87 | |||
88 | argv_to_buf(&pubkey, &pubkeylen, argv[5]); | ||
89 | if (!pubkey) { | ||
90 | usage(argv[0]); | ||
91 | } | ||
92 | gcry_mpi_scan(&pubv, GCRYMPI_FMT_USG, pubkey, pubkeylen, NULL); | ||
93 | free(pubkey); | ||
94 | |||
95 | argv_to_buf(&ctr, &ctrlen, argv[6]); | ||
96 | if (!ctr) { | ||
97 | usage(argv[0]); | ||
98 | } | ||
99 | |||
100 | if (ctrlen != 8) { | ||
101 | fprintf(stderr, "The counter must be 16 hex chars long.\n"); | ||
102 | usage(argv[0]); | ||
103 | } | ||
104 | |||
105 | argv_to_buf(&encdata, &encdatalen, argv[7]); | ||
106 | if (!encdata) { | ||
107 | usage(argv[0]); | ||
108 | } | ||
109 | |||
110 | argv_to_buf(&mackeys, &mackeyslen, argv[8]); | ||
111 | if (!mackeys) { | ||
112 | usage(argv[0]); | ||
113 | } | ||
114 | |||
115 | newdatamsg = assemble_datamsg(mackey, flags, snd_keyid, rcp_keyid, | ||
116 | pubv, ctr, encdata, encdatalen, mackeys, mackeyslen); | ||
117 | printf("%s\n", newdatamsg); | ||
118 | free(newdatamsg); | ||
119 | |||
120 | free(mackey); | ||
121 | gcry_mpi_release(pubv); | ||
122 | free(ctr); | ||
123 | free(encdata); | ||
124 | free(mackeys); | ||
125 | fflush(stdout); | ||
126 | return 0; | ||
127 | } | ||
diff --git a/linden/indra/libotr/libotr-3.2.0/toolkit/otr_sesskeys.c b/linden/indra/libotr/libotr-3.2.0/toolkit/otr_sesskeys.c new file mode 100755 index 0000000..5c5583f --- /dev/null +++ b/linden/indra/libotr/libotr-3.2.0/toolkit/otr_sesskeys.c | |||
@@ -0,0 +1,92 @@ | |||
1 | /* | ||
2 | * Off-the-Record Messaging Toolkit | ||
3 | * Copyright (C) 2004-2008 Ian Goldberg, Chris Alexander, Nikita Borisov | ||
4 | * <otr@cypherpunks.ca> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of version 2 of the GNU General Public License as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | /* system headers */ | ||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | |||
24 | /* toolkit headers */ | ||
25 | #include "parse.h" | ||
26 | #include "sesskeys.h" | ||
27 | |||
28 | static void usage(const char *progname) | ||
29 | { | ||
30 | fprintf(stderr, "Usage: %s our_privkey their_pubkey\n" | ||
31 | "Calculate and display our public key, the session id, two AES keys,\n" | ||
32 | "and two MAC keys generated by the given DH private key and public key.\n", | ||
33 | progname); | ||
34 | exit(1); | ||
35 | } | ||
36 | |||
37 | int main(int argc, char **argv) | ||
38 | { | ||
39 | unsigned char *argbuf; | ||
40 | size_t argbuflen; | ||
41 | gcry_mpi_t our_x, our_y, their_y; | ||
42 | unsigned char *pubbuf; | ||
43 | size_t publen; | ||
44 | unsigned char sessionid[20], sendenc[16], rcvenc[16]; | ||
45 | unsigned char sendmac[20], rcvmac[20]; | ||
46 | int is_high; | ||
47 | |||
48 | if (argc != 3) { | ||
49 | usage(argv[0]); | ||
50 | } | ||
51 | |||
52 | argv_to_buf(&argbuf, &argbuflen, argv[1]); | ||
53 | /* Private keys are only 320 bits long, so check for that to make | ||
54 | * sure they didn't get the args the wrong way around */ | ||
55 | if (!argbuf || argbuflen > 40) usage(argv[0]); | ||
56 | gcry_mpi_scan(&our_x, GCRYMPI_FMT_USG, argbuf, argbuflen, NULL); | ||
57 | free(argbuf); | ||
58 | argv_to_buf(&argbuf, &argbuflen, argv[2]); | ||
59 | if (!argbuf) usage(argv[0]); | ||
60 | gcry_mpi_scan(&their_y, GCRYMPI_FMT_USG, argbuf, argbuflen, NULL); | ||
61 | free(argbuf); | ||
62 | |||
63 | sesskeys_gen(sessionid, sendenc, rcvenc, &is_high, &our_y, our_x, their_y); | ||
64 | sesskeys_make_mac(sendmac, sendenc); | ||
65 | sesskeys_make_mac(rcvmac, rcvenc); | ||
66 | |||
67 | /* Print our public key into a buffer */ | ||
68 | gcry_mpi_print(GCRYMPI_FMT_USG, NULL, 0, &publen, our_y); | ||
69 | pubbuf = malloc(publen); | ||
70 | if (!pubbuf) { | ||
71 | fprintf(stderr, "Out of memory!\n"); | ||
72 | exit(1); | ||
73 | } | ||
74 | gcry_mpi_print(GCRYMPI_FMT_USG, pubbuf, publen, NULL, our_y); | ||
75 | |||
76 | puts(""); | ||
77 | printf("We are the %s end of this key exchange.\n", | ||
78 | is_high ? "high" : "low"); | ||
79 | puts(""); | ||
80 | dump_data(stdout, "Our public key", pubbuf, publen); | ||
81 | puts(""); | ||
82 | dump_data(stdout, "Session id", sessionid, 20); | ||
83 | puts(""); | ||
84 | dump_data(stdout, "Sending AES key", sendenc, 16); | ||
85 | dump_data(stdout, "Sending MAC key", sendmac, 20); | ||
86 | dump_data(stdout, "Receiving AES key", rcvenc, 16); | ||
87 | dump_data(stdout, "Receiving MAC key", rcvmac, 20); | ||
88 | puts(""); | ||
89 | fflush(stdout); | ||
90 | |||
91 | return 0; | ||
92 | } | ||
diff --git a/linden/indra/libotr/libotr-3.2.0/toolkit/otr_toolkit.1 b/linden/indra/libotr/libotr-3.2.0/toolkit/otr_toolkit.1 new file mode 100755 index 0000000..45a8e72 --- /dev/null +++ b/linden/indra/libotr/libotr-3.2.0/toolkit/otr_toolkit.1 | |||
@@ -0,0 +1,109 @@ | |||
1 | .\" Hey, EMACS: -*- nroff -*- | ||
2 | .\" First parameter, NAME, should be all caps | ||
3 | .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection | ||
4 | .\" other parameters are allowed: see man(7), man(1) | ||
5 | .TH OTR_PARSE 1 "October 27, 2005" | ||
6 | .\" Please adjust this date whenever revising the manpage. | ||
7 | .\" | ||
8 | .\" Some roff macros, for reference: | ||
9 | .\" .nh disable hyphenation | ||
10 | .\" .hy enable hyphenation | ||
11 | .\" .ad l left justify | ||
12 | .\" .ad b justify to both left and right margins | ||
13 | .\" .nf disable filling | ||
14 | .\" .fi enable filling | ||
15 | .\" .br insert line break | ||
16 | .\" .sp <n> insert n+1 empty lines | ||
17 | .\" for manpage-specific macros, see man(7) | ||
18 | .SH NAME | ||
19 | otr_parse, otr_sesskeys, otr_mackey, otr_readforge, otr_modify, otr_remac \- Process Off-the-Record Messaging transcripts | ||
20 | .SH SYNOPSIS | ||
21 | .B otr_parse | ||
22 | .br | ||
23 | .B otr_sesskeys | ||
24 | .I our_privkey their_pubkey | ||
25 | .br | ||
26 | .B otr_mackey | ||
27 | .I aes_enc_key | ||
28 | .br | ||
29 | .B otr_readforge | ||
30 | .I aes_enc_key [newmsg] | ||
31 | .br | ||
32 | .B otr_modify | ||
33 | .I mackey old_text new_text offset | ||
34 | .br | ||
35 | .B otr_remac | ||
36 | .I mackey flags snd_keyid rcv_keyid pubkey counter encdata revealed_mackeys | ||
37 | .SH DESCRIPTION | ||
38 | Off-the-Record (OTR) Messaging allows you to have private conversations | ||
39 | over IM by providing: | ||
40 | - Encryption | ||
41 | - No one else can read your instant messages. | ||
42 | - Authentication | ||
43 | - You are assured the correspondent is who you think it is. | ||
44 | - Deniability | ||
45 | - The messages you send do \fInot\fP have digital signatures that are | ||
46 | checkable by a third party. Anyone can forge messages after a | ||
47 | conversation to make them look like they came from you. However, | ||
48 | \fIduring\fP a conversation, your correspondent is assured the messages | ||
49 | he sees are authentic and unmodified. | ||
50 | - Perfect forward secrecy | ||
51 | - If you lose control of your private keys, no previous conversation | ||
52 | is compromised. | ||
53 | .PP | ||
54 | The OTR Toolkit is useful for analyzing and/or | ||
55 | forging OTR messages. Why do we offer this? Primarily, to make | ||
56 | absolutely sure that transcripts of OTR conversations are really easy | ||
57 | to forge after the fact. [Note that \fIduring\fP an OTR conversation, | ||
58 | messages can't be forged without real-time access to the secret keys on | ||
59 | the participants' computers, and in that case, all security has already | ||
60 | been lost.] Easily-forgeable transcripts help us provide the | ||
61 | "Deniability" property: if someone claims you said something over OTR, | ||
62 | they'll have no proof, as anyone at all can modify a transcript to make | ||
63 | it say whatever they like, and still have all the verification come out | ||
64 | correctly. | ||
65 | |||
66 | Here are the six programs in the toolkit: | ||
67 | |||
68 | - otr_parse | ||
69 | - Parse OTR messages given on stdin, showing the values of all the | ||
70 | fields in OTR protocol messages. | ||
71 | |||
72 | - otr_sesskeys our_privkey their_pubkey | ||
73 | - Shows our public key, the session id, two AES and two MAC keys | ||
74 | derived from the given Diffie-Hellman keys (one private, one public). | ||
75 | |||
76 | - otr_mackey aes_enc_key | ||
77 | - Shows the MAC key derived from the given AES key. | ||
78 | |||
79 | - otr_readforge aes_enc_key [newmsg] | ||
80 | - Decrypts an OTR Data message using the given AES key, and displays | ||
81 | the message. | ||
82 | - If newmsg is given, replace the message with that one, encrypt | ||
83 | and MAC it properly, and output the resulting OTR Data Message. | ||
84 | This works even if the given key was not correct for the original | ||
85 | message, so as to enable complete forgeries. | ||
86 | |||
87 | - otr_modify mackey old_text new_text offset | ||
88 | - Even if you can't read the data because you don't know either | ||
89 | the AES key or the Diffie-Hellman private key, but you can make a | ||
90 | good guess that the substring "old_text" appears at the given | ||
91 | offset in the message, replace the old_text with the new_text | ||
92 | (which must be of the same length), recalculate the MAC with the | ||
93 | given mackey, and output the resulting Data message. | ||
94 | - Note that, even if you don't know any text in an existing message, | ||
95 | you can still forge messages of your choice using the | ||
96 | otr_readforge command, above. | ||
97 | |||
98 | - otr_remac mackey flags snd_keyid rcv_keyid pubkey counter encdata revealed_mackeys | ||
99 | - Make a new OTR Data Message, with the given pieces (note that the | ||
100 | data part is already encrypted). MAC it with the given mackey. | ||
101 | |||
102 | .SH SEE ALSO | ||
103 | .BR "Off-the-Record Messaging" , | ||
104 | at | ||
105 | .UR http://www.cypherpunks.ca/otr/ | ||
106 | http://www.cypherpunks.ca/otr/ | ||
107 | .UE | ||
108 | .SH AUTHOR | ||
109 | otr_toolkit was written by the OTR Dev Team <otr@cypherpunks.ca>. | ||
diff --git a/linden/indra/libotr/libotr-3.2.0/toolkit/parse.c b/linden/indra/libotr/libotr-3.2.0/toolkit/parse.c new file mode 100755 index 0000000..5f357fc --- /dev/null +++ b/linden/indra/libotr/libotr-3.2.0/toolkit/parse.c | |||
@@ -0,0 +1,585 @@ | |||
1 | /* | ||
2 | * Off-the-Record Messaging Toolkit | ||
3 | * Copyright (C) 2004-2008 Ian Goldberg, Chris Alexander, Nikita Borisov | ||
4 | * <otr@cypherpunks.ca> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of version 2 of the GNU General Public License as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | /* system headers */ | ||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | |||
24 | /* libotr headers */ | ||
25 | #include "b64.h" | ||
26 | |||
27 | /* toolkit headers */ | ||
28 | #include "sha1hmac.h" | ||
29 | #include "parse.h" | ||
30 | |||
31 | /* Dump an unsigned int to a FILE * */ | ||
32 | void dump_int(FILE *stream, const char *title, unsigned int val) | ||
33 | { | ||
34 | fprintf(stream, "%s: %u\n", title, val); | ||
35 | } | ||
36 | |||
37 | /* Dump an mpi to a FILE * */ | ||
38 | void dump_mpi(FILE *stream, const char *title, gcry_mpi_t val) | ||
39 | { | ||
40 | size_t plen; | ||
41 | unsigned char *d; | ||
42 | |||
43 | gcry_mpi_print(GCRYMPI_FMT_USG, NULL, 0, &plen, val); | ||
44 | d = malloc(plen); | ||
45 | gcry_mpi_print(GCRYMPI_FMT_USG, d, plen, NULL, val); | ||
46 | dump_data(stream, title, d, plen); | ||
47 | free(d); | ||
48 | } | ||
49 | |||
50 | /* Dump data to a FILE * */ | ||
51 | void dump_data(FILE *stream, const char *title, const unsigned char *data, | ||
52 | size_t datalen) | ||
53 | { | ||
54 | size_t i; | ||
55 | fprintf(stream, "%s: ", title); | ||
56 | for(i=0;i<datalen;++i) { | ||
57 | fprintf(stream, "%02x", data[i]); | ||
58 | } | ||
59 | fprintf(stream, "\n"); | ||
60 | } | ||
61 | |||
62 | /* base64 decode the message, and put the resulting size into *lenp */ | ||
63 | static unsigned char *decode(const char *msg, size_t *lenp) | ||
64 | { | ||
65 | const char *header, *footer; | ||
66 | unsigned char *raw; | ||
67 | |||
68 | /* Find the header */ | ||
69 | header = strstr(msg, "?OTR:"); | ||
70 | if (!header) return NULL; | ||
71 | /* Skip the header */ | ||
72 | header += 5; | ||
73 | |||
74 | /* Find the trailing '.' */ | ||
75 | footer = strchr(header, '.'); | ||
76 | if (!footer) footer = header + strlen(header); | ||
77 | |||
78 | raw = malloc((footer-header) / 4 * 3); | ||
79 | if (raw == NULL && (footer-header >= 4)) return NULL; | ||
80 | *lenp = otrl_base64_decode(raw, header, footer-header); | ||
81 | |||
82 | return raw; | ||
83 | } | ||
84 | |||
85 | #define require_len(l) do { if (lenp < (l)) goto inv; } while(0) | ||
86 | #define read_int(x) do { \ | ||
87 | require_len(4); \ | ||
88 | (x) = (bufp[0] << 24) | (bufp[1] << 16) | (bufp[2] << 8 ) | bufp[3]; \ | ||
89 | bufp += 4; lenp -= 4; \ | ||
90 | } while(0) | ||
91 | #define read_mpi(x) do { \ | ||
92 | size_t mpilen; \ | ||
93 | read_int(mpilen); \ | ||
94 | require_len(mpilen); \ | ||
95 | gcry_mpi_scan(&(x), GCRYMPI_FMT_USG, bufp, mpilen, NULL); \ | ||
96 | bufp += mpilen; lenp -= mpilen; \ | ||
97 | } while(0) | ||
98 | #define read_raw(b, l) do { \ | ||
99 | require_len(l); \ | ||
100 | memmove((b), bufp, (l)); \ | ||
101 | bufp += (l); lenp -= (l); \ | ||
102 | } while(0) | ||
103 | #define write_int(x) do { \ | ||
104 | bufp[0] = ((x) >> 24) & 0xff; \ | ||
105 | bufp[1] = ((x) >> 16) & 0xff; \ | ||
106 | bufp[2] = ((x) >> 8) & 0xff; \ | ||
107 | bufp[3] = (x) & 0xff; \ | ||
108 | bufp += 4; lenp -= 4; \ | ||
109 | } while(0) | ||
110 | #define write_mpi(x,l) do { \ | ||
111 | write_int(l); \ | ||
112 | gcry_mpi_print(GCRYMPI_FMT_USG, bufp, lenp, NULL, (x)); \ | ||
113 | bufp += (l); lenp -= (l); \ | ||
114 | } while(0) | ||
115 | #define write_raw(x,l) do { \ | ||
116 | memmove(bufp, (x), (l)); \ | ||
117 | bufp += (l); lenp -= (l); \ | ||
118 | } while(0) | ||
119 | |||
120 | /* Parse a Key Exchange Message into a newly-allocated KeyExchMsg structure */ | ||
121 | KeyExchMsg parse_keyexch(const char *msg) | ||
122 | { | ||
123 | KeyExchMsg kem = NULL; | ||
124 | size_t lenp; | ||
125 | unsigned char *raw = decode(msg, &lenp); | ||
126 | unsigned char *bufp = raw; | ||
127 | if (!raw) goto inv; | ||
128 | |||
129 | kem = calloc(1, sizeof(struct s_KeyExchMsg)); | ||
130 | if (!kem) { | ||
131 | free(raw); | ||
132 | goto inv; | ||
133 | } | ||
134 | |||
135 | kem->raw = raw; | ||
136 | kem->sigstart = bufp; | ||
137 | |||
138 | require_len(3); | ||
139 | if (memcmp(bufp, "\x00\x01\x0a", 3)) goto inv; | ||
140 | bufp += 3; lenp -= 3; | ||
141 | |||
142 | require_len(1); | ||
143 | kem->reply = *bufp; | ||
144 | bufp += 1; lenp -= 1; | ||
145 | |||
146 | read_mpi(kem->p); | ||
147 | read_mpi(kem->q); | ||
148 | read_mpi(kem->g); | ||
149 | read_mpi(kem->e); | ||
150 | |||
151 | read_int(kem->keyid); | ||
152 | |||
153 | read_mpi(kem->y); | ||
154 | |||
155 | kem->sigend = bufp; | ||
156 | |||
157 | require_len(40); | ||
158 | gcry_mpi_scan(&kem->r, GCRYMPI_FMT_USG, bufp, 20, NULL); | ||
159 | gcry_mpi_scan(&kem->s, GCRYMPI_FMT_USG, bufp+20, 20, NULL); | ||
160 | bufp += 40; lenp -= 40; | ||
161 | |||
162 | if (lenp != 0) goto inv; | ||
163 | |||
164 | return kem; | ||
165 | inv: | ||
166 | free_keyexch(kem); | ||
167 | return NULL; | ||
168 | } | ||
169 | |||
170 | /* Deallocate a KeyExchMsg and all of the data it points to */ | ||
171 | void free_keyexch(KeyExchMsg keyexch) | ||
172 | { | ||
173 | if (!keyexch) return; | ||
174 | free(keyexch->raw); | ||
175 | gcry_mpi_release(keyexch->p); | ||
176 | gcry_mpi_release(keyexch->q); | ||
177 | gcry_mpi_release(keyexch->g); | ||
178 | gcry_mpi_release(keyexch->e); | ||
179 | gcry_mpi_release(keyexch->y); | ||
180 | gcry_mpi_release(keyexch->r); | ||
181 | gcry_mpi_release(keyexch->s); | ||
182 | free(keyexch); | ||
183 | } | ||
184 | |||
185 | /* Parse a D-H Commit Message into a newly-allocated CommitMsg structure */ | ||
186 | CommitMsg parse_commit(const char *msg) | ||
187 | { | ||
188 | CommitMsg cmsg = NULL; | ||
189 | size_t lenp; | ||
190 | unsigned char *raw = decode(msg, &lenp); | ||
191 | unsigned char *bufp = raw; | ||
192 | if (!raw) goto inv; | ||
193 | |||
194 | cmsg = calloc(1, sizeof(struct s_CommitMsg)); | ||
195 | if (!cmsg) { | ||
196 | free(raw); | ||
197 | goto inv; | ||
198 | } | ||
199 | |||
200 | cmsg->raw = raw; | ||
201 | |||
202 | require_len(3); | ||
203 | if (memcmp(bufp, "\x00\x02\x02", 3)) goto inv; | ||
204 | bufp += 3; lenp -= 3; | ||
205 | |||
206 | read_int(cmsg->enckeylen); | ||
207 | cmsg->enckey = malloc(cmsg->enckeylen); | ||
208 | if (!cmsg->enckey && cmsg->enckeylen > 0) goto inv; | ||
209 | read_raw(cmsg->enckey, cmsg->enckeylen); | ||
210 | |||
211 | read_int(cmsg->hashkeylen); | ||
212 | cmsg->hashkey = malloc(cmsg->hashkeylen); | ||
213 | if (!cmsg->hashkey && cmsg->hashkeylen > 0) goto inv; | ||
214 | read_raw(cmsg->hashkey, cmsg->hashkeylen); | ||
215 | |||
216 | if (lenp != 0) goto inv; | ||
217 | |||
218 | return cmsg; | ||
219 | inv: | ||
220 | free_commit(cmsg); | ||
221 | return NULL; | ||
222 | } | ||
223 | |||
224 | /* Deallocate a CommitMsg and all of the data it points to */ | ||
225 | void free_commit(CommitMsg cmsg) | ||
226 | { | ||
227 | if (!cmsg) return; | ||
228 | free(cmsg->raw); | ||
229 | free(cmsg->enckey); | ||
230 | free(cmsg->hashkey); | ||
231 | free(cmsg); | ||
232 | } | ||
233 | |||
234 | /* Parse a D-H Key Message into a newly-allocated KeyMsg structure */ | ||
235 | KeyMsg parse_key(const char *msg) | ||
236 | { | ||
237 | KeyMsg kmsg = NULL; | ||
238 | size_t lenp; | ||
239 | unsigned char *raw = decode(msg, &lenp); | ||
240 | unsigned char *bufp = raw; | ||
241 | if (!raw) goto inv; | ||
242 | |||
243 | kmsg = calloc(1, sizeof(struct s_KeyMsg)); | ||
244 | if (!kmsg) { | ||
245 | free(raw); | ||
246 | goto inv; | ||
247 | } | ||
248 | |||
249 | kmsg->raw = raw; | ||
250 | |||
251 | require_len(3); | ||
252 | if (memcmp(bufp, "\x00\x02\x0a", 3)) goto inv; | ||
253 | bufp += 3; lenp -= 3; | ||
254 | |||
255 | read_mpi(kmsg->y); | ||
256 | |||
257 | if (lenp != 0) goto inv; | ||
258 | |||
259 | return kmsg; | ||
260 | inv: | ||
261 | free_key(kmsg); | ||
262 | return NULL; | ||
263 | } | ||
264 | |||
265 | /* Deallocate a KeyMsg and all of the data it points to */ | ||
266 | void free_key(KeyMsg kmsg) | ||
267 | { | ||
268 | if (!kmsg) return; | ||
269 | free(kmsg->raw); | ||
270 | gcry_mpi_release(kmsg->y); | ||
271 | free(kmsg); | ||
272 | } | ||
273 | |||
274 | /* Parse a Reveal Signature Message into a newly-allocated RevealSigMsg | ||
275 | * structure */ | ||
276 | RevealSigMsg parse_revealsig(const char *msg) | ||
277 | { | ||
278 | RevealSigMsg rmsg = NULL; | ||
279 | size_t lenp; | ||
280 | unsigned char *raw = decode(msg, &lenp); | ||
281 | unsigned char *bufp = raw; | ||
282 | if (!raw) goto inv; | ||
283 | |||
284 | rmsg = calloc(1, sizeof(struct s_RevealSigMsg)); | ||
285 | if (!rmsg) { | ||
286 | free(raw); | ||
287 | goto inv; | ||
288 | } | ||
289 | |||
290 | rmsg->raw = raw; | ||
291 | |||
292 | require_len(3); | ||
293 | if (memcmp(bufp, "\x00\x02\x11", 3)) goto inv; | ||
294 | bufp += 3; lenp -= 3; | ||
295 | |||
296 | read_int(rmsg->keylen); | ||
297 | rmsg->key = malloc(rmsg->keylen); | ||
298 | if (!rmsg->key && rmsg->keylen > 0) goto inv; | ||
299 | read_raw(rmsg->key, rmsg->keylen); | ||
300 | |||
301 | read_int(rmsg->encsiglen); | ||
302 | rmsg->encsig = malloc(rmsg->encsiglen); | ||
303 | if (!rmsg->encsig && rmsg->encsiglen > 0) goto inv; | ||
304 | read_raw(rmsg->encsig, rmsg->encsiglen); | ||
305 | |||
306 | read_raw(rmsg->mac, 20); | ||
307 | |||
308 | if (lenp != 0) goto inv; | ||
309 | |||
310 | return rmsg; | ||
311 | inv: | ||
312 | free_revealsig(rmsg); | ||
313 | return NULL; | ||
314 | } | ||
315 | |||
316 | /* Deallocate a RevealSigMsg and all of the data it points to */ | ||
317 | void free_revealsig(RevealSigMsg rmsg) | ||
318 | { | ||
319 | if (!rmsg) return; | ||
320 | free(rmsg->raw); | ||
321 | free(rmsg->key); | ||
322 | free(rmsg->encsig); | ||
323 | free(rmsg); | ||
324 | } | ||
325 | |||
326 | /* Parse a Signature Message into a newly-allocated SignatureMsg structure */ | ||
327 | SignatureMsg parse_signature(const char *msg) | ||
328 | { | ||
329 | SignatureMsg smsg = NULL; | ||
330 | size_t lenp; | ||
331 | unsigned char *raw = decode(msg, &lenp); | ||
332 | unsigned char *bufp = raw; | ||
333 | if (!raw) goto inv; | ||
334 | |||
335 | smsg = calloc(1, sizeof(struct s_SignatureMsg)); | ||
336 | if (!smsg) { | ||
337 | free(raw); | ||
338 | goto inv; | ||
339 | } | ||
340 | |||
341 | smsg->raw = raw; | ||
342 | |||
343 | require_len(3); | ||
344 | if (memcmp(bufp, "\x00\x02\x12", 3)) goto inv; | ||
345 | bufp += 3; lenp -= 3; | ||
346 | |||
347 | read_int(smsg->encsiglen); | ||
348 | smsg->encsig = malloc(smsg->encsiglen); | ||
349 | if (!smsg->encsig && smsg->encsiglen > 0) goto inv; | ||
350 | read_raw(smsg->encsig, smsg->encsiglen); | ||
351 | |||
352 | read_raw(smsg->mac, 20); | ||
353 | |||
354 | if (lenp != 0) goto inv; | ||
355 | |||
356 | return smsg; | ||
357 | inv: | ||
358 | free_signature(smsg); | ||
359 | return NULL; | ||
360 | } | ||
361 | |||
362 | /* Deallocate a SignatureMsg and all of the data it points to */ | ||
363 | void free_signature(SignatureMsg smsg) | ||
364 | { | ||
365 | if (!smsg) return; | ||
366 | free(smsg->raw); | ||
367 | free(smsg->encsig); | ||
368 | free(smsg); | ||
369 | } | ||
370 | |||
371 | /* Parse a Data Message into a newly-allocated DataMsg structure */ | ||
372 | DataMsg parse_datamsg(const char *msg) | ||
373 | { | ||
374 | DataMsg datam = NULL; | ||
375 | size_t lenp; | ||
376 | unsigned char *raw = decode(msg, &lenp); | ||
377 | unsigned char *bufp = raw; | ||
378 | unsigned char version; | ||
379 | if (!raw) goto inv; | ||
380 | |||
381 | datam = calloc(1, sizeof(struct s_DataMsg)); | ||
382 | if (!datam) { | ||
383 | free(raw); | ||
384 | goto inv; | ||
385 | } | ||
386 | |||
387 | datam->raw = raw; | ||
388 | datam->rawlen = lenp; | ||
389 | datam->macstart = bufp; | ||
390 | |||
391 | require_len(3); | ||
392 | if (memcmp(bufp, "\x00\x01\x03", 3) && memcmp(bufp, "\x00\x02\x03", 3)) | ||
393 | goto inv; | ||
394 | version = bufp[1]; | ||
395 | bufp += 3; lenp -= 3; | ||
396 | |||
397 | if (version == 2) { | ||
398 | require_len(1); | ||
399 | datam->flags = bufp[0]; | ||
400 | bufp += 1; lenp -= 1; | ||
401 | } else { | ||
402 | datam->flags = -1; | ||
403 | } | ||
404 | read_int(datam->sender_keyid); | ||
405 | read_int(datam->rcpt_keyid); | ||
406 | read_mpi(datam->y); | ||
407 | read_raw(datam->ctr, 8); | ||
408 | read_int(datam->encmsglen); | ||
409 | datam->encmsg = malloc(datam->encmsglen); | ||
410 | if (!datam->encmsg && datam->encmsglen > 0) goto inv; | ||
411 | read_raw(datam->encmsg, datam->encmsglen); | ||
412 | datam->macend = bufp; | ||
413 | read_raw(datam->mac, 20); | ||
414 | read_int(datam->mackeyslen); | ||
415 | datam->mackeys = malloc(datam->mackeyslen); | ||
416 | if (!datam->mackeys && datam->mackeyslen > 0) goto inv; | ||
417 | read_raw(datam->mackeys, datam->mackeyslen); | ||
418 | |||
419 | if (lenp != 0) goto inv; | ||
420 | |||
421 | return datam; | ||
422 | inv: | ||
423 | free_datamsg(datam); | ||
424 | return NULL; | ||
425 | } | ||
426 | |||
427 | /* Recalculate the MAC on the message, base64-encode the resulting MAC'd | ||
428 | * message, and put on the appropriate header and footer. Return a | ||
429 | * newly-allocated pointer to the result, which the caller will have to | ||
430 | * free(). */ | ||
431 | char *remac_datamsg(DataMsg datamsg, unsigned char mackey[20]) | ||
432 | { | ||
433 | size_t rawlen, lenp; | ||
434 | size_t ylen; | ||
435 | size_t base64len; | ||
436 | char *outmsg; | ||
437 | unsigned char *raw, *bufp; | ||
438 | unsigned char version = (datamsg->flags >= 0 ? 2 : 1); | ||
439 | |||
440 | /* Calculate the size of the message that will result */ | ||
441 | gcry_mpi_print(GCRYMPI_FMT_USG, NULL, 0, &ylen, datamsg->y); | ||
442 | rawlen = 3 + (version == 2 ? 1 : 0) + 4 + 4 + 4 + ylen + 8 + 4 + | ||
443 | datamsg->encmsglen + 20 + 4 + datamsg->mackeyslen; | ||
444 | |||
445 | /* Construct the new raw message (note that some of the pieces may | ||
446 | * have been altered, so we construct it from scratch). */ | ||
447 | raw = malloc(rawlen); | ||
448 | if (!raw) { | ||
449 | fprintf(stderr, "Out of memory!\n"); | ||
450 | exit(1); | ||
451 | } | ||
452 | bufp = raw; | ||
453 | lenp = rawlen; | ||
454 | datamsg->macstart = raw; | ||
455 | datamsg->macend = NULL; | ||
456 | free(datamsg->raw); | ||
457 | datamsg->raw = raw; | ||
458 | datamsg->rawlen = rawlen; | ||
459 | |||
460 | if (version == 1) { | ||
461 | memmove(bufp, "\x00\x01\x03", 3); | ||
462 | } else { | ||
463 | memmove(bufp, "\x00\x02\x03", 3); | ||
464 | } | ||
465 | bufp += 3; lenp -= 3; | ||
466 | if (version == 2) { | ||
467 | bufp[0] = datamsg->flags; | ||
468 | bufp += 1; lenp -= 1; | ||
469 | } | ||
470 | write_int(datamsg->sender_keyid); | ||
471 | write_int(datamsg->rcpt_keyid); | ||
472 | write_mpi(datamsg->y, ylen); | ||
473 | write_raw(datamsg->ctr, 8); | ||
474 | write_int(datamsg->encmsglen); | ||
475 | write_raw(datamsg->encmsg, datamsg->encmsglen); | ||
476 | datamsg->macend = bufp; | ||
477 | |||
478 | /* Recalculate the MAC */ | ||
479 | sha1hmac(datamsg->mac, mackey, datamsg->macstart, | ||
480 | datamsg->macend - datamsg->macstart); | ||
481 | |||
482 | write_raw(datamsg->mac, 20); | ||
483 | write_int(datamsg->mackeyslen); | ||
484 | write_raw(datamsg->mackeys, datamsg->mackeyslen); | ||
485 | |||
486 | if (lenp != 0) { | ||
487 | fprintf(stderr, "Error creating OTR Data Message.\n"); | ||
488 | exit(1); | ||
489 | } | ||
490 | |||
491 | base64len = 5 + ((datamsg->rawlen + 2) / 3) * 4 + 1 + 1; | ||
492 | outmsg = malloc(base64len); | ||
493 | if (!outmsg) return NULL; | ||
494 | |||
495 | memmove(outmsg, "?OTR:", 5); | ||
496 | otrl_base64_encode(outmsg + 5, datamsg->raw, datamsg->rawlen); | ||
497 | strcpy(outmsg + base64len - 2, "."); | ||
498 | return outmsg; | ||
499 | } | ||
500 | |||
501 | /* Assemble a new Data Message from its pieces. Return a | ||
502 | * newly-allocated string containing the base64 representation. */ | ||
503 | char *assemble_datamsg(unsigned char mackey[20], int flags, | ||
504 | unsigned int sender_keyid, unsigned int rcpt_keyid, gcry_mpi_t y, | ||
505 | unsigned char ctr[8], unsigned char *encmsg, size_t encmsglen, | ||
506 | unsigned char *mackeys, size_t mackeyslen) | ||
507 | { | ||
508 | DataMsg datam = calloc(1, sizeof(struct s_DataMsg)); | ||
509 | char *newmsg = NULL; | ||
510 | if (!datam) goto inv; | ||
511 | datam->flags = flags; | ||
512 | datam->sender_keyid = sender_keyid; | ||
513 | datam->rcpt_keyid = rcpt_keyid; | ||
514 | datam->y = gcry_mpi_copy(y); | ||
515 | memmove(datam->ctr, ctr, 8); | ||
516 | datam->encmsg = malloc(encmsglen); | ||
517 | if (!datam->encmsg && encmsglen > 0) goto inv; | ||
518 | memmove(datam->encmsg, encmsg, encmsglen); | ||
519 | datam->encmsglen = encmsglen; | ||
520 | datam->mackeys = malloc(mackeyslen); | ||
521 | if (!datam->mackeys && mackeyslen > 0) goto inv; | ||
522 | memmove(datam->mackeys, mackeys, mackeyslen); | ||
523 | datam->mackeyslen = mackeyslen; | ||
524 | |||
525 | /* Recalculate the MAC and base64-encode the result */ | ||
526 | newmsg = remac_datamsg(datam, mackey); | ||
527 | free_datamsg(datam); | ||
528 | return newmsg; | ||
529 | inv: | ||
530 | free_datamsg(datam); | ||
531 | return NULL; | ||
532 | } | ||
533 | |||
534 | /* Deallocate a DataMsg and all of the data it points to */ | ||
535 | void free_datamsg(DataMsg datamsg) | ||
536 | { | ||
537 | if (!datamsg) return; | ||
538 | free(datamsg->raw); | ||
539 | gcry_mpi_release(datamsg->y); | ||
540 | free(datamsg->encmsg); | ||
541 | free(datamsg->mackeys); | ||
542 | free(datamsg); | ||
543 | } | ||
544 | |||
545 | static int ctoh(char c) | ||
546 | { | ||
547 | if (c >= '0' && c <= '9') return (c-'0'); | ||
548 | if (c >= 'a' && c <= 'f') return (c-'a'+10); | ||
549 | if (c >= 'A' && c <= 'F') return (c-'A'+10); | ||
550 | return -1; | ||
551 | } | ||
552 | |||
553 | /* Convert a string of hex chars to a buffer of unsigned chars. */ | ||
554 | void argv_to_buf(unsigned char **bufp, size_t *lenp, char *arg) | ||
555 | { | ||
556 | unsigned char *buf; | ||
557 | size_t len, i; | ||
558 | |||
559 | *bufp = NULL; | ||
560 | *lenp = 0; | ||
561 | |||
562 | len = strlen(arg); | ||
563 | if (len % 2) { | ||
564 | fprintf(stderr, "Argument ``%s'' must have even length.\n", arg); | ||
565 | return; | ||
566 | } | ||
567 | buf = malloc(len/2); | ||
568 | if (buf == NULL && len > 0) { | ||
569 | fprintf(stderr, "Out of memory!\n"); | ||
570 | return; | ||
571 | } | ||
572 | |||
573 | for(i=0;i<len/2;++i) { | ||
574 | int hi = ctoh(arg[2*i]); | ||
575 | int lo = ctoh(arg[2*i+1]); | ||
576 | if (hi < 0 || lo < 0) { | ||
577 | free(buf); | ||
578 | fprintf(stderr, "Illegal hex char in argument ``%s''.\n", arg); | ||
579 | return; | ||
580 | } | ||
581 | buf[i] = (hi << 4) + lo; | ||
582 | } | ||
583 | *bufp = buf; | ||
584 | *lenp = len/2; | ||
585 | } | ||
diff --git a/linden/indra/libotr/libotr-3.2.0/toolkit/parse.h b/linden/indra/libotr/libotr-3.2.0/toolkit/parse.h new file mode 100755 index 0000000..f98cb6a --- /dev/null +++ b/linden/indra/libotr/libotr-3.2.0/toolkit/parse.h | |||
@@ -0,0 +1,145 @@ | |||
1 | /* | ||
2 | * Off-the-Record Messaging Toolkit | ||
3 | * Copyright (C) 2004-2008 Ian Goldberg, Chris Alexander, Nikita Borisov | ||
4 | * <otr@cypherpunks.ca> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of version 2 of the GNU General Public License as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | #ifndef __PARSE_H__ | ||
21 | #define __PARSE_H__ | ||
22 | |||
23 | #include <gcrypt.h> | ||
24 | |||
25 | typedef struct s_KeyExchMsg { | ||
26 | unsigned char *raw; /* The base64-decoded data; must be free()d */ | ||
27 | unsigned char reply; | ||
28 | gcry_mpi_t p, q, g, e; | ||
29 | unsigned int keyid; | ||
30 | gcry_mpi_t y; | ||
31 | gcry_mpi_t r, s; | ||
32 | unsigned char *sigstart; /* Pointers into the "raw" array. Don't */ | ||
33 | unsigned char *sigend; /* free() these. */ | ||
34 | } * KeyExchMsg; | ||
35 | |||
36 | typedef struct s_DataMsg { | ||
37 | unsigned char *raw; /* The base64-decoded data; must be free()d */ | ||
38 | size_t rawlen; | ||
39 | int flags; | ||
40 | unsigned int sender_keyid; | ||
41 | unsigned int rcpt_keyid; | ||
42 | gcry_mpi_t y; | ||
43 | unsigned char ctr[8]; | ||
44 | unsigned char *encmsg; /* A copy; must be free()d */ | ||
45 | size_t encmsglen; | ||
46 | unsigned char mac[20]; | ||
47 | unsigned char *mackeys; /* A copy; must be free()d */ | ||
48 | size_t mackeyslen; | ||
49 | unsigned char *macstart; /* Pointers into the "raw" array. Don't */ | ||
50 | unsigned char *macend; /* free() these. */ | ||
51 | } * DataMsg; | ||
52 | |||
53 | typedef struct s_CommitMsg { | ||
54 | unsigned char *raw; /* The base64-decoded data; must be free()d */ | ||
55 | unsigned char *enckey; | ||
56 | size_t enckeylen; | ||
57 | unsigned char *hashkey; | ||
58 | size_t hashkeylen; | ||
59 | } * CommitMsg; | ||
60 | |||
61 | typedef struct s_KeyMsg { | ||
62 | unsigned char *raw; /* The base64-decoded data; must be free()d */ | ||
63 | gcry_mpi_t y; | ||
64 | } * KeyMsg; | ||
65 | |||
66 | typedef struct s_RevealSigMsg { | ||
67 | unsigned char *raw; /* The base64-decoded data; must be free()d */ | ||
68 | unsigned char *key; | ||
69 | size_t keylen; | ||
70 | unsigned char *encsig; | ||
71 | size_t encsiglen; | ||
72 | unsigned char mac[20]; | ||
73 | } * RevealSigMsg; | ||
74 | |||
75 | typedef struct s_SignatureMsg { | ||
76 | unsigned char *raw; /* The base64-decoded data; must be free()d */ | ||
77 | unsigned char *encsig; | ||
78 | size_t encsiglen; | ||
79 | unsigned char mac[20]; | ||
80 | } * SignatureMsg; | ||
81 | |||
82 | /* Dump an unsigned int to a FILE * */ | ||
83 | void dump_int(FILE *stream, const char *title, unsigned int val); | ||
84 | |||
85 | /* Dump an mpi to a FILE * */ | ||
86 | void dump_mpi(FILE *stream, const char *title, gcry_mpi_t val); | ||
87 | |||
88 | /* Dump data to a FILE * */ | ||
89 | void dump_data(FILE *stream, const char *title, const unsigned char *data, | ||
90 | size_t datalen); | ||
91 | |||
92 | /* Parse a Key Exchange Message into a newly-allocated KeyExchMsg structure */ | ||
93 | KeyExchMsg parse_keyexch(const char *msg); | ||
94 | |||
95 | /* Deallocate a KeyExchMsg and all of the data it points to */ | ||
96 | void free_keyexch(KeyExchMsg keyexch); | ||
97 | |||
98 | /* Parse a D-H Commit Message into a newly-allocated CommitMsg structure */ | ||
99 | CommitMsg parse_commit(const char *msg); | ||
100 | |||
101 | /* Parse a Data Message into a newly-allocated DataMsg structure */ | ||
102 | DataMsg parse_datamsg(const char *msg); | ||
103 | |||
104 | /* Deallocate a CommitMsg and all of the data it points to */ | ||
105 | void free_commit(CommitMsg cmsg); | ||
106 | |||
107 | /* Parse a Reveal Signature Message into a newly-allocated RevealSigMsg | ||
108 | * structure */ | ||
109 | RevealSigMsg parse_revealsig(const char *msg); | ||
110 | |||
111 | /* Deallocate a RevealSigMsg and all of the data it points to */ | ||
112 | void free_revealsig(RevealSigMsg rmsg); | ||
113 | |||
114 | /* Parse a Signature Message into a newly-allocated SignatureMsg structure */ | ||
115 | SignatureMsg parse_signature(const char *msg); | ||
116 | |||
117 | /* Deallocate a SignatureMsg and all of the data it points to */ | ||
118 | void free_signature(SignatureMsg smsg); | ||
119 | |||
120 | /* Parse a D-H Key Message into a newly-allocated KeyMsg structure */ | ||
121 | KeyMsg parse_key(const char *msg); | ||
122 | |||
123 | /* Deallocate a KeyMsg and all of the data it points to */ | ||
124 | void free_key(KeyMsg cmsg); | ||
125 | |||
126 | /* Recalculate the MAC on the message, base64-encode the resulting MAC'd | ||
127 | * message, and put on the appropriate header and footer. Return a | ||
128 | * newly-allocated pointer to the result, which the caller will have to | ||
129 | * free(). */ | ||
130 | char *remac_datamsg(DataMsg datamsg, unsigned char mackey[20]); | ||
131 | |||
132 | /* Assemble a new Data Message from its pieces. Return a | ||
133 | * newly-allocated string containing the base64 representation. */ | ||
134 | char *assemble_datamsg(unsigned char mackey[20], int flags, | ||
135 | unsigned int sender_keyid, unsigned int rcpt_keyid, gcry_mpi_t y, | ||
136 | unsigned char ctr[8], unsigned char *encmsg, size_t encmsglen, | ||
137 | unsigned char *mackeys, size_t mackeyslen); | ||
138 | |||
139 | /* Deallocate a DataMsg and all of the data it points to */ | ||
140 | void free_datamsg(DataMsg datamsg); | ||
141 | |||
142 | /* Convert a string of hex chars to a buffer of unsigned chars. */ | ||
143 | void argv_to_buf(unsigned char **bufp, size_t *lenp, char *arg); | ||
144 | |||
145 | #endif | ||
diff --git a/linden/indra/libotr/libotr-3.2.0/toolkit/readotr.c b/linden/indra/libotr/libotr-3.2.0/toolkit/readotr.c new file mode 100755 index 0000000..04e9fca --- /dev/null +++ b/linden/indra/libotr/libotr-3.2.0/toolkit/readotr.c | |||
@@ -0,0 +1,91 @@ | |||
1 | /* | ||
2 | * Off-the-Record Messaging Toolkit | ||
3 | * Copyright (C) 2004-2008 Ian Goldberg, Chris Alexander, Nikita Borisov | ||
4 | * <otr@cypherpunks.ca> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of version 2 of the GNU General Public License as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | /* system headers */ | ||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <string.h> | ||
24 | |||
25 | typedef struct { | ||
26 | char *data; | ||
27 | size_t len; | ||
28 | size_t alloclen; | ||
29 | } Buffer; | ||
30 | |||
31 | static void buf_new(Buffer *bufp) | ||
32 | { | ||
33 | bufp->data = NULL; | ||
34 | bufp->len = 0; | ||
35 | bufp->alloclen = 0; | ||
36 | } | ||
37 | |||
38 | static void buf_put(Buffer *bufp, const char *str, size_t len) | ||
39 | { | ||
40 | while (bufp->len + len + 1 > bufp->alloclen) { | ||
41 | char *newdata = realloc(bufp->data, bufp->alloclen + 1024); | ||
42 | if (!newdata) { | ||
43 | fprintf(stderr, "Out of memory!\n"); | ||
44 | exit(1); | ||
45 | } | ||
46 | bufp->data = newdata; | ||
47 | bufp->alloclen += 1024; | ||
48 | } | ||
49 | memmove(bufp->data + bufp->len, str, len); | ||
50 | bufp->len += len; | ||
51 | bufp->data[bufp->len] = '\0'; | ||
52 | } | ||
53 | |||
54 | static void buf_putc(Buffer *bufp, char c) | ||
55 | { | ||
56 | buf_put(bufp, &c, 1); | ||
57 | } | ||
58 | |||
59 | /* Read from the given stream until we see a complete OTR Key Exchange | ||
60 | * or OTR Data message. Return a newly-allocated pointer to a copy of | ||
61 | * this message, which the caller should free(). Returns NULL if no | ||
62 | * such message could be found. */ | ||
63 | char *readotr(FILE *stream) | ||
64 | { | ||
65 | int seen = 0; | ||
66 | const char header[] = "?OTR:"; /* There are no '?' chars other than | ||
67 | the leading one */ | ||
68 | int headerlen = strlen(header); | ||
69 | Buffer buf; | ||
70 | |||
71 | while(seen < headerlen) { | ||
72 | int c = fgetc(stream); | ||
73 | if (c == EOF) return NULL; | ||
74 | else if (c == header[seen]) seen++; | ||
75 | else if (c == header[0]) seen = 1; | ||
76 | else seen = 0; | ||
77 | } | ||
78 | |||
79 | buf_new(&buf); | ||
80 | buf_put(&buf, header, headerlen); | ||
81 | |||
82 | /* Look for the trailing '.' */ | ||
83 | while(1) { | ||
84 | int c = fgetc(stream); | ||
85 | if (c == EOF) break; | ||
86 | buf_putc(&buf, c); | ||
87 | if (c == '.') break; | ||
88 | } | ||
89 | |||
90 | return buf.data; | ||
91 | } | ||
diff --git a/linden/indra/libotr/libotr-3.2.0/toolkit/readotr.h b/linden/indra/libotr/libotr-3.2.0/toolkit/readotr.h new file mode 100755 index 0000000..75a7e2f --- /dev/null +++ b/linden/indra/libotr/libotr-3.2.0/toolkit/readotr.h | |||
@@ -0,0 +1,29 @@ | |||
1 | /* | ||
2 | * Off-the-Record Messaging Toolkit | ||
3 | * Copyright (C) 2004-2008 Ian Goldberg, Chris Alexander, Nikita Borisov | ||
4 | * <otr@cypherpunks.ca> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of version 2 of the GNU General Public License as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | #ifndef __READOTR_H__ | ||
21 | #define __READOTR_H__ | ||
22 | |||
23 | /* Read from the given stream until we see a complete OTR Key Exchange | ||
24 | * or OTR Data message. Return a newly-allocated pointer to a copy of | ||
25 | * this message, which the caller should free(). Returns NULL if no | ||
26 | * such message could be found. */ | ||
27 | char *readotr(FILE *stream); | ||
28 | |||
29 | #endif | ||
diff --git a/linden/indra/libotr/libotr-3.2.0/toolkit/sesskeys.c b/linden/indra/libotr/libotr-3.2.0/toolkit/sesskeys.c new file mode 100755 index 0000000..d823ebc --- /dev/null +++ b/linden/indra/libotr/libotr-3.2.0/toolkit/sesskeys.c | |||
@@ -0,0 +1,94 @@ | |||
1 | /* | ||
2 | * Off-the-Record Messaging Toolkit | ||
3 | * Copyright (C) 2004-2008 Ian Goldberg, Chris Alexander, Nikita Borisov | ||
4 | * <otr@cypherpunks.ca> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of version 2 of the GNU General Public License as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | /* system headers */ | ||
21 | #include <stdlib.h> | ||
22 | |||
23 | /* libgcrypt headers */ | ||
24 | #include <gcrypt.h> | ||
25 | |||
26 | static const char* DH1536_MODULUS_S = "0x" | ||
27 | "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" | ||
28 | "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" | ||
29 | "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" | ||
30 | "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" | ||
31 | "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" | ||
32 | "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" | ||
33 | "83655D23DCA3AD961C62F356208552BB9ED529077096966D" | ||
34 | "670C354E4ABC9804F1746C08CA237327FFFFFFFFFFFFFFFF"; | ||
35 | static const char *DH1536_GENERATOR_S = "0x02"; | ||
36 | |||
37 | /* Generate the session id and the two encryption keys from our private | ||
38 | * DH key and their public DH key. Also indicate in *high_endp if we | ||
39 | * are the "high" end of the key exchange (set to 1) or the "low" end | ||
40 | * (set to 0) */ | ||
41 | void sesskeys_gen(unsigned char sessionid[20], unsigned char sendenc[16], | ||
42 | unsigned char rcvenc[16], int *high_endp, gcry_mpi_t *our_yp, | ||
43 | gcry_mpi_t our_x, gcry_mpi_t their_y) | ||
44 | { | ||
45 | gcry_mpi_t modulus, generator, secretv; | ||
46 | unsigned char *secret; | ||
47 | size_t secretlen; | ||
48 | unsigned char hash[20]; | ||
49 | int is_high; | ||
50 | |||
51 | gcry_mpi_scan(&modulus, GCRYMPI_FMT_HEX, DH1536_MODULUS_S, 0, NULL); | ||
52 | gcry_mpi_scan(&generator, GCRYMPI_FMT_HEX, DH1536_GENERATOR_S, 0, NULL); | ||
53 | *our_yp = gcry_mpi_new(0); | ||
54 | gcry_mpi_powm(*our_yp, generator, our_x, modulus); | ||
55 | secretv = gcry_mpi_new(0); | ||
56 | gcry_mpi_powm(secretv, their_y, our_x, modulus); | ||
57 | gcry_mpi_release(generator); | ||
58 | gcry_mpi_release(modulus); | ||
59 | gcry_mpi_print(GCRYMPI_FMT_USG, NULL, 0, &secretlen, secretv); | ||
60 | secret = malloc(secretlen + 5); | ||
61 | |||
62 | secret[1] = (secretlen >> 24) & 0xff; | ||
63 | secret[2] = (secretlen >> 16) & 0xff; | ||
64 | secret[3] = (secretlen >> 8) & 0xff; | ||
65 | secret[4] = (secretlen) & 0xff; | ||
66 | gcry_mpi_print(GCRYMPI_FMT_USG, secret+5, secretlen, NULL, secretv); | ||
67 | gcry_mpi_release(secretv); | ||
68 | |||
69 | is_high = (gcry_mpi_cmp(*our_yp, their_y) > 0); | ||
70 | |||
71 | /* Calculate the session id */ | ||
72 | secret[0] = 0x00; | ||
73 | gcry_md_hash_buffer(GCRY_MD_SHA1, hash, secret, secretlen+5); | ||
74 | memmove(sessionid, hash, 20); | ||
75 | |||
76 | /* Calculate the sending enc key */ | ||
77 | secret[0] = is_high ? 0x01 : 0x02; | ||
78 | gcry_md_hash_buffer(GCRY_MD_SHA1, hash, secret, secretlen+5); | ||
79 | memmove(sendenc, hash, 16); | ||
80 | |||
81 | /* Calculate the receiving enc key */ | ||
82 | secret[0] = is_high ? 0x02 : 0x01; | ||
83 | gcry_md_hash_buffer(GCRY_MD_SHA1, hash, secret, secretlen+5); | ||
84 | memmove(rcvenc, hash, 16); | ||
85 | |||
86 | *high_endp = is_high; | ||
87 | free(secret); | ||
88 | } | ||
89 | |||
90 | /* Generate a MAC key from the corresponding encryption key */ | ||
91 | void sesskeys_make_mac(unsigned char mackey[20], unsigned char enckey[16]) | ||
92 | { | ||
93 | gcry_md_hash_buffer(GCRY_MD_SHA1, mackey, enckey, 16); | ||
94 | } | ||
diff --git a/linden/indra/libotr/libotr-3.2.0/toolkit/sesskeys.h b/linden/indra/libotr/libotr-3.2.0/toolkit/sesskeys.h new file mode 100755 index 0000000..7a98ac8 --- /dev/null +++ b/linden/indra/libotr/libotr-3.2.0/toolkit/sesskeys.h | |||
@@ -0,0 +1,34 @@ | |||
1 | /* | ||
2 | * Off-the-Record Messaging Toolkit | ||
3 | * Copyright (C) 2004-2008 Ian Goldberg, Chris Alexander, Nikita Borisov | ||
4 | * <otr@cypherpunks.ca> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of version 2 of the GNU General Public License as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | #ifndef __SESSKEYS_H__ | ||
21 | #define __SESSKEYS_H__ | ||
22 | |||
23 | /* Generate the session id and the two encryption keys from our private | ||
24 | * DH key and their public DH key. Also indicate in *high_endp if we | ||
25 | * are the "high" end of the key exchange (set to 1) or the "low" end | ||
26 | * (set to 0) */ | ||
27 | void sesskeys_gen(unsigned char sessionid[20], unsigned char sendenc[16], | ||
28 | unsigned char rcvenc[16], int *high_endp, gcry_mpi_t *our_yp, | ||
29 | gcry_mpi_t our_x, gcry_mpi_t their_y); | ||
30 | |||
31 | /* Generate a MAC key from the corresponding encryption key */ | ||
32 | void sesskeys_make_mac(unsigned char mackey[20], unsigned char enckey[16]); | ||
33 | |||
34 | #endif | ||
diff --git a/linden/indra/libotr/libotr-3.2.0/toolkit/sha1hmac.c b/linden/indra/libotr/libotr-3.2.0/toolkit/sha1hmac.c new file mode 100755 index 0000000..272a4fb --- /dev/null +++ b/linden/indra/libotr/libotr-3.2.0/toolkit/sha1hmac.c | |||
@@ -0,0 +1,61 @@ | |||
1 | /* | ||
2 | * Off-the-Record Messaging Toolkit | ||
3 | * Copyright (C) 2004-2008 Ian Goldberg, Chris Alexander, Nikita Borisov | ||
4 | * <otr@cypherpunks.ca> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of version 2 of the GNU General Public License as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | /* system headers */ | ||
21 | #include <stdio.h> | ||
22 | #include <stdlib.h> | ||
23 | |||
24 | /* libgcrypt headers */ | ||
25 | #include <gcrypt.h> | ||
26 | |||
27 | /* Implementation of SHA1-HMAC. We're rolling our own just to | ||
28 | * double-check that the calls libotr makes to libgcrypt are in fact | ||
29 | * doing the right thing. */ | ||
30 | void sha1hmac(unsigned char digest[20], unsigned char key[20], | ||
31 | unsigned char *data, size_t datalen) | ||
32 | { | ||
33 | unsigned char ipad[64], opad[64]; | ||
34 | size_t i; | ||
35 | gcry_md_hd_t sha1; | ||
36 | gcry_error_t err; | ||
37 | unsigned char hash[20]; | ||
38 | |||
39 | memset(ipad, 0, 64); | ||
40 | memset(opad, 0, 64); | ||
41 | memmove(ipad, key, 20); | ||
42 | memmove(opad, key, 20); | ||
43 | for(i=0;i<64;++i) { | ||
44 | ipad[i] ^= 0x36; | ||
45 | opad[i] ^= 0x5c; | ||
46 | } | ||
47 | |||
48 | err = gcry_md_open(&sha1, GCRY_MD_SHA1, 0); | ||
49 | if (err) { | ||
50 | fprintf(stderr, "Error: %s\n", gcry_strerror(err)); | ||
51 | exit(1); | ||
52 | } | ||
53 | gcry_md_write(sha1, ipad, 64); | ||
54 | gcry_md_write(sha1, data, datalen); | ||
55 | memmove(hash, gcry_md_read(sha1, 0), 20); | ||
56 | gcry_md_reset(sha1); | ||
57 | gcry_md_write(sha1, opad, 64); | ||
58 | gcry_md_write(sha1, hash, 20); | ||
59 | memmove(digest, gcry_md_read(sha1, 0), 20); | ||
60 | gcry_md_close(sha1); | ||
61 | } | ||
diff --git a/linden/indra/libotr/libotr-3.2.0/toolkit/sha1hmac.h b/linden/indra/libotr/libotr-3.2.0/toolkit/sha1hmac.h new file mode 100755 index 0000000..ad5159a --- /dev/null +++ b/linden/indra/libotr/libotr-3.2.0/toolkit/sha1hmac.h | |||
@@ -0,0 +1,29 @@ | |||
1 | /* | ||
2 | * Off-the-Record Messaging Toolkit | ||
3 | * Copyright (C) 2004-2008 Ian Goldberg, Chris Alexander, Nikita Borisov | ||
4 | * <otr@cypherpunks.ca> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of version 2 of the GNU General Public License as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | |||
20 | #ifndef __SHA1HMAC_H__ | ||
21 | #define __SHA1HMAC_H__ | ||
22 | |||
23 | /* Implementation of SHA1-HMAC. We're rolling our own just to | ||
24 | * double-check that the calls libotr makes to libgcrypt are in fact | ||
25 | * doing the right thing. */ | ||
26 | void sha1hmac(unsigned char digest[20], unsigned char key[20], | ||
27 | unsigned char *data, size_t datalen); | ||
28 | |||
29 | #endif | ||