]>
Commit | Line | Data |
---|---|---|
e1c5b1f6 | 1 | /* |
3c2bdd7d | 2 | * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. |
e1c5b1f6 P |
3 | * |
4 | * Licensed under the Apache License 2.0 (the "License"). You may not use | |
5 | * this file except in compliance with the License. You can obtain a copy | |
6 | * in the file LICENSE in the source distribution or at | |
7 | * https://www.openssl.org/source/license.html | |
8 | */ | |
9 | ||
10 | #include "internal/cryptlib.h" | |
11 | #include <openssl/opensslconf.h> | |
08edd447 | 12 | #include "crypto/rand_pool.h" |
7f791b25 | 13 | #include "prov/seeding.h" |
e1c5b1f6 P |
14 | |
15 | #ifdef OPENSSL_RAND_SEED_RDTSC | |
16 | /* | |
17 | * IMPORTANT NOTE: It is not currently possible to use this code | |
18 | * because we are not sure about the amount of randomness it provides. | |
19 | * Some SP800-90B tests have been run, but there is internal skepticism. | |
20 | * So for now this code is not used. | |
21 | */ | |
22 | # error "RDTSC enabled? Should not be possible!" | |
23 | ||
24 | /* | |
25 | * Acquire entropy from high-speed clock | |
26 | * | |
27 | * Since we get some randomness from the low-order bits of the | |
28 | * high-speed clock, it can help. | |
29 | * | |
30 | * Returns the total entropy count, if it exceeds the requested | |
31 | * entropy count. Otherwise, returns an entropy count of 0. | |
32 | */ | |
1335ca4b | 33 | size_t ossl_prov_acquire_entropy_from_tsc(RAND_POOL *pool) |
e1c5b1f6 P |
34 | { |
35 | unsigned char c; | |
36 | int i; | |
37 | ||
38 | if ((OPENSSL_ia32cap_P[0] & (1 << 4)) != 0) { | |
39 | for (i = 0; i < TSC_READ_COUNT; i++) { | |
40 | c = (unsigned char)(OPENSSL_rdtsc() & 0xFF); | |
1335ca4b | 41 | ossl_rand_pool_add(pool, &c, 1, 4); |
e1c5b1f6 P |
42 | } |
43 | } | |
1335ca4b | 44 | return ossl_rand_pool_entropy_available(pool); |
e1c5b1f6 P |
45 | } |
46 | #else | |
47 | NON_EMPTY_TRANSLATION_UNIT | |
48 | #endif |