Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
name: Tests
on: [push, pull_request]

jobs:
Test-Randombytes:
runs-on: "${{ matrix.os }}"
strategy:
matrix:
cc:
- gcc
- clang
os:
- ubuntu-latest
- macos-latest
env:
CC: "${{ matrix.cc }}"
steps:
- uses: actions/checkout@v3
- run: |
make check

Test-Randombytes-Musl:
runs-on: ubuntu-latest
env:
CC: musl-gcc
steps:
- uses: actions/checkout@v3
- name: Install musl-tools
run: sudo apt-get install -y musl-tools
- run: make check

Test-Randombytes-Windows:
runs-on: windows-latest
strategy:
matrix:
arch:
- x64
- x86
steps:
- uses: actions/checkout@v3
- uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{ matrix.arch }}
- run: cl /c /nologo /W3 /WX randombytes.c
65 changes: 0 additions & 65 deletions .travis.yml

This file was deleted.

3 changes: 0 additions & 3 deletions appveyor.yml

This file was deleted.

13 changes: 10 additions & 3 deletions randombytes.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,24 @@


#if defined(_WIN32)
static int randombytes_win32_randombytes(void* buf, const size_t n)
static int randombytes_win32_randombytes(void* buf, size_t n)
{
HCRYPTPROV ctx;
BOOL tmp;
DWORD to_read = 0;
const size_t MAX_DWORD = 0xFFFFFFFF;

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

tmp = CryptGenRandom(ctx, n, (BYTE*) buf);
if (tmp == FALSE) return -1;
while (n > 0) {
to_read = (DWORD)(n < MAX_DWORD ? n : MAX_DWORD);
tmp = CryptGenRandom(ctx, to_read, (BYTE*) buf);
if (tmp == FALSE) return -1;
buf = ((char*)buf) + to_read;
n -= to_read;
}

tmp = CryptReleaseContext(ctx, 0);
if (tmp == FALSE) return -1;
Expand Down