Make bssl-crypto no_std compatible

Bug: 649
Change-Id: Ib47e843496e58a5cdb3cd04b3929e0a08ba09744
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/63145
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
chromium-stable
Alice Wang 1 year ago committed by Boringssl LUCI CQ
parent a1843d660b
commit cfcb954901
  1. 4
      rust/bssl-crypto/Cargo.toml
  2. 2
      rust/bssl-crypto/src/aead.rs
  3. 6
      rust/bssl-crypto/src/cipher/mod.rs
  4. 5
      rust/bssl-crypto/src/ec.rs
  5. 3
      rust/bssl-crypto/src/ecdh.rs
  6. 1
      rust/bssl-crypto/src/hkdf.rs
  7. 6
      rust/bssl-crypto/src/lib.rs
  8. 5
      rust/bssl-crypto/src/pkey.rs
  9. 1
      rust/bssl-crypto/src/test_helpers.rs
  10. 2
      rust/bssl-crypto/src/x25519.rs

@ -7,3 +7,7 @@ license = "MIT"
[dependencies]
bssl-sys = {path = "../bssl-sys"}
[features]
default = []
std = []

@ -12,7 +12,9 @@
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
use crate::{CSlice, CSliceMut};
use alloc::vec::Vec;
use bssl_sys::{EVP_AEAD, EVP_AEAD_CTX};
/// Error returned in the event of an unsuccessful AEAD operation.

@ -15,8 +15,8 @@
use crate::{CSlice, CSliceMut};
use bssl_sys::EVP_CIPHER;
use std::ffi::c_int;
use std::marker::PhantomData;
use core::ffi::c_int;
use core::marker::PhantomData;
/// AES-CTR stream cipher operations.
pub mod aes_ctr;
@ -98,7 +98,7 @@ impl<C: EvpCipherType> Cipher<C> {
bssl_sys::EVP_EncryptInit_ex(
ctx,
C::evp_cipher(),
std::ptr::null_mut(),
core::ptr::null_mut(),
key_cslice.as_ptr(),
iv_cslice.as_ptr(),
)

@ -17,8 +17,11 @@
//! intended for internal use within this crate only, to create higher-level abstractions suitable
//! to be exposed externally.
use alloc::borrow::ToOwned;
use alloc::vec;
use alloc::vec::Vec;
use core::panic;
use std::{borrow::Borrow, fmt::Debug, ops::Deref};
use core::{borrow::Borrow, fmt::Debug, ops::Deref};
use crate::{bn::BigNum, CSlice, CSliceMut, ForeignType, ForeignTypeRef};

@ -13,7 +13,8 @@
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
use std::marker::PhantomData;
use alloc::vec::Vec;
use core::marker::PhantomData;
use crate::{
ec::{Curve, EcKey},

@ -15,6 +15,7 @@
use crate::digest::Md;
use crate::digest::{Sha256, Sha512};
use crate::{CSlice, CSliceMut, ForeignTypeRef};
use alloc::vec::Vec;
use core::marker::PhantomData;
/// Implementation of HKDF-SHA-256

@ -21,8 +21,10 @@
clippy::panic,
clippy::expect_used
)]
#![cfg_attr(not(any(feature = "std", test)), no_std)]
//! Rust BoringSSL bindings
extern crate alloc;
extern crate core;
@ -79,7 +81,7 @@ impl CSlice<'_> {
/// Returns a raw pointer to the value, which is safe to pass over FFI.
pub fn as_ptr<T>(&self) -> *const T {
if self.0.is_empty() {
std::ptr::null()
core::ptr::null()
} else {
self.0.as_ptr() as *const T
}
@ -97,7 +99,7 @@ impl CSliceMut<'_> {
/// Returns a raw pointer to the value, which is safe to pass over FFI.
pub fn as_mut_ptr<T>(&mut self) -> *mut T {
if self.0.is_empty() {
std::ptr::null_mut()
core::ptr::null_mut()
} else {
self.0.as_mut_ptr() as *mut T
}

@ -18,6 +18,8 @@
//! externally.
use crate::{ec::EcKey, CSliceMut, ForeignType};
use alloc::borrow::ToOwned;
use alloc::string::String;
pub(crate) struct Pkey {
ptr: *mut bssl_sys::EVP_PKEY,
@ -45,8 +47,7 @@ impl From<&EcKey> for Pkey {
// - pkey is just allocated and is null-checked
// - EcKey ensures eckey.ptr is valid during its lifetime
// - EVP_PKEY_set1_EC_KEY doesn't take ownership
let result =
unsafe { bssl_sys::EVP_PKEY_set1_EC_KEY(pkey, eckey.as_ptr()) };
let result = unsafe { bssl_sys::EVP_PKEY_set1_EC_KEY(pkey, eckey.as_ptr()) };
assert_eq!(result, 1, "bssl_sys::EVP_PKEY_set1_EC_KEY failed");
Self { ptr: pkey }
}

@ -12,6 +12,7 @@
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
use alloc::vec::Vec;
#[allow(clippy::expect_used, clippy::unwrap_used, clippy::indexing_slicing)]
pub(crate) fn decode_hex<const N: usize>(s: &str) -> [u8; N] {

@ -17,6 +17,8 @@
//! “curve25519”, but “X25519” is a more precise name. See http://cr.yp.to/ecdh.html and
//! https://tools.ietf.org/html/rfc7748.
use alloc::borrow::ToOwned;
/// Number of bytes in a private key in X25519
pub const PRIVATE_KEY_LEN: usize = bssl_sys::X25519_PRIVATE_KEY_LEN as usize;
/// Number of bytes in a public key in X25519

Loading…
Cancel
Save