github.com/deroproject/derosuite@v2.1.6-1.0.20200307070847-0f2e589c7a2b+incompatible/crypto/keccak_test.go (about) 1 // Copyright 2017-2018 DERO Project. All rights reserved. 2 // Use of this source code in any form is governed by RESEARCH license. 3 // license can be found in the LICENSE file. 4 // GPG: 0F39 E425 8C65 3947 702A 8234 08B2 0360 A03A 9DE8 5 // 6 // 7 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 8 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 9 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 10 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 11 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 12 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 13 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 14 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 15 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 16 17 package crypto 18 19 import "testing" 20 import "encoding/hex" 21 22 func TestKeccak256(t *testing.T) { 23 tests := []struct { 24 name string 25 messageHex string 26 wantHex string 27 }{ 28 { 29 name: "from monero 1", 30 messageHex: "c8fedd380dbae40ffb52", 31 wantHex: "8e41962058b7422e7404253121489a3e63d186ed115086919a75105661483ba9", 32 }, 33 { 34 name: "from monero 2", 35 messageHex: "5020c4d530b6ec6cb4d9", 36 wantHex: "8a597f11961935e32e0adeab2ce48b3df2d907c9b26619dad22f42ff65ab7593", 37 }, 38 { 39 name: "hello", 40 messageHex: "68656c6c6f", 41 wantHex: "1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8", 42 }, 43 { 44 name: "from monero cryptotest.pl", 45 messageHex: "0f3fe9c20b24a11bf4d6d1acd335c6a80543f1f0380590d7323caf1390c78e88", 46 wantHex: "73b7a236f2a97c4e1805f7a319f1283e3276598567757186c526caf9a49e0a92", 47 }, 48 } 49 for _, test := range tests { 50 message, _ := hex.DecodeString(test.messageHex) 51 got := Keccak256(message) 52 want := HexToHash(test.wantHex) 53 if want != got { 54 t.Errorf("want %x, got %x", want, got) 55 } 56 } 57 }