run "make style"

This commit is contained in:
PhaseLoop 2023-05-08 17:08:24 +00:00
commit 19d7851c73
7 changed files with 124 additions and 98 deletions

View file

@ -28,50 +28,50 @@ uint8_t charset_uppercase[] = {
'X', 'Y', 'Z'
};
void bf_generator_init(generator_context_t* ctx, uint8_t mode){
void bf_generator_init(generator_context_t *ctx, uint8_t mode) {
memset(ctx, 0, sizeof(generator_context_t));
ctx->mode = mode;
}
int bf_generator_set_charset(generator_context_t* ctx, uint8_t charsets){
if (ctx->mode != BRUTEFORCE_MODE_CHARSET){
int bf_generator_set_charset(generator_context_t *ctx, uint8_t charsets) {
if (ctx->mode != BRUTEFORCE_MODE_CHARSET) {
return -1;
}
if(charsets & CHARSET_DIGITS){
if (charsets & CHARSET_DIGITS) {
memcpy(ctx->charset, charset_digits, sizeof(charset_digits));
ctx->charset_length += sizeof(charset_digits);
}
if(charsets & CHARSET_UPPERCASE){
memcpy(ctx->charset+ctx->charset_length, charset_uppercase, sizeof(charset_uppercase));
if (charsets & CHARSET_UPPERCASE) {
memcpy(ctx->charset + ctx->charset_length, charset_uppercase, sizeof(charset_uppercase));
ctx->charset_length += sizeof(charset_uppercase);
}
return 0;
}
int bf_generate32(generator_context_t *ctx){
int bf_generate32(generator_context_t *ctx) {
switch(ctx->mode){
switch (ctx->mode) {
case BRUTEFORCE_MODE_RANGE:
return _bf_generate_mode_range32(ctx);
case BRUTEFORCE_MODE_CHARSET:
return _bf_generate_mode_charset32(ctx);
}
}
return GENERATOR_ERROR;
return GENERATOR_ERROR;
}
int _bf_generate_mode_range32(generator_context_t *ctx){
if(ctx->current_key32 >= ctx->range_high){
int _bf_generate_mode_range32(generator_context_t *ctx) {
if (ctx->current_key32 >= ctx->range_high) {
return GENERATOR_END;
}
// we use flag1 as indicator if value of range_low was already emitted
// so the range generated is <range_low, range_high>
if(ctx->current_key32 <= ctx->range_low && ctx->flag1==false){
if (ctx->current_key32 <= ctx->range_low && ctx->flag1 == false) {
ctx->current_key32 = ctx->range_low;
ctx->pos[0] = true;
return GENERATOR_NEXT;
@ -81,44 +81,44 @@ int _bf_generate_mode_range32(generator_context_t *ctx){
return GENERATOR_NEXT;
}
int _bf_generate_mode_charset32(generator_context_t *ctx){
int _bf_generate_mode_charset32(generator_context_t *ctx) {
if(ctx->flag1)
if (ctx->flag1)
return GENERATOR_END;
ctx->current_key32 = ctx->charset[ctx->pos[0]] << 24 | ctx->charset[ctx->pos[1]] << 16 |
ctx->charset[ctx->pos[2]] << 8 | ctx->charset[ctx->pos[3]];
if(bf_array_increment(ctx->pos, 4, ctx->charset_length) == -1)
if (bf_array_increment(ctx->pos, 4, ctx->charset_length) == -1)
// set flag1 to emit value last time and end generation
ctx->flag1 = true;
return GENERATOR_NEXT;
}
// increments values in array with carryover using modulo limit for each byte
// this is used to iterate each byte in key over charset table
// returns -1 if incrementing reaches its end
int bf_array_increment(uint8_t *data, uint8_t data_len, uint8_t modulo){
int bf_array_increment(uint8_t *data, uint8_t data_len, uint8_t modulo) {
uint8_t prev_value;
// check if we reached max value already
uint8_t i;
for (i = 0; i < data_len; i++)
if(data[i] < modulo - 1)
if (data[i] < modulo - 1)
break;
if(i == data_len)
return -1;
if (i == data_len)
return -1;
for (uint8_t pos = data_len - 1;; pos--){
for (uint8_t pos = data_len - 1;; pos--) {
prev_value = ++data[pos];
data[pos] = data[pos] % modulo;
if (prev_value == data[pos])
return 0;
else if (pos == 0){
else if (pos == 0) {
// we cannot carryover to next byte
// with the max value check in place before, we should not reach this place
return -1;
@ -144,4 +144,4 @@ int main(){
// printf("Uppercase len: %d\n", sizeof(charset_uppercase));
return 1;
}
*/
*/

View file

@ -25,11 +25,11 @@ typedef uint8_t bruteforce_mode_t;
// bruteforcing all keys sequentially between X and Y
#define BRUTEFORCE_MODE_RANGE 1
// try keys based on limited charset/passphrases
// try keys based on limited charset/passphrases
// some payment systems use user-provided passphrase as system key
#define BRUTEFORCE_MODE_CHARSET 2
// "smart" mode - try some predictable patterns
// "smart" mode - try some predictable patterns
#define BRUTEFORCE_MODE_SMART 3
@ -57,8 +57,8 @@ typedef struct {
uint32_t current_key32;
uint8_t mode;
uint8_t charset[
CHARSET_DIGITS_SIZE
+ CHARSET_UPPERCASE_SIZE
CHARSET_DIGITS_SIZE
+ CHARSET_UPPERCASE_SIZE
];
uint8_t charset_length;
@ -76,4 +76,4 @@ int _bf_generate_mode_range32(generator_context_t *ctx);
int _bf_generate_mode_charset32(generator_context_t *ctx);
int _bf_generate_mode_smart32(generator_context_t *ctx);
int bf_array_increment(uint8_t *data, uint8_t data_len, uint8_t modulo);
#endif // BRUTEFORCE_H__
#endif // BRUTEFORCE_H__