2 Star 0 Fork 0

mirrors_jedisct1/libzerocoin

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Accumulator.cpp 2.59 KB
一键复制 编辑 原始数据 按行查看 历史
Ian Miers 提交于 2013-07-04 23:21 . libzerocoin initial commit
/**
* @file Accumulator.cpp
*
* @brief Accumulator and AccumulatorWitness classes for the Zerocoin library.
*
* @author Ian Miers, Christina Garman and Matthew Green
* @date June 2013
*
* @copyright Copyright 2013 Ian Miers, Christina Garman and Matthew Green
* @license This project is released under the MIT license.
**/
#include <sstream>
#include "Accumulator.h"
namespace libzerocoin {
//Accumulator class
Accumulator::Accumulator(const AccumulatorAndProofParams* p, const CoinDenomination d): params(p), denonination(d) {
if (!(params->initialized)){
throw ZerocoinException("Invalid parameters for accumulator");
}
this->value = this->params->accumulatorBase;
}
void Accumulator::accumulate(const PublicCoin& coin) {
// Make sure we're initialized
if(!(this->value)){
throw ZerocoinException("Accumulator is not initialized");
}
if(this->denonination != coin.getDenomination()){
std::stringstream msg;
msg << "Wrong denomination for coin. Expected coins of denomination: " <<
this->denonination << ". Instead, got a coin of denomination: " <<
coin.getDenomination() << std::ends;
throw std::invalid_argument(msg.str());
}
if(coin.validate()){
// Compute new accumulator = "old accumulator"^{element} mod N
this->value = this->value.pow_mod(coin.getValue(), this->params->accumulatorModulus);
}else{
throw std::invalid_argument("Coin is not valid");
}
}
const CoinDenomination Accumulator::getDenomination() const {
return static_cast<CoinDenomination> (this->denonination);
}
const Bignum& Accumulator::getValue() const {
return this->value;
}
Accumulator& Accumulator::operator += (const PublicCoin& c) {
this->accumulate(c);
return *this;
}
bool Accumulator::operator == (const Accumulator rhs) const{
return this->value == rhs.value;
}
//AccumulatorWitness class
AccumulatorWitness::AccumulatorWitness(const Params* p,
const Accumulator& checkpoint, const PublicCoin coin): params(p), witness(checkpoint), element(coin) {
}
void AccumulatorWitness::AddElement(const PublicCoin& c) {
if(element != c){
witness += c;
}
}
const Bignum& AccumulatorWitness::getValue() const{
return this->witness.getValue();
}
bool AccumulatorWitness::VerifyWitness(const Accumulator& a) const {
Accumulator temp(witness);
temp += element;
return temp == a;
}
AccumulatorWitness& AccumulatorWitness::operator +=(
const PublicCoin& rhs) {
this->AddElement(rhs);
return *this;
}
} /* namespace libzerocoin */
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_jedisct1/libzerocoin.git
git@gitee.com:mirrors_jedisct1/libzerocoin.git
mirrors_jedisct1
libzerocoin
libzerocoin
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385