use C99 for loop where possible

This commit is contained in:
Pavol Rusnak 2017-07-23 22:20:51 +02:00
parent e9fb5b08c7
commit 3d7d0f0734
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
15 changed files with 86 additions and 128 deletions

View File

@ -289,8 +289,7 @@ uint8_t *cryptoHDNodePathToPubkey(const HDNodePathType *hdnodepath)
return 0;
}
layoutProgressUpdate(true);
uint32_t i;
for (i = 0; i < hdnodepath->address_n_count; i++) {
for (uint32_t i = 0; i < hdnodepath->address_n_count; i++) {
if (hdnode_public_ckd(&node, hdnodepath->address_n[i]) == 0) {
return 0;
}
@ -301,8 +300,7 @@ uint8_t *cryptoHDNodePathToPubkey(const HDNodePathType *hdnodepath)
int cryptoMultisigPubkeyIndex(const MultisigRedeemScriptType *multisig, const uint8_t *pubkey)
{
size_t i;
for (i = 0; i < multisig->pubkeys_count; i++) {
for (size_t i = 0; i < multisig->pubkeys_count; i++) {
const uint8_t *node_pubkey = cryptoHDNodePathToPubkey(&(multisig->pubkeys[i]));
if (node_pubkey && memcmp(node_pubkey, pubkey, 33) == 0) {
return i;
@ -318,17 +316,16 @@ int cryptoMultisigFingerprint(const MultisigRedeemScriptType *multisig, uint8_t
if (n > 15) {
return 0;
}
uint32_t i, j;
// check sanity
if (!multisig->has_m || multisig->m < 1 || multisig->m > 15) return 0;
for (i = 0; i < n; i++) {
for (uint32_t i = 0; i < n; i++) {
ptr[i] = &(multisig->pubkeys[i]);
if (!ptr[i]->node.has_public_key || ptr[i]->node.public_key.size != 33) return 0;
if (ptr[i]->node.chain_code.size != 32) return 0;
}
// minsort according to pubkey
for (i = 0; i < n - 1; i++) {
for (j = n - 1; j > i; j--) {
for (uint32_t i = 0; i < n - 1; i++) {
for (uint32_t j = n - 1; j > i; j--) {
if (memcmp(ptr[i]->node.public_key.bytes, ptr[j]->node.public_key.bytes, 33) > 0) {
swap = ptr[i];
ptr[i] = ptr[j];
@ -340,7 +337,7 @@ int cryptoMultisigFingerprint(const MultisigRedeemScriptType *multisig, uint8_t
SHA256_CTX ctx;
sha256_Init(&ctx);
sha256_Update(&ctx, (const uint8_t *)&(multisig->m), sizeof(uint32_t));
for (i = 0; i < n; i++) {
for (uint32_t i = 0; i < n; i++) {
sha256_Update(&ctx, (const uint8_t *)&(ptr[i]->node.depth), sizeof(uint32_t));
sha256_Update(&ctx, (const uint8_t *)&(ptr[i]->node.fingerprint), sizeof(uint32_t));
sha256_Update(&ctx, (const uint8_t *)&(ptr[i]->node.child_num), sizeof(uint32_t));

View File

@ -26,15 +26,14 @@
void oledDebug(const char *line)
{
int i;
static const char *lines[8] = {0, 0, 0, 0, 0, 0, 0, 0};
static char id = 3;
for (i = 0; i < 7; i++) {
for (int i = 0; i < 7; i++) {
lines[i] = lines[i + 1];
}
lines[7] = line;
oledClear();
for (i = 0; i < 8; i++) {
for (int i = 0; i < 8; i++) {
if (lines[i]) {
oledDrawChar(0, i * 8, '0' + (id + i) % 10, 1);
oledDrawString(8, i * 8, lines[i]);

View File

@ -283,12 +283,12 @@ static void layoutEthereumData(const uint8_t *data, uint32_t len, uint32_t total
{
char hexdata[3][17];
char summary[20];
int i;
uint32_t printed = 0;
for (i = 0; i < 3; i++) {
for (int i = 0; i < 3; i++) {
uint32_t linelen = len - printed;
if (linelen > 8)
if (linelen > 8) {
linelen = 8;
}
data2hex(data, linelen, hexdata[i]);
data += linelen;
printed += linelen;

View File

@ -1169,7 +1169,7 @@ void fsm_msgDebugLinkMemoryWrite(DebugLinkMemoryWrite *msg)
if (msg->flash) {
flash_clear_status_flags();
flash_unlock();
for (unsigned int i = 0; i < length; i += 4) {
for (uint32_t i = 0; i < length; i += 4) {
uint32_t word;
memcpy(&word, msg->memory.bytes + i, 4);
flash_program_word(msg->address + i, word);

View File

@ -143,8 +143,7 @@ static inline void msg_debug_out_pad(void)
static bool pb_callback_out(pb_ostream_t *stream, const uint8_t *buf, size_t count)
{
(void)stream;
size_t i;
for (i = 0; i < count; i++) {
for (size_t i = 0; i < count; i++) {
msg_out_append(buf[i]);
}
return true;
@ -155,8 +154,7 @@ static bool pb_callback_out(pb_ostream_t *stream, const uint8_t *buf, size_t cou
static bool pb_debug_callback_out(pb_ostream_t *stream, const uint8_t *buf, size_t count)
{
(void)stream;
size_t i;
for (i = 0; i < count; i++) {
for (size_t i = 0; i < count; i++) {
msg_debug_out_append(buf[i]);
}
return true;

View File

@ -33,11 +33,10 @@ void pinmatrix_draw(const char *text)
};
oledSwipeLeft();
const int w = bmp_digit0.width, h = bmp_digit0.height, pad = 2;
int i, j, k;
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
// use (2 - j) instead of j to achieve 789456123 layout
k = pinmatrix_perm[i + (2 - j) * 3] - '0';
int k = pinmatrix_perm[i + (2 - j) * 3] - '0';
if (text) {
oledDrawStringCenter(0, text);
}
@ -49,8 +48,7 @@ void pinmatrix_draw(const char *text)
void pinmatrix_start(const char *text)
{
int i;
for (i = 0; i < 9; i++) {
for (int i = 0; i < 9; i++) {
pinmatrix_perm[i] = '1' + i;
}
pinmatrix_perm[9] = 0;

View File

@ -130,11 +130,10 @@ static void recovery_request(void) {
* Check mnemonic and send success/failure.
*/
static void recovery_done(void) {
uint32_t i;
char new_mnemonic[sizeof(storage.mnemonic)] = {0};
strlcpy(new_mnemonic, words[0], sizeof(new_mnemonic));
for (i = 1; i < word_count; i++) {
for (uint32_t i = 1; i < word_count; i++) {
strlcat(new_mnemonic, " ", sizeof(new_mnemonic));
strlcat(new_mnemonic, words[i], sizeof(new_mnemonic));
}
@ -202,9 +201,8 @@ static void recovery_done(void) {
*/
static void add_choice(char choice[12], int prefixlen, const char *first, const char *last) {
// assert prefixlen < 4
int i;
char *dest = choice;
for (i = 0; i < prefixlen; i++) {
for (int i = 0; i < prefixlen; i++) {
*dest++ = toupper((int) first[i]);
}
if (first[0] != last[0]) {
@ -216,7 +214,7 @@ static void add_choice(char choice[12], int prefixlen, const char *first, const
} else if (prefixlen < 3) {
/* AB-AC, etc. */
*dest++ = '-';
for (i = 0; i < prefixlen; i++) {
for (int i = 0; i < prefixlen; i++) {
*dest++ = toupper((int) last[i]);
}
} else {
@ -240,11 +238,9 @@ static void add_choice(char choice[12], int prefixlen, const char *first, const
*/
static void display_choices(bool twoColumn, char choices[9][12], int num)
{
int i;
int nColumns = twoColumn ? 2 : 3;
int displayedChoices = nColumns * 3;
int row, col;
for (i = 0; i < displayedChoices; i++) {
const int nColumns = twoColumn ? 2 : 3;
const int displayedChoices = nColumns * 3;
for (int i = 0; i < displayedChoices; i++) {
word_matrix[i] = i;
}
/* scramble matrix */
@ -259,9 +255,9 @@ static void display_choices(bool twoColumn, char choices[9][12], int num)
oledBox(0, 27, 127, 63, false);
}
for (row = 0; row < 3; row ++) {
for (int row = 0; row < 3; row ++) {
int y = 55 - row * 11;
for (col = 0; col < nColumns; col++) {
for (int col = 0; col < nColumns; col++) {
int x = twoColumn ? 64 * col + 32 : 42 * col + 22;
int choice = word_matrix[nColumns*row + col];
const char *text = choice < num ? choices[choice] : "-";
@ -276,14 +272,14 @@ static void display_choices(bool twoColumn, char choices[9][12], int num)
oledRefresh();
/* avoid picking out of range numbers */
for (i = 0; i < displayedChoices; i++) {
for (int i = 0; i < displayedChoices; i++) {
if (word_matrix[i] > num)
word_matrix[i] = 0;
}
/* two column layout: middle column = right column */
if (twoColumn) {
static const uint8_t twolayout[9] = { 0, 1, 1, 2, 3, 3, 4, 5, 5 };
for (i = 8; i >= 2; i--) {
for (int i = 8; i >= 2; i--) {
word_matrix[i] = word_matrix[twolayout[i]];
}
}
@ -295,15 +291,15 @@ static void display_choices(bool twoColumn, char choices[9][12], int num)
static void next_matrix(void) {
const char * const *wl = mnemonic_wordlist();
char word_choices[9][12];
uint32_t i, idx, first, num;
uint32_t idx, num;
bool last = (word_index % 4) == 3;
switch (word_index % 4) {
case 3:
idx = TABLE1(word_pincode / 9) + word_pincode % 9;
first = word_table2[idx] & 0xfff;
num = (word_table2[idx+1] & 0xfff) - first;
for (i = 0; i < num; i++) {
const uint32_t first = word_table2[idx] & 0xfff;
num = (word_table2[idx + 1] & 0xfff) - first;
for (uint32_t i = 0; i < num; i++) {
strlcpy(word_choices[i], wl[first + i], sizeof(word_choices[i]));
}
break;
@ -311,7 +307,7 @@ static void next_matrix(void) {
case 2:
idx = TABLE1(word_pincode);
num = TABLE1(word_pincode + 1) - idx;
for (i = 0; i < num; i++) {
for (uint32_t i = 0; i < num; i++) {
add_choice(word_choices[i], (word_table2[idx + i] >> 12),
wl[TABLE2(idx + i)],
wl[TABLE2(idx + i + 1) - 1]);
@ -321,7 +317,7 @@ static void next_matrix(void) {
case 1:
idx = word_pincode * 9;
num = 9;
for (i = 0; i < num; i++) {
for (uint32_t i = 0; i < num; i++) {
add_choice(word_choices[i], (word_table1[idx + i] >> 12),
wl[TABLE2(TABLE1(idx + i))],
wl[TABLE2(TABLE1(idx + i + 1)) - 1]);
@ -330,7 +326,7 @@ static void next_matrix(void) {
case 0:
num = 9;
for (i = 0; i < num; i++) {
for (uint32_t i = 0; i < num; i++) {
add_choice(word_choices[i], 1,
wl[TABLE2(TABLE1(9*i))],
wl[TABLE2(TABLE1(9*(i+1)))-1]);
@ -437,11 +433,10 @@ void recovery_init(uint32_t _word_count, bool passphrase_protection, bool pin_pr
word_index = 0;
next_matrix();
} else {
uint32_t i;
for (i = 0; i < word_count; i++) {
for (uint32_t i = 0; i < word_count; i++) {
word_order[i] = i + 1;
}
for (i = word_count; i < 24; i++) {
for (uint32_t i = word_count; i < 24; i++) {
word_order[i] = 0;
}
random_permute(word_order, 24);

View File

@ -120,13 +120,11 @@ void reset_backup(bool separated)
storage.needs_backup = false;
storage_commit();
int pass, word_pos, i = 0, j;
for (pass = 0; pass < 2; pass++) {
i = 0;
for (word_pos = 1; word_pos <= (int)strength/32*3; word_pos++) {
for (int pass = 0; pass < 2; pass++) {
int i = 0;
for (int word_pos = 1; word_pos <= (int)strength/32*3; word_pos++) {
// copy current_word
j = 0;
int j = 0;
while (storage.mnemonic[i] != ' ' && storage.mnemonic[i] != 0 && j + 1 < (int)sizeof(current_word)) {
current_word[j] = storage.mnemonic[i];
i++; j++;

View File

@ -702,8 +702,6 @@ static bool signing_sign_segwit_input(TxInputType *txinput) {
resp.serialized.signature.size = ecdsa_sig_to_der(sig, resp.serialized.signature.bytes);
if (txinput->has_multisig) {
uint32_t r, i, script_len;
int nwitnesses;
// fill in the signature
int pubkey_idx = cryptoMultisigPubkeyIndex(&(txinput->multisig), node.public_key);
if (pubkey_idx < 0) {
@ -714,10 +712,10 @@ static bool signing_sign_segwit_input(TxInputType *txinput) {
memcpy(txinput->multisig.signatures[pubkey_idx].bytes, resp.serialized.signature.bytes, resp.serialized.signature.size);
txinput->multisig.signatures[pubkey_idx].size = resp.serialized.signature.size;
r = 1; // skip number of items (filled in later)
uint32_t r = 1; // skip number of items (filled in later)
resp.serialized.serialized_tx.bytes[r] = 0; r++;
nwitnesses = 2;
for (i = 0; i < txinput->multisig.signatures_count; i++) {
int nwitnesses = 2;
for (uint32_t i = 0; i < txinput->multisig.signatures_count; i++) {
if (txinput->multisig.signatures[i].size == 0) {
continue;
}
@ -725,7 +723,7 @@ static bool signing_sign_segwit_input(TxInputType *txinput) {
txinput->multisig.signatures[i].bytes[txinput->multisig.signatures[i].size] = 1;
r += tx_serialize_script(txinput->multisig.signatures[i].size + 1, txinput->multisig.signatures[i].bytes, resp.serialized.serialized_tx.bytes + r);
}
script_len = compile_script_multisig(&txinput->multisig, 0);
uint32_t script_len = compile_script_multisig(&txinput->multisig, 0);
r += ser_length(script_len, resp.serialized.serialized_tx.bytes + r);
r += compile_script_multisig(&txinput->multisig, resp.serialized.serialized_tx.bytes + r);
resp.serialized.serialized_tx.bytes[0] = nwitnesses;

View File

@ -212,8 +212,7 @@ void session_clear(bool clear_pin)
}
static uint32_t storage_flash_words(uint32_t addr, uint32_t *src, int nwords) {
int i;
for (i = 0; i < nwords; i++) {
for (int i = 0; i < nwords; i++) {
flash_program_word(addr, *src++);
addr += 4;
}

View File

@ -249,10 +249,10 @@ uint32_t compile_script_multisig(const MultisigRedeemScriptType *multisig, uint8
const uint32_t n = multisig->pubkeys_count;
if (m < 1 || m > 15) return 0;
if (n < 1 || n > 15) return 0;
uint32_t i, r = 0;
uint32_t r = 0;
if (out) {
out[r] = 0x50 + m; r++;
for (i = 0; i < n; i++) {
for (uint32_t i = 0; i < n; i++) {
out[r] = 33; r++; // OP_PUSH 33
const uint8_t *pubkey = cryptoHDNodePathToPubkey(&(multisig->pubkeys[i]));
if (!pubkey) return 0;
@ -279,8 +279,7 @@ uint32_t compile_script_multisig_hash(const MultisigRedeemScriptType *multisig,
uint8_t d[2];
d[0] = 0x50 + m; sha256_Update(&ctx, d, 1);
uint32_t i;
for (i = 0; i < n; i++) {
for (uint32_t i = 0; i < n; i++) {
d[0] = 33; sha256_Update(&ctx, d, 1); // OP_PUSH 33
const uint8_t *pubkey = cryptoHDNodePathToPubkey(&(multisig->pubkeys[i]));
if (!pubkey) return 0;
@ -308,9 +307,9 @@ uint32_t serialize_script_sig(const uint8_t *signature, uint32_t signature_len,
uint32_t serialize_script_multisig(const MultisigRedeemScriptType *multisig, uint8_t *out)
{
uint32_t i, r = 0;
uint32_t r = 0;
out[r] = 0x00; r++;
for (i = 0; i < multisig->signatures_count; i++) {
for (uint32_t i = 0; i < multisig->signatures_count; i++) {
if (multisig->signatures[i].size == 0) {
continue;
}
@ -331,8 +330,7 @@ uint32_t serialize_script_multisig(const MultisigRedeemScriptType *multisig, uin
uint32_t tx_prevout_hash(SHA256_CTX *ctx, const TxInputType *input)
{
int i;
for (i = 0; i < 32; i++) {
for (int i = 0; i < 32; i++) {
sha256_Update(ctx, &(input->prev_hash.bytes[31 - i]), 1);
}
sha256_Update(ctx, (const uint8_t *)&input->prev_index, 4);
@ -391,7 +389,6 @@ uint32_t tx_serialize_header_hash(TxStruct *tx)
uint32_t tx_serialize_input(TxStruct *tx, const TxInputType *input, uint8_t *out)
{
int i;
if (tx->have_inputs >= tx->inputs_len) {
// already got all inputs
return 0;
@ -400,7 +397,7 @@ uint32_t tx_serialize_input(TxStruct *tx, const TxInputType *input, uint8_t *out
if (tx->have_inputs == 0) {
r += tx_serialize_header(tx, out + r);
}
for (i = 0; i < 32; i++) {
for (int i = 0; i < 32; i++) {
*(out + r + i) = input->prev_hash.bytes[31 - i];
}
r += 32;
@ -558,9 +555,8 @@ void tx_hash_final(TxStruct *t, uint8_t *hash, bool reverse)
sha256_Final(&(t->ctx), hash);
sha256_Raw(hash, 32, hash);
if (!reverse) return;
uint8_t i, k;
for (i = 0; i < 16; i++) {
k = hash[31 - i];
for (uint8_t i = 0; i < 16; i++) {
uint8_t k = hash[31 - i];
hash[31 - i] = hash[i];
hash[i] = k;
}

View File

@ -431,10 +431,9 @@ void u2f_version(const APDU *a)
}
void getReadableAppId(const uint8_t appid[U2F_APPID_SIZE], const char **appname, const BITMAP **appicon) {
unsigned int i;
static char buf[8+2+8+1];
for (i = 0; i < sizeof(u2f_well_known)/sizeof(U2FWellKnown); i++) {
for (unsigned int i = 0; i < sizeof(u2f_well_known)/sizeof(U2FWellKnown); i++) {
if (memcmp(appid, u2f_well_known[i].appid, U2F_APPID_SIZE) == 0) {
*appname = u2f_well_known[i].appname;
*appicon = u2f_well_known[i].appicon;
@ -473,9 +472,9 @@ const HDNode *generateKeyHandle(const uint8_t app_id[], uint8_t key_handle[])
uint8_t keybase[U2F_APPID_SIZE + KEY_PATH_LEN];
// Derivation path is m/U2F'/r'/r'/r'/r'/r'/r'/r'/r'
uint32_t i, key_path[KEY_PATH_ENTRIES];
uint32_t key_path[KEY_PATH_ENTRIES];
key_path[0] = U2F_KEY_PATH;
for (i = 1; i < KEY_PATH_ENTRIES; i++) {
for (uint32_t i = 1; i < KEY_PATH_ENTRIES; i++) {
// high bit for hardened keys
key_path[i]= 0x80000000 | random32();
}

58
oled.c
View File

@ -81,9 +81,8 @@ static bool is_debug_link = 0;
*/
inline void SPISend(uint32_t base, uint8_t *data, int len)
{
int i;
delay(1);
for (i = 0; i < len; i++) {
for (int i = 0; i < len; i++) {
spi_send(base, data[i]);
}
while (!(SPI_SR(base) & SPI_SR_TXE));
@ -219,17 +218,13 @@ void oledClearPixel(int x, int y)
void oledDrawChar(int x, int y, char c, int zoom)
{
int char_width;
const uint8_t *char_data;
if ((x >= OLED_WIDTH) || (y >= OLED_HEIGHT)) return;
char_width = fontCharWidth(c);
char_data = fontCharData(c);
int char_width = fontCharWidth(c);
const uint8_t *char_data = fontCharData(c);
int xo, yo;
for (xo = 0; xo < char_width; xo++) {
for (yo = 0; yo < FONT_HEIGHT; yo++) {
for (int xo = 0; xo < char_width; xo++) {
for (int yo = 0; yo < FONT_HEIGHT; yo++) {
if (char_data[xo] & (1 << (FONT_HEIGHT - 1 - yo))) {
if (zoom <= 1) {
oledDrawPixel(x + xo, y + yo);
@ -254,9 +249,8 @@ char oledConvertChar(const char c) {
int oledStringWidth(const char *text) {
if (!text) return 0;
int l = 0;
char c;
for (; *text; text++) {
c = oledConvertChar(*text);
char c = oledConvertChar(*text);
if (c) {
l += fontCharWidth(c) + 1;
}
@ -273,9 +267,8 @@ void oledDrawString(int x, int y, const char* text)
size = 2;
}
int l = 0;
char c;
for (; *text; text++) {
c = oledConvertChar(*text);
char c = oledConvertChar(*text);
if (c) {
oledDrawChar(x + l, y, c, size);
l += size * (fontCharWidth(c) + 1);
@ -299,9 +292,8 @@ void oledDrawStringRight(int x, int y, const char* text)
void oledDrawBitmap(int x, int y, const BITMAP *bmp)
{
int i, j;
for (i = 0; i < min(bmp->width, OLED_WIDTH - x); i++) {
for (j = 0; j < min(bmp->height, OLED_HEIGHT - y); j++) {
for (int i = 0; i < min(bmp->width, OLED_WIDTH - x); i++) {
for (int j = 0; j < min(bmp->height, OLED_HEIGHT - y); j++) {
if (bmp->data[(i / 8) + j * bmp->width / 8] & (1 << (7 - i % 8))) {
OLED_BUFSET(x + i, y + j);
} else {
@ -314,9 +306,8 @@ void oledDrawBitmap(int x, int y, const BITMAP *bmp)
void oledInvert(int x1, int y1, int x2, int y2)
{
if ((x1 >= OLED_WIDTH) || (y1 >= OLED_HEIGHT) || (x2 >= OLED_WIDTH) || (y2 >= OLED_HEIGHT)) return;
int x, y;
for (x = x1; x <= x2; x++) {
for (y = y1; y <= y2; y++) {
for (int x = x1; x <= x2; x++) {
for (int y = y1; y <= y2; y++) {
OLED_BUFTGL(x,y);
}
}
@ -327,17 +318,15 @@ void oledInvert(int x1, int y1, int x2, int y2)
*/
void oledBox(int x1, int y1, int x2, int y2, bool set)
{
int x, y;
for (x = x1; x <= x2; x++) {
for (y = y1; y <= y2; y++) {
for (int x = x1; x <= x2; x++) {
for (int y = y1; y <= y2; y++) {
set ? oledDrawPixel(x, y) : oledClearPixel(x, y);
}
}
}
void oledHLine(int y) {
int x;
for (x = 0; x < OLED_WIDTH; x++) {
for (int x = 0; x < OLED_WIDTH; x++) {
oledDrawPixel(x, y);
}
}
@ -347,12 +336,11 @@ void oledHLine(int y) {
*/
void oledFrame(int x1, int y1, int x2, int y2)
{
int x, y;
for (x = x1; x <= x2; x++) {
for (int x = x1; x <= x2; x++) {
oledDrawPixel(x, y1);
oledDrawPixel(x, y2);
}
for (y = y1 + 1; y < y2; y++) {
for (int y = y1 + 1; y < y2; y++) {
oledDrawPixel(x1, y);
oledDrawPixel(x2, y);
}
@ -364,10 +352,9 @@ void oledFrame(int x1, int y1, int x2, int y2)
*/
void oledSwipeLeft(void)
{
int i, j, k;
for (i = 0; i < OLED_WIDTH; i++) {
for (j = 0; j < OLED_HEIGHT / 8; j++) {
for (k = OLED_WIDTH-1; k > 0; k--) {
for (int i = 0; i < OLED_WIDTH; i++) {
for (int j = 0; j < OLED_HEIGHT / 8; j++) {
for (int k = OLED_WIDTH-1; k > 0; k--) {
_oledbuffer[j * OLED_WIDTH + k] = _oledbuffer[j * OLED_WIDTH + k - 1];
}
_oledbuffer[j * OLED_WIDTH] = 0;
@ -382,10 +369,9 @@ void oledSwipeLeft(void)
*/
void oledSwipeRight(void)
{
int i, j, k;
for (i = 0; i < OLED_WIDTH / 4; i++) {
for (j = 0; j < OLED_HEIGHT / 8; j++) {
for (k = 0; k < OLED_WIDTH / 4 - 1; k++) {
for (int i = 0; i < OLED_WIDTH / 4; i++) {
for (int j = 0; j < OLED_HEIGHT / 8; j++) {
for (int k = 0; k < OLED_WIDTH / 4 - 1; k++) {
_oledbuffer[k * 4 + 0 + j * OLED_WIDTH] = _oledbuffer[k * 4 + 4 + j * OLED_WIDTH];
_oledbuffer[k * 4 + 1 + j * OLED_WIDTH] = _oledbuffer[k * 4 + 5 + j * OLED_WIDTH];
_oledbuffer[k * 4 + 2 + j * OLED_WIDTH] = _oledbuffer[k * 4 + 6 + j * OLED_WIDTH];

11
rng.c
View File

@ -44,9 +44,8 @@ uint32_t random_uniform(uint32_t n)
void random_buffer(uint8_t *buf, size_t len)
{
size_t i;
uint32_t r = 0;
for (i = 0; i < len; i++) {
for (size_t i = 0; i < len; i++) {
if (i % 4 == 0) {
r = random32();
}
@ -56,11 +55,9 @@ void random_buffer(uint8_t *buf, size_t len)
void random_permute(char *str, size_t len)
{
int i, j;
char t;
for (i = len - 1; i >= 1; i--) {
j = random_uniform(i + 1);
t = str[j];
for (int i = len - 1; i >= 1; i--) {
int j = random_uniform(i + 1);
char t = str[j];
str[j] = str[i];
str[i] = t;
}

6
util.c
View File

@ -29,8 +29,7 @@ static const char *hexdigits = "0123456789ABCDEF";
void uint32hex(uint32_t num, char *str)
{
uint32_t i;
for (i = 0; i < 8; i++) {
for (uint32_t i = 0; i < 8; i++) {
str[i] = hexdigits[(num >> (28 - i * 4)) & 0xF];
}
}
@ -38,9 +37,8 @@ void uint32hex(uint32_t num, char *str)
// converts data to hexa
void data2hex(const void *data, uint32_t len, char *str)
{
uint32_t i;
const uint8_t *cdata = (uint8_t *)data;
for (i = 0; i < len; i++) {
for (uint32_t i = 0; i < len; i++) {
str[i * 2 ] = hexdigits[(cdata[i] >> 4) & 0xF];
str[i * 2 + 1] = hexdigits[cdata[i] & 0xF];
}