| |
| /pliant/util/crypto/cipher.pli |
| |
| 1 |
module "/pliant/language/unsafe.pli" | |
| 2 |
module "rc4.pli" | |
| 3 |
module "random.pli" | |
| 4 |
module "/pliant/language/type/misc/blob.pli" | |
| 5 |
| |
| 6 |
constant cipher_seed_bits 128 | |
| 7 |
constant cipher_rc4_laps 100 | |
| 8 |
| |
| 9 |
| |
| 10 |
function cipher clear password seed_bits laps -> ciphered | |
| 11 |
arg Str clear password ; arg Int seed_bits laps ; arg Str ciphered | |
| 12 |
if password="" | |
| 13 |
return clear | |
| 14 |
rc4_init (var RC4Ctx ctx) password laps | |
| 15 |
ciphered := (random_string seed_bits\8)+clear | |
| 16 |
rc4_cipher ctx ciphered:characters ciphered:characters ciphered:len | |
| 17 |
| |
| 18 |
function cipher clear password -> ciphered | |
| 19 |
arg Str clear password ciphered | |
| 20 |
ciphered := cipher clear password cipher_seed_bits cipher_rc4_laps | |
| 21 |
| |
| 22 |
function cipher clear password -> ciphered | |
| 23 |
arg Blob clear ; arg Str password ; arg Blob ciphered | |
| 24 |
addressof:ciphered map Str := cipher (addressof:clear map Str) password | |
| 25 |
| |
| 26 |
function uncipher ciphered password seed_bits laps -> clear | |
| 27 |
arg Str ciphered password ; arg Int seed_bits laps ; arg Str clear | |
| 28 |
if password="" | |
| 29 |
return ciphered | |
| 30 |
rc4_init (var RC4Ctx ctx) password laps | |
| 31 |
clear := ciphered | |
| 32 |
rc4_cipher ctx clear:characters clear:characters clear:len | |
| 33 |
clear := clear seed_bits\8 clear:len | |
| 34 |
| |
| 35 |
function uncipher ciphered password -> clear | |
| 36 |
arg Str ciphered password clear | |
| 37 |
clear := uncipher ciphered password cipher_seed_bits cipher_rc4_laps | |
| 38 |
| |
| 39 |
function uncipher ciphered password -> clear | |
| 40 |
arg Blob ciphered ; arg Str password ; arg Blob clear | |
| 41 |
addressof:clear map Str := uncipher (addressof:ciphered map Str) password | |
| 42 |
| |
| 43 |
export cipher uncipher | |
| |