1 // Copyright 2015 Google Inc. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // A RAPPOR random implementation using bytes from a file like /dev/urandom or 16 // /dev/random. 17 18 #ifndef UNIX_KERNEL_RAND_IMPL_H_ 19 #define UNIX_KERNEL_RAND_IMPL_H_ 20 21 #include <stdint.h> // uint8_t 22 #include <stdio.h> // FILE* 23 24 #include "rappor_deps.h" 25 26 namespace rappor { 27 28 class UnixKernelRand : public IrrRandInterface { 29 public: UnixKernelRand(FILE * fp)30 explicit UnixKernelRand(FILE* fp) 31 : fp_(fp) { 32 } ~UnixKernelRand()33 virtual ~UnixKernelRand() {} 34 35 virtual bool GetMask(float prob, int num_bits, Bits* mask_out) const; 36 37 private: 38 FILE* fp_; // open device, e.g. /dev/urandom 39 }; 40 41 } // namespace rappor 42 43 #endif // UNIX_KERNEL_RAND_IMPL_H_ 44