rfuzz 0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +55 -0
- data/LICENSE +55 -0
- data/README +252 -0
- data/Rakefile +48 -0
- data/doc/rdoc/classes/RFuzz.html +146 -0
- data/doc/rdoc/classes/RFuzz/HttpClient.html +481 -0
- data/doc/rdoc/classes/RFuzz/HttpClient.src/M000010.html +24 -0
- data/doc/rdoc/classes/RFuzz/HttpClient.src/M000011.html +34 -0
- data/doc/rdoc/classes/RFuzz/HttpClient.src/M000012.html +49 -0
- data/doc/rdoc/classes/RFuzz/HttpClient.src/M000013.html +49 -0
- data/doc/rdoc/classes/RFuzz/HttpClient.src/M000014.html +57 -0
- data/doc/rdoc/classes/RFuzz/HttpClient.src/M000015.html +37 -0
- data/doc/rdoc/classes/RFuzz/HttpClient.src/M000016.html +26 -0
- data/doc/rdoc/classes/RFuzz/HttpClient.src/M000017.html +34 -0
- data/doc/rdoc/classes/RFuzz/HttpClient.src/M000018.html +18 -0
- data/doc/rdoc/classes/RFuzz/HttpClient.src/M000019.html +26 -0
- data/doc/rdoc/classes/RFuzz/HttpEncoding.html +294 -0
- data/doc/rdoc/classes/RFuzz/HttpEncoding.src/M000001.html +26 -0
- data/doc/rdoc/classes/RFuzz/HttpEncoding.src/M000002.html +18 -0
- data/doc/rdoc/classes/RFuzz/HttpEncoding.src/M000003.html +26 -0
- data/doc/rdoc/classes/RFuzz/HttpEncoding.src/M000004.html +18 -0
- data/doc/rdoc/classes/RFuzz/HttpEncoding.src/M000005.html +32 -0
- data/doc/rdoc/classes/RFuzz/HttpEncoding.src/M000006.html +18 -0
- data/doc/rdoc/classes/RFuzz/HttpEncoding.src/M000007.html +20 -0
- data/doc/rdoc/classes/RFuzz/HttpEncoding.src/M000008.html +20 -0
- data/doc/rdoc/classes/RFuzz/HttpEncoding.src/M000009.html +32 -0
- data/doc/rdoc/classes/RFuzz/HttpResponse.html +180 -0
- data/doc/rdoc/classes/RFuzz/Notifier.html +252 -0
- data/doc/rdoc/classes/RFuzz/Notifier.src/M000044.html +17 -0
- data/doc/rdoc/classes/RFuzz/Notifier.src/M000045.html +17 -0
- data/doc/rdoc/classes/RFuzz/Notifier.src/M000046.html +17 -0
- data/doc/rdoc/classes/RFuzz/Notifier.src/M000047.html +17 -0
- data/doc/rdoc/classes/RFuzz/Notifier.src/M000048.html +17 -0
- data/doc/rdoc/classes/RFuzz/Notifier.src/M000049.html +17 -0
- data/doc/rdoc/classes/RFuzz/RandomGenerator.html +362 -0
- data/doc/rdoc/classes/RFuzz/RandomGenerator.src/M000032.html +21 -0
- data/doc/rdoc/classes/RFuzz/RandomGenerator.src/M000033.html +23 -0
- data/doc/rdoc/classes/RFuzz/RandomGenerator.src/M000036.html +22 -0
- data/doc/rdoc/classes/RFuzz/RandomGenerator.src/M000037.html +20 -0
- data/doc/rdoc/classes/RFuzz/RandomGenerator.src/M000038.html +22 -0
- data/doc/rdoc/classes/RFuzz/RandomGenerator.src/M000039.html +20 -0
- data/doc/rdoc/classes/RFuzz/RandomGenerator.src/M000040.html +18 -0
- data/doc/rdoc/classes/RFuzz/RandomGenerator.src/M000041.html +18 -0
- data/doc/rdoc/classes/RFuzz/RandomGenerator.src/M000042.html +22 -0
- data/doc/rdoc/classes/RFuzz/RandomGenerator.src/M000043.html +18 -0
- data/doc/rdoc/classes/RFuzz/Sampler.html +383 -0
- data/doc/rdoc/classes/RFuzz/Sampler.src/M000056.html +19 -0
- data/doc/rdoc/classes/RFuzz/Sampler.src/M000057.html +23 -0
- data/doc/rdoc/classes/RFuzz/Sampler.src/M000058.html +26 -0
- data/doc/rdoc/classes/RFuzz/Sampler.src/M000059.html +18 -0
- data/doc/rdoc/classes/RFuzz/Sampler.src/M000060.html +18 -0
- data/doc/rdoc/classes/RFuzz/Sampler.src/M000061.html +18 -0
- data/doc/rdoc/classes/RFuzz/Sampler.src/M000062.html +18 -0
- data/doc/rdoc/classes/RFuzz/Sampler.src/M000063.html +19 -0
- data/doc/rdoc/classes/RFuzz/Sampler.src/M000064.html +18 -0
- data/doc/rdoc/classes/RFuzz/Sampler.src/M000065.html +23 -0
- data/doc/rdoc/classes/RFuzz/Sampler.src/M000066.html +18 -0
- data/doc/rdoc/classes/RFuzz/Sampler.src/M000067.html +20 -0
- data/doc/rdoc/classes/RFuzz/Session.html +415 -0
- data/doc/rdoc/classes/RFuzz/Session.src/M000020.html +31 -0
- data/doc/rdoc/classes/RFuzz/Session.src/M000021.html +18 -0
- data/doc/rdoc/classes/RFuzz/Session.src/M000022.html +18 -0
- data/doc/rdoc/classes/RFuzz/Session.src/M000023.html +34 -0
- data/doc/rdoc/classes/RFuzz/Session.src/M000024.html +19 -0
- data/doc/rdoc/classes/RFuzz/Session.src/M000025.html +19 -0
- data/doc/rdoc/classes/RFuzz/Session.src/M000026.html +26 -0
- data/doc/rdoc/classes/RFuzz/Session.src/M000027.html +29 -0
- data/doc/rdoc/classes/RFuzz/Session.src/M000028.html +19 -0
- data/doc/rdoc/classes/RFuzz/Session.src/M000029.html +18 -0
- data/doc/rdoc/classes/RFuzz/Session.src/M000030.html +18 -0
- data/doc/rdoc/classes/RFuzz/Session.src/M000031.html +23 -0
- data/doc/rdoc/classes/RFuzz/StatsTracker.html +242 -0
- data/doc/rdoc/classes/RFuzz/StatsTracker.src/M000050.html +19 -0
- data/doc/rdoc/classes/RFuzz/StatsTracker.src/M000051.html +19 -0
- data/doc/rdoc/classes/RFuzz/StatsTracker.src/M000052.html +18 -0
- data/doc/rdoc/classes/RFuzz/StatsTracker.src/M000053.html +18 -0
- data/doc/rdoc/classes/RFuzz/StatsTracker.src/M000054.html +28 -0
- data/doc/rdoc/classes/RFuzz/StatsTracker.src/M000055.html +18 -0
- data/doc/rdoc/created.rid +1 -0
- data/doc/rdoc/files/COPYING.html +168 -0
- data/doc/rdoc/files/LICENSE.html +168 -0
- data/doc/rdoc/files/README.html +473 -0
- data/doc/rdoc/files/lib/rfuzz/client_rb.html +111 -0
- data/doc/rdoc/files/lib/rfuzz/random_rb.html +116 -0
- data/doc/rdoc/files/lib/rfuzz/rfuzz_rb.html +109 -0
- data/doc/rdoc/files/lib/rfuzz/session_rb.html +111 -0
- data/doc/rdoc/files/lib/rfuzz/stats_rb.html +113 -0
- data/doc/rdoc/fr_class_index.html +35 -0
- data/doc/rdoc/fr_file_index.html +34 -0
- data/doc/rdoc/fr_method_index.html +93 -0
- data/doc/rdoc/index.html +24 -0
- data/doc/rdoc/rdoc-style.css +208 -0
- data/examples/amazon_headers.rb +38 -0
- data/examples/hpricot_pudding.rb +22 -0
- data/examples/kill_routes.rb +26 -0
- data/examples/mongrel_test_suite/lib/gen.rb +24 -0
- data/examples/mongrel_test_suite/test/camping/static_files.rb +9 -0
- data/examples/mongrel_test_suite/test/camping/upload_file.rb +9 -0
- data/examples/mongrel_test_suite/test/camping/upload_progress.rb +9 -0
- data/examples/mongrel_test_suite/test/http/base_protocol.rb +23 -0
- data/examples/mongrel_test_suite/test/nitro/upload_file.rb +9 -0
- data/examples/mongrel_test_suite/test/nitro/upload_progress.rb +9 -0
- data/examples/mongrel_test_suite/test/rails/static_files.rb +9 -0
- data/examples/mongrel_test_suite/test/rails/upload_file.rb +9 -0
- data/examples/mongrel_test_suite/test/rails/upload_progress.rb +9 -0
- data/examples/perftest.rb +30 -0
- data/ext/fuzzrnd/ext_help.h +14 -0
- data/ext/fuzzrnd/extconf.rb +6 -0
- data/ext/fuzzrnd/fuzzrnd.c +149 -0
- data/ext/http11_client/ext_help.h +14 -0
- data/ext/http11_client/extconf.rb +6 -0
- data/ext/http11_client/http11_client.c +288 -0
- data/ext/http11_client/http11_parser.c +629 -0
- data/ext/http11_client/http11_parser.h +46 -0
- data/ext/http11_client/http11_parser.rl +169 -0
- data/lib/rfuzz/client.rb +498 -0
- data/lib/rfuzz/random.rb +110 -0
- data/lib/rfuzz/rfuzz.rb +12 -0
- data/lib/rfuzz/session.rb +154 -0
- data/lib/rfuzz/stats.rb +159 -0
- data/resources/defaults.yaml +2 -0
- data/resources/words.txt +3310 -0
- data/test/coverage/index.html +388 -0
- data/test/coverage/lib-rfuzz-client_rb.html +1127 -0
- data/test/coverage/lib-rfuzz-random_rb.html +739 -0
- data/test/coverage/lib-rfuzz-session_rb.html +783 -0
- data/test/coverage/lib-rfuzz-stats_rb.html +788 -0
- data/test/server.rb +101 -0
- data/test/test_client.rb +164 -0
- data/test/test_fuzzrnd.rb +31 -0
- data/test/test_httpparser.rb +48 -0
- data/test/test_random.rb +75 -0
- data/test/test_session.rb +33 -0
- data/test/test_stats.rb +45 -0
- data/tools/rakehelp.rb +119 -0
- metadata +201 -0
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rfuzz/session'
|
3
|
+
require 'hpricot'
|
4
|
+
|
5
|
+
include RFuzz
|
6
|
+
agent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.4) Gecko/20060608 Ubuntu/dapper-security Firefox/1.5.0.4"
|
7
|
+
|
8
|
+
amazon = HttpClient.new("www.amazon.com", 80, :head => {"User-Agent" => agent}, :redirect => 10)
|
9
|
+
|
10
|
+
r = amazon.get("/")
|
11
|
+
|
12
|
+
puts "## AMAZON'S WACKY HEADERS:"
|
13
|
+
puts r.inspect
|
14
|
+
|
15
|
+
puts "\n\n## AMAZON'S LAME EASTER EGG:"
|
16
|
+
puts r.http_body.split("\n").last
|
17
|
+
|
18
|
+
a9 = {}
|
19
|
+
doc = Hpricot(r.http_body)
|
20
|
+
(doc/:form).collect {|f|
|
21
|
+
if /a9.amazon.com/ === f.attributes["action"]
|
22
|
+
a9["action"] = f.attributes["action"]
|
23
|
+
a9["method"] = f.attributes["method"]
|
24
|
+
(f/:input).each {|i| a9[i.attributes["name"]] = i.attributes }
|
25
|
+
end
|
26
|
+
}
|
27
|
+
|
28
|
+
puts "A9 FORM: #{a9.inspect}"
|
29
|
+
http://pastie.caboo.se/4810
|
30
|
+
# do a search
|
31
|
+
_, host, uri = a9["action"].split(/http:\/\/([a-z0-9\.]*)/)
|
32
|
+
|
33
|
+
a9client = HttpClient.new(host, 80, :head => {"User-Agent" => agent}, :redirect => 10)
|
34
|
+
r = a9client.get(uri, :query => {"q" => "test"})
|
35
|
+
|
36
|
+
puts "\n\n## RESULTS"
|
37
|
+
puts r.http_body
|
38
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'hpricot'
|
3
|
+
require 'rfuzz/session'
|
4
|
+
include RFuzz
|
5
|
+
|
6
|
+
agent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.4) Gecko/20060608 Ubuntu/dapper-security Firefox/1.5.0.4"
|
7
|
+
|
8
|
+
google = HttpClient.new("www.google.com", 80)
|
9
|
+
r = google.get("/search", :head => {"User-Agent" => agent}, :query => {
|
10
|
+
"q" => ARGV[0], "hl" => "en", "btnG" => "Google Search"})
|
11
|
+
|
12
|
+
if r.http_status != "200"
|
13
|
+
puts "Wrong Status: #{r.http_status}, did you forget to search for something?"
|
14
|
+
else
|
15
|
+
doc = Hpricot(r.http_body)
|
16
|
+
(doc/:a).each do |link|
|
17
|
+
if link.attributes["class"] == "l"
|
18
|
+
puts link.attributes["href"]
|
19
|
+
puts " -- " + link.children.join
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# An example of handing tons of nasty URLs to Rails to see what it does.
|
2
|
+
|
3
|
+
require 'rfuzz/session'
|
4
|
+
|
5
|
+
include RFuzz
|
6
|
+
|
7
|
+
s = Session.new :host => "localhost", :port => 3000
|
8
|
+
s.run 10, :save_as => ["runs.csv","counts.csv"] do |c,r|
|
9
|
+
len = r.num(90) + 1
|
10
|
+
s.count :len, len
|
11
|
+
uris = r.uris(ARGV[0].to_i,len)
|
12
|
+
|
13
|
+
uris.each do |u|
|
14
|
+
s.count_errors(:legal) do
|
15
|
+
# first sample for legal uris
|
16
|
+
resp = c.get(u)
|
17
|
+
s.count resp.http_status
|
18
|
+
end
|
19
|
+
|
20
|
+
# next sample for illegal uris
|
21
|
+
s.count_errors(:illegal) do
|
22
|
+
resp = c.get(u * 512)
|
23
|
+
s.count resp.http_status
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
def sub_rant(name)
|
3
|
+
return <<-END
|
4
|
+
desc "Behavior for #{name}"
|
5
|
+
task :all do
|
6
|
+
sys "spec", sys["*.rb"]
|
7
|
+
end
|
8
|
+
END
|
9
|
+
end
|
10
|
+
|
11
|
+
def spec_file(context)
|
12
|
+
return <<-END
|
13
|
+
require 'rfuzz/session'
|
14
|
+
|
15
|
+
context "#{context}" do
|
16
|
+
setup do
|
17
|
+
end
|
18
|
+
|
19
|
+
specify "#{context} spec" do
|
20
|
+
end
|
21
|
+
end
|
22
|
+
END
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rfuzz/session'
|
2
|
+
|
3
|
+
context "Base HTTP Protocol" do
|
4
|
+
setup do
|
5
|
+
@sess = RFuzz::Session.new :host => "localhost", :port => 3000
|
6
|
+
end
|
7
|
+
|
8
|
+
specify "Blocks Long URIs" do
|
9
|
+
@sess.run(10) do |c,r|
|
10
|
+
len = r.num(90) + 1
|
11
|
+
uris = r.uris(50,len)
|
12
|
+
|
13
|
+
uris.each do |u|
|
14
|
+
# next sample for illegal uris
|
15
|
+
@sess.count_errors(:illegal) do
|
16
|
+
resp = c.get(u * 512)
|
17
|
+
@sess.count resp.http_status
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Simple script that hits a host port and URI with a bunch of connections
|
2
|
+
# and measures the timings.
|
3
|
+
|
4
|
+
require 'rfuzz/client'
|
5
|
+
require 'rfuzz/stats'
|
6
|
+
include RFuzz
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
if ARGV.length != 4
|
11
|
+
STDERR.puts "usage: ruby perftest.rb host port uri count"
|
12
|
+
exit 1
|
13
|
+
end
|
14
|
+
|
15
|
+
host, port, uri, count = ARGV[0], ARGV[1], ARGV[2], ARGV[3].to_i
|
16
|
+
|
17
|
+
codes = {}
|
18
|
+
cl = HttpClient.new(host, port, :notifier => StatsTracker.new)
|
19
|
+
count.times do
|
20
|
+
begin
|
21
|
+
resp = cl.get(uri)
|
22
|
+
code = resp.http_status.to_i
|
23
|
+
codes[code] ||= 0
|
24
|
+
codes[code] += 1
|
25
|
+
rescue Object
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
puts cl.notifier.to_s
|
30
|
+
puts "Status Codes: #{codes.inspect}"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#ifndef ext_help_h
|
2
|
+
#define ext_help_h
|
3
|
+
|
4
|
+
#define RAISE_NOT_NULL(T) if(T == NULL) rb_raise(rb_eArgError, "NULL found for " # T " when shouldn't be.");
|
5
|
+
#define DATA_GET(from,type,name) Data_Get_Struct(from,type,name); RAISE_NOT_NULL(name);
|
6
|
+
#define REQUIRE_TYPE(V, T) if(TYPE(V) != T) rb_raise(rb_eTypeError, "Wrong argument type for " # V " required " # T);
|
7
|
+
|
8
|
+
#ifdef DEBUG
|
9
|
+
#define TRACE() fprintf(stderr, "> %s:%d:%s\n", __FILE__, __LINE__, __FUNCTION__)
|
10
|
+
#else
|
11
|
+
#define TRACE()
|
12
|
+
#endif
|
13
|
+
|
14
|
+
#endif
|
@@ -0,0 +1,149 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2005 Zed A. Shaw
|
3
|
+
* You can redistribute it and/or modify it under the same terms as Ruby.
|
4
|
+
*/
|
5
|
+
|
6
|
+
#include "ruby.h"
|
7
|
+
#include "ext_help.h"
|
8
|
+
#include <assert.h>
|
9
|
+
#include <string.h>
|
10
|
+
#include <ctype.h>
|
11
|
+
#include <inttypes.h>
|
12
|
+
|
13
|
+
static VALUE mRFuzz;
|
14
|
+
static VALUE cFuzzRnd;
|
15
|
+
static VALUE eFuzzRndError;
|
16
|
+
|
17
|
+
|
18
|
+
/**
|
19
|
+
* We use one source of ArcFour data for now. This means that things aren't
|
20
|
+
* thread safe yet, but since the ArcFour is just for the current weaker implementation
|
21
|
+
* I'm not investing any more time making it thread safe.
|
22
|
+
*/
|
23
|
+
static struct
|
24
|
+
{
|
25
|
+
unsigned char i,j; /* ArcFour variables */
|
26
|
+
unsigned char sbox[256]; /* ArcFour s-box */
|
27
|
+
} ArcFour;
|
28
|
+
|
29
|
+
|
30
|
+
/**
|
31
|
+
* call-seq:
|
32
|
+
* rnd.seed -> rnd
|
33
|
+
*
|
34
|
+
* Returns a String of random bytes of length that you can use
|
35
|
+
* for generating randomness. It uses the ArcFour cipher to
|
36
|
+
* make the randomness, so the same seeds produce the same
|
37
|
+
* random bits, and the randomness is reasonably high quality.
|
38
|
+
*
|
39
|
+
* Don't use this for secure random generation. It probably would
|
40
|
+
* work if you seeded from a /dev/random that worked, but don't
|
41
|
+
* blame me if you get hacked.
|
42
|
+
*
|
43
|
+
* The main motiviation for using ArcFour without automated reseed
|
44
|
+
* is to produce lots of random bytes quickly, make them high enough
|
45
|
+
* quality for good random tests, and to make sure that we can replay
|
46
|
+
* possible sequences if there's a sequence that we want to test.
|
47
|
+
*/
|
48
|
+
VALUE FuzzRnd_data(VALUE self, VALUE length)
|
49
|
+
{
|
50
|
+
|
51
|
+
uint32_t n;
|
52
|
+
unsigned char a,b;
|
53
|
+
size_t len = 0;
|
54
|
+
VALUE data;
|
55
|
+
char *p = NULL;
|
56
|
+
|
57
|
+
REQUIRE_TYPE(length, T_FIXNUM);
|
58
|
+
|
59
|
+
len = FIX2INT(length);
|
60
|
+
data = rb_str_buf_new(len);
|
61
|
+
p = RSTRING(data)->ptr;
|
62
|
+
rb_str_resize(data, len);
|
63
|
+
|
64
|
+
for (n=0;n<len;n++) /* run the ArcFour algorithm as long as it needs */
|
65
|
+
{
|
66
|
+
ArcFour.i++;
|
67
|
+
a = ArcFour.sbox[ArcFour.i];
|
68
|
+
ArcFour.j = (unsigned char) (ArcFour.j + a); /* avoid MSVC picky compiler warning */
|
69
|
+
b = ArcFour.sbox[ArcFour.j];
|
70
|
+
ArcFour.sbox[ArcFour.i] = b;
|
71
|
+
ArcFour.sbox[ArcFour.j] = a;
|
72
|
+
p[n] = ArcFour.sbox[(a+b) & 0xFF];
|
73
|
+
}
|
74
|
+
|
75
|
+
return data;
|
76
|
+
}
|
77
|
+
|
78
|
+
|
79
|
+
/**
|
80
|
+
* call-seq:
|
81
|
+
* rnd.seed -> rnd
|
82
|
+
*
|
83
|
+
* Seeds the global ArcFour random generator with the given seed. The same seeds
|
84
|
+
* should produce the exact same stream of random data so that you can get
|
85
|
+
* large amounts of randomness but replay possible interactions using just
|
86
|
+
* an initial key.
|
87
|
+
*
|
88
|
+
* This function also doubles as the FuzzRnd.initialize method since they
|
89
|
+
* do nearly the same thing.
|
90
|
+
*
|
91
|
+
* Taken from http://www.mozilla.org/projects/security/pki/nss/draft-kaukonen-cipher-arcfour-03.txt
|
92
|
+
* sample code, but compared with the output of the ArcFour implementation in
|
93
|
+
* the Phelix test code to make sure it is the same initialization. The main
|
94
|
+
* difference is that this init takes an arbitrary keysize while the original
|
95
|
+
* Phelix ArcFour only took a 32bit key.
|
96
|
+
*
|
97
|
+
* Returns itself so you can seed and then get data easily.
|
98
|
+
*/
|
99
|
+
VALUE FuzzRnd_seed(VALUE self, VALUE data) {
|
100
|
+
|
101
|
+
unsigned int t, u;
|
102
|
+
unsigned int keyindex;
|
103
|
+
unsigned int stateindex;
|
104
|
+
unsigned char *state;
|
105
|
+
unsigned int counter;
|
106
|
+
char *key = NULL;
|
107
|
+
size_t key_len = 0;
|
108
|
+
|
109
|
+
REQUIRE_TYPE(data, T_STRING);
|
110
|
+
|
111
|
+
key = RSTRING(data)->ptr;
|
112
|
+
key_len = RSTRING(data)->len;
|
113
|
+
|
114
|
+
state = ArcFour.sbox;
|
115
|
+
ArcFour.i = 0;
|
116
|
+
ArcFour.j = 0;
|
117
|
+
|
118
|
+
for (counter = 0; counter < 256; counter++)
|
119
|
+
state[counter] = counter;
|
120
|
+
|
121
|
+
keyindex = 0;
|
122
|
+
stateindex = 0;
|
123
|
+
for (counter = 0; counter < 256; counter++)
|
124
|
+
{
|
125
|
+
t = state[counter];
|
126
|
+
stateindex = (stateindex + key[keyindex] + t) & 0xff;
|
127
|
+
u = state[stateindex];
|
128
|
+
state[stateindex] = t;
|
129
|
+
state[counter] = u;
|
130
|
+
if (++keyindex >= key_len)
|
131
|
+
keyindex = 0;
|
132
|
+
}
|
133
|
+
|
134
|
+
return self;
|
135
|
+
}
|
136
|
+
|
137
|
+
void Init_fuzzrnd()
|
138
|
+
{
|
139
|
+
mRFuzz = rb_define_module("RFuzz");
|
140
|
+
|
141
|
+
eFuzzRndError = rb_define_class_under(mRFuzz, "FuzzRndError", rb_eIOError);
|
142
|
+
|
143
|
+
cFuzzRnd = rb_define_class_under(mRFuzz, "FuzzRnd", rb_cObject);
|
144
|
+
rb_define_method(cFuzzRnd, "initialize", FuzzRnd_seed, 1);
|
145
|
+
rb_define_method(cFuzzRnd, "seed", FuzzRnd_seed,1);
|
146
|
+
rb_define_method(cFuzzRnd, "data", FuzzRnd_data,1);
|
147
|
+
}
|
148
|
+
|
149
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#ifndef ext_help_h
|
2
|
+
#define ext_help_h
|
3
|
+
|
4
|
+
#define RAISE_NOT_NULL(T) if(T == NULL) rb_raise(rb_eArgError, "NULL found for " # T " when shouldn't be.");
|
5
|
+
#define DATA_GET(from,type,name) Data_Get_Struct(from,type,name); RAISE_NOT_NULL(name);
|
6
|
+
#define REQUIRE_TYPE(V, T) if(TYPE(V) != T) rb_raise(rb_eTypeError, "Wrong argument type for " # V " required " # T);
|
7
|
+
|
8
|
+
#ifdef DEBUG
|
9
|
+
#define TRACE() fprintf(stderr, "> %s:%d:%s\n", __FILE__, __LINE__, __FUNCTION__)
|
10
|
+
#else
|
11
|
+
#define TRACE()
|
12
|
+
#endif
|
13
|
+
|
14
|
+
#endif
|