"forcing to 32-bit"

Status
Not open for further replies.

electroRF

Member
Hi,
I'm reading on SHA1 algorithm, and saw this line of code:
C:
/* Force it to 32 bits */
        context->Length_Low &= 0xFFFFFFFF;

where Length_Low was defined as unsigned
C:
unsigned Length_Low;       /* Message length in bits           */

What does it mean "forcing"?

isn't Length_Low is already 32-bit, assuming unsigned is 4-byte? (it was indeed mentioned in the comments that they assume 32-bit machine at least).
 
In C we say "casting" Lets assume you want an unsigned short and you pass it to a 32 bit register, the top two bytes may contain data... When you cast or force the move it remains the same value..

Similarly truncating a 32 bit number to a 16 bit number.. ensuring the data remains intact.... Remember when a computer boots... You have no idea what each memory or register contains...
 
Could be 64-bit on some computers. They try to make the code portable.



Got you guys

They wanted to ensure that if the unsigned was 8-byte and not 4-byte, then this operation would zero the most significant 4 Bytes.

Thank a lot!
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…