Split Wii encryption code from librvth into libwiicrypto.

This will allow us to reuse the encryption code for the new wadtool,
which will allow converting debug WADs to retail and vice-versa.

This also moves common.h, byteorder.h, byteswap.h, gcn_structs.h,
and win32/.

Moved nettle detection to src/CMakeLists.txt and a separate config file.
This commit is contained in:
David Korth 2018-09-23 10:48:42 -04:00
parent 9b8f13604b
commit 2343a0eb75
39 changed files with 266 additions and 173 deletions

View File

@ -5,6 +5,7 @@
# NETTLE_LIBRARIES - List of libraries when using libnettle.
# NETTLE_FOUND - True if libnettle found.
IF(NOT TARGET nettle_dll_target)
IF(NOT WIN32)
if(NETTLE_INCLUDE_DIRS)
# Already in cache, be silent
@ -80,3 +81,4 @@ ELSE(NOT WIN32)
UNSET(DLL_DESTDIR)
ENDIF(NOT WIN32)
ENDIF(NOT TARGET nettle_dll_target)

View File

@ -11,10 +11,43 @@ ENDIF(MSVC)
INCLUDE(CheckHiddenVisibility)
CHECK_HIDDEN_VISIBILITY()
# Find nettle.
FIND_PACKAGE(Nettle REQUIRED)
SET(HAVE_NETTLE 1)
IF(NOT WIN32)
# Find GMP.
# On Windows, we're using nettle's mini-GMP.
FIND_PACKAGE(GMP REQUIRED)
SET(HAVE_GMP 1)
ENDIF(NOT WIN32)
# Check if this is Nettle 3.x.
# Nettle 3.1 added version.h, which isn't available
# in older verisons, so we can't simply check that.
INCLUDE(CheckSymbolExists)
SET(OLD_CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES}")
SET(OLD_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
SET(CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES} ${NETTLE_INCLUDE_DIRS}")
SET(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES} ${NETTLE_LIBRARY}")
CHECK_SYMBOL_EXISTS(aes128_set_decrypt_key "nettle/aes.h" HAVE_NETTLE_3)
IF(HAVE_NETTLE_3)
# Check for Nettle versioning symbols.
# Nettle 3.1 added version.h.
CHECK_SYMBOL_EXISTS(NETTLE_VERSION_MAJOR "nettle/version.h" HAVE_NETTLE_VERSION_H)
CHECK_SYMBOL_EXISTS(nettle_version_major "nettle/version.h" HAVE_NETTLE_VERSION_FUNCTIONS)
ENDIF(HAVE_NETTLE_3)
SET(CMAKE_REQUIRED_INCLUDES "${OLD_CMAKE_REQUIRED_INCLUDES}")
SET(CMAKE_REQUIRED_LIBRARIES "${OLD_CMAKE_REQUIRED_LIBRARIES}")
UNSET(OLD_CMAKE_REQUIRED_INCLUDES)
UNSET(OLD_CMAKE_REQUIRED_LIBRARIES)
# Write the version number to config.version.h.
CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/config.version.h.in" "${CMAKE_CURRENT_BINARY_DIR}/config.version.h")
# Write the Nettle configuration to config.nettle.h.
CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/config.nettle.h.in" "${CMAKE_CURRENT_BINARY_DIR}/config.nettle.h")
# Source Code subdirectories.
ADD_SUBDIRECTORY(libwiicrypto)
ADD_SUBDIRECTORY(librvth)
ADD_SUBDIRECTORY(rvthtool)
ADD_SUBDIRECTORY(qrvthtool)

39
src/config.nettle.h.in Normal file
View File

@ -0,0 +1,39 @@
/***************************************************************************
* RVT-H Tool *
* config.nettle.h.in: Nettle configuration. (source file) *
* *
* Copyright (c) 2018 by David Korth. *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef __RVTHTOOL_NETTLE_CONFIG_H__
#define __RVTHTOOL_NETTLE_CONFIG_H__
/* Define to 1 if you have gmp. */
#cmakedefine HAVE_GMP 1
/* Define to 1 if we're using nettle for decryption. */
#cmakedefine HAVE_NETTLE 1
/* Define to 1 if we're using nettle and it is v3.0 or later. */
#cmakedefine HAVE_NETTLE_3 1
/* Define to 1 if "nettle/version.h" is present. */
#cmakedefine HAVE_NETTLE_VERSION_H
/* Define to 1 if nettle version functions are present. */
#cmakedefine HAVE_NETTLE_VERSION_FUNCTIONS
#endif /* __RVTHTOOL_NETTLE_CONFIG_H__ */

View File

@ -6,36 +6,6 @@ IF(NOT WIN32)
CHECK_FUNCTION_EXISTS(ftruncate HAVE_FTRUNCATE)
ENDIF(NOT WIN32)
# Find nettle.
FIND_PACKAGE(Nettle REQUIRED)
SET(HAVE_NETTLE 1)
IF(NOT WIN32)
# Find GMP.
# On Windows, we're using nettle's mini-GMP.
FIND_PACKAGE(GMP REQUIRED)
SET(HAVE_GMP 1)
ENDIF(NOT WIN32)
# Check if this is Nettle 3.x.
# Nettle 3.1 added version.h, which isn't available
# in older verisons, so we can't simply check that.
INCLUDE(CheckSymbolExists)
SET(OLD_CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES}")
SET(OLD_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
SET(CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES} ${NETTLE_INCLUDE_DIRS}")
SET(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES} ${NETTLE_LIBRARY}")
CHECK_SYMBOL_EXISTS(aes128_set_decrypt_key "nettle/aes.h" HAVE_NETTLE_3)
IF(HAVE_NETTLE_3)
# Check for Nettle versioning symbols.
# Nettle 3.1 added version.h.
CHECK_SYMBOL_EXISTS(NETTLE_VERSION_MAJOR "nettle/version.h" HAVE_NETTLE_VERSION_H)
CHECK_SYMBOL_EXISTS(nettle_version_major "nettle/version.h" HAVE_NETTLE_VERSION_FUNCTIONS)
ENDIF(HAVE_NETTLE_3)
SET(CMAKE_REQUIRED_INCLUDES "${OLD_CMAKE_REQUIRED_INCLUDES}")
SET(CMAKE_REQUIRED_LIBRARIES "${OLD_CMAKE_REQUIRED_LIBRARIES}")
UNSET(OLD_CMAKE_REQUIRED_INCLUDES)
UNSET(OLD_CMAKE_REQUIRED_LIBRARIES)
IF(ENABLE_UDEV)
# Find UDEV.
IF(UNIX AND NOT APPLE)
@ -63,9 +33,6 @@ SET(librvth_SRCS
rvth_time.c
rvth_recrypt.c
ref_file.c
cert_store.c
cert.c
priv_key_store.c
disc_header.c
query.c
ptbl.c
@ -80,22 +47,13 @@ SET(librvth_SRCS
)
# Headers.
SET(librvth_H
common.h
byteorder.h
byteswap.h
nhcd_structs.h
gcn_structs.h
rvth.h
rvth_p.h
rvth_time.h
rvth_recrypt.h
ref_file.h
tcharx.h
cert_store.h
cert.h
rsaw.h
aesw.h
priv_key_store.h
disc_header.h
query.h
ptbl.h
@ -109,17 +67,6 @@ SET(librvth_H
libwbfs.h
reader_wbfs.h
)
IF(HAVE_NETTLE)
SET(librvth_RSA_SRCS rsaw_nettle.c)
ELSE()
MESSAGE(FATAL_ERROR "No hash function wrappers for this platform.")
ENDIF()
IF(HAVE_NETTLE)
SET(librvth_AES_SRCS aesw_nettle.c)
ELSE()
MESSAGE(FATAL_ERROR "No AES function wrappers for this platform.")
ENDIF()
IF(HAVE_UDEV)
SET(librvth_QUERY_SRCS query_udev.c)
@ -154,26 +101,25 @@ IF(TARGET git_version)
ADD_DEPENDENCIES(rvth git_version)
ENDIF(TARGET git_version)
IF(WIN32)
TARGET_LINK_LIBRARIES(rvth advapi32)
ENDIF(WIN32)
# libwiicrypto
TARGET_LINK_LIBRARIES(rvth PRIVATE wiicrypto)
# GMP
IF(HAVE_GMP)
TARGET_INCLUDE_DIRECTORIES(rvth PRIVATE ${GMP_INCLUDE_DIR})
TARGET_LINK_LIBRARIES(rvth ${GMP_LIBRARIES})
TARGET_LINK_LIBRARIES(rvth PRIVATE ${GMP_LIBRARIES})
ENDIF(HAVE_GMP)
# Nettle
IF(HAVE_NETTLE)
TARGET_INCLUDE_DIRECTORIES(rvth PRIVATE ${NETTLE_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(rvth ${NETTLE_LIBRARIES})
TARGET_LINK_LIBRARIES(rvth PRIVATE ${NETTLE_LIBRARIES})
ENDIF(HAVE_NETTLE)
# UDEV
IF(HAVE_UDEV)
TARGET_INCLUDE_DIRECTORIES(rvth PRIVATE ${UDEV_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(rvth ${UDEV_LIBRARIES})
TARGET_LINK_LIBRARIES(rvth PRIVATE ${UDEV_LIBRARIES})
ENDIF(HAVE_UDEV)
# Unix: Add -fpic/-fPIC in order to use this static library in plugins.
@ -181,8 +127,3 @@ IF(UNIX AND NOT APPLE)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpic -fPIC")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpic -fPIC")
ENDIF(UNIX AND NOT APPLE)
# Test suite.
IF(BUILD_TESTING)
ADD_SUBDIRECTORY(tests)
ENDIF(BUILD_TESTING)

View File

@ -20,8 +20,10 @@
#include "bank_init.h"
#include "byteswap.h"
#include "cert.h"
#include "libwiicrypto/byteswap.h"
#include "libwiicrypto/cert.h"
#include "libwiicrypto/cert_store.h"
#include "disc_header.h"
#include "nhcd_structs.h"
#include "ptbl.h"

View File

@ -24,21 +24,6 @@
/* Define to 1 if you have the `ftruncate' function. */
#cmakedefine HAVE_FTRUNCATE 1
/* Define to 1 if you have gmp. */
#cmakedefine HAVE_GMP 1
/* Define to 1 if we're using nettle for decryption. */
#cmakedefine HAVE_NETTLE 1
/* Define to 1 if we're using nettle and it is v3.0 or later. */
#cmakedefine HAVE_NETTLE_3 1
/* Define to 1 if "nettle/version.h" is present. */
#cmakedefine HAVE_NETTLE_VERSION_H
/* Define to 1 if nettle version functions are present. */
#cmakedefine HAVE_NETTLE_VERSION_FUNCTIONS
/* Define to 1 if udev is present. */
#cmakedefine HAVE_UDEV 1

View File

@ -21,7 +21,7 @@
#ifndef __RVTHTOOL_LIBRVTH_DISC_HEADER_H__
#define __RVTHTOOL_LIBRVTH_DISC_HEADER_H__
#include "common.h"
#include "libwiicrypto/common.h"
#include <stdint.h>

View File

@ -9,8 +9,8 @@
#pragma warning(disable:4200)
#endif
#include "common.h"
#include <stdint.h>
#include "libwiicrypto/common.h"
#ifdef __cplusplus
extern "C" {

View File

@ -29,7 +29,7 @@
#define __RVTHTOOL_LIBRVTH_NHCD_STRUCTS_H__
#include <stdint.h>
#include "common.h"
#include "libwiicrypto/common.h"
#ifdef __cplusplus
extern "C" {

View File

@ -21,7 +21,7 @@
#ifndef __RVTHTOOL_LIBRVTH_READER_H__
#define __RVTHTOOL_LIBRVTH_READER_H__
#include "common.h"
#include "libwiicrypto/common.h"
#include "ref_file.h"
#include "rvth_imagetype.h"

View File

@ -21,7 +21,7 @@
#ifndef __RVTHTOOL_LIBRVTH_REF_FILE_H__
#define __RVTHTOOL_LIBRVTH_REF_FILE_H__
#include "common.h"
#include "libwiicrypto/common.h"
#include "tcharx.h"
#include <stdint.h>

View File

@ -21,11 +21,11 @@
#ifndef __RVTHTOOL_LIBRVTH_RVTH_H__
#define __RVTHTOOL_LIBRVTH_RVTH_H__
#include "common.h"
#include "libwiicrypto/common.h"
#include "libwiicrypto/gcn_structs.h"
#include "ref_file.h"
#include "reader.h"
#include "cert_store.h"
#include "gcn_structs.h"
#include <stdint.h>
#include <stdio.h>

View File

@ -21,8 +21,6 @@
#ifndef __RVTHTOOL_LIBRVTH_RVTH_P_H__
#define __RVTHTOOL_LIBRVTH_RVTH_P_H__
#include "common.h"
#include "rvth.h"
#include "rvth_imagetype.h"
#include "ref_file.h"

View File

@ -30,7 +30,6 @@
#include "rsaw.h"
#include "priv_key_store.h"
#include "common.h"
#include "byteswap.h"
#include <assert.h>

View File

@ -19,7 +19,7 @@
***************************************************************************/
#include "rvth_time.h"
#include "common.h"
#include "libwiicrypto/common.h"
#include <ctype.h>
#include <errno.h>

View File

@ -0,0 +1,98 @@
PROJECT(libwiicrypto)
# Check for C library functions.
IF(NOT WIN32)
INCLUDE(CheckFunctionExists)
CHECK_FUNCTION_EXISTS(ftruncate HAVE_FTRUNCATE)
ENDIF(NOT WIN32)
# Sources.
SET(libwiicrypto_SRCS
cert_store.c
cert.c
priv_key_store.c
)
# Headers.
SET(libwiicrypto_H
common.h
byteorder.h
byteswap.h
gcn_structs.h
cert_store.h
cert.h
rsaw.h
aesw.h
priv_key_store.h
)
IF(WIN32)
SET(libwiicrypto_H ${libwiicrypto_H}
win32/Win32_sdk.h
win32/secoptions.h
win32/secoptions_win8.h
)
ENDIF(WIN32)
IF(HAVE_NETTLE)
SET(libwiicrypto_RSA_SRCS rsaw_nettle.c)
SET(libwiicrypto_AES_SRCS aesw_nettle.c)
ELSE()
MESSAGE(FATAL_ERROR "No crypto wrappers are available for this platform.")
ENDIF()
######################
# Build the library. #
######################
ADD_LIBRARY(wiicrypto STATIC
${libwiicrypto_SRCS} ${libwiicrypto_H}
${libwiicrypto_RSA_SRCS}
${libwiicrypto_AES_SRCS}
)
# Include paths:
# - Public: Current source and binary directories.
# - Private: Parent source and binary directories,
# and top-level binary directory for git_version.h.
TARGET_INCLUDE_DIRECTORIES(wiicrypto
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> # libwiicrypto
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> # libwiicrypto
PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..> # src
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/..> # src
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}> # build
)
# Exclude from ALL builds.
SET_TARGET_PROPERTIES(wiicrypto PROPERTIES EXCLUDE_FROM_ALL TRUE)
# Make sure git_version.h is created before compiling this target.
IF(TARGET git_version)
ADD_DEPENDENCIES(wiicrypto git_version)
ENDIF(TARGET git_version)
# Windows-specific
IF(WIN32)
# CryptGenRandom()
TARGET_LINK_LIBRARIES(wiicrypto PRIVATE advapi32)
ENDIF(WIN32)
# GMP
IF(HAVE_GMP)
TARGET_INCLUDE_DIRECTORIES(wiicrypto PRIVATE ${GMP_INCLUDE_DIR})
TARGET_LINK_LIBRARIES(wiicrypto PRIVATE ${GMP_LIBRARIES})
ENDIF(HAVE_GMP)
# Nettle
IF(HAVE_NETTLE)
TARGET_INCLUDE_DIRECTORIES(wiicrypto PRIVATE ${NETTLE_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(wiicrypto PRIVATE ${NETTLE_LIBRARIES})
ENDIF(HAVE_NETTLE)
# Unix: Add -fpic/-fPIC in order to use this static library in plugins.
IF(UNIX AND NOT APPLE)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpic -fPIC")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpic -fPIC")
ENDIF(UNIX AND NOT APPLE)
# Test suite.
IF(BUILD_TESTING)
ADD_SUBDIRECTORY(tests)
ENDIF(BUILD_TESTING)

View File

@ -1,5 +1,5 @@
/***************************************************************************
* RVT-H Tool (librvth) *
* RVT-H Tool (libwiicrypto) *
* aesw.h: AES wrapper functions. *
* *
* Copyright (c) 2018 by David Korth. *
@ -20,8 +20,8 @@
// NOTE: Currently only supports AES-128-CBC.
#ifndef __RVTHTOOL_LIBRVTH_AESW_H__
#define __RVTHTOOL_LIBRVTH_AESW_H__
#ifndef __RVTHTOOL_LIBWIICRYPTO_AESW_H__
#define __RVTHTOOL_LIBWIICRYPTO_AESW_H__
#include <stdint.h>
#include <stddef.h>
@ -85,4 +85,4 @@ size_t aesw_decrypt(AesCtx *aesw, uint8_t *pData, size_t size);
}
#endif
#endif /* __RVTHTOOL_LIBRVTH_HASHW_H__ */
#endif /* __RVTHTOOL_LIBWIICRYPTO_AESW_H__ */

View File

@ -1,5 +1,5 @@
/***************************************************************************
* RVT-H Tool (librvth) *
* RVT-H Tool (libwiicrypto) *
* aesw_nettle.c: AES wrapper functions. (nettle version) *
* *
* Copyright (c) 2018 by David Korth. *
@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "config.librvth.h"
#include "config.nettle.h"
#include "aesw.h"

View File

@ -1,5 +1,5 @@
/***************************************************************************
* RVT-H Tool (librvth) *
* RVT-H Tool (libwiicrypto) *
* byteorder.h: System byte order header. *
* *
* Copyright (c) 2011-2018 by David Korth. *
@ -19,8 +19,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef __RVTHTOOL_LIBRVTH_BYTEORDER_H__
#define __RVTHTOOL_LIBRVTH_BYTEORDER_H__
#ifndef __RVTHTOOL_LIBWIICRYPTO_BYTEORDER_H__
#define __RVTHTOOL_LIBWIICRYPTO_BYTEORDER_H__
/**
* Check the system byte order.
@ -73,4 +73,4 @@
#endif
#endif /* __RVTHTOOL_LIBRVTH_BYTEORDER_H__ */
#endif /* __RVTHTOOL_LIBWIICRYPTO_BYTEORDER_H__ */

View File

@ -1,5 +1,5 @@
/***************************************************************************
* RVT-H Tool (librvth) *
* RVT-H Tool (libwiicrypto) *
* byteswap.h: Byteswapping functions. *
* *
* Copyright (c) 2008-2018 by David Korth. *
@ -19,8 +19,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef __RVTHTOOL_LIBRVTH_BYTESWAP_H__
#define __RVTHTOOL_LIBRVTH_BYTESWAP_H__
#ifndef __RVTHTOOL_LIBWIICRYPTO_BYTESWAP_H__
#define __RVTHTOOL_LIBWIICRYPTO_BYTESWAP_H__
// C includes.
#include <stdint.h>
@ -115,4 +115,4 @@
# define BE32_CONST(x) (x)
#endif
#endif /* __RVTHTOOL_LIBRVTH_BYTESWAP_H__ */
#endif /* __RVTHTOOL_LIBWIICRYPTO_BYTESWAP_H__ */

View File

@ -1,5 +1,5 @@
/***************************************************************************
* RVT-H Tool (librvth) *
* RVT-H Tool (libwiicrypto*
* cert.c: Certificate management. *
* *
* Copyright (c) 2018 by David Korth. *
@ -18,8 +18,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "config.librvth.h"
#include "cert.h"
#include "cert_store.h"

View File

@ -1,5 +1,5 @@
/***************************************************************************
* RVT-H Tool (librvth) *
* RVT-H Tool (libwiicrypto) *
* cert.h: Certificate management. *
* *
* Copyright (c) 2018 by David Korth. *
@ -18,13 +18,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef __RVTHTOOL_LIBRVTH_CERT_H__
#define __RVTHTOOL_LIBRVTH_CERT_H__
#ifndef __RVTHTOOL_LIBWIICRYPTO_CERT_H__
#define __RVTHTOOL_LIBWIICRYPTO_CERT_H__
#include <stdint.h>
#include <stddef.h>
#include "common.h"
#include "gcn_structs.h"
#include "rsaw.h"
@ -148,4 +147,4 @@ int cert_realsign_tmd(uint8_t *tmd, size_t size, const RSA2048PrivateKey *key);
}
#endif
#endif /* __RVTHTOOL_LIBRVTH_CERT_STORE_H__ */
#endif /* __RVTHTOOL_LIBWIICRYPTO_CERT_H__ */

View File

@ -1,5 +1,5 @@
/***************************************************************************
* RVT-H Tool (librvth) *
* RVT-H Tool (libwiicrypto) *
* cert_store.c: Certificate store. *
* *
* Copyright (c) 2018 by David Korth. *

View File

@ -1,5 +1,5 @@
/***************************************************************************
* RVT-H Tool (librvth) *
* RVT-H Tool (libwiicrypto) *
* cert_store.h: Certificate store. *
* *
* Copyright (c) 2018 by David Korth. *
@ -18,11 +18,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef __RVTHTOOL_LIBRVTH_CERT_STORE_H__
#define __RVTHTOOL_LIBRVTH_CERT_STORE_H__
#ifndef __RVTHTOOL_LIBWIICRYPTO_CERT_STORE_H__
#define __RVTHTOOL_LIBWIICRYPTO_CERT_STORE_H__
#include "common.h"
#include <stdint.h>
#include "common.h"
#ifdef __cplusplus
extern "C" {
@ -271,4 +271,4 @@ ASSERT_STRUCT(RVL_Cert_RSA2048_ECC, 0x240);
}
#endif
#endif /* __RVTHTOOL_LIBRVTH_CERT_STORE_H__ */
#endif /* __RVTHTOOL_LIBWIICRYPTO_CERT_STORE_H__ */

View File

@ -1,5 +1,5 @@
/***************************************************************************
* RVT-H Tool (librvth) *
* RVT-H Tool (libwiicrypto) *
* common.h: Common types and macros. *
* *
* Copyright (c) 2016-2018 by David Korth. *
@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef __RVTHTOOL_LIBRVTH_COMMON_H__
#define __RVTHTOOL_LIBRVTH_COMMON_H__
#ifndef __RVTHTOOL_LIBWIICRYPTO_COMMON_H__
#define __RVTHTOOL_LIBWIICRYPTO_COMMON_H__
/**
* Number of elements in an array.
@ -45,14 +45,16 @@
* Also defines a constant of form StructName_SIZE
*/
// TODO: Check MSVC support for static_assert() in C mode.
#if defined(__cplusplus)
# define ASSERT_STRUCT(st,sz) enum { st##_SIZE = (sz), }; \
#ifndef ASSERT_STRUCT
# if defined(__cplusplus)
# define ASSERT_STRUCT(st,sz) enum { st##_SIZE = (sz), }; \
static_assert(sizeof(st)==(sz),#st " is not " #sz " bytes.")
#elif defined(__GNUC__) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
# define ASSERT_STRUCT(st,sz) enum { st##_SIZE = (sz), }; \
# elif defined(__GNUC__) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
# define ASSERT_STRUCT(st,sz) enum { st##_SIZE = (sz), }; \
_Static_assert(sizeof(st)==(sz),#st " is not " #sz " bytes.")
#else
# define ASSERT_STRUCT(st, sz)
# else
# define ASSERT_STRUCT(st, sz)
# endif
#endif
// RP equivalent of Q_UNUSED().
@ -132,4 +134,4 @@ typedef unsigned char bool;
# endif
#endif /* __cplusplus */
#endif /* __RVTHTOOL_LIBRVTH_COMMON_H__ */
#endif /* __RVTHTOOL_LIBWIICRYPTO_COMMON_H__ */

View File

@ -1,5 +1,5 @@
/***************************************************************************
* RVT-H Tool (librvth) *
* RVT-H Tool (libwiicrypto) *
* gcn_structs.h: Nintendo GameCube and Wii data structures. *
* *
* Copyright (c) 2016-2018 by David Korth. *
@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef __RVTHTOOL_LIBRVTH_GCN_STRUCTS_H__
#define __RVTHTOOL_LIBRVTH_GCN_STRUCTS_H__
#ifndef __RVTHTOOL_LIBWIICRYPTO_GCN_STRUCTS_H__
#define __RVTHTOOL_LIBWIICRYPTO_GCN_STRUCTS_H__
#include <stdint.h>
#include "common.h"
@ -381,4 +381,4 @@ typedef struct PACKED _RVL_RegionSetting {
}
#endif
#endif /* __RVTHTOOL_LIBRVTH_GCN_STRUCTS_H__ */
#endif /* __RVTHTOOL_LIBWIICRYPTO_GCN_STRUCTS_H__ */

View File

@ -1,5 +1,5 @@
/***************************************************************************
* RVT-H Tool (librvth) *
* RVT-H Tool (libwiicrypto) *
* priv_key_store.c: Private key store. *
* *
* Copyright (c) 2018 by David Korth. *

View File

@ -1,5 +1,5 @@
/***************************************************************************
* RVT-H Tool (librvth) *
* RVT-H Tool (libwiicrypto) *
* priv_key_store.h: Private key store. *
* *
* Copyright (c) 2018 by David Korth. *
@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef __RVTHTOOL_LIBRVTH_PRIV_KEY_STORE_H__
#define __RVTHTOOL_LIBRVTH_PRIV_KEY_STORE_H__
#ifndef __RVTHTOOL_LIBWIICRYPTO_PRIV_KEY_STORE_H__
#define __RVTHTOOL_LIBWIICRYPTO_PRIV_KEY_STORE_H__
#include <stdint.h>
#include "rsaw.h"
@ -39,4 +39,4 @@ extern const RSA2048PrivateKey rvth_privkey_debug_tmd;
}
#endif
#endif /* __RVTHTOOL_LIBRVTH_PRIV_KEY_STORE_H__ */
#endif /* __RVTHTOOL_LIBWIICRYPTO_PRIV_KEY_STORE_H__ */

View File

@ -1,5 +1,5 @@
/***************************************************************************
* RVT-H Tool (librvth) *
* RVT-H Tool (libwiicrypto) *
* rsaw.h: RSA encryption wrapper functions. *
* *
* Copyright (c) 2018 by David Korth. *
@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef __RVTHTOOL_LIBRVTH_RSAW_H__
#define __RVTHTOOL_LIBRVTH_RSAW_H__
#ifndef __RVTHTOOL_LIBWIICRYPTO_RSAW_H__
#define __RVTHTOOL_LIBWIICRYPTO_RSAW_H__
#include <stdint.h>
#include <stddef.h>
@ -90,4 +90,4 @@ int rsaw_sha1_sign(uint8_t *buf, size_t buf_size,
}
#endif
#endif /* __RVTHTOOL_LIBRVTH_RSAW_H__ */
#endif /* __RVTHTOOL_LIBWIICRYPTO_RSAW_H__ */

View File

@ -1,5 +1,5 @@
/***************************************************************************
* RVT-H Tool (librvth) *
* RVT-H Tool (libwiicrypto) *
* rsaw_nettle.c: RSA encryption wrapper functions. (Nettle/GMP version) *
* *
* Copyright (c) 2018 by David Korth. *

View File

@ -1,4 +1,4 @@
PROJECT(librvth-tests)
PROJECT(libwiicrypto-tests)
# Top-level src directory.
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../..)
@ -6,7 +6,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../..)
# Certificate verification test.
ADD_EXECUTABLE(CertVerifyTest CertVerifyTest.cpp)
TARGET_LINK_LIBRARIES(CertVerifyTest rvth)
TARGET_LINK_LIBRARIES(CertVerifyTest wiicrypto)
TARGET_LINK_LIBRARIES(CertVerifyTest gtest)
DO_SPLIT_DEBUG(CertVerifyTest)
SET_WINDOWS_SUBSYSTEM(CertVerifyTest CONSOLE)

View File

@ -1,5 +1,5 @@
/***************************************************************************
* RVT-H Tool (librvth/tests) *
* RVT-H Tool (libwiicrypto/tests) *
* CertVerifyTest.cpp: Certificate verification test. *
* *
* Copyright (c) 2018 by David Korth. *
@ -21,8 +21,8 @@
// Google Test
#include "gtest/gtest.h"
#include "librvth/cert_store.h"
#include "librvth/cert.h"
#include "libwiicrypto/cert_store.h"
#include "libwiicrypto/cert.h"
// C includes. (C++ namespace)
#include <cassert>
@ -35,7 +35,7 @@ using std::string;
# define final sealed
#endif
namespace LibRvth { namespace Tests {
namespace LibWiiCrypto { namespace Tests {
class CertVerifyTest : public ::testing::TestWithParam<RVL_Cert_Issuer>
{
@ -140,7 +140,7 @@ INSTANTIATE_TEST_CASE_P(certVerifyTest, CertVerifyTest,
*/
int RVTH_CDECL main(int argc, char *argv[])
{
fprintf(stderr, "librvth test suite: Certification verification tests.\n\n");
fprintf(stderr, "libwiicrypto test suite: Certification verification tests.\n\n");
fflush(nullptr);
// coverity[fun_call_w_exception]: uncaught exceptions cause nonzero exit anyway, so don't warn.

View File

@ -1,5 +1,5 @@
/***************************************************************************
* RVT-H Tool (librvth) *
* RVT-H Tool (libwiicrypto) *
* Win32_sdk.h: Windows SDK defines and includes. *
* *
* Copyright (c) 2009-2018 by David Korth. *
@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef __RVTHTOOL_LIBRVTH_WIN32_SECOPTIONS_WIN32_SDK_H__
#define __RVTHTOOL_LIBRVTH_WIN32_SECOPTIONS_WIN32_SDK_H__
#ifndef __RVTHTOOL_LIBWIICRYPTO_WIN32_SECOPTIONS_WIN32_SDK_H__
#define __RVTHTOOL_LIBWIICRYPTO_WIN32_SECOPTIONS_WIN32_SDK_H__
// Show a warning if one of the macros isn't defined in CMake.
#ifndef WINVER
@ -127,4 +127,4 @@ static inline ULONG InterlockedDecrement(ULONG volatile *Addend)
EXTERN_C IMAGE_DOS_HEADER __ImageBase;
#define HINST_THISCOMPONENT ((HINSTANCE)&__ImageBase)
#endif /* __RVTHTOOL_LIBRVTH_WIN32_SECOPTIONS_WIN32_SDK_H__ */
#endif /* __RVTHTOOL_LIBWIICRYPTO_WIN32_SECOPTIONS_WIN32_SDK_H__ */

View File

@ -1,5 +1,5 @@
/***************************************************************************
* RVT-H Tool (librvth) *
* RVT-H Tool (libwiicrypto) *
* secoptions.h: Security options for executables. *
* *
* Copyright (c) 2016-2018 by David Korth. *
@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef __RVTHTOOL_LIBRVTH_WIN32_SECOPTIONS_H__
#define __RVTHTOOL_LIBRVTH_WIN32_SECOPTIONS_H__
#ifndef __RVTHTOOL_LIBWIICRYPTO_WIN32_SECOPTIONS_H__
#define __RVTHTOOL_LIBWIICRYPTO_WIN32_SECOPTIONS_H__
#include "Win32_sdk.h"
#include "sdkddkver.h"
@ -244,4 +244,4 @@ static INLINE int secoptions_init(void)
}
#endif
#endif /* __RVTHTOOL_LIBRVTH_SECOPTIONS_H__ */
#endif /* __RVTHTOOL_LIBWIICRYPTO_SECOPTIONS_H__ */

View File

@ -1,5 +1,5 @@
/***************************************************************************
* RVT-H Tool (librvth) *
* RVT-H Tool (libwiicrypto) *
* secoptions_win8.h: Security options for executables. (Win8) *
* *
* Copyright (c) 2016-2018 by David Korth. *
@ -18,10 +18,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef __RVTHTOOL_LIBRVTH_WIN32_SECOPTIONS_WIN8_H__
#define __RVTHTOOL_LIBRVTH_WIN32_SECOPTIONS_WIN8_H__
#ifndef __RVTHTOOL_LIBWIICRYPTO_WIN32_SECOPTIONS_WIN8_H__
#define __RVTHTOOL_LIBWIICRYPTO_WIN32_SECOPTIONS_WIN8_H__
#ifndef __RVTHTOOL_LIBRVTH_WIN32_SECOPTIONS_H__
#ifndef __RVTHTOOL_LIBWIICRYPTO_WIN32_SECOPTIONS_H__
#error secoptions_win8.h should not be included directly - include secoptions.h instead
#endif
@ -186,4 +186,4 @@ typedef struct _PROCESS_MITIGATION_IMAGE_LOAD_POLICY {
} PROCESS_MITIGATION_IMAGE_LOAD_POLICY, *PPROCESS_MITIGATION_IMAGE_LOAD_POLICY;
#endif /* !_WIN32_WINNT_WIN10 */
#endif /* __RVTHTOOL_LIBRVTH_SECOPTIONS_WIN8_H__ */
#endif /* __RVTHTOOL_LIBWIICRYPTO_SECOPTIONS_WIN8_H__ */

View File

@ -54,7 +54,7 @@ TARGET_INCLUDE_DIRECTORIES(rvthtool
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
)
TARGET_LINK_LIBRARIES(rvthtool rvth)
TARGET_LINK_LIBRARIES(rvthtool rvth wiicrypto)
IF(MSVC)
TARGET_LINK_LIBRARIES(rvthtool getopt_msvc)
ENDIF(MSVC)

View File

@ -20,7 +20,7 @@
#include "list-banks.h"
#include "librvth/rvth.h"
#include "librvth/gcn_structs.h"
#include "libwiicrypto/gcn_structs.h"
#include <assert.h>
#include <errno.h>

View File

@ -29,12 +29,11 @@
#include <getopt.h>
#include "librvth/config.librvth.h"
#include "librvth/common.h"
#include "librvth/byteswap.h"
#include "librvth/rvth.h"
#include "libwiicrypto/cert.h"
#ifdef _WIN32
#include "librvth/win32/secoptions.h"
# include "libwiicrypto/win32/secoptions.h"
#endif /* _WIN32 */
#include "list-banks.h"
@ -55,8 +54,6 @@
# define DEVICE_NAME_EXAMPLE "/dev/sdX"
#endif
#include "librvth/cert.h"
#ifdef __GNUC__
# define ATTR_PRINTF(fmt, args) __attribute__ ((format (printf, (fmt), (args))))
#else

View File

@ -25,7 +25,7 @@
#ifdef HAVE_QUERY
#include "librvth/common.h"
#include "libwiicrypto/common.h"
#include "librvth/query.h"
#include <stdio.h>