小编haf*_*idh的帖子

将uint8_t数组转换为c中的char数组

最初我想将此uint8_t数组转换为charc中的数组.我试图解决这个问题有点困难.我的第一个替代解决方案是将另一个类型值复制到临时值,将tmp值复制到可写char,然后从内存中删除tmp值.顺便说一句,这用于伴随blake哈希函数.这是我的代码片段:

char * bl(char *input)
{
    uint8_t  output[64];
    char msg[]= "";
    char *tmp;

    int dInt;

    memset(output,0,64);
    tmp = (char*) malloc(64);
    if (!tmp){
            exit( 1);
    }

    dInt = strlen(input);

    if (dInt > 0xffff){
            exit( 1);
    }
    uint8_t data[dInt];

    memset(data,0, dInt);
    strlcpy(data,input,dInt);
    uint64_t dLen =dInt;
    blake512_hash(output, data,dLen);

    int k;
    for (k=0;k<64;k++){
            tmp[k] = output[k];  //does this "copy" is buggy code?
    }

    memcpy(msg, tmp,64);
    //so here I can to delete tmp value
    // I dont want there were left …
Run Code Online (Sandbox Code Playgroud)

c arrays hash

0
推荐指数
1
解决办法
2万
查看次数

标签 统计

arrays ×1

c ×1

hash ×1