1
# ---------------------------------------------------------------------------
3
# - afnix:sec module test unit -
4
# ---------------------------------------------------------------------------
5
# - This program is free software; you can redistribute it and/or modify -
6
# - it provided that this copyright notice is kept intact. -
8
# - This program is distributed in the hope that it will be useful, but -
9
# - without any warranty; without even the implied warranty of -
10
# - merchantability or fitness for a particular purpose. In no event shall -
11
# - the copyright holder be liable for any direct, indirect, incidental or -
12
# - special damages arising in any way out of the use of this software. -
13
# ---------------------------------------------------------------------------
14
# - copyright (c) 1999-2011 amaury darsch -
15
# ---------------------------------------------------------------------------
17
# @info rc4 serial cipher test unit
18
# @author amaury darsch
21
interp:library "afnix-sec"
23
# this procedure test the rc4 cipher
24
const test-rc4-cipher (kbuf ivec ovec) {
26
const key (afnix:sec:Key kbuf)
27
# create the cipher and check
28
const rc4 (afnix:sec:Rc4 key)
29
assert "RC4" (rc4:get-name)
30
assert true (afnix:sec:rc4-p rc4)
32
trans ib (Buffer ivec)
35
trans blen (rc4:stream ob ib)
36
trans vb (Buffer ovec)
37
# verify the output buffer
38
loop (trans i 0) (< i blen) (i:++) {
39
assert (vb:get i) (ob:get i)
41
# reset in decode mode
42
trans vb (Buffer ivec)
45
trans blen (rc4:stream ib ob)
46
loop (trans i 0) (< i blen) (i:++) {
47
assert (vb:get i) (ib:get i)
52
trans kbuf "0123456789ABCDEF"
54
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
57
0x74 0x94 0xc2 0xe7 0x10 0x4b 0x08 0x79
59
test-rc4-cipher kbuf ivec ovec
62
trans kbuf "618A63D2FB"
64
0xdc 0xee 0x4c 0xf9 0x2c
67
0xf1 0x38 0x29 0xc9 0xde
69
test-rc4-cipher kbuf ivec ovec