modified some output and made sure a local state is used for multithreaded. Also added the mod fix from Doegox in sma.cpp

This commit is contained in:
iceman1001 2023-08-21 12:36:02 +02:00
parent e602287839
commit b17a733bdb
3 changed files with 34 additions and 18 deletions

View file

@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
## [unreleased][unreleased] ## [unreleased][unreleased]
- Fixed `cryptorf/sma_multi` - local state used in multithread (@iceman1001)
- Changed `fpga_compress` - better deallocation of memory and closing of file handles (@iceman1001) - Changed `fpga_compress` - better deallocation of memory and closing of file handles (@iceman1001)
- Changed `hf search` - less swaps of fpga images on device side (@iceman1001) - Changed `hf search` - less swaps of fpga images on device side (@iceman1001)
- Changed `mkversion.sh` - now regenerates version_pm3.c (and consequently the binaries) only when needed (@doegox) - Changed `mkversion.sh` - now regenerates version_pm3.c (and consequently the binaries) only when needed (@doegox)

View file

@ -159,6 +159,10 @@ void print_cs(const char *text, pcs s) {
} }
static inline uint8_t mod(uint8_t a, uint8_t m) { static inline uint8_t mod(uint8_t a, uint8_t m) {
if (m == 0) {
return 0; // Actually, divide by zero error
}
// Just return the input when this is less or equal than the modular value // Just return the input when this is less or equal than the modular value
if (a < m) return a; if (a < m) return a;
@ -754,7 +758,7 @@ int main(int argc, const char *argv[]) {
Q[pos] = rand(); Q[pos] = rand();
} }
sm_auth(Gc, Ci, Q, Ch, Ci_1, &ostate); sm_auth(Gc, Ci, Q, Ch, Ci_1, &ostate);
printf(" Gc: "); printf(" Gc... ");
print_bytes(Gc, 8); print_bytes(Gc, 8);
} else { } else {
sscanf(argv[1], "%016" SCNx64, &nCi); sscanf(argv[1], "%016" SCNx64, &nCi);
@ -765,7 +769,7 @@ int main(int argc, const char *argv[]) {
num_to_bytes(nCh, 8, Ch); num_to_bytes(nCh, 8, Ch);
sscanf(argv[4], "%016" SCNx64, &nCi_1); sscanf(argv[4], "%016" SCNx64, &nCi_1);
num_to_bytes(nCi_1, 8, Ci_1); num_to_bytes(nCi_1, 8, Ci_1);
printf(" Gc: unknown\n"); printf(" Gc... unknown\n");
} }
for (pos = 0; pos < 8; pos++) { for (pos = 0; pos < 8; pos++) {
@ -773,16 +777,16 @@ int main(int argc, const char *argv[]) {
ks[(2 * pos) + 1] = Ch[pos]; ks[(2 * pos) + 1] = Ch[pos];
} }
printf(" Ci: "); printf(" Ci... ");
print_bytes(Ci, 8); print_bytes(Ci, 8);
printf(" Q: "); printf(" Q... ");
print_bytes(Q, 8); print_bytes(Q, 8);
printf(" Ch: "); printf(" Ch... ");
print_bytes(Ch, 8); print_bytes(Ch, 8);
printf("Ci+1: "); printf("Ci+1... ");
print_bytes(Ci_1, 8); print_bytes(Ci_1, 8);
printf("\n"); printf("\n");
printf(" Ks: "); printf(" Ks... ");
print_bytes(ks, 16); print_bytes(ks, 16);
printf("\n"); printf("\n");

View file

@ -168,6 +168,7 @@ static inline uint8_t mod(uint8_t a, uint8_t m) {
if (m == 0) { if (m == 0) {
return 0; // Actually, divide by zero error return 0; // Actually, divide by zero error
} }
// Just return the input when this is less or equal than the modular value // Just return the input when this is less or equal than the modular value
if (a < m) return a; if (a < m) return a;
@ -935,9 +936,19 @@ static void ice_compare(
uint8_t *Ch, uint8_t *Ch,
uint8_t *Ci_1 uint8_t *Ci_1
) { ) {
uint8_t Gc_chk[8]; uint8_t Gc_chk[8] = {0};
uint8_t Ch_chk[ 8]; uint8_t Ch_chk[8] = {0};
uint8_t Ci_1_chk[ 8]; uint8_t Ci_1_chk[8] = {0};
crypto_state_t ls;
ls.b0 = ostate->b0;
ls.b1 = ostate->b1;
ls.b1l = ostate->b1l;
ls.b1r = ostate->b1r;
ls.b1s = ostate->b1s;
ls.l = ostate->l;
ls.m = ostate->m;
ls.r = ostate->r;
for (std::size_t i = offset; i < candidates->size(); i += skips) { for (std::size_t i = offset; i < candidates->size(); i += skips) {
if (key_found.load(std::memory_order_relaxed)) if (key_found.load(std::memory_order_relaxed))
@ -946,7 +957,7 @@ static void ice_compare(
uint64_t tkey = candidates->at(i); uint64_t tkey = candidates->at(i);
num_to_bytes(tkey, 8, Gc_chk); num_to_bytes(tkey, 8, Gc_chk);
sm_auth(Gc_chk, Ci, Q, Ch_chk, Ci_1_chk, ostate); sm_auth(Gc_chk, Ci, Q, Ch_chk, Ci_1_chk, &ls);
if ((memcmp(Ch_chk, Ch, 8) == 0) && (memcmp(Ci_1_chk, Ci_1, 8) == 0)) { if ((memcmp(Ch_chk, Ch, 8) == 0) && (memcmp(Ci_1_chk, Ci_1, 8) == 0)) {
g_ice_mtx.lock(); g_ice_mtx.lock();
key_found = true; key_found = true;
@ -1008,7 +1019,7 @@ int main(int argc, const char *argv[]) {
Q[pos] = rand(); Q[pos] = rand();
} }
sm_auth(Gc, Ci, Q, Ch, Ci_1, &ostate); sm_auth(Gc, Ci, Q, Ch, Ci_1, &ostate);
printf(" Gc: "); printf(" Gc... ");
print_bytes(Gc, 8); print_bytes(Gc, 8);
} else { } else {
sscanf(argv[1], "%016" SCNx64, &nCi); sscanf(argv[1], "%016" SCNx64, &nCi);
@ -1019,7 +1030,7 @@ int main(int argc, const char *argv[]) {
num_to_bytes(nCh, 8, Ch); num_to_bytes(nCh, 8, Ch);
sscanf(argv[4], "%016" SCNx64, &nCi_1); sscanf(argv[4], "%016" SCNx64, &nCi_1);
num_to_bytes(nCi_1, 8, Ci_1); num_to_bytes(nCi_1, 8, Ci_1);
printf(" Gc: unknown\n"); printf(" Gc... unknown\n");
} }
for (pos = 0; pos < 8; pos++) { for (pos = 0; pos < 8; pos++) {
@ -1027,16 +1038,16 @@ int main(int argc, const char *argv[]) {
ks[(2 * pos) + 1] = Ch[pos]; ks[(2 * pos) + 1] = Ch[pos];
} }
printf(" Ci: "); printf(" Ci... ");
print_bytes(Ci, 8); print_bytes(Ci, 8);
printf(" Q: "); printf(" Q... ");
print_bytes(Q, 8); print_bytes(Q, 8);
printf(" Ch: "); printf(" Ch... ");
print_bytes(Ch, 8); print_bytes(Ch, 8);
printf("Ci+1: "); printf("Ci+1... ");
print_bytes(Ci_1, 8); print_bytes(Ci_1, 8);
printf("\n"); printf("\n");
printf(" Ks: "); printf(" Ks... ");
print_bytes(ks, 16); print_bytes(ks, 16);
printf("\n"); printf("\n");