Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Encryption DiffieHellman_key_exchlsl  

DiffieHellman_key_exchlsl

Diffie-Hellman_key_exch-lsl.lsl

Category: Encryption
By : John Hurliman
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for DiffieHellman_key_exchlsl
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. DiffieHellman_key_exchlsl_1.lsl
1
2
3 // Diffie-Hellman Key Exchange
4 // Proof of concept, v0.0.1
5 //
6 // This is initial proof of concept code for a Diffie-Hellman key exchange in
7 // LSL. It's intended for eventual use in securing an XML-RPC channel to the
8 // outside world, and is not a secure solution in game as Diffie-Hellman
9 // provides no authentication mechanism.
10 //
11 // USE: Drop this script in a two separate prims, click on one of them to
12 // initiate the exchange protocol. A new secret value will be generated for
13 // the initiator each time you click.
14 //
15 // NOTES: The llModPow() function limits our secret key (exponent) size to
16 // 0xFFFF (16 bits). No testing has been done with using negative exponents,
17 // that could potentially double the size of the secret key space. 16 bit
18 // encryption is trivial to crack, making this a limited use algorithm
19 // for specific cases, not a general purpose security layer. p and g were
20 // picked somewhat at random, and I was having problems using a larger prime
21 // number. It would be worthwhile to investigate the problem and find the exact
22 // limits of this algorithm. Also the open_channel value would not exist in an
23 // XML-RPC implementation, so that value is negligible. Better string parsing
24 // should be used to prevent bad data (like "INIT123ABC"), and a more compact
25 // data format should be used to save precious characters in XML-RPC
26 // transportation.
27 //
28 //(c)(cc-by) John Hurliman (jhurliman{at}wsu.edu | [url]http://www.jhurliman.org/[/url])
29 // [url]http://creativecommons.org/licenses/by/2.5/[/url]
30
31 integer x; // Secret exponent
32 integer p = 38183; // Public (palindromic) Sophie Germain prime
33 integer g = 53; // Public generator
34 integer open_channel = 14614510; // Open channel for key exchange example
35 float x_limit = 65535.0; // Limit for the random 16-bit integer x
36
37 default
38 {
40 {
41 // Generate an initial secret exponent
42 x = llFloor(llFrand(x_limit)) + 1;
43
44 // Start listening on the key exchange channel
45 llListen(open_channel, "", NULL_KEY, "");
46 llWhisper(0, "LSL Diffie-Hellman v0.0.1, secret is " + (string)x + ". Listening...");
47 }
48
49 touch_start(integer total_number)
50 {
51 // Generate a new secret exponent for the new session
52 x = llFloor(llFrand(x_limit)) + 1;
53 llWhisper(0, "New secret is " + (string)x);
54
55 integer ya = llModPow(g, x, p);
56
57 // Send computed ya to target
58 llSay(open_channel, "INIT" + (string)ya);
59 llWhisper(0, "Sent INIT" + (string)ya);
60 }
61
62 listen(integer channel, string name, key id, string message)
63 {
64 // Ignore our own messages
65 if(id != llGetKey())
66 {
67 if(llGetSubString(message, 0, 3) == "INIT")
68 {
69 llWhisper(0, "Got init message: " + message + " from " + (string)id);
70 integer ya = (integer)llDeleteSubString(message, 0, 3);
71 integer k = llModPow(ya, x, p);
72 llWhisper(0, "Computed key " + (string)k);
73
74 // Send our response
75 integer yb = llModPow(g, x, p);
76 llSay(open_channel, "RESP" + (string)yb);
77 llWhisper(0, "Sent RESP" + (string)yb);
78 }
79
80 else if(llGetSubString(message, 0, 3) == "RESP")
81 {
82 llWhisper(0, "Got response message: " + message + " from " + (string)id);
83 integer yb = (integer)llDeleteSubString(message, 0, 3);
84 integer k = llModPow(yb, x, p);
85 llWhisper(0, "Computed key " + (string)k);
86 }
87 }
88 }
89 } // end

Back to the Best Free Tools in Second Life and OpenSim.