LCOV - code coverage report
Current view: top level - src/libzerocoin - Commitment.h (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 0 6 0.0 %
Date: 2025-02-23 09:33:43 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /**
       2             :  * @file       Commitment.h
       3             :  *
       4             :  * @brief      Commitment and CommitmentProof classes for the Zerocoin library.
       5             :  *
       6             :  * @author     Ian Miers, Christina Garman and Matthew Green
       7             :  * @date       June 2013
       8             :  *
       9             :  * @copyright  Copyright 2013 Ian Miers, Christina Garman and Matthew Green
      10             :  * @license    This project is released under the MIT license.
      11             :  **/
      12             : // Copyright (c) 2017-2021 The PIVX Core developers
      13             : 
      14             : #ifndef PIVX_LIBZEROCOIN_COMMITMENT_H
      15             : #define PIVX_LIBZEROCOIN_COMMITMENT_H
      16             : 
      17             : #include "Params.h"
      18             : #include "serialize.h"
      19             : 
      20             : // We use a SHA256 hash for our PoK challenges. Update the following
      21             : // if we ever change hash functions.
      22             : #define COMMITMENT_EQUALITY_CHALLENGE_SIZE  256
      23             : 
      24             : // A 512-bit security parameter for the statistical ZK PoK.
      25             : #define COMMITMENT_EQUALITY_SECMARGIN       512
      26             : 
      27             : namespace libzerocoin {
      28             : 
      29             : /**
      30             :  * A commitment, complete with contents and opening randomness.
      31             :  * These should remain secret. Publish only the commitment value.
      32             :  */
      33             : class Commitment {
      34             : public:
      35           0 :     explicit Commitment(const IntegerGroupParams* p, const CBigNum& bnSerial, const CBigNum& bnRandomness):
      36             :                 params(p),
      37             :                 randomness(bnRandomness),
      38           0 :                 contents(bnSerial)
      39             :     {
      40           0 :         this->commitmentValue = (params->g.pow_mod(this->contents, params->modulus).mul_mod(
      41           0 :                                  params->h.pow_mod(this->randomness, params->modulus), params->modulus));
      42           0 :     }
      43             : 
      44             :     Commitment(const IntegerGroupParams* p, const CBigNum& value):
      45             :         Commitment(p, value, CBigNum::randBignum(p->groupOrder)) {};
      46             : 
      47           0 :     const CBigNum& getCommitmentValue() const { return this->commitmentValue; };
      48             :     const CBigNum& getRandomness() const { return this->randomness; };
      49             :     const CBigNum& getContents() const { return this->contents; };
      50             : 
      51             : private:
      52             :     const IntegerGroupParams *params;
      53             :     CBigNum commitmentValue;
      54             :     CBigNum randomness;
      55             :     const CBigNum contents;
      56             : 
      57             :     SERIALIZE_METHODS(Commitment, obj) { READWRITE(obj.commitmentValue, obj.randomness, obj.contents); }
      58             : };
      59             : } /* namespace libzerocoin */
      60             : #endif // PIVX_LIBZEROCOIN_COMMITMENT_H

Generated by: LCOV version 1.14