aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/libotr/libotr-3.2.0/toolkit/otr_sesskeys.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_sesskeys.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 '')
-rwxr-xr-xlinden/indra/libotr/libotr-3.2.0/toolkit/otr_sesskeys.c92
1 files changed, 92 insertions, 0 deletions
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
28static 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
37int 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}