<NME> sigma_primitives.hpp
<BEF> #include "../../crypto/sha256.h"

namespace sigma {

template<class Exponent, class GroupElement>
void SigmaPrimitives<Exponent, GroupElement>::commit(const GroupElement& g,
        const std::vector<GroupElement>& h,
        const std::vector<Exponent>& exp,
        const Exponent& r,
        GroupElement& result_out) {
    secp_primitives::MultiExponent mult(h, exp);
    result_out += g * r + mult.get_multiple();
}

template<class Exponent, class GroupElement>
GroupElement SigmaPrimitives<Exponent, GroupElement>::commit(
        const GroupElement& g,
        const Exponent m,
        const GroupElement h,
        const Exponent r){
    return g * m + h * r;
}

template<class Exponent, class GroupElement>
void SigmaPrimitives<Exponent, GroupElement>::convert_to_sigma(
        std::size_t num,
        std::size_t n,
        std::size_t m,
        std::vector<Exponent>& out) {
    std::size_t rem;
    std::size_t j = 0;

    for (j = 0; j < m; ++j)
    {
        rem = num % n;
        num /= n;
        for (std::size_t i = 0; i < n; ++i) {
            if(i == rem)
                out.push_back(Exponent(uint64_t(1)));
            else
                out.push_back(Exponent(uint64_t(0)));
        }
    }
}

template<class Exponent, class GroupElement>
std::vector<std::size_t> SigmaPrimitives<Exponent, GroupElement>::convert_to_nal(
        std::size_t num,
        std::size_t n,
        std::size_t m) {
    std::vector<std::size_t> result;
    result.reserve(m);
    while (num != 0)
    {
        result.emplace_back(num % n);
        num /= n;
    }
    result.resize(m);
    return result;
}

template<class Exponent, class GroupElement>
void SigmaPrimitives<Exponent, GroupElement>::generate_challenge(
        const std::vector<GroupElement>& group_elements,
        Exponent& result_out) {
    if (group_elements.empty())
        throw std::runtime_error("Group elements empty while generating a challenge.");
    CSHA256 hash;
    std::vector<unsigned char> data(group_elements.size() * group_elements[0].memoryRequired());
    unsigned char* current = data.data();
    for (size_t i = 0; i < group_elements.size(); ++i) {
        current = group_elements[i].serialize(current);
    }
    hash.Write(data.data(), data.size());
    unsigned char result_data[CSHA256::OUTPUT_SIZE];
    hash.Finalize(result_data);
    result_out = result_data;
}

template<class Exponent, class GroupElement>
    unsigned char* current = A.serialize(data);
    current = C.serialize(current);
    D.serialize(current);
    hash.Write(data, 3 * 34);
    unsigned char result_data[32];
    hash.Finalize(result_data);
    result_out = result_data;
}
    coefficients[0] *= a;
}

} // namespace sigma

<MSG> Fix use memoryRequired function instead of hard code serialized data size

<DFF> @@ -81,8 +81,8 @@ void SigmaPrimitives<Exponent, GroupElement>::get_x(
     unsigned char* current = A.serialize(data);
     current = C.serialize(current);
     D.serialize(current);
-    hash.Write(data, 3 * 34);
-    unsigned char result_data[32];
+    hash.Write(data, 3 * A.memoryRequired());
+    unsigned char result_data[CSHA256::OUTPUT_SIZE];
     hash.Finalize(result_data);
     result_out = result_data;
 }

{'commit': 'diff --git a/src/sigma/sigma_primitives.hpp b/src/sigma/sigma_primitives.hpp\nindex d20cc1698..a91c1e87f 100644\n--- a/src/sigma/sigma_primitives.hpp\n+++ b/src/sigma/sigma_primitives.hpp\n@@ -81,8 +81,8 @@ void SigmaPrimitives<Exponent, GroupElement>::get_x(\n     unsigned char* current = A.serialize(data);\n     current = C.serialize(current);\n     D.serialize(current);\n-    hash.Write(data, 3 * 34);\n-    unsigned char result_data[32];\n+    hash.Write(data, 3 * A.memoryRequired());\n+    unsigned char result_data[CSHA256::OUTPUT_SIZE];\n     hash.Finalize(result_data);\n     result_out = result_data;\n }\n', 'commit_subject': 'Fix use memoryRequired function instead of hard code serialized data size', 'repo_name': 'zcoinofficial/zcoin', 'committer': {'name': 'thebevrishot', 'email': 'df68310a96b635c8ab540357a2252b83c0286dae@satang.com', 'time_sec': '1553762805', 'tz_offset': '420', 'date': {'seconds': '1553762805'}}, 'commit_tree': '912c4dac1e89e3eb14372e7773ea1bec22d40c16', 'commit_message': 'Fix use memoryRequired function instead of hard code serialized data size\n', 'language_name': 'Rust', 'license': 'mit', 'hunks': '@@ -81,8 +81,8 @@ void SigmaPrimitives<Exponent, GroupElement>::get_x(\n     unsigned char* current = A.serialize(data);\n     current = C.serialize(current);\n     D.serialize(current);\n-    hash.Write(data, 3 * 34);\n-    unsigned char result_data[32];\n+    hash.Write(data, 3 * A.memoryRequired());\n+    unsigned char result_data[CSHA256::OUTPUT_SIZE];\n     hash.Finalize(result_data);\n     result_out = result_data;\n }\n', 'addition_count': 2, 'deletion_count': 2, 'src_file': 'a/src/sigma/sigma_primitives.hpp', 'tgt_file': 'b/src/sigma/sigma_primitives.hpp', 'file_extension': '.hpp', 'before_file': '#include "../../crypto/sha256.h"\n\nnamespace sigma {\n\ntemplate<class Exponent, class GroupElement>\nvoid SigmaPrimitives<Exponent, GroupElement>::commit(const GroupElement& g,\n        const std::vector<GroupElement>& h,\n        const std::vector<Exponent>& exp,\n        const Exponent& r,\n        GroupElement& result_out) {\n    secp_primitives::MultiExponent mult(h, exp);\n    result_out += g * r + mult.get_multiple();\n}\n\ntemplate<class Exponent, class GroupElement>\nGroupElement SigmaPrimitives<Exponent, GroupElement>::commit(\n        const GroupElement& g,\n        const Exponent m,\n        const GroupElement h,\n        const Exponent r){\n    return g * m + h * r;\n}\n\ntemplate<class Exponent, class GroupElement>\nvoid SigmaPrimitives<Exponent, GroupElement>::convert_to_sigma(\n        std::size_t num,\n        std::size_t n,\n        std::size_t m,\n        std::vector<Exponent>& out) {\n    std::size_t rem;\n    std::size_t j = 0;\n\n    for (j = 0; j < m; ++j)\n    {\n        rem = num % n;\n        num /= n;\n        for (std::size_t i = 0; i < n; ++i) {\n            if(i == rem)\n                out.push_back(Exponent(uint64_t(1)));\n            else\n                out.push_back(Exponent(uint64_t(0)));\n        }\n    }\n}\n\ntemplate<class Exponent, class GroupElement>\nstd::vector<std::size_t> SigmaPrimitives<Exponent, GroupElement>::convert_to_nal(\n        std::size_t num,\n        std::size_t n,\n        std::size_t m) {\n    std::vector<std::size_t> result;\n    result.reserve(m);\n    while (num != 0)\n    {\n        result.emplace_back(num % n);\n        num /= n;\n    }\n    result.resize(m);\n    return result;\n}\n\ntemplate<class Exponent, class GroupElement>\nvoid SigmaPrimitives<Exponent, GroupElement>::generate_challenge(\n        const std::vector<GroupElement>& group_elements,\n        Exponent& result_out) {\n    if (group_elements.empty())\n        throw std::runtime_error("Group elements empty while generating a challenge.");\n    CSHA256 hash;\n    std::vector<unsigned char> data(group_elements.size() * group_elements[0].memoryRequired());\n    unsigned char* current = data.data();\n    for (size_t i = 0; i < group_elements.size(); ++i) {\n        current = group_elements[i].serialize(current);\n    }\n    hash.Write(data.data(), data.size());\n    unsigned char result_data[CSHA256::OUTPUT_SIZE];\n    hash.Finalize(result_data);\n    result_out = result_data;\n}\n\ntemplate<class Exponent, class GroupElement>\n    unsigned char* current = A.serialize(data);\n    current = C.serialize(current);\n    D.serialize(current);\n    hash.Write(data, 3 * 34);\n    unsigned char result_data[32];\n    hash.Finalize(result_data);\n    result_out = result_data;\n}\n    coefficients[0] *= a;\n}\n\n} // namespace sigma\n', 'message': 'Fix use memoryRequired function instead of hard code serialized data size\n', 'author_name': 'thebevrishot', 'lang': 'hpp'}