Initial attempt to reimplement ecdsa certificates

This commit is contained in:
Phillip Stephens 2016-06-29 22:20:27 -07:00
parent 99dcef42f1
commit aff3349c33
8 changed files with 30 additions and 15 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "easy-ecc"]
path = extern/easy-ecc
url = https://github.com/libAthena/easy-ecc.git

View File

@ -19,7 +19,8 @@ set(ATHENA_VERSION
add_subdirectory(extern)
include_directories(include ${LZO_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR})
include_directories(include ${LZO_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} ${EASYECC_INCLUDE_DIR})
if (NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
endif()
@ -122,6 +123,7 @@ if(NOT MSVC AND NOT GEKKO)
set_source_files_properties(src/aes.cpp PROPERTIES COMPILE_FLAGS -maes)
endif()
add_library(athena-zelda EXCLUDE_FROM_ALL
src/athena/ALTTPFile.cpp
src/athena/ALTTPFileReader.cpp

View File

@ -1,3 +1,4 @@
add_subdirectory(lzo)
add_subdirectory(zlib)
add_subdirectory(yaml)
add_subdirectory(easy-ecc)

1
extern/easy-ecc vendored Submodule

@ -0,0 +1 @@
Subproject commit da2748507cbe429d3e1be918c54cfba3be06d4b2

View File

@ -42,7 +42,7 @@ public:
* \brief readSave
* \return
*/
WiiSave* readSave();
std::unique_ptr<WiiSave> readSave();
private:
WiiBanner* readBanner();
WiiFile* readFile();

View File

@ -4,10 +4,6 @@
#include "athena/MemoryReader.hpp"
#include "athena/MemoryWriter.hpp"
#include "athena/Utility.hpp"
#include "aes.hpp"
#include "ec.h"
#include "md5.h"
#include "sha1.h"
#include <stdio.h>
#include <vector>

View File

@ -7,7 +7,7 @@
#include "athena/FileWriter.hpp"
#include "md5.h"
#include "aes.hpp"
#include "ec.h"
#include "ecc.h"
#include "sha1.h"
#include <iostream>
#include <iomanip>
@ -31,7 +31,7 @@ WiiSaveReader::WiiSaveReader(const std::string& filename)
setEndian(Endian::BigEndian);
}
WiiSave* WiiSaveReader::readSave()
std::unique_ptr<WiiSave> WiiSaveReader::readSave()
{
WiiSave* ret = new WiiSave;
@ -92,7 +92,7 @@ WiiSave* WiiSaveReader::readSave()
ret->setRoot(buildTree(files));
readCerts(totalSize);
return ret;
return std::unique_ptr<WiiSave>(ret);
}
WiiBanner* WiiSaveReader::readBanner()
@ -292,9 +292,9 @@ WiiFile* WiiSaveReader::readFile()
return ret;
}
void WiiSaveReader::readCerts(atUint32 totalSize)
{
#if 0
std::cout << "Reading certs..." << std::endl;
atUint32 dataSize = totalSize - 0x340;
std::unique_ptr<atUint8[]> sig = base::readUBytes(0x40);
@ -304,12 +304,24 @@ void WiiSaveReader::readCerts(atUint32 totalSize)
std::unique_ptr<atUint8[]> data = base::readUBytes(dataSize);
atUint8* hash;
std::cout << "validating..." << std::endl;
hash = getSha1(data.get(), dataSize);
atUint8* hash2 = getSha1(hash, 20);
#if 0
std::cout << "validating..." << std::endl;
std::cout << (check_ec(ngCert.get(), apCert.get(), sig.get(), hash2) ? "ok" : "invalid") << "...";
std::cout << "done" << std::endl;
bool failed = false;
if (!ecdsa_verify(ngCert.get(), hash, sig.get()))
{
std::cout << "NGCert failure" << std::endl;
failed = true;
}
if (!ecdsa_verify(apCert.get(), hash2, sig.get()))
{
std::cout << "APCert failure" << std::endl;
failed = true;
}
if (!failed)
std::cout << "certificates ok" << std::endl;
#endif
}

View File

@ -10,7 +10,7 @@
#include "athena/Utility.hpp"
#include "aes.hpp"
#include "ec.h"
#include "ecc.h"
#include "md5.h"
#include "sha1.h"