Skip to content

Commit

Permalink
vita: stub getentropy
Browse files Browse the repository at this point in the history
  • Loading branch information
frangarcj committed Aug 2, 2021
1 parent e6c0e3a commit 2a63b0f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion newlib/libc/sys/vita/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ NET_OBJS = gethostbyaddr.o gethostbyname.o getaddrinfo.o freeaddrinfo.o getservb
DIRENT_OBJS = closedir.o opendir.o readdir.o readdir_r.o rewinddir.o seekdir.o telldir.o

NET_SOURCES = net/gethostbyaddr.c net/gethostbyname.c net/getaddrinfo.c net/freeaddrinfo.c net/getservbyname.c net/inet_ntop.c net/inet_ntoa.c net/inet_netof.c net/inet_pton.c net/inet_lnaof.c net/inet_addr.c net/inet_network.c net/inet_net_ntop.c net/inet_aton.c net/inet_net_pton.c net/inet_makeaddr.c
STUB_SOURCES = chroot.c groups.c
STUB_SOURCES = chroot.c getentropy.c groups.c
lib_a_SOURCES = syscalls.c access.c sbrk.c threading.c mlock.c io.c socket.c dup.c select.c error.c dirent.c lcltime_r.c sleep.c usleep.c truncate.c ${STUB_SOURCES} ${NET_SOURCES}
lib_a_LIBADD = ${SOCKET_OBJS} ${NET_OBJS} ${DIRENT_OBJS}
lib_a_CCASFLAGS = $(AM_CCASFLAGS)
Expand Down
11 changes: 9 additions & 2 deletions newlib/libc/sys/vita/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ LIBRARIES = $(noinst_LIBRARIES)
ARFLAGS = cru
lib_a_AR = $(AR) $(ARFLAGS)
lib_a_DEPENDENCIES = $(SOCKET_OBJS) $(NET_OBJS) $(DIRENT_OBJS)
am__objects_1 = lib_a-chroot.$(OBJEXT) lib_a-groups.$(OBJEXT)
am__objects_1 = lib_a-chroot.$(OBJEXT) lib_a-getentropy.$(OBJEXT) \
lib_a-groups.$(OBJEXT)
am__objects_2 = lib_a-gethostbyaddr.$(OBJEXT) \
lib_a-gethostbyname.$(OBJEXT) lib_a-getaddrinfo.$(OBJEXT) \
lib_a-freeaddrinfo.$(OBJEXT) lib_a-getservbyname.$(OBJEXT) \
Expand Down Expand Up @@ -216,7 +217,7 @@ SOCKET_OBJS = accept.o bind.o connect.o getpeername.o getsockname.o getsockopt.o
NET_OBJS = gethostbyaddr.o gethostbyname.o getaddrinfo.o freeaddrinfo.o getservbyname.o inet_ntop.o inet_ntoa.o inet_netof.o inet_pton.o inet_lnaof.o inet_addr.o inet_network.o inet_net_ntop.o inet_aton.o inet_net_pton.o inet_makeaddr.o
DIRENT_OBJS = closedir.o opendir.o readdir.o readdir_r.o rewinddir.o seekdir.o telldir.o
NET_SOURCES = net/gethostbyaddr.c net/gethostbyname.c net/getaddrinfo.c net/freeaddrinfo.c net/getservbyname.c net/inet_ntop.c net/inet_ntoa.c net/inet_netof.c net/inet_pton.c net/inet_lnaof.c net/inet_addr.c net/inet_network.c net/inet_net_ntop.c net/inet_aton.c net/inet_net_pton.c net/inet_makeaddr.c
STUB_SOURCES = chroot.c groups.c
STUB_SOURCES = chroot.c getentropy.c groups.c
lib_a_SOURCES = syscalls.c access.c sbrk.c threading.c mlock.c io.c socket.c dup.c select.c error.c dirent.c lcltime_r.c sleep.c usleep.c truncate.c ${STUB_SOURCES} ${NET_SOURCES}
lib_a_LIBADD = ${SOCKET_OBJS} ${NET_OBJS} ${DIRENT_OBJS}
lib_a_CCASFLAGS = $(AM_CCASFLAGS)
Expand Down Expand Up @@ -377,6 +378,12 @@ lib_a-chroot.o: chroot.c
lib_a-chroot.obj: chroot.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-chroot.obj `if test -f 'chroot.c'; then $(CYGPATH_W) 'chroot.c'; else $(CYGPATH_W) '$(srcdir)/chroot.c'; fi`

lib_a-getentropy.o: getentropy.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getentropy.o `test -f 'getentropy.c' || echo '$(srcdir)/'`getentropy.c

lib_a-getentropy.obj: getentropy.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-getentropy.obj `if test -f 'getentropy.c'; then $(CYGPATH_W) 'getentropy.c'; else $(CYGPATH_W) '$(srcdir)/getentropy.c'; fi`

lib_a-groups.o: groups.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-groups.o `test -f 'groups.c' || echo '$(srcdir)/'`groups.c

Expand Down
48 changes: 48 additions & 0 deletions newlib/libc/sys/vita/getentropy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Copyright (C) 2021, vitasdk
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/

#include <errno.h>
#include <sys/types.h>
#include <unistd.h>

#include <psp2/kernel/rng.h>

#define MAX_ENTROPY 64

int getentropy(void *ptr, size_t n)
{
if (n > MAX_ENTROPY) {
errno = -EIO;
return -1;
}

int ret = sceKernelGetRandomNumber(ptr, n);

return (ret == 0) ? 0 : -1;
}

void _arc4random_getentropy_fail(void)
{

}

0 comments on commit 2a63b0f

Please sign in to comment.