/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::error::Error; use std::io::Cursor;
use log::{debug, warn};
use prio::vdaf::prio3::Prio3Sum; use prio::vdaf::prio3::Prio3SumVec; use thin_vec::ThinVec;
pubmod types; use types::HpkeConfig; use types::PlaintextInputShare; use types::Report; use types::ReportID; use types::ReportMetadata; use types::Time;
use prio::codec::Encode; use prio::codec::{decode_u16_items, encode_u32_items}; use prio::vdaf::Client; use prio::vdaf::VdafError;
let measurement: Vec<u128> = self.iter().map(|e| (*e as u128)).collect(); let (public_share, input_shares) = prio.shard(&measurement, nonce)?;
debug_assert_eq!(input_shares.len(), 2);
let encoded_input_shares = input_shares
.iter()
.map(|s| s.get_encoded())
.collect::<Result<Vec<_>, _>>()?; let encoded_public_share = public_share.get_encoded()?;
Ok((encoded_public_share, encoded_input_shares))
}
}
/// Pre-fill the info part of the HPKE sealing with the constants from the standard. fn make_base_info() -> Vec<u8> { letmut info = Vec::<u8>::new(); const START: &[u8] = "dap-09 input share".as_bytes();
info.extend(START); const FIXED: u8 = 1;
info.push(FIXED);
/// This function creates a full report - ready to send - for a measurement. /// /// To do that it also needs the HPKE configurations for the endpoints and some /// additional data which is part of the authentication. fn get_dap_report_internal<T: Shardable>(
leader_hpke_config_encoded: &ThinVec<u8>,
helper_hpke_config_encoded: &ThinVec<u8>,
measurement: &T,
task_id: &[u8; 32],
time_precision: u64,
) -> Result<Report, Box<dyn std::error::Error>> { let leader_hpke_configs: Vec<HpkeConfig> =
decode_u16_items(&(), &mut Cursor::new(leader_hpke_config_encoded))?; let leader_hpke_config = select_hpke_config(leader_hpke_configs)?; let helper_hpke_configs: Vec<HpkeConfig> =
decode_u16_items(&(), &mut Cursor::new(helper_hpke_config_encoded))?; let helper_hpke_config = select_hpke_config(helper_hpke_configs)?;
let report_id = ReportID::generate(); let (encoded_public_share, encoded_input_shares) = measurement.shard(report_id.as_ref())?;
let metadata = ReportMetadata {
report_id,
time: Time::generate(time_precision),
};
// This quote from the standard describes which info and aad to use for the encryption: // enc, payload = SealBase(pk, // "dap-02 input share" || 0x01 || server_role, // task_id || metadata || public_share, input_share) // https://www.ietf.org/archive/id/draft-ietf-ppm-dap-02.html#name-upload-request letmut info = make_base_info();
/// Wraps the function above with minor C interop. /// Mostly it turns any error result into a return value of false. #[no_mangle] pubextern"C"fn dapGetReportU8(
leader_hpke_config_encoded: &ThinVec<u8>,
helper_hpke_config_encoded: &ThinVec<u8>,
measurement: u8,
task_id: &ThinVec<u8>,
time_precision: u64,
out_report: &mut ThinVec<u8>,
) -> bool {
assert_eq!(task_id.len(), 32);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.