prepare libamiibo.a inclusion

This commit is contained in:
Philippe Teuwen 2019-09-03 00:18:29 +02:00
commit bccb9069f9
7 changed files with 42 additions and 11 deletions

19
client/amiitool/Makefile Normal file
View file

@ -0,0 +1,19 @@
MYSRCPATHS =
MYINCLUDES = -I. -I.. -I../jansson -I../../common/ -I../../include/
MYCFLAGS = -std=c99 -D_ISOC99_SOURCE
MYDEFS =
MYSRCS = \
amiibo.c \
drbg.c \
keygen.c
LIB_A = libamiibo.a
include ../../Makefile.host
# just for testing amiitool before complete migration into a lib:
amiitool:
gcc $(CFLAGS) \
amiitool.c $(MYSRCS) ../../common/commonutil.c ../ui.c -lreadline -lm ../../common/mbedtls/libmbedtls.a \
-o amiitool

View file

@ -8,6 +8,7 @@
#include "amiibo.h"
#include "mbedtls/md.h"
#include "mbedtls/aes.h"
#include "commonutil.h"
#define HMAC_POS_DATA 0x008
#define HMAC_POS_TAG 0x1B4

View file

@ -13,7 +13,6 @@
#include <string.h>
#include <stdio.h>
#include "keygen.h"
#include "util.h"
#define NFC3D_AMIIBO_SIZE 520

View file

@ -5,10 +5,11 @@
* SPDX-License-Identifier: MIT
*/
#include <amiibo.h>
#include <stdio.h>
#include <string.h>
#include "../loclass/fileutils.h"
#include "fileutils.h"
#include "amiibo.h"
#include "getopt.h"
#define NTAG215_SIZE 540
@ -16,7 +17,7 @@ static char *self;
void amiitool_usage() {
fprintf(stderr,
"amiitool build %i (commit %s-%08x)\n"
/*"amiitool build %i (commit %s-%08x)\n"*/
"by Marcos Del Sol Vives <marcos@dracon.es>\n"
"\n"
"Usage: %s (-e|-d|-c) -k keyfile [-i input] [-s input2] [-o output]\n"
@ -28,7 +29,7 @@ void amiitool_usage() {
" -s input save file, save from this file will replace input file ones.\n"
" -o output file. If not specified, stdout will be used.\n"
" -l decrypt files with invalid signatures.\n",
, self
self
);
}
@ -62,6 +63,9 @@ int main(int argc, char **argv) {
case 'i':
infile = optarg;
break;
case 'k':
keyfile = optarg;
break;
case 's':
savefile = optarg;
break;
@ -83,7 +87,8 @@ int main(int argc, char **argv) {
}
nfc3d_amiibo_keys amiiboKeys;
if (! LoadAmiikey(amiiboKeys, keyfile))
return 5;
uint8_t original[NTAG215_SIZE];
uint8_t modified[NFC3D_AMIIBO_SIZE];

View file

@ -8,7 +8,7 @@
#include "drbg.h"
#include <assert.h>
#include <string.h>
#include <mbedtls/md.h>
#include "mbedtls/md.h"
void nfc3d_drbg_init(nfc3d_drbg_ctx *ctx, const uint8_t *hmacKey, size_t hmacKeySize, const uint8_t *seed, size_t seedSize) {
assert(ctx != NULL);

View file

@ -19,7 +19,7 @@ void nfc3d_keygen_prepare_seed(const nfc3d_keygen_masterkeys *baseKeys, const ui
uint8_t *start = output;
// 1: Copy whole type string
output = memccpy(output, baseKeys->typeString, '\0', sizeof(baseKeys->typeString));
output = (uint8_t *)strcpy((char *)output, baseKeys->typeString);
// 2: Append (16 - magicBytesSize) from the input seed
size_t leadingSeedBytes = 16 - baseKeys->magicBytesSize;