services/crypto/tests/unit/test_utils_sha1.js

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 _("Make sure sha1 digests works with various messages");
michael@0 5
michael@0 6 Cu.import("resource://services-crypto/utils.js");
michael@0 7
michael@0 8 function run_test() {
michael@0 9 let mes1 = "hello";
michael@0 10 let mes2 = "world";
michael@0 11
michael@0 12 let dig0 = CryptoUtils.UTF8AndSHA1(mes1);
michael@0 13 do_check_eq(dig0,
michael@0 14 "\xaa\xf4\xc6\x1d\xdc\xc5\xe8\xa2\xda\xbe\xde\x0f\x3b\x48\x2c\xd9\xae\xa9\x43\x4d");
michael@0 15
michael@0 16 _("Make sure right sha1 digests are generated");
michael@0 17 let dig1 = CryptoUtils.sha1(mes1);
michael@0 18 do_check_eq(dig1, "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d");
michael@0 19 let dig2 = CryptoUtils.sha1(mes2);
michael@0 20 do_check_eq(dig2, "7c211433f02071597741e6ff5a8ea34789abbf43");
michael@0 21 let dig12 = CryptoUtils.sha1(mes1 + mes2);
michael@0 22 do_check_eq(dig12, "6adfb183a4a2c94a2f92dab5ade762a47889a5a1");
michael@0 23 let dig21 = CryptoUtils.sha1(mes2 + mes1);
michael@0 24 do_check_eq(dig21, "5715790a892990382d98858c4aa38d0617151575");
michael@0 25
michael@0 26 _("Repeated sha1s shouldn't change the digest");
michael@0 27 do_check_eq(CryptoUtils.sha1(mes1), dig1);
michael@0 28 do_check_eq(CryptoUtils.sha1(mes2), dig2);
michael@0 29 do_check_eq(CryptoUtils.sha1(mes1 + mes2), dig12);
michael@0 30 do_check_eq(CryptoUtils.sha1(mes2 + mes1), dig21);
michael@0 31
michael@0 32 _("Nested sha1 should work just fine");
michael@0 33 let nest1 = CryptoUtils.sha1(CryptoUtils.sha1(CryptoUtils.sha1(CryptoUtils.sha1(CryptoUtils.sha1(mes1)))));
michael@0 34 do_check_eq(nest1, "23f340d0cff31e299158b3181b6bcc7e8c7f985a");
michael@0 35 let nest2 = CryptoUtils.sha1(CryptoUtils.sha1(CryptoUtils.sha1(CryptoUtils.sha1(CryptoUtils.sha1(mes2)))));
michael@0 36 do_check_eq(nest2, "1f6453867e3fb9876ae429918a64cdb8dc5ff2d0");
michael@0 37 }

mercurial