Skip to content
Open
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
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os:
- macos-latest
# - macos-latest
- ubuntu-latest
- windows-latest
rust:
Expand All @@ -18,10 +18,9 @@ jobs:
update-liboqs:
- true
- false
env:
# env: # auto-allocated in runtime
# 20 MiB stack
RUST_MIN_STACK: 20971520

# RUST_MIN_STACK: 20971520
steps:
- uses: actions/checkout@v4
with:
Expand Down
47 changes: 39 additions & 8 deletions oqs/src/kem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,46 @@ impl Kem {
let mut sk = SecretKey {
bytes: Vec::with_capacity(kem.length_secret_key),
};
let status = unsafe { func(pk.bytes.as_mut_ptr(), sk.bytes.as_mut_ptr()) };
status_to_result(status)?;
// update the lengths of the vecs
// this is safe to do, as we have initialised them now.
unsafe {
pk.bytes.set_len(kem.length_public_key);
sk.bytes.set_len(kem.length_secret_key);

let pklen = kem.length_public_key;
let sklen = kem.length_secret_key;

#[cfg(feature = "std")]
{
// Particularly the classic McEliece kem is very stack-heavy.
// The reason we're using a thread is that it allows
// to increase stack space, on demand, in run time.
// Not only does this eliminate the need to set compiler options for each build;
// it also means we won't be holding on to memory unnecessarily in runtime.
let handle = std::thread::Builder::new()
.stack_size(16_000_000)
.spawn(move || {
let status = unsafe { func(pk.bytes.as_mut_ptr(), sk.bytes.as_mut_ptr()) };
status_to_result(status)?;
// update the lengths of the vecs
// this is safe to do, as we have initialised them now.
unsafe {
pk.bytes.set_len(pklen);
sk.bytes.set_len(sklen);
}
Ok((pk, sk))
})
.unwrap();
handle.join().unwrap()
}
#[cfg(not(feature = "std"))]
{
// For embedded, something different needs to be done to spawn a new task. For now, do it inline.
let status = unsafe { func(pk.bytes.as_mut_ptr(), sk.bytes.as_mut_ptr()) };
status_to_result(status)?;
// update the lengths of the vecs
// this is safe to do, as we have initialised them now.
unsafe {
pk.bytes.set_len(pklen);
sk.bytes.set_len(sklen);
}
Ok((pk, sk))
}
Ok((pk, sk))
}

/// Encapsulate to the provided public key
Expand Down