1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

"forcing to 32-bit"

Discussion in 'Microcontrollers' started by electroRF, Jan 11, 2014.

  1. electroRF

    electroRF Member

    Joined:
    Jun 23, 2012
    Messages:
    689
    Likes:
    9
    Location:
    Portugal
    Hi,
    I'm reading on SHA1 algorithm, and saw this line of code:
    Code (C):
    /* Force it to 32 bits */
            context->Length_Low &= 0xFFFFFFFF;
    where Length_Low was defined as unsigned
    Code (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).
     
  2. NorthGuy

    NorthGuy Well-Known Member

    Joined:
    Sep 8, 2013
    Messages:
    1,218
    Likes:
    206
    Location:
    Northern Canada
    Could be 64-bit on some computers. They try to make the code portable.
     
  3. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,310
    Likes:
    914
    Location:
    Rochdale UK
    ONLINE
    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...
     
    • Agree Agree x 1
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. electroRF

    electroRF Member

    Joined:
    Jun 23, 2012
    Messages:
    689
    Likes:
    9
    Location:
    Portugal


    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!
     

Share This Page