Path: blob/main/crypto/openssl/providers/implementations/rands/seeding/rand_tsc.c
48531 views
/*1* Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.2*3* Licensed under the Apache License 2.0 (the "License"). You may not use4* this file except in compliance with the License. You can obtain a copy5* in the file LICENSE in the source distribution or at6* https://www.openssl.org/source/license.html7*/89#include "internal/cryptlib.h"10#include <openssl/opensslconf.h>11#include "crypto/rand_pool.h"12#include "prov/seeding.h"1314#ifdef OPENSSL_RAND_SEED_RDTSC15/*16* IMPORTANT NOTE: It is not currently possible to use this code17* because we are not sure about the amount of randomness it provides.18* Some SP800-90B tests have been run, but there is internal skepticism.19* So for now this code is not used.20*/21# error "RDTSC enabled? Should not be possible!"2223/*24* Acquire entropy from high-speed clock25*26* Since we get some randomness from the low-order bits of the27* high-speed clock, it can help.28*29* Returns the total entropy count, if it exceeds the requested30* entropy count. Otherwise, returns an entropy count of 0.31*/32size_t ossl_prov_acquire_entropy_from_tsc(RAND_POOL *pool)33{34unsigned char c;35int i;3637if ((OPENSSL_ia32cap_P[0] & (1 << 4)) != 0) {38for (i = 0; i < TSC_READ_COUNT; i++) {39c = (unsigned char)(OPENSSL_rdtsc() & 0xFF);40ossl_rand_pool_add(pool, &c, 1, 4);41}42}43return ossl_rand_pool_entropy_available(pool);44}45#else46NON_EMPTY_TRANSLATION_UNIT47#endif484950