Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
T
tun
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
tun
Commits
d1b6812f
Commit
d1b6812f
authored
Dec 19, 2025
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better decrypt
parent
f99f8f1a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
10 deletions
+42
-10
src/router.rs
src/router.rs
+42
-10
No files found.
src/router.rs
View file @
d1b6812f
...
...
@@ -47,22 +47,54 @@ pub struct Router {
pub
tcp_listener_connection
:
Atomic
<
Socket
>
,
}
impl
Router
{
pub
(
crate
)
fn
decrypt
(
&
self
,
data
:
&
mut
[
u8
],
secret
:
&
[
u8
;
SECRET_LENGTH
])
{
for
(
i
,
b
)
in
data
.iter_mut
()
.enumerate
()
{
*
b
^=
secret
[
i
%
SECRET_LENGTH
];
#[inline]
fn
xor_with_secret_offset
<
const
L
:
usize
>
(
data
:
&
mut
[
u8
],
secret
:
&
[
u8
;
L
],
offset
:
usize
)
{
let
len
=
data
.len
();
if
len
==
0
{
return
;
}
let
mut
i
=
0
;
let
mut
key_pos
=
offset
%
L
;
// 1) 先把 key_pos 补到 0(也就是把相位对齐到块边界),这样后面能走“完整块”
if
key_pos
!=
0
{
let
head
=
(
L
-
key_pos
)
.min
(
len
);
for
j
in
0
..
head
{
data
[
j
]
^=
secret
[
key_pos
+
j
];
// 这里不会越界,因为 j < L - key_pos
}
i
+=
head
;
key_pos
=
0
;
}
pub
(
crate
)
fn
decrypt2
(
&
self
,
data
:
&
mut
[
u8
],
secret
:
&
[
u8
;
SECRET_LENGTH
],
range
:
Range
<
usize
>
)
{
for
(
i
,
b
)
in
data
[
range
.clone
()]
.iter_mut
()
.enumerate
()
{
*
b
^=
secret
[(
range
.start
+
i
)
%
SECRET_LENGTH
];
// 2) 处理完整块(key_pos 已经对齐到 0)
while
i
+
L
<=
len
{
for
j
in
0
..
L
{
data
[
i
+
j
]
^=
secret
[
j
];
}
i
+=
L
;
}
// 3) 处理尾部
for
j
in
0
..
(
len
-
i
)
{
data
[
i
+
j
]
^=
secret
[
j
];
}
}
impl
Router
{
pub
(
crate
)
fn
decrypt
(
&
self
,
data
:
&
mut
[
u8
],
secret
:
&
[
u8
;
SECRET_LENGTH
])
{
xor_with_secret_offset
::
<
SECRET_LENGTH
>
(
data
,
secret
,
0
);
}
pub
(
crate
)
fn
decrypt2
(
&
self
,
data
:
&
mut
[
u8
],
secret
:
&
[
u8
;
SECRET_LENGTH
],
range
:
Range
<
usize
>
,
)
{
xor_with_secret_offset
::
<
SECRET_LENGTH
>
(
&
mut
data
[
range
.clone
()],
secret
,
range
.start
);
}
pub
(
crate
)
fn
encrypt
(
&
self
,
data
:
&
mut
[
u8
])
{
for
(
i
,
b
)
in
data
.iter_mut
()
.enumerate
()
{
*
b
^=
self
.config.remote_secret
[
i
%
SECRET_LENGTH
];
}
xor_with_secret_offset
::
<
SECRET_LENGTH
>
(
data
,
&
self
.config.remote_secret
,
0
);
}
pub
fn
create_socket
(
config
:
&
ConfigRouter
)
->
Result
<
Socket
>
{
...
...
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