Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Serpent (cipher)
(section)
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 schedule in C++ === <syntaxhighlight lang="cpp"> #define FRAC 0x9e3779b9 // fractional part of the golden ratio #define ROTL(A, n) ((A) << n | (A) >> 32-n) uint32_t key[8]; // key provided by user uint32_t subkey[33][4]; // roundkeys const uint8_t S[8][16] = {}; // S-boxes /* key schedule: get prekeys */ void get_pre(uint32_t w[4*33], const uint32_t k[8]) { uint32_t x[4*33+8]; for (int i = 0; i < 8; i++) x[i] = k[i]; for (int i = 8; i < 140; i++) { x[i] = ROTL(x[i-8] ^ x[i-5] ^ x[i-3] ^ x[i-1] ^ FRAC ^ (i-8), 11); w[i-8] = x[i]; } } /* key schedule: get subkeys */ void get_sk(const uint32_t w[4*33], uint32_t (*sk)[4]) { uint8_t i, p, j, s, k; for (i = 0; i < 33; i++) { p = 32 + 3 - i; for (j = 0; j < 4; j++) sk[i][j] = 0; for (k = 0; k < 32; k++) { s = S[p % 8][((w[4 * i + 0] >> k) & 0x1) << 0 | ((w[4 * i + 1] >> k) & 0x1) << 1 | ((w[4 * i + 2] >> k) & 0x1) << 2 | ((w[4 * i + 3] >> k) & 0x1) << 3 ]; for (j = 0; j < 4; j++) { sk[i][j] |= ((s >> j) & 0x1) << k; } } } } void key_schedule() { uint32_t w[4*33]; get_pre(w, key); get_sk(w, subkey); } </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)