less global vars
This commit is contained in:
@@ -26,39 +26,33 @@
|
||||
#include "ui.h" // Print...
|
||||
#include "bignum.h"
|
||||
|
||||
static uint8_t g_primes[ROCA_PRINTS_LENGTH] = {
|
||||
11, 13, 17, 19, 37, 53, 61, 71, 73, 79, 97, 103, 107, 109, 127, 151, 157
|
||||
};
|
||||
|
||||
mbedtls_mpi g_prints[ROCA_PRINTS_LENGTH];
|
||||
|
||||
static void rocacheck_init(void) {
|
||||
static void rocacheck_init(mbedtls_mpi *prints) {
|
||||
|
||||
for (int i = 0; i < ROCA_PRINTS_LENGTH; i++)
|
||||
mbedtls_mpi_init(&g_prints[i]);
|
||||
mbedtls_mpi_init(&prints[i]);
|
||||
|
||||
mbedtls_mpi_read_string(&g_prints[0], 10, "1026");
|
||||
mbedtls_mpi_read_string(&g_prints[1], 10, "5658");
|
||||
mbedtls_mpi_read_string(&g_prints[2], 10, "107286");
|
||||
mbedtls_mpi_read_string(&g_prints[3], 10, "199410");
|
||||
mbedtls_mpi_read_string(&g_prints[4], 10, "67109890");
|
||||
mbedtls_mpi_read_string(&g_prints[5], 10, "5310023542746834");
|
||||
mbedtls_mpi_read_string(&g_prints[6], 10, "1455791217086302986");
|
||||
mbedtls_mpi_read_string(&g_prints[7], 10, "20052041432995567486");
|
||||
mbedtls_mpi_read_string(&g_prints[8], 10, "6041388139249378920330");
|
||||
mbedtls_mpi_read_string(&g_prints[9], 10, "207530445072488465666");
|
||||
mbedtls_mpi_read_string(&g_prints[10], 10, "79228162521181866724264247298");
|
||||
mbedtls_mpi_read_string(&g_prints[11], 10, "1760368345969468176824550810518");
|
||||
mbedtls_mpi_read_string(&g_prints[12], 10, "50079290986288516948354744811034");
|
||||
mbedtls_mpi_read_string(&g_prints[13], 10, "473022961816146413042658758988474");
|
||||
mbedtls_mpi_read_string(&g_prints[14], 10, "144390480366845522447407333004847678774");
|
||||
mbedtls_mpi_read_string(&g_prints[15], 10, "1800793591454480341970779146165214289059119882");
|
||||
mbedtls_mpi_read_string(&g_prints[16], 10, "126304807362733370595828809000324029340048915994");
|
||||
mbedtls_mpi_read_string(&prints[0], 10, "1026");
|
||||
mbedtls_mpi_read_string(&prints[1], 10, "5658");
|
||||
mbedtls_mpi_read_string(&prints[2], 10, "107286");
|
||||
mbedtls_mpi_read_string(&prints[3], 10, "199410");
|
||||
mbedtls_mpi_read_string(&prints[4], 10, "67109890");
|
||||
mbedtls_mpi_read_string(&prints[5], 10, "5310023542746834");
|
||||
mbedtls_mpi_read_string(&prints[6], 10, "1455791217086302986");
|
||||
mbedtls_mpi_read_string(&prints[7], 10, "20052041432995567486");
|
||||
mbedtls_mpi_read_string(&prints[8], 10, "6041388139249378920330");
|
||||
mbedtls_mpi_read_string(&prints[9], 10, "207530445072488465666");
|
||||
mbedtls_mpi_read_string(&prints[10], 10, "79228162521181866724264247298");
|
||||
mbedtls_mpi_read_string(&prints[11], 10, "1760368345969468176824550810518");
|
||||
mbedtls_mpi_read_string(&prints[12], 10, "50079290986288516948354744811034");
|
||||
mbedtls_mpi_read_string(&prints[13], 10, "473022961816146413042658758988474");
|
||||
mbedtls_mpi_read_string(&prints[14], 10, "144390480366845522447407333004847678774");
|
||||
mbedtls_mpi_read_string(&prints[15], 10, "1800793591454480341970779146165214289059119882");
|
||||
mbedtls_mpi_read_string(&prints[16], 10, "126304807362733370595828809000324029340048915994");
|
||||
}
|
||||
|
||||
static void rocacheck_cleanup(void) {
|
||||
static void rocacheck_cleanup(mbedtls_mpi *prints) {
|
||||
for (int i = 0; i < ROCA_PRINTS_LENGTH; i++)
|
||||
mbedtls_mpi_free(&g_prints[i]);
|
||||
mbedtls_mpi_free(&prints[i]);
|
||||
}
|
||||
|
||||
static int bitand_is_zero(mbedtls_mpi *a, mbedtls_mpi *b) {
|
||||
@@ -97,8 +91,12 @@ bool emv_rocacheck(const unsigned char *buf, size_t buflen, bool verbose) {
|
||||
mbedtls_mpi_init(&t_modulus);
|
||||
|
||||
bool ret = false;
|
||||
mbedtls_mpi prints[ROCA_PRINTS_LENGTH];
|
||||
uint8_t primes[ROCA_PRINTS_LENGTH] = {
|
||||
11, 13, 17, 19, 37, 53, 61, 71, 73, 79, 97, 103, 107, 109, 127, 151, 157
|
||||
};
|
||||
|
||||
rocacheck_init();
|
||||
rocacheck_init(prints);
|
||||
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_read_binary(&t_modulus, buf, buflen));
|
||||
|
||||
@@ -114,13 +112,13 @@ bool emv_rocacheck(const unsigned char *buf, size_t buflen, bool verbose) {
|
||||
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_read_string(&g_one, 10, "1"));
|
||||
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_add_int(&t_prime, &t_prime, g_primes[i]));
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_add_int(&t_prime, &t_prime, primes[i]));
|
||||
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_mod_mpi(&t_temp, &t_modulus, &t_prime));
|
||||
|
||||
MBEDTLS_MPI_CHK(mbedtls_mpi_shift_l(&g_one, mpi_get_uint(&t_temp)));
|
||||
|
||||
if (bitand_is_zero(&g_one, &g_prints[i])) {
|
||||
if (bitand_is_zero(&g_one, &prints[i])) {
|
||||
if (verbose)
|
||||
PrintAndLogEx(FAILED, "No fingerprint found.\n");
|
||||
goto cleanup;
|
||||
@@ -138,7 +136,7 @@ bool emv_rocacheck(const unsigned char *buf, size_t buflen, bool verbose) {
|
||||
cleanup:
|
||||
mbedtls_mpi_free(&t_modulus);
|
||||
|
||||
rocacheck_cleanup();
|
||||
rocacheck_cleanup(prints);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user