Bug 1433003 - Optimize sync by using digestBytes instead of digestUTF8. r=markh
authorThom Chiovoloni <tchiovoloni@mozilla.com>
Wed, 24 Jan 2018 20:09:16 -0500
changeset 400791 89ce3d9a44f659e9c75c7ecfbfc4e1464569392d
parent 400790 405b7ae324671a9e0004a2c0512d1172e3e590fc
child 400792 89401c18ca7dc930ce5de789d7621776985ee7b1
push id33318
push useraiakab@mozilla.com
push dateFri, 26 Jan 2018 00:17:50 +0000
treeherdermozilla-central@c25d4fc1b17e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh
bugs1433003
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1433003 - Optimize sync by using digestBytes instead of digestUTF8. r=markh MozReview-Commit-ID: IbyeOUjKdi9
services/crypto/modules/utils.js
services/sync/modules/record.js
--- a/services/crypto/modules/utils.js
+++ b/services/crypto/modules/utils.js
@@ -51,17 +51,20 @@ this.CryptoUtils = {
 
   /**
    * Treat the given message as a bytes string and hash it with the given
    * hasher. Returns a string containing bytes. The hasher is reset if it's
    * an HMAC hasher.
    */
   digestBytes: function digestBytes(message, hasher) {
     // No UTF-8 encoding for you, sunshine.
-    let bytes = Array.prototype.slice.call(message).map(b => b.charCodeAt(0));
+    let bytes = new Uint8Array(message.length);
+    for (let i = 0; i < message.length; ++i) {
+      bytes[i] = message.charCodeAt(i) & 0xff;
+    }
     hasher.update(bytes, bytes.length);
     let result = hasher.finish(false);
     if (hasher instanceof Ci.nsICryptoHMAC) {
       hasher.reset();
     }
     return result;
   },
 
--- a/services/sync/modules/record.js
+++ b/services/sync/modules/record.js
@@ -119,17 +119,17 @@ CryptoWrapper.prototype = {
   _logName: "Sync.Record.CryptoWrapper",
 
   ciphertextHMAC: function ciphertextHMAC(keyBundle) {
     let hasher = keyBundle.sha256HMACHasher;
     if (!hasher) {
       throw new Error("Cannot compute HMAC without an HMAC key.");
     }
 
-    return CommonUtils.bytesAsHex(Utils.digestUTF8(this.ciphertext, hasher));
+    return CommonUtils.bytesAsHex(Utils.digestBytes(this.ciphertext, hasher));
   },
 
   /*
    * Don't directly use the sync key. Instead, grab a key for this
    * collection, which is decrypted with the sync key.
    *
    * Cache those keys; invalidate the cache if the time on the keys collection
    * changes, or other auth events occur.