|
|
|
|
|
#define NAME "nisse" |
|
int main(int argc, array(string) argv) |
{ |
object rsa = keys.pub_to_rsa(Stdio.read_file(NAME + ".pub")); |
|
|
|
function r = Crypto.randomness.reasonably_random()->read; |
|
|
|
string iv = r(8); |
|
|
string session_key = r(16); |
|
|
object cipher = Crypto.crypto(Crypto.idea_cbc() |
->set_encrypt_key(session_key) |
->set_iv(iv)); |
|
|
|
string data = Stdio.stdin->read(0x7fffffff); |
|
|
if (!data) |
{ |
werror("Read from stdin failed.\n"); |
return 1; |
} |
|
string gibberish = cipher->crypt(data) + cipher->pad(); |
|
|
string encrypted_key = rsa->encrypt(session_key); |
|
|
string data = sprintf("%s%s%s%s", iv, |
iv ^ sprintf("%4c%4c", |
strlen(encrypted_key), |
strlen(gibberish)), |
encrypted_key, |
gibberish); |
|
|
|
|
|
|
|
|
if (strlen(data) != Stdio.stdout->write(data)) |
{ |
werror("Write to stdout failed.\n"); |
return 1; |
} |
|
return 0; |
} |
|
|