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 // This header declares the dependencies that the application must provide to 16 // the RAPPOR. 17 18 #ifndef RAPPOR_DEPS_H_ 19 #define RAPPOR_DEPS_H_ 20 21 #include <stdint.h> // for uint32_t 22 #include <string> 23 #include <vector> 24 25 namespace rappor { 26 27 // rappor::Bits type is used for Bloom Filter, PRR, and IRR 28 typedef uint32_t Bits; 29 30 // rappor::Encoder needs a hash function for the bloom filter, and an HMAC 31 // function for the PRR. 32 33 typedef bool HashFunc(const std::string& value, std::vector<uint8_t>* output); 34 typedef bool HmacFunc(const std::string& key, const std::string& value, 35 std::vector<uint8_t>* output); 36 37 // Interface that the encoder use to generate randomness for the IRR. 38 // Applications should implement this based on their platform and requirements. 39 class IrrRandInterface { 40 public: ~IrrRandInterface()41 virtual ~IrrRandInterface() {} 42 // Compute a bitmask with each bit set to 1 with probability 'prob'. 43 // Returns false if there is an error. 44 virtual bool GetMask(float prob, int num_bits, Bits* mask_out) const = 0; 45 }; 46 47 // Dependencies 48 // - hash_func: hash function for the Bloom Filter client step 49 // - client_secret: key for deterministic randomness in the PRR 50 // - hmac_func: function for deterministic randomness in the PRR 51 // - irr_rand: randomness for the IRR 52 53 class Deps { 54 public: Deps(HashFunc * const hash_func,const std::string & client_secret,HmacFunc * const hmac_func,const IrrRandInterface & irr_rand)55 Deps(HashFunc* const hash_func, const std::string& client_secret, 56 HmacFunc* const hmac_func, const IrrRandInterface& irr_rand) 57 : hash_func_(hash_func), 58 client_secret_(client_secret), 59 hmac_func_(hmac_func), 60 irr_rand_(irr_rand) { 61 } 62 63 private: 64 friend class Encoder; 65 66 HashFunc* hash_func_; // for bloom filter 67 const std::string client_secret_; // for PRR; copy of constructor param 68 HmacFunc* hmac_func_; // PRR 69 const IrrRandInterface& irr_rand_; // IRR 70 }; 71 72 } // namespace rappor 73 74 #endif // RAPPOR_DEPS_H_ 75 76