PSP/Vita: Switch to using BearSSL for SSL support

This commit is contained in:
UnknownShadow200 2023-09-15 08:41:09 +10:00
parent 2f2d6aadbb
commit e555fdc21f
5 changed files with 89 additions and 25 deletions

View file

@ -144,9 +144,9 @@ irix:
# consoles builds require special handling, so are moved to
# separate makefiles to avoid having one giant messy makefile
psp:
$(MAKE) -f src/Makefile_PSP PLAT=psp
$(MAKE) -f misc/psp/Makefile PLAT=psp
vita:
$(MAKE) -f src/Makefile_vita PLAT=vita
$(MAKE) -f misc/vita/Makefile PLAT=vita
ps3:
$(MAKE) -f src/Makefile_PS3 PLAT=ps3
3ds:

View file

@ -1,19 +1,19 @@
TARGET = ClassiCube-psp
SOURCES = $(wildcard src/*.c)
OBJS = $(patsubst %.c, %.o, $(SOURCES))
INCDIR =
CFLAGS = -g -O1 -fno-math-errno
ASFLAGS = $(CFLAGS)
LIBDIR =
LDFLAGS =
LIBS = -lm -lpspgum -lpspgu -lpspge -lpspdisplay -lpspctrl
BUILD_PRX = 1
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = ClassiCube
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
TARGET = ClassiCube-psp
SOURCES = $(wildcard src/*.c) $(wildcard third_party/bearssl/src/*.c)
OBJS = $(patsubst %.c, %.o, $(SOURCES))
INCDIR = third_party/bearssl/inc
CFLAGS = -g -O1 -fno-math-errno
ASFLAGS = $(CFLAGS)
LIBDIR =
LDFLAGS =
LIBS = -lm -lpspgum -lpspgu -lpspge -lpspdisplay -lpspctrl
BUILD_PRX = 1
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = ClassiCube
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak

49
misc/vita/Makefile Normal file
View file

@ -0,0 +1,49 @@
PROJECT_TITLE := ClassiCube
PROJECT_TITLEID := CUBE00200
TARGET := ClassiCube-vita
BUILD_DIR := build-vita
SOURCE_DIRS := src third_party/bearssl/src
CFLAGS += -Wl,-q -Ithird_party/bearssl/inc -O1
C_FILES := $(foreach dir,$(SOURCE_DIRS),$(wildcard $(dir)/*.c))
OBJS := $(addprefix $(BUILD_DIR)/, $(notdir $(C_FILES:%.c=%.o)))
# Needed by psvDebugScreenPrintf
LIBS += -lm -lSceDisplay_stub -lSceCtrl_stub -lSceTouch_stub -lSceGxm_stub
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
default: $(BUILD_DIR) $(TARGET).vpk
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(TARGET).vpk: eboot.bin param.sfo
vita-pack-vpk -s param.sfo -b eboot.bin $(TARGET).vpk
eboot.bin: $(TARGET).velf
vita-make-fself $(TARGET).velf eboot.bin
param.sfo:
vita-mksfoex -s TITLE_ID="$(PROJECT_TITLEID)" "$(PROJECT_TITLE)" param.sfo
$(TARGET).velf: $(TARGET).elf
arm-vita-eabi-strip -g $<
vita-elf-create $< $@
$(TARGET).elf: $(OBJS)
arm-vita-eabi-gcc $(CFLAGS) $^ $(LIBS) -o $@
$(BUILD_DIR)/%.o : src/%.c
arm-vita-eabi-gcc -c $(CFLAGS) -o $@ $<
$(BUILD_DIR)/%.o : third_party/bearssl/src/%.c
arm-vita-eabi-gcc -c $(CFLAGS) -o $@ $<
# TODO: There's gotta be a better way of .o to .c than this
clean:
rm $(TARGET).velf $(TARGET).elf $(TARGET).vpk param.sfo eboot.bin $(OBJS)

View file

@ -266,6 +266,7 @@ typedef cc_uint8 cc_bool;
#define CC_BUILD_HTTPCLIENT
#define CC_BUILD_OPENAL
#define CC_BUILD_PSP
#define CC_BUILD_BEARSSL
#define CC_BUILD_LOWMEM
#undef CC_BUILD_FREETYPE
#elif defined __3DS__
@ -286,6 +287,7 @@ typedef cc_uint8 cc_bool;
#define CC_BUILD_HTTPCLIENT
#define CC_BUILD_OPENAL
#define CC_BUILD_PSVITA
#define CC_BUILD_BEARSSL
#define CC_BUILD_LOWMEM
#undef CC_BUILD_FREETYPE
#elif defined _arch_dreamcast

View file

@ -418,10 +418,9 @@ cc_result SSL_Free(void* ctx_) {
return 0;
}
#elif defined CC_BUILD_BEARSSL
#include "bearssl.h"
#define CERT_ATTRIBUTES
#include "../misc/certs.h"
#include "String.h"
#include "bearssl.h"
#include "../misc/certs.h"
// https://github.com/unkaktus/bearssl/blob/master/samples/client_basic.c#L283
#define SSL_ERROR_SHIFT 0xB5510000
@ -459,6 +458,20 @@ static void InjectEntropy(SSLContext* ctx) {
br_ssl_engine_inject_entropy(&ctx->sc.eng, buf, 32);
}
#elif defined CC_BUILD_PSP
static void InjectEntropy(SSLContext* ctx) {
char buf[32];
// TODO: Is there an actual API to retrieve random data?
br_ssl_engine_inject_entropy(&ctx->sc.eng, buf, 32);
}
#elif defined CC_BUILD_VITA
static void InjectEntropy(SSLContext* ctx) {
char buf[32];
// TODO: Is there an actual API to retrieve random data?
br_ssl_engine_inject_entropy(&ctx->sc.eng, buf, 32);
}
#else
static void InjectEntropy(SSLContext* ctx) { }
#endif
@ -551,4 +564,4 @@ cc_result SSL_Write(void* ctx, const cc_uint8* data, cc_uint32 count, cc_uint32*
}
cc_result SSL_Free(void* ctx) { return 0; }
#endif
#endif