Manipulating 80 bits datatype in C

Deadly 提交于 2019-12-22 04:38:11

问题


I'm implementing some cryptographic algorithm in C which involves an 80 bits key. A particular operation involves a rotate shifting the key x number of bits.

I've tried the long double type which if I'm not wrong is 80bits, but that doesn't work with the bitshift operator.

The only alternative I can come up with is to use a 10 element char array with some complicated looping and if-else.

My question is whether there's some simple and efficient way of carrying this out.

Thanks.


回答1:


There is something a bit messed up here. If I understand you correctly, you are using a "soft" cpu on the FPGA.

  1. Traditionally, people use the FPGA to make their own shift registers through VHDL/Verilog. These kind of algorithms are fairly painless to implement and very fast. Back at the university I did this is for a cryptography project.

  2. Moreover, the paper you mentioned talks about a 128 bit key. This would be significantly easier to implement?




回答2:


Sadly you need a bignum library. While C native data types have support for 80 bit floats it doesn't actually do what you want.

It is possible to link something like GMP or even use a less desirable approaches like 10 character array or two numbers a long and short (64bit and 16bit integers).

Neither is particularly pretty but they do work and if you're planning on using this for anything but a class, GMP is the way to go. Otherwise you could end up with a whole mess of timing attacks which you could code around but it could get really nasty, real quick.



来源:https://stackoverflow.com/questions/9849764/manipulating-80-bits-datatype-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!