aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/libotr/libotr-3.2.0/toolkit/otr_remac.c
diff options
context:
space:
mode:
authorJay Threeth2011-04-04 11:48:26 -0700
committerJay Threeth2011-04-04 11:48:26 -0700
commit3c9cc506f741b980565ff5b3b001cd8b6ee36b12 (patch)
treecb862c57b3d5f74177cde3bd962a53fc377166f6 /linden/indra/libotr/libotr-3.2.0/toolkit/otr_remac.c
parentbuild fixes, might build on linux now (diff)
downloadmeta-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/otr_remac.c')
-rwxr-xr-xlinden/indra/libotr/libotr-3.2.0/toolkit/otr_remac.c127
1 files changed, 127 insertions, 0 deletions
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
31static 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
42int 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}