Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(10)

Side by Side Diff: src/pkg/crypto/sha256/sha256_test.go

Issue 176062: code review 176062: Adds the SHA256 Hash functions as specified in FIPS 180-2. (Closed)
Patch Set: code review 176062: Adds the SHA256 Hash functions as specified in FIPS 180-2. Created 15 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/crypto/sha256/sha256.go ('k') | src/pkg/crypto/sha256/sha256block.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // SHA256 hash algorithm. See FIPS 180-2.
6
7 package sha256
8
9 import (
10 "fmt";
11 "io";
12 "testing";
13 )
14
15 type sha256Test struct {
16 out string;
17 in string;
18 }
19
20 var golden = []sha256Test{
21 sha256Test{"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852 b855", ""},
22 sha256Test{"ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee 48bb", "a"},
23 sha256Test{"fb8e20fc2e4c3f248c60c39bd652f3c1347298bb977b8b4d5903b8505562 0603", "ab"},
24 sha256Test{"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f200 15ad", "abc"},
25 sha256Test{"88d4266fd4e6338d13b845fcf289579d209c897823b9217da3e161936f03 1589", "abcd"},
26 sha256Test{"36bbe50ed96841d10443bcb670d6554f0a34b761be67ec9c4a8ad2c0c44c a42c", "abcde"},
27 sha256Test{"bef57ec7f53a6d40beb640a780a639c83bc29ac8a9816f1fc6c5c6dcd93c 4721", "abcdef"},
28 sha256Test{"7d1a54127b222502f5b79b5fb0803061152a44f92b37e23c6527baf665d4 da9a", "abcdefg"},
29 sha256Test{"9c56cc51b374c3ba189210d5b6d4bf57790d351c96c47c02190ecf1e4306 35ab", "abcdefgh"},
30 sha256Test{"19cc02f26df43cc571bc9ed7b0c4d29224a3ec229529221725ef76d021c8 326f", "abcdefghi"},
31 sha256Test{"72399361da6a7754fec986dca5b7cbaf1c810a28ded4abaf56b2106d06cb 78b0", "abcdefghij"},
32 sha256Test{"a144061c271f152da4d151034508fed1c138b8c976339de229c3bb6d4bbb 4fce", "Discard medicine more than two years old."},
33 sha256Test{"6dae5caa713a10ad04b46028bf6dad68837c581616a1589a265a11288d4b b5c4", "He who has a shady past knows that nice guys finish last."},
34 sha256Test{"ae7a702a9509039ddbf29f0765e70d0001177914b86459284dab8b348c2d ce3f", "I wouldn't marry him with a ten foot pole."},
35 sha256Test{"6748450b01c568586715291dfa3ee018da07d36bb7ea6f180c1af6270215 c64f", "Free! Free!/A trip/to Mars/for 900/empty jars/Burma Shave"},
36 sha256Test{"14b82014ad2b11f661b5ae6a99b75105c2ffac278cd071cd6c0583279363 5774", "The days of the digital watch are numbered. -Tom Stoppard"},
37 sha256Test{"7102cfd76e2e324889eece5d6c41921b1e142a4ac5a2692be78803097f6a 48d8", "Nepal premier won't resign."},
38 sha256Test{"23b1018cd81db1d67983c5f7417c44da9deb582459e378d7a068552ea649 dc9f", "For every action there is an equal and opposite government program."},
39 sha256Test{"8001f190dfb527261c4cfcab70c98e8097a7a1922129bc4096950e57c799 9a5a", "His money is twice tainted: 'taint yours and 'taint mine."},
40 sha256Test{"8c87deb65505c3993eb24b7a150c4155e82eee6960cf0c3a8114ff736d69 cad5", "There is no reason for any individual to have a computer in their home. -Ken Olsen, 1977"},
41 sha256Test{"bfb0a67a19cdec3646498b2e0f751bddc41bba4b7f30081b0b932aad214d 16d7", "It's a tiny change to the code and not completely disgusting. - Bob Manc hek"},
42 sha256Test{"7f9a0b9bf56332e19f5a0ec1ad9c1425a153da1c624868fda44561d6b74d af36", "size: a.out: bad magic"},
43 sha256Test{"b13f81b8aad9e3666879af19886140904f7f429ef083286195982a758885 8cfc", "The major problem is with sendmail. -Mark Horton"},
44 sha256Test{"b26c38d61519e894480c70c8374ea35aa0ad05b2ae3d6674eec5f52a6930 5ed4", "Give me a rock, paper and scissors and I will move the world. CCFestoon "},
45 sha256Test{"049d5e26d4f10222cd841a119e38bd8d2e0d1129728688449575d4ff42b8 42c1", "If the enemy is within range, then so are you."},
46 sha256Test{"0e116838e3cc1c1a14cd045397e29b4d087aa11b0853fc69ec82e90330d6 0949", "It's well we cannot hear the screams/That we create in others' dreams."} ,
47 sha256Test{"4f7d8eb5bcf11de2a56b971021a444aa4eafd6ecd0f307b5109e4e776cd0 fe46", "You remind me of a TV show, but that's all right: I watch it anyway."},
48 sha256Test{"61c0cc4c4bd8406d5120b3fb4ebc31ce87667c162f29468b3c779675a85a ebce", "C is as portable as Stonehedge!!"},
49 sha256Test{"1fb2eb3688093c4a3f80cd87a5547e2ce940a4f923243a79a2a1e2422206 93ac", "Even if I could be Shakespeare, I think I should still choose to be Fara day. - A. Huxley"},
50 sha256Test{"395585ce30617b62c80b93e8208ce866d4edc811a177fdb4b82d3911d869 6423", "The fugacity of a constituent in a mixture of gases at a given temperatu re is proportional to its mole fraction. Lewis-Randall Rule"},
51 sha256Test{"4f9b189a13d030838269dce846b16a1ce9ce81fe63e65de2f636863336a9 8fe6", "How can you write a big system without C++? -Paul Glick"},
52 }
53
54 func TestGolden(t *testing.T) {
55 for i := 0; i < len(golden); i++ {
56 g := golden[i];
57 c := New();
58 for j := 0; j < 2; j++ {
59 io.WriteString(c, g.in);
60 s := fmt.Sprintf("%x", c.Sum());
61 if s != g.out {
62 t.Errorf("sha256[%d](%s) = %s want %s", j, g.in, s, g.out);
63 t.FailNow();
64 }
65 c.Reset();
66 }
67 }
68 }
OLDNEW
« no previous file with comments | « src/pkg/crypto/sha256/sha256.go ('k') | src/pkg/crypto/sha256/sha256block.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b