/* Fills BUF with SIZE pseudo-random bytes. */ void prng_get_bytes (void *buf_, size_t size) { unsigned char *buf; for (buf = buf_; size-- > 0; buf++) *buf = prng_get_byte (); }
/** * Updates the locations of game objects after one timestep. * Checks for collisions and updates state if we lost. */ void game_step() { if (game_lost) return; unsigned i; if (timer_tick % 5 == 0) { for (i = 0; i < NUM_PIPES; i++) { if (pipes[i].position != -1) { pipes[i].position--; if (pipes[i].position == BIRD_POS - 1) score++; } } pipespawn--; if (pipespawn == 0) { for (i = 0; i < NUM_PIPES; i++) { if (pipes[i].position == -1) { pipes[i].position = SCREEN_WIDTH - 1; pipes[i].height = prng_get_byte() % (SKY_HEIGHT - PIPE_GAP); break; } } pipespawn = PIPE_TIME; } } if (timer_tick % 7 == 0) { if (bird_collide(bird_height)) { game_lost = 1; if (score > maxscore) maxscore = score; return; } bird_height += bird_direction; if (bird_countdown) { bird_countdown--; if (!bird_countdown) { bird_direction = 1; } } } }
uint8_t rsa_encrypt_oaep(void* dest, uint16_t* out_length, const void* src, uint16_t length_B, rsa_publickey_t* key, const rsa_oaep_parameter_t *p, const rsa_label_t* label, const void* seed){ if(!p){ p = &rsa_oaep_default_parameter; } if(!label){ label = &rsa_oaep_default_label; } uint16_t hv_len = (hfal_hash_getHashsize(p->hf)+7)/8; if(length_B > bigint_length_B(&key->modulus) - 2*hv_len - 2){ /* message too long */ return 1; } uint16_t buffer_len = bigint_length_B(&key->modulus); #if DEBUG cli_putstr("\r\n buffer_len = "); cli_hexdump_rev(&buffer_len, 2); cli_putstr("\r\n modulus_len = "); cli_hexdump_rev(&key->modulus.length_B, 2); #endif uint8_t* buffer = (uint8_t*)dest; uint8_t off; /* the following needs some explanation: * off is the offset which is used for compensating the effect of * changeendian() when it operates on multi-byte words. * */ off = (sizeof(bigint_word_t) - (bigint_get_first_set_bit(&key->modulus)/8+1) % sizeof(bigint_word_t)) % (sizeof(bigint_word_t)); buffer += off; buffer_len -= off; uint8_t* seed_buffer = buffer + 1; uint16_t db_len = buffer_len - hv_len - 1; uint8_t* db = seed_buffer + hv_len; uint16_t maskbuffer_len = db_len>hv_len?db_len:hv_len; uint8_t maskbuffer[maskbuffer_len]; bigint_t x; memset(dest, 0, seed_buffer - buffer + off); memset(db + hv_len, 0, db_len - hv_len - length_B -1); hfal_hash_mem(p->hf, db, label->label, label->length_b); db[db_len - length_B - 1] = 0x01; memcpy(db+db_len - length_B, src, length_B); if(seed){ memcpy(seed_buffer, seed, hv_len); }else{ /* generate random seed */ if(!prng_get_byte){ return 2; /* ERROR: no random generator specified */ } uint16_t i; for(i=0; i<hv_len; ++i){ seed_buffer[i] = prng_get_byte(); } } #if DEBUG cli_putstr("\r\n msg (raw, pre-feistel):\r\n"); cli_hexdump_block(dest, bigint_length_B(&key->modulus), 4, 16); #endif p->mgf(maskbuffer, seed_buffer, hv_len, db_len, p->mgf_parameter); memxor(db, maskbuffer, db_len); p->mgf(maskbuffer, db, db_len, hv_len, p->mgf_parameter); memxor(seed_buffer, maskbuffer, hv_len); #if DEBUG cli_putstr("\r\n msg (raw, post-feistel):\r\n"); cli_hexdump_block(dest, bigint_length_B(&key->modulus), 4, 16); #endif x.info = 0; x.length_B = key->modulus.length_B; x.wordv = dest; bigint_adjust(&x); rsa_os2ip(&x, NULL, bigint_length_B(&key->modulus)); #if DEBUG cli_putstr("\r\ninput-msg (pre enc):\r\n"); cli_hexdump_rev(&src, 2); cli_hexdump_block(src, length_B, 4, 16); #endif rsa_enc(&x, key); #if DEBUG cli_putstr("\r\ninput-msg (post enc):\r\n"); cli_hexdump_rev(&src, 2); cli_hexdump_block(src, length_B, 4, 16); #endif rsa_i2osp(NULL, &x, out_length); return 0; }