简体   繁体   English

如何将SHA1转换为无符号长整数的array [5]?

[英]How to convert SHA1 to array[5] of unsigned long ints?

For the purposes of library/subsystem that I use I have to convert SHA1 (calculated with use of eg opensll) to 5 element array of unsigned long ints (32 bits variables) or create the aforementioned SHA1-5-long-array by myself. 为了我使用的库/子系统的目的,我必须将SHA1(使用openssl计算)转换为5个元素的无符号长整数(32位变量)数组,或者由我自己创建上述SHA1-5-long-array。

Reason: 原因:

SHA1 (160 bits) = 5 x unsigned long int (32 bits)

I think that first solution will be better so here is my question: how should I go around this task? 我认为第一个解决方案会更好,所以这是我的问题:我应该如何处理此任务? Read byte/bit by byte/bit and then create unsigned long ints from it and put it in the array or is there a different solution? 逐字节读取字节/位,然后从中创建无符号长整数并将其放入数组中,还是有其他解决方案?

SHA1 produces a 20 byte hash-value. SHA1产生20字节的哈希值。 In openssl it returns an unsigned char* . 在openssl中,它返回一个unsigned char* I'm guessing you can use a union of unsigned char[20] and uint32_t[5] and use the chars for easy byte access: 我猜你可以使用unionunsigned char[20]uint32_t[5]和使用,便于字节访问字符:

union mysha1{
    uint32_t shaint[5];
    unsigned char shachar[20];
};

Add to that a bunch of operators (indexing for example) and you are good to go. 再加上一堆运算符(例如索引),您就可以开始了。

If you wanna keep it crude and simple you can do a memcpy between the SHA1 output and your uint32_t[5] , though. 如果您想保持它的简洁和简单,则可以在SHA1输出和uint32_t[5]之间进行一次memcpy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM