Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
caabc153
Commit
caabc153
authored
7 years ago
by
Kaspar Schleiser
Browse files
Options
Downloads
Patches
Plain Diff
sys/random: provide generic random_bytes()
parent
b378bd4e
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
sys/random/Makefile
+1
-1
1 addition, 1 deletion
sys/random/Makefile
sys/random/random.c
+15
-0
15 additions, 0 deletions
sys/random/random.c
sys/random/tinymt32.c
+0
-30
0 additions, 30 deletions
sys/random/tinymt32.c
with
16 additions
and
31 deletions
sys/random/Makefile
+
1
−
1
View file @
caabc153
SRC
:=
seed
.c
SRC
:=
random
.c
BASE_MODULE
:=
prng
SUBMODULES
:=
1
...
...
This diff is collapsed.
Click to expand it.
sys/random/
seed
.c
→
sys/random/
random
.c
+
15
−
0
View file @
caabc153
...
...
@@ -39,3 +39,18 @@ void auto_init_random(void)
DEBUG
(
"random: using seed value %u
\n
"
,
(
unsigned
)
seed
);
random_init
(
seed
);
}
void
random_bytes
(
uint8_t
*
target
,
size_t
n
)
{
uint32_t
random
;
uint8_t
*
random_pos
=
(
uint8_t
*
)
&
random
;
unsigned
_n
=
0
;
while
(
n
--
)
{
if
(
!
(
_n
++
&
0x3
))
{
random
=
random_uint32
();
random_pos
=
(
uint8_t
*
)
&
random
;
}
*
target
++
=
*
random_pos
++
;
}
}
This diff is collapsed.
Click to expand it.
sys/random/tinymt32.c
+
0
−
30
View file @
caabc153
...
...
@@ -44,36 +44,6 @@ uint32_t random_uint32(void)
return
tinymt32_generate_uint32
(
&
_random
);
}
void
random_bytes
(
uint8_t
*
buf
,
size_t
size
)
{
size_t
iter
=
size
;
size_t
diff
=
_align
(
buf
)
-
buf
;
uint32_t
tmp
;
/* Fill first <4 unaligned bytes */
if
(
diff
)
{
tmp
=
tinymt32_generate_uint32
(
&
_random
);
if
(
diff
>
size
)
{
diff
=
size
;
}
memcpy
(
buf
,
&
tmp
,
diff
);
iter
-=
diff
;
}
/* Fill aligned bytes */
while
(
iter
>=
sizeof
(
uint32_t
))
{
*
((
uint32_t
*
)
buf
)
=
tinymt32_generate_uint32
(
&
_random
);
buf
+=
sizeof
(
uint32_t
);
iter
-=
sizeof
(
uint32_t
);
}
/* Fill last bytes */
if
(
iter
)
{
tmp
=
tinymt32_generate_uint32
(
&
_random
);
memcpy
(
buf
,
&
tmp
,
iter
);
}
}
void
random_init_by_array
(
uint32_t
init_key
[],
int
key_length
)
{
tinymt32_init_by_array
(
&
_random
,
init_key
,
key_length
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment