{
FILE *fp;
uint64_t seed;
+ size_t rc = 0;
fp = fopen("/dev/urandom", "rb");
- do {
- size_t rc = 0;
-
- if (fp != nullptr) {
- rc = fread(&seed, 1, sizeof(seed), fp);
- fclose(fp);
- }
-
- if (rc < sizeof(seed))
- break;
+ if (fp) {
+ rc = fread(&seed, 1, sizeof(seed), fp);
+ fclose(fp);
+ }
- return seed;
- } while (false);
+ if (rc < sizeof(seed)) {
+ ErrPrint("get random Fail");
+ return 0;
+ }
- srandom(static_cast<unsigned int>(time(nullptr)));
- return random();
+ return seed;
}
int Peer::GrpcClient::ExchangeKey(void)
beyond::AuthenticatorInterface *auth = nullptr;
unsigned long nonce = GetRandom();
+ if (nonce == 0)
+ return -EIO;
if (peer->caAuthenticator != nullptr) {
DbgPrint("CA Authenticator is selected");