• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cryspen / hacl-packages / 9565668261

18 Jun 2024 01:10PM UTC coverage: 48.135% (-5.9%) from 54.055%
9565668261

push

github

web-flow
Merge pull request #461 from cryspen/franziskus/update-hacl-star

update hacl star

1867 of 10088 new or added lines in 12 files covered. (18.51%)

24 existing lines in 6 files now uncovered.

29403 of 61085 relevant lines covered (48.13%)

1067323.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

64.29
/src/Lib_RandomBuffer_System.c
1
#include "Lib_RandomBuffer_System.h"
2

3
#if (defined(_WIN32) || defined(_WIN64))
4

5
#include <inttypes.h>
6
#include <stdbool.h>
7
#include <malloc.h>
8
#include <windows.h>
9

10
bool read_random_bytes(uint32_t len, uint8_t *buf) {
11
  HCRYPTPROV ctxt;
12
  if (!(CryptAcquireContext(&ctxt, NULL, NULL, PROV_RSA_FULL,
13
                            CRYPT_VERIFYCONTEXT))) {
14
    DWORD error = GetLastError();
15
    /* printf("Cannot acquire crypto context: 0x%lx\n", error); */
16
    return false;
17
  }
18
  bool pass = true;
19
  if (!(CryptGenRandom(ctxt, (uint64_t)len, buf))) {
20
    /* printf("Cannot read random bytes\n"); */
21
    pass = false;
22
  }
23
  CryptReleaseContext(ctxt, 0);
24
  return pass;
25
}
26

27
#else
28

29
/* assume POSIX here */
30
#include <fcntl.h>
31
#include <stdlib.h>
32
#include <sys/stat.h>
33
#include <sys/types.h>
34
#include <sys/syscall.h>
35
#include <unistd.h>
36

37
bool read_random_bytes(uint32_t len, uint8_t *buf) {
40✔
38
#ifdef SYS_getrandom
40✔
39
  ssize_t res = syscall(SYS_getrandom, buf, (size_t)len, 0);
40✔
40
  if (res == -1) {
40✔
UNCOV
41
    return false;
×
UNCOV
42
  }
×
43
#else // !defined(SYS_getrandom)
44
  int fd = open("/dev/urandom", O_RDONLY);
45
  if (fd == -1) {
46
    return false;
47
  }
48
  ssize_t res = read(fd, buf, (uint64_t)len);
49
  close(fd);
50
#endif // defined(SYS_getrandom)
51
  return ((size_t)res == (size_t)len);
40✔
52
}
40✔
53

54
#endif
55

56
// WARNING: this function is deprecated
57
bool Lib_RandomBuffer_System_randombytes(uint8_t *x, uint32_t len) {
40✔
58
  return read_random_bytes(len, x);
40✔
59
}
40✔
60

61
void Lib_RandomBuffer_System_crypto_random(uint8_t *x, uint32_t len) {
×
62
    while(!read_random_bytes(len, x)) {}
×
63
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc