fuchsia-cprng-0.1.1/AUTHORS010064421107500257523000000004321342635202200135470ustar0000000000000000# This is the list of Fuchsia Authors. # Names should be added to this file as one of # Organization's name # Individual's name # Individual's name Google Inc. The Chromium Authors The Go Authors fuchsia-cprng-0.1.1/Cargo.toml.orig010064421107500257523000000011531342635200500153700ustar0000000000000000# Copyright 2019 The Fuchsia Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. [package] name = "fuchsia-cprng" version = "0.1.1" license-file = "LICENSE" authors = ["Erick Tryzelaar "] description = "Rust crate for the Fuchsia cryptographically secure pseudorandom number generator" repository = "https://fuchsia.googlesource.com/fuchsia/+/master/garnet/public/rust/fuchsia-cprng" edition = "2018" readme = "README.md" include = [ "src/*.rs", "Cargo.toml", "AUTHORS", "LICENSE", "PATENTS", ] fuchsia-cprng-0.1.1/Cargo.toml0000644000000016760000000000000116330ustar00# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g. crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] edition = "2018" name = "fuchsia-cprng" version = "0.1.1" authors = ["Erick Tryzelaar "] include = ["src/*.rs", "Cargo.toml", "AUTHORS", "LICENSE", "PATENTS"] description = "Rust crate for the Fuchsia cryptographically secure pseudorandom number generator" readme = "README.md" license-file = "LICENSE" repository = "https://fuchsia.googlesource.com/fuchsia/+/master/garnet/public/rust/fuchsia-cprng" fuchsia-cprng-0.1.1/LICENSE010064421107500257523000000027101342635202200135050ustar0000000000000000Copyright 2019 The Fuchsia Authors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. fuchsia-cprng-0.1.1/PATENTS010064421107500257523000000024051342635202200135420ustar0000000000000000Additional IP Rights Grant (Patents) "This implementation" means the copyrightable works distributed by Google as part of the Fuchsia project. Google hereby grants to you a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, transfer, and otherwise run, modify and propagate the contents of this implementation of Fuchsia, where such license applies only to those patent claims, both currently owned by Google and acquired in the future, licensable by Google that are necessarily infringed by this implementation. This grant does not include claims that would be infringed only as a consequence of further modification of this implementation. If you or your agent or exclusive licensee institute or order or agree to the institution of patent litigation or any other patent enforcement activity against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that this implementation of Fuchsia constitutes direct or contributory patent infringement, or inducement of patent infringement, then any patent rights granted to you under this License for this implementation of Fuchsia shall terminate as of the date such litigation is filed. fuchsia-cprng-0.1.1/src/lib.rs010064421107500257523000000026041342635200500144060ustar0000000000000000// Copyright 2019 The Fuchsia Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. //! Type-safe bindings for the Zircon kernel's CPRNG. #![no_std] #![deny(warnings)] /// Draw random bytes from the kernel's CPRNG to fill the given buffer. /// /// Wraps the /// [zx_cprng_draw](https://fuchsia.googlesource.com/fuchsia/+/master/zircon/docs/syscalls/cprng_draw.md) /// syscall. pub fn cprng_draw(buffer: &mut [u8]) { unsafe { zx_cprng_draw(buffer.as_mut_ptr(), buffer.len()) }; } #[link(name = "zircon")] extern "C" { fn zx_cprng_draw(buffer: *mut u8, length: usize); } #[cfg(test)] mod tests { use super::*; #[test] fn cprng() { let mut buffer = [0; 20]; cprng_draw(&mut buffer); let mut first_zero = 0; let mut last_zero = 0; for _ in 0..30 { let mut buffer = [0; 20]; cprng_draw(&mut buffer); if buffer[0] == 0 { first_zero += 1; } if buffer[19] == 0 { last_zero += 1; } } assert_ne!(first_zero, 30); assert_ne!(last_zero, 30); } #[test] fn cprng_large() { let mut buffer = [0; 1024]; cprng_draw(&mut buffer); for mut s in buffer.chunks_mut(256) { cprng_draw(&mut s); } } }