Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
shrapnel
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
shrapnel
Commits
02b03ce6
Commit
02b03ce6
authored
Feb 12, 2013
by
Sam Rushing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cython translation of dns_random.c
parent
f21e7304
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
0 deletions
+73
-0
coro/dns/surf.pyx
coro/dns/surf.pyx
+73
-0
No files found.
coro/dns/surf.pyx
0 → 100644
View file @
02b03ce6
# -*- Mode: Cython -*-
from
libc.stdint
cimport
uint32_t
,
uint8_t
# cython translation of Eric Huss' version of djb's dns_random.c
# crummy emulation of the C macros
cdef
inline
uint32_t
ROTATE
(
uint32_t
x
,
uint32_t
b
):
return
(((
x
)
<<
(
b
))
|
((
x
)
>>
(
32
-
(
b
))))
cdef
inline
void
MUSH
(
uint32_t
i
,
uint32_t
b
,
uint32_t
*
x
,
uint32_t
*
t
,
uint32_t
s
):
t
[
i
]
+=
(((
x
[
0
]
^
seed
[
i
])
+
s
)
^
ROTATE
(
x
[
0
],
b
))
x
[
0
]
=
t
[
i
]
cdef
uint32_t
seed
[
32
]
cdef
uint32_t
iin
[
12
]
cdef
uint32_t
out
[
8
]
cdef
int
outleft
=
0
#
# Simple Unpredictable Random Function
#
cdef
surf
():
cdef
uint32_t
t
[
12
],
x
,
sum
=
0
cdef
int
r
,
i
,
loop
for
i
in
range
(
12
):
t
[
i
]
=
iin
[
i
]
^
seed
[
12
+
i
]
for
i
in
range
(
8
):
out
[
i
]
=
seed
[
24
+
i
]
x
=
t
[
11
]
for
loop
in
range
(
2
):
for
r
in
range
(
16
):
sum
+=
0x9e3779b9
U
MUSH
(
0
,
5
,
&
x
,
t
,
sum
)
MUSH
(
1
,
7
,
&
x
,
t
,
sum
)
MUSH
(
2
,
9
,
&
x
,
t
,
sum
)
MUSH
(
3
,
13
,
&
x
,
t
,
sum
)
MUSH
(
4
,
5
,
&
x
,
t
,
sum
)
MUSH
(
5
,
7
,
&
x
,
t
,
sum
)
MUSH
(
6
,
9
,
&
x
,
t
,
sum
)
MUSH
(
7
,
13
,
&
x
,
t
,
sum
)
MUSH
(
8
,
5
,
&
x
,
t
,
sum
)
MUSH
(
9
,
7
,
&
x
,
t
,
sum
)
MUSH
(
10
,
9
,
&
x
,
t
,
sum
)
MUSH
(
11
,
13
,
&
x
,
t
,
sum
)
for
i
in
range
(
8
):
out
[
i
]
^=
t
[
i
+
4
]
from
cython.operator
cimport
preincrement
as
incr
,
predecrement
as
decr
#cython: cdivision=True
def
dns_random
(
uint32_t
n
):
"return an unpredictable random number in the range 0-n"
global
outleft
if
not
n
:
return
0
elif
not
outleft
:
if
not
incr
(
iin
[
0
]):
if
not
incr
(
iin
[
1
]):
if
not
incr
(
iin
[
2
]):
incr
(
iin
[
3
])
surf
()
outleft
=
8
return
out
[
decr
(
outleft
)]
%
n
def
set_seed
(
bytes
b
):
"set the initial seed for the SURF PRNG"
cdef
int
i
cdef
uint8_t
*
p
p
=
<
uint8_t
*>
(
&
seed
[
0
])
cdef
unsigned
char
*
x
=
b
for
i
in
range
(
len
(
b
)):
p
[
i
]
=
<
uint8_t
>
x
[
i
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment