You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.1 KiB

  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. package crypto
  17. import "testing"
  18. import "encoding/hex"
  19. func TestKeccak256(t *testing.T) {
  20. tests := []struct {
  21. name string
  22. messageHex string
  23. wantHex string
  24. }{
  25. {
  26. name: "from monero 1",
  27. messageHex: "c8fedd380dbae40ffb52",
  28. wantHex: "8e41962058b7422e7404253121489a3e63d186ed115086919a75105661483ba9",
  29. },
  30. {
  31. name: "from monero 2",
  32. messageHex: "5020c4d530b6ec6cb4d9",
  33. wantHex: "8a597f11961935e32e0adeab2ce48b3df2d907c9b26619dad22f42ff65ab7593",
  34. },
  35. {
  36. name: "hello",
  37. messageHex: "68656c6c6f",
  38. wantHex: "1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8",
  39. },
  40. {
  41. name: "from monero cryptotest.pl",
  42. messageHex: "0f3fe9c20b24a11bf4d6d1acd335c6a80543f1f0380590d7323caf1390c78e88",
  43. wantHex: "73b7a236f2a97c4e1805f7a319f1283e3276598567757186c526caf9a49e0a92",
  44. },
  45. }
  46. for _, test := range tests {
  47. message, _ := hex.DecodeString(test.messageHex)
  48. got := Keccak256(message)
  49. want := HexToHash(test.wantHex)
  50. if want != got {
  51. t.Errorf("want %x, got %x", want, got)
  52. }
  53. }
  54. }