SystemRandomSeed.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #include "crypto/random/seed/RandomSeed.h"
  16. #include "util/log/Log.h"
  17. #include "crypto/random/seed/RandomSeedProvider.h"
  18. #include "crypto/random/seed/RtlGenRandomSeed.h"
  19. #include "crypto/random/seed/BsdKernArndSysctlRandomSeed.h"
  20. #include "crypto/random/seed/DevUrandomRandomSeed.h"
  21. #include "crypto/random/seed/LinuxRandomUuidSysctlRandomSeed.h"
  22. #include "crypto/random/seed/ProcSysKernelRandomUuidRandomSeed.h"
  23. static RandomSeed_Provider PROVIDERS[] = { RandomSeedProvider_list() };
  24. #define PROVIDERS_COUNT ((int)(sizeof(PROVIDERS) / sizeof(RandomSeed_Provider)))
  25. struct RandomSeed* SystemRandomSeed_new(RandomSeed_Provider* additionalProviders,
  26. int additionalProviderCount,
  27. struct Log* logger,
  28. struct Allocator* alloc)
  29. {
  30. int providerCount = PROVIDERS_COUNT + additionalProviderCount;
  31. RandomSeed_Provider* allProviders =
  32. Allocator_calloc(alloc, sizeof(RandomSeed_Provider), providerCount+1);
  33. int i = 0;
  34. for (int j = 0; j < additionalProviderCount; j++) {
  35. allProviders[i++] = additionalProviders[j];
  36. }
  37. for (int j = 0; j < PROVIDERS_COUNT; j++) {
  38. allProviders[i++] = PROVIDERS[j];
  39. }
  40. return RandomSeed_new(allProviders, providerCount, logger, alloc);
  41. }