| 1 | // Copyright (c) 2019-2024 Alexander Medvednikov. All rights reserved. |
| 2 | // Use of this source code is governed by an MIT license |
| 3 | // that can be found in the LICENSE file. |
| 4 | import crypto.cipher |
| 5 | import crypto.rc4 |
| 6 | |
| 7 | struct StreamCipher { |
| 8 | cipher cipher.Stream |
| 9 | } |
| 10 | |
| 11 | fn test_cfb_stream_cipher() ! { |
| 12 | key := 'tthisisourrc4key'.bytes() |
| 13 | c := rc4.new_cipher(key)! |
| 14 | |
| 15 | s := StreamCipher{ |
| 16 | cipher: c |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | fn test_crypto_rc4() { |
| 21 | key := 'tthisisourrc4key'.bytes() |
| 22 | |
| 23 | mut c := rc4.new_cipher(key) or { |
| 24 | println(err) |
| 25 | return |
| 26 | } |
| 27 | |
| 28 | mut src := 'toencrypt'.bytes() |
| 29 | |
| 30 | // src & dst same, encrypt in place |
| 31 | c.xor_key_stream(mut src, src) // encrypt data |
| 32 | |
| 33 | c.reset() |
| 34 | |
| 35 | assert src.hex() == '189a39a91aea8afa65' |
| 36 | } |
| 37 | |