Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rc4 stream cipher #354

Merged
merged 9 commits into from
Aug 19, 2019
Merged

Rc4 stream cipher #354

merged 9 commits into from
Aug 19, 2019

Conversation

jjnicola
Copy link
Member

Add functions to open a cipher handler, the function to encrypt stream data using the cipher handle,
and the function to close a handler.
Currently, encrypt_stream_data only supports GCRY_CIPHER_ARCFOUR algorithm.

$ cat rc4.nasl
include("dump.inc");

display("\n\nComplet 1");
iv = raw_string(0x01, 0x00);
key = raw_string(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1);
data = raw_string(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0xbb, 0xaa);

enc = rc4_encrypt(key: key, data: data);
display(hexstr(enc));
display(hexdump(ddata: enc));

display("\n\nComplet 2");
iv = raw_string(0x01, 0x00);
key = raw_string(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1);
data = raw_string(0x23, 0x01, 0x34, 0x03, 0x45, 0x32, 0xac, 0xac, 0x08, 0x09, 0x0a, 0x0b, 0x3c, 0x0d, 0x0e, 0x0f, 0xba, 0x1a);

enc = rc4_encrypt(key: key, data: data);
display(hexstr(enc));
display(hexdump(ddata: enc));

display("\n\nPart 1.1");
key = raw_string(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1);
data = raw_string(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
hd = open_rc4_cipher(key: key);
display("nasl hd: ", hd);
enc =rc4_encrypt(data: data, hd: hd);
display(hexstr(enc));
display(hexdump(ddata: enc));

display("\n\nPart 2.1");
key = raw_string(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1);
data = raw_string(0x23, 0x01, 0x34, 0x03, 0x45, 0x32, 0xac, 0xac, 0x08, 0x09, 0x0a, 0x0b, 0x3c, 0x0d);
hd1 = open_rc4_cipher(key: key);
display("nasl hd: ", hd1);
enc = rc4_encrypt(data: data, hd: hd1);
display(hexstr(enc));
display(hexdump(ddata: enc));

display("\n\nPart 1.2");
data = raw_string(0xbb, 0xaa);
enc = rc4_encrypt(data: data, hd: hd);
display(hexstr(enc));
display(hexdump(ddata: enc));

display("\n\nPart 2.2");
data = raw_string(0x0e, 0x0f, 0xba, 0x1a);
enc = rc4_encrypt(data: data, hd: hd1);
display(hexstr(enc));
display(hexdump(ddata: enc));

close_stream_cipher(hd: hd1);
close_stream_cipher(hd: hd);`
```

mattmundell
mattmundell previously approved these changes Aug 19, 2019
nasl/nasl_crypto2.c Show resolved Hide resolved
nasl/nasl_crypto2.c Outdated Show resolved Hide resolved
Add function to remove the item, verify, and find it in the table.
Also, the function to encrypt stream data using the cipher handle,
and the function to close a handler.
Currently,encrypt_stream_data only supports GCRY_CIPHER_ARCFOUR algorithm.
This function was modify to support stream data encrytion.
If an hd param exist in the lexix context, it will use this handler
to encrypt the data as part of a stream data.
This changes does not affect the old use of the function (it keep compatibility).
@mattmundell mattmundell merged commit b89cd0f into greenbone:master Aug 19, 2019
@jjnicola jjnicola deleted the rc4-stream-cipher branch August 19, 2019 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants