diff options
| author | Charles.Forsyth <devnull@localhost> | 2009-03-30 08:58:09 +0000 |
|---|---|---|
| committer | Charles.Forsyth <devnull@localhost> | 2009-03-30 08:58:09 +0000 |
| commit | 9e85ae9b75acdbe245243784d8d5b1b4de1b24f9 (patch) | |
| tree | 5dfaf8c8881bbf352dab7338cc9fba000c24eb03 /appl/cmd/ssh/cipher3des.b | |
| parent | 77bf0d6355c02a5d5199dd37033066727cad375b (diff) | |
x20090330-0957
Diffstat (limited to 'appl/cmd/ssh/cipher3des.b')
| -rw-r--r-- | appl/cmd/ssh/cipher3des.b | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/appl/cmd/ssh/cipher3des.b b/appl/cmd/ssh/cipher3des.b new file mode 100644 index 00000000..36359fb4 --- /dev/null +++ b/appl/cmd/ssh/cipher3des.b @@ -0,0 +1,46 @@ +implement Cipher; + +include "sys.m"; + +include "keyring.m"; + kr: Keyring; + DESstate: import kr; + +include "sshio.m"; + +Cipherstate: adt +{ + enc: array of ref DESstate; + dec: array of ref DESstate; +}; + +cs: ref Cipherstate; + +id(): int +{ + return SSH_CIPHER_3DES; +} + +init(key: array of byte, nil: int) +{ + kr = load Keyring Keyring->PATH; + cs = ref Cipherstate(array[3] of ref DESstate, array[3] of ref DESstate); + for(i := 0; i < 3; i++){ + cs.enc[i] = kr->dessetup(key[i*8:], nil); + cs.dec[i] = kr->dessetup(key[i*8:], nil); + } +} + +encrypt(buf: array of byte, nbuf: int) +{ + kr->descbc(cs.enc[0], buf, nbuf, Keyring->Encrypt); + kr->descbc(cs.enc[1], buf, nbuf, Keyring->Decrypt); + kr->descbc(cs.enc[2], buf, nbuf, Keyring->Encrypt); +} + +decrypt(buf: array of byte, nbuf: int) +{ + kr->descbc(cs.dec[2], buf, nbuf, Keyring->Decrypt); + kr->descbc(cs.dec[1], buf, nbuf, Keyring->Encrypt); + kr->descbc(cs.dec[0], buf, nbuf, Keyring->Decrypt); +} |
