0

我有以下代码。当我使用数组时它工作得很好,我只想用向量重构它,这样我就可以减少我的哈希的足迹。

uint8_t* rip(uint8_t *in, vector<uint8_t*> *out)
{
    RIPEMD160(in, 32, out);
    return out;
}

int main()
{
    char pub_key[] = "0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B23522CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6";
    vector<uint8_t> res_rip(20);
    uint8_t res_sha[32];
    uint8_t res_tmp[65];
    hex_decode(pub_key,131,res_tmp);
    for(int i =0; i < 65; i++)
        cout << setw(2) << setfill('0') << hex << (int)res_tmp[i];
    cout << endl << endl;
    sha(res_tmp,res_sha);
    rip(res_sha,&res_rip);
    for(int i =0; i < 32; i++)
        cout << setw(2) << setfill('0') << hex << (int)res_sha[i];
    cout << endl << endl;
    for(int i =0; i < 20; i++)
        cout << setw(2) << setfill('0') << hex << (int)res_rip[i];
    return 0;
}

我不确定我需要如何将向量传递给函数,或者我需要做什么才能正确返回它。

我收到编译器消息error: cannot convert 'std::vector<unsigned char*>*' to 'unsigned char*' for argument '3' to 'unsigned char* RIPEMD160(const unsigned char*, size_t, unsigned char*)'

4

1 回答 1

4

That function expects a pointer to the data, not a std::vector.

In C++11, you can get a pointer to the data in a vector by calling std::vector::data().

RIPEMD160(in, 32, out->data() );

In C++03 or later, you can get a pointer to the data in a vector by taking the address of the first element.

RIPEMD160(in, 32, &out->at(0) );
于 2013-04-22T17:53:34.277 回答