lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

i have to reduce the memory consumption of the function function. 
Are there *obvious* things you see in there ? As as possible, i will try to port this code to some other library, but in the meanwhile I really would like some suggestions by expert lua develpers.

it's ugly, I know.

Decrypt the data with the specified private key. 
If the decoded nexthop is "000000000000", the function
returns the plaintext message.
If not, the function returns the triplet data,ip_nexthop,port_nexthop. 
function onion_decrypt(key,data)
--write key to file
local privk_file = "/tmp/""sha1"):digest(math.random().."temp_file") --os.tmpname()
local out = assert(, "w"))
local priv_exp = rsa.initPrivExp(privk_file)
local priv_modulus = rsa.initModulus(privk_file)
local decrypted = ""
local number_parts = #data / RSA_LENGTH_HEX
for i= 1, number_parts do
part = string.sub(data, 1, RSA_LENGTH_HEX)
local dec_part = rsa.decrypt_hex(part, priv_exp, priv_modulus)
local F_pos = string.find(dec_part, "F")
decrypted = decrypted..string.sub(dec_part, F_pos+1)
data = "" RSA_LENGTH_HEX + 1)
local data = "" 1, #decrypted-12)
local nexthop_hex = string.sub(decrypted, #decrypted-11)
if nexthop_hex == LAST_HOP then
return rsa.hex2string(data)
local nexthop_ip, nexthop_port = hex2ip_port(nexthop_hex)
return data, nexthop_ip, nexthop_port

Thank you,