Path: blob/main/crypto/libecc/src/utils/utils_rand.c
34889 views
/*1* Copyright (C) 2023 - This file is part of libecc project2*3* Authors:4* Ryad BENADJILA <[email protected]>5* Arnaud EBALARD <[email protected]>6*7* This software is licensed under a dual BSD and GPL v2 license.8* See LICENSE file at the root folder of the project.9*/10#include <libecc/utils/utils_rand.h>1112/* Unsafe random source:13* Initial seeding is performed using good entropy, then14* a congruential linear system is used.15*/16static u64 seed = 0;17int get_unsafe_random(unsigned char *buf, u16 len)18{19int ret;20u64 a, b;21u16 i, j;22a = (u64)2862933555777941757;23b = (u64)3037000493;2425if(seed == 0){26ret = get_random((u8*)&seed, sizeof(seed));27if(ret){28ret = -1;29goto err;30}31}3233i = 0;34while(i < len){35/* Use a congruential linear generator */36seed = ((a * seed) + b);3738for(j = 0; j < sizeof(seed); j++){39if((i + j) < len){40buf[i + j] = (u8)((seed >> (j * 8)) & 0xff);41}42}43i = (u16)(i + sizeof(seed));44}4546ret = 0;4748err:49return ret;50}515253