Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manipulating 80 bits datatype in C

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.

like image 840
gamerx Avatar asked Mar 24 '12 06:03

gamerx


2 Answers

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?

like image 170
Mikhail Avatar answered Nov 09 '22 22:11

Mikhail


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.

like image 29
Ben Avatar answered Nov 09 '22 22:11

Ben