extra check if malloc failed
This commit is contained in:
@@ -376,6 +376,7 @@ uint32_t lfsr_rollback_word(struct Crypto1State *s, uint32_t in, int fb) {
|
|||||||
static uint16_t *dist = 0;
|
static uint16_t *dist = 0;
|
||||||
int nonce_distance(uint32_t from, uint32_t to) {
|
int nonce_distance(uint32_t from, uint32_t to) {
|
||||||
if (!dist) {
|
if (!dist) {
|
||||||
|
// allocation 2bytes * 0xFFFF times.
|
||||||
dist = calloc(2 << 16, sizeof(uint8_t));
|
dist = calloc(2 << 16, sizeof(uint8_t));
|
||||||
if (!dist)
|
if (!dist)
|
||||||
return -1;
|
return -1;
|
||||||
@@ -396,7 +397,8 @@ int nonce_distance(uint32_t from, uint32_t to) {
|
|||||||
*/
|
*/
|
||||||
bool validate_prng_nonce(uint32_t nonce) {
|
bool validate_prng_nonce(uint32_t nonce) {
|
||||||
// init prng table:
|
// init prng table:
|
||||||
nonce_distance(nonce, nonce);
|
if (nonce_distance(nonce, nonce) == -1)
|
||||||
|
return false;
|
||||||
return ((65535 - dist[nonce >> 16] + dist[nonce & 0xffff]) % 65535) == 16;
|
return ((65535 - dist[nonce >> 16] + dist[nonce & 0xffff]) % 65535) == 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user