Merge branch 'master' into smartcard-relay

This commit is contained in:
Grayson Martin 2023-09-12 22:30:59 -05:00
commit 7f91da8a9a
No known key found for this signature in database
GPG key ID: 4914C62F2696A273
1001 changed files with 51581 additions and 4531 deletions

View file

@ -371,7 +371,7 @@ uint64_t CRACK_STATES_BITSLICED(uint32_t cuid, uint8_t *best_first_bytes, statel
for (uint32_t tests = 0; tests < nonces_to_bruteforce; ++tests) {
// common bits with preceding test nonce
uint32_t common_bits = next_common_bits; //tests ? trailing_zeros(bf_test_nonce_2nd_byte[tests] ^ bf_test_nonce_2nd_byte[tests-1]) : 0;
next_common_bits = tests < nonces_to_bruteforce - 1 ? trailing_zeros(bf_test_nonce_2nd_byte[tests] ^ bf_test_nonce_2nd_byte[tests + 1]) : 0;
next_common_bits = (tests < nonces_to_bruteforce - 1) ? trailing_zeros(bf_test_nonce_2nd_byte[tests] ^ bf_test_nonce_2nd_byte[tests + 1]) : 0;
uint32_t parity_bit_idx = 1; // start checking with the parity of second nonce byte
bitslice_value_t fb_bits = fbb[common_bits]; // start with precomputed feedback bits from previous nonce
bitslice_value_t ks_bits = ksb[common_bits]; // dito for first keystream bits

View file

@ -96,7 +96,7 @@ static uint32_t keys_found = 0;
static uint64_t num_keys_tested;
static uint64_t found_bs_key = 0;
inline uint8_t trailing_zeros(uint8_t byte) {
uint8_t trailing_zeros(uint8_t byte) {
static const uint8_t trailing_zeros_LUT[256] = {
8, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
@ -304,12 +304,13 @@ static bool ensure_buckets_alloc(size_t need_buckets) {
while (need_buckets > alloc_sz) {
alloc_sz *= 2;
}
buckets = realloc(buckets, sizeof(statelist_t *) * alloc_sz);
if (buckets == NULL) {
statelist_t **new_buckets = realloc(buckets, sizeof(statelist_t *) * alloc_sz);
if (new_buckets == NULL) {
free(buckets);
buckets_allocated = 0;
return false;
}
buckets = new_buckets;
memset(buckets + buckets_allocated, 0, (alloc_sz - buckets_allocated) * sizeof(statelist_t *));
buckets_allocated = alloc_sz;
}
@ -412,11 +413,14 @@ static bool read_bench_data(statelist_t *test_candidates) {
return false;
}
free(path);
bytes_read = fread(&nonces_to_bruteforce, 1, sizeof(nonces_to_bruteforce), benchfile);
if (bytes_read != sizeof(nonces_to_bruteforce)) {
// read 4 bytes of data ?
bytes_read = fread(&nonces_to_bruteforce, 1, sizeof(uint32_t), benchfile);
if (bytes_read != sizeof(uint32_t) || (nonces_to_bruteforce >= 256)) {
fclose(benchfile);
return false;
}
for (uint32_t i = 0; i < nonces_to_bruteforce && i < 256; i++) {
bytes_read = fread(&bf_test_nonce[i], 1, sizeof(uint32_t), benchfile);
if (bytes_read != sizeof(uint32_t)) {
@ -430,11 +434,13 @@ static bool read_bench_data(statelist_t *test_candidates) {
return false;
}
}
bytes_read = fread(&num_states, 1, sizeof(uint32_t), benchfile);
if (bytes_read != sizeof(uint32_t)) {
fclose(benchfile);
return false;
}
for (states_read = 0; states_read < MIN(num_states, TEST_BENCH_SIZE); states_read++) {
bytes_read = fread(test_candidates->states[EVEN_STATE] + states_read, 1, sizeof(uint32_t), benchfile);
if (bytes_read != sizeof(uint32_t)) {
@ -442,9 +448,11 @@ static bool read_bench_data(statelist_t *test_candidates) {
return false;
}
}
for (uint32_t i = states_read; i < TEST_BENCH_SIZE; i++) {
test_candidates->states[EVEN_STATE][i] = test_candidates->states[EVEN_STATE][i - states_read];
}
for (uint32_t i = states_read; i < num_states; i++) {
bytes_read = fread(&temp, 1, sizeof(uint32_t), benchfile);
if (bytes_read != sizeof(uint32_t)) {
@ -452,6 +460,7 @@ static bool read_bench_data(statelist_t *test_candidates) {
return false;
}
}
for (states_read = 0; states_read < MIN(num_states, TEST_BENCH_SIZE); states_read++) {
bytes_read = fread(test_candidates->states[ODD_STATE] + states_read, 1, sizeof(uint32_t), benchfile);
if (bytes_read != sizeof(uint32_t)) {
@ -459,6 +468,7 @@ static bool read_bench_data(statelist_t *test_candidates) {
return false;
}
}
for (uint32_t i = states_read; i < TEST_BENCH_SIZE; i++) {
test_candidates->states[ODD_STATE][i] = test_candidates->states[ODD_STATE][i - states_read];
}

View file

@ -10,8 +10,8 @@ add_library(pm3rrg_rdv4_mbedtls STATIC
../../common/mbedtls/error.c
../../common/mbedtls/ecp.c
../../common/mbedtls/ecdh.c
../../common/mbedtls/ecc_point_compression.c
../../common/mbedtls/gcm.c
../../common/mbedtls/ecc_point_compression.c
../../common/mbedtls/gcm.c
../../common/mbedtls/ecp_curves.c
../../common/mbedtls/certs.c
../../common/mbedtls/camellia.c

View file

@ -232,21 +232,21 @@ static inline void put64(void *where, uint64_t v) {
memcpy(where, &v, sizeof(v));
}
static inline bool would_overflow(CborEncoder *encoder, size_t len) {
static bool would_overflow(CborEncoder *encoder, size_t len) {
ptrdiff_t remaining = (ptrdiff_t)encoder->end;
remaining -= remaining ? (ptrdiff_t)encoder->data.ptr : encoder->data.bytes_needed;
remaining -= (ptrdiff_t)len;
return unlikely(remaining < 0);
}
static inline void advance_ptr(CborEncoder *encoder, size_t n) {
static void advance_ptr(CborEncoder *encoder, size_t n) {
if (encoder->end)
encoder->data.ptr += n;
else
encoder->data.bytes_needed += n;
}
static inline CborError append_to_buffer(CborEncoder *encoder, const void *data, size_t len) {
static CborError append_to_buffer(CborEncoder *encoder, const void *data, size_t len) {
if (would_overflow(encoder, len)) {
if (encoder->end != NULL) {
len -= encoder->end - encoder->data.ptr;
@ -263,11 +263,11 @@ static inline CborError append_to_buffer(CborEncoder *encoder, const void *data,
return CborNoError;
}
static inline CborError append_byte_to_buffer(CborEncoder *encoder, uint8_t byte) {
static CborError append_byte_to_buffer(CborEncoder *encoder, uint8_t byte) {
return append_to_buffer(encoder, &byte, 1);
}
static inline CborError encode_number_no_update(CborEncoder *encoder, uint64_t ui, uint8_t shiftedMajorType) {
static CborError encode_number_no_update(CborEncoder *encoder, uint64_t ui, uint8_t shiftedMajorType) {
/* Little-endian would have been so much more convenient here:
* We could just write at the beginning of buf but append_to_buffer
* only the necessary bytes.

View file

@ -142,19 +142,19 @@
* \endif
*/
static inline uint16_t get16(const uint8_t *ptr) {
static uint16_t get16(const uint8_t *ptr) {
uint16_t result;
memcpy(&result, ptr, sizeof(result));
return cbor_ntohs(result);
}
static inline uint32_t get32(const uint8_t *ptr) {
static uint32_t get32(const uint8_t *ptr) {
uint32_t result;
memcpy(&result, ptr, sizeof(result));
return cbor_ntohl(result);
}
static inline uint64_t get64(const uint8_t *ptr) {
static uint64_t get64(const uint8_t *ptr) {
uint64_t result;
memcpy(&result, ptr, sizeof(result));
return cbor_ntohll(result);
@ -949,7 +949,7 @@ CborError cbor_value_calculate_string_length(const CborValue *value, size_t *len
return _cbor_value_copy_string(value, NULL, len, NULL);
}
static inline void prepare_string_iteration(CborValue *it) {
static void prepare_string_iteration(CborValue *it) {
if (!cbor_value_is_length_known(it)) {
/* chunked string: we're before the first chunk;
* advance to the first chunk */