mirror of
https://github.com/DarkStore-3DS/Project_CTR.git
synced 2026-07-03 00:39:14 +00:00
Partially migrate makerom to libmbedtls
This commit is contained in:
+19
-20
@@ -1,16 +1,16 @@
|
|||||||
#include "lib.h"
|
#include "lib.h"
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
|
|
||||||
|
#include <polarssl/rsa.h>
|
||||||
|
|
||||||
|
#include <mbedtls/aes.h>
|
||||||
|
#include <mbedtls/rsa.h>
|
||||||
|
#include <mbedtls/sha1.h>
|
||||||
|
#include <mbedtls/sha256.h>
|
||||||
|
|
||||||
const u8 RSA_PUB_EXP[0x3] = {0x01,0x00,0x01};
|
const u8 RSA_PUB_EXP[0x3] = {0x01,0x00,0x01};
|
||||||
const int HASH_MAX_LEN = 0x20;
|
const int HASH_MAX_LEN = 0x20;
|
||||||
|
|
||||||
int ctr_rsa_rsassa_pkcs1_v15_sign( rsa_context *ctx,
|
|
||||||
int mode,
|
|
||||||
int hash_id,
|
|
||||||
unsigned int hashlen,
|
|
||||||
const unsigned char *hash,
|
|
||||||
unsigned char *sig );
|
|
||||||
|
|
||||||
bool VerifySha256(void *data, u64 size, u8 hash[32])
|
bool VerifySha256(void *data, u64 size, u8 hash[32])
|
||||||
{
|
{
|
||||||
u8 calchash[32];
|
u8 calchash[32];
|
||||||
@@ -21,8 +21,8 @@ bool VerifySha256(void *data, u64 size, u8 hash[32])
|
|||||||
void ShaCalc(void *data, u64 size, u8 *hash, int mode)
|
void ShaCalc(void *data, u64 size, u8 *hash, int mode)
|
||||||
{
|
{
|
||||||
switch(mode){
|
switch(mode){
|
||||||
case(CTR_SHA_1): sha1((u8*)data, size, hash); break;
|
case(CTR_SHA_1): mbedtls_sha1((u8*)data, size, hash); break;
|
||||||
case(CTR_SHA_256): sha2((u8*)data, size, hash, 0); break;
|
case(CTR_SHA_256): mbedtls_sha256((u8*)data, size, hash, 0); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,32 +34,31 @@ void SetAesCtrOffset(u8 *ctr, u64 offset)
|
|||||||
void AesCtrCrypt(u8 *key, u8 *ctr, u8 *input, u8 *output, u64 length, u64 offset)
|
void AesCtrCrypt(u8 *key, u8 *ctr, u8 *input, u8 *output, u64 length, u64 offset)
|
||||||
{
|
{
|
||||||
u8 stream[16];
|
u8 stream[16];
|
||||||
aes_context aes;
|
mbedtls_aes_context aes;
|
||||||
size_t nc_off = 0;
|
size_t nc_off = 0;
|
||||||
|
|
||||||
clrmem(&aes,sizeof(aes_context));
|
mbedtls_aes_init(&aes);
|
||||||
aes_setkey_enc(&aes, key, 128);
|
mbedtls_aes_setkey_enc(&aes, key, 128);
|
||||||
SetAesCtrOffset(ctr,offset);
|
SetAesCtrOffset(ctr,offset);
|
||||||
|
|
||||||
aes_crypt_ctr(&aes, length, &nc_off, ctr, stream, input, output);
|
mbedtls_aes_crypt_ctr(&aes, length, &nc_off, ctr, stream, input, output);
|
||||||
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AesCbcCrypt(u8 *key, u8 *iv, u8 *input, u8 *output, u64 length, u8 mode)
|
void AesCbcCrypt(u8 *key, u8 *iv, u8 *input, u8 *output, u64 length, u8 mode)
|
||||||
{
|
{
|
||||||
aes_context aes;
|
mbedtls_aes_context aes;
|
||||||
clrmem(&aes,sizeof(aes_context));
|
mbedtls_aes_init(&aes);
|
||||||
|
|
||||||
switch(mode){
|
switch(mode){
|
||||||
case(ENC):
|
case(ENC):
|
||||||
aes_setkey_enc(&aes, key, 128);
|
mbedtls_aes_setkey_enc(&aes, key, 128);
|
||||||
aes_crypt_cbc(&aes, AES_ENCRYPT, length, iv, input, output);
|
mbedtls_aes_crypt_cbc(&aes, MBEDTLS_AES_ENCRYPT, length, iv, input, output);
|
||||||
return;
|
return;
|
||||||
case(DEC):
|
case(DEC):
|
||||||
aes_setkey_dec(&aes, key, 128);
|
mbedtls_aes_setkey_dec(&aes, key, 128);
|
||||||
aes_crypt_cbc(&aes, AES_DECRYPT, length, iv, input, output);
|
mbedtls_aes_crypt_cbc(&aes, MBEDTLS_AES_DECRYPT, length, iv, input, output);
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <polarssl/config.h>
|
|
||||||
#include <polarssl/aes.h>
|
|
||||||
#include <polarssl/rsa.h>
|
|
||||||
#include <polarssl/sha1.h>
|
|
||||||
#include <polarssl/sha2.h>
|
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
RSA_4096_SHA1 = 0x00010000,
|
RSA_4096_SHA1 = 0x00010000,
|
||||||
|
|||||||
Reference in New Issue
Block a user