Skip to content

Commit ebb563c

Browse files
authored
Merge pull request #40 from thomwiggers/github-actions
Move CI to github actions and fix DWORD for CryptGenRandom
2 parents 92b2262 + 4ca4200 commit ebb563c

File tree

4 files changed

+55
-71
lines changed

4 files changed

+55
-71
lines changed

.github/workflows/test.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
name: Tests
3+
on: [push, pull_request]
4+
5+
jobs:
6+
Test-Randombytes:
7+
runs-on: "${{ matrix.os }}"
8+
strategy:
9+
matrix:
10+
cc:
11+
- gcc
12+
- clang
13+
os:
14+
- ubuntu-latest
15+
- macos-latest
16+
env:
17+
CC: "${{ matrix.cc }}"
18+
steps:
19+
- uses: actions/checkout@v3
20+
- run: |
21+
make check
22+
23+
Test-Randombytes-Musl:
24+
runs-on: ubuntu-latest
25+
env:
26+
CC: musl-gcc
27+
steps:
28+
- uses: actions/checkout@v3
29+
- name: Install musl-tools
30+
run: sudo apt-get install -y musl-tools
31+
- run: make check
32+
33+
Test-Randombytes-Windows:
34+
runs-on: windows-latest
35+
strategy:
36+
matrix:
37+
arch:
38+
- x64
39+
- x86
40+
steps:
41+
- uses: actions/checkout@v3
42+
- uses: ilammy/msvc-dev-cmd@v1
43+
with:
44+
arch: ${{ matrix.arch }}
45+
- run: cl /c /nologo /W3 /WX randombytes.c

.travis.yml

Lines changed: 0 additions & 65 deletions
This file was deleted.

appveyor.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

randombytes.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,24 @@
7676

7777

7878
#if defined(_WIN32)
79-
static int randombytes_win32_randombytes(void* buf, const size_t n)
79+
static int randombytes_win32_randombytes(void* buf, size_t n)
8080
{
8181
HCRYPTPROV ctx;
8282
BOOL tmp;
83+
DWORD to_read = 0;
84+
const size_t MAX_DWORD = 0xFFFFFFFF;
8385

8486
tmp = CryptAcquireContext(&ctx, NULL, NULL, PROV_RSA_FULL,
8587
CRYPT_VERIFYCONTEXT);
8688
if (tmp == FALSE) return -1;
8789

88-
tmp = CryptGenRandom(ctx, n, (BYTE*) buf);
89-
if (tmp == FALSE) return -1;
90+
while (n > 0) {
91+
to_read = (DWORD)(n < MAX_DWORD ? n : MAX_DWORD);
92+
tmp = CryptGenRandom(ctx, to_read, (BYTE*) buf);
93+
if (tmp == FALSE) return -1;
94+
buf = ((char*)buf) + to_read;
95+
n -= to_read;
96+
}
9097

9198
tmp = CryptReleaseContext(ctx, 0);
9299
if (tmp == FALSE) return -1;

0 commit comments

Comments
 (0)