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.

78 lines
2.5 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 ringct
  17. import "fmt"
  18. /* this files handles the generation and verification in ringct full */
  19. // NOTE the transaction must have been expanded earlier and must have a key image, mixring etc
  20. // this is implementation of verRctMG from rctSigs.cpp file
  21. func (r *RctSig) VerifyRCTSimple_Core() (result bool) {
  22. result = false
  23. if r.sigType != RCTTypeSimple {
  24. if DEBUGGING_MODE {
  25. fmt.Printf("Signature NOT RingCT Simple type, verification failed\n")
  26. }
  27. result = false
  28. return
  29. }
  30. pre_mlsag_hash := Key(Get_pre_mlsag_hash(r))
  31. // loop through all the inputs
  32. for inputi := 0; inputi < len(r.pseudoOuts); inputi++ {
  33. rows := 1
  34. cols := len(r.MixRing[inputi])
  35. if cols <= 2 {
  36. result = false
  37. }
  38. M := make([][]Key, cols) // lets create the double dimensional array
  39. for i := 0; i < cols; i++ {
  40. M[i] = make([]Key, rows+1, rows+1)
  41. }
  42. //create the matrix to mg sig
  43. for i := 0; i < cols; i++ {
  44. M[i][0] = r.MixRing[inputi][i].Destination
  45. SubKeys(&M[i][1], &r.MixRing[inputi][i].Mask, &r.pseudoOuts[inputi])
  46. }
  47. // do the mlsag verification
  48. result = MLSAG_Ver(pre_mlsag_hash, M, &r.MlsagSigs[inputi], rows, r)
  49. if result == false { // verification of 1 one vin failed mark, entire TX as failed
  50. if DEBUGGING_MODE {
  51. fmt.Printf("RCT Simple signature verification failed for input %d\n", inputi)
  52. }
  53. return
  54. }
  55. }
  56. // we are here means everything went smoothly
  57. if DEBUGGING_MODE {
  58. fmt.Printf(" RCT Simple Signature successfully verified\n")
  59. }
  60. // result is already true so
  61. return
  62. }