Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
RC5
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Key expansion=== The key expansion algorithm is illustrated below, first in [[pseudocode]], then example [[C (programming language)|C code]] copied directly from the reference paper's appendix. Following the naming scheme of the paper, the following variable names are used: * {{math|{{var|w}}}} β The length of a word in bits, typically 16, 32 or 64. Encryption is done in 2-word blocks. * {{math|1={{var|u}} = {{var|w}}/8}} β The length of a word in bytes. * {{math|{{var|b}}}} β The length of the key in bytes. * {{math|K[]}} β The key, considered as an array of bytes (using 0-based indexing). * {{math|{{var|c}}}} β The length of the key in words (or 1, if b = 0). * {{math|L[]}} β A temporary working array used during key scheduling, initialized to the key in words. * {{math|{{var|r}}}} β The number of rounds to use when encrypting data. * {{math|1={{var|t}} = 2({{var|r}}+1)}} β the number of round subkeys required. * {{math|S[]}} β The round subkey words. * {{math|P{{sub|{{var|w}}}}}} β The first magic constant, defined as {{math|Odd(({{var|e}} β 2) {{times}} 2{{sup|{{var|w}}}})}}, where {{math|Odd}} is the nearest odd integer to the given input, {{math|{{var|e}}}} is the [[e (mathematical constant)|base of the natural logarithm]], and {{math|{{var|w}}}} is defined above. For common values of {{math|{{var|w}}}}, the associated values of {{math|P{{sub|{{var|w}}}}}} are given here in hexadecimal: ** For ''w'' = 16: 0xB7E1 ** For ''w'' = 32: 0xB7E15163 ** For ''w'' = 64: 0xB7E151628AED2A6B * {{math|Q{{sub|{{var|w}}}}}} β The second magic constant, defined as {{math|Odd(({{phi}} β 1) {{times}} 2{{sup|{{var|w}}}})}}, where {{math|Odd}} is the nearest odd integer to the given input, where {{math|{{phi}}}} is the [[golden ratio]], and {{math|{{var|w}}}} is defined above. For common values of {{math|{{var|w}}}}, the associated values of {{math|Q{{sub|{{var|w}}}}}} are given here in hexadecimal: ** For ''w'' = 16: 0x9E37 ** For ''w'' = 32: 0x9E3779B9 ** For ''w'' = 64: 0x9E3779B97F4A7C15 <syntaxhighlight lang="python"> # Break K into words # u = w / 8 c = ceiling(max(b, 1) / u) # L is initially a c-length list of 0-valued w-length words for i = b-1 down to 0 do: L[i / u] = (L[i / u] <<< 8) + K[i] # Initialize key-independent pseudorandom S array # S is initially a t=2(r+1) length list of undefined w-length words S[0] = P_w for i = 1 to t-1 do: S[i] = S[i - 1] + Q_w # The main key scheduling loop i = j = 0 A = B = 0 do 3 * max(t, c) times: A = S[i] = (S[i] + A + B) <<< 3 B = L[j] = (L[j] + A + B) <<< (A + B) i = (i + 1) % t j = (j + 1) % c # return S </syntaxhighlight> The example source code is provided from the appendix of Rivest's paper on RC5. The implementation is designed to work with w = 32, r = 12, and b = 16. <syntaxhighlight lang="c"> void RC5_SETUP(unsigned char *K) { // w = 32, r = 12, b = 16 // c = max(1, ceil(8 * b/w)) // t = 2 * (r+1) WORD i, j, k, u = w/8, A, B, L[c]; for (i = b-1, L[c-1] = 0; i != -1; i--) L[i/u] = (L[i/u] << 8) + K[i]; for (S[0] = P, i = 1; i < t; i++) S[i] = S[i-1] + Q; for (A = B = i = j = k = 0; k < 3 * t; k++, i = (i+1) % t, j = (j+1) % c) { A = S[i] = ROTL(S[i] + (A + B), 3); B = L[j] = ROTL(L[j] + (A + B), (A + B)); } } </syntaxhighlight>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
RC5
(section)
Add topic