tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_WebCrypto_telemetry.js (908B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 /* global tv */
      8 
      9 const WEBCRYPTO_ALG_PROBE = "WEBCRYPTO_ALG";
     10 
     11 ChromeUtils.defineESModuleGetters(this, {
     12  TelemetryTestUtils: "resource://testing-common/TelemetryTestUtils.sys.mjs",
     13 });
     14 
     15 add_task(async function ecdh_key() {
     16  let hist = TelemetryTestUtils.getAndClearHistogram(WEBCRYPTO_ALG_PROBE);
     17 
     18  let alg = { name: "ECDH", namedCurve: "P-256" };
     19 
     20  let x = await crypto.subtle.generateKey(alg, false, [
     21    "deriveKey",
     22    "deriveBits",
     23  ]);
     24  let data = await crypto.subtle.deriveBits(
     25    { name: "ECDH", public: x.publicKey },
     26    x.privateKey,
     27    128
     28  );
     29  is(data.byteLength, 128 / 8, "Should be 16 bytes derived");
     30 
     31  TelemetryTestUtils.assertHistogram(hist, 20, 1);
     32 });