allow 256 key max

This commit is contained in:
TLINDEN
2015-09-02 06:06:04 +02:00
parent 28bf5306c2
commit cf85600b57
2 changed files with 8 additions and 8 deletions

View File

@@ -55,10 +55,10 @@ TWENTY4 uses two S-Box arrays, one for key expansion and one for encryption.
## Key expansion ## Key expansion
The input key will be expanded into a 17 byte array. Maximum key size is The input key will be expanded into a 17 byte array. Maximum key size is
17 bytes (136 bit). 32 bytes (256 bit).
IV = KU[0] IV = KU[0]
for ROUND in 0..16 for ROUND in 0..31
if KU[ROUND] if KU[ROUND]
K[ROUND] = IV xor KU[ROUND] K[ROUND] = IV xor KU[ROUND]
else else
@@ -69,7 +69,7 @@ The input key will be expanded into a 17 byte array. Maximum key size is
endfor endfor
for KROUND in 0..31 for KROUND in 0..31
for ROUND in 0..17 for ROUND in 0..31
K[ROUND] = IV xor (rotateleft-3(K[ROUND]) xor KBOX[rcon(IV)]) K[ROUND] = IV xor (rotateleft-3(K[ROUND]) xor KBOX[rcon(IV)])
IV = K[ROUND] IV = K[ROUND]
endfor endfor
@@ -79,7 +79,7 @@ where:
KU: input key KU: input key
K[17]: initial round key array K[17]: initial round key array
ROUND: encryption round 1-17 ROUND: encryption round 1-32
KROUND: key expansion round 1-32 KROUND: key expansion round 1-32
KBOX[256]: pre computed S-Box for key expansion KBOX[256]: pre computed S-Box for key expansion
@@ -98,7 +98,7 @@ where:
endfor endfor
func rotatekey(K, B) func rotatekey(K, B)
[rotate K[17] array elementy 1 to the right] [rotate K[32] array elementy 1 to the right]
for N in 0..16: for N in 0..16:
K[N] = KBOX[K[N] xor B] K[N] = KBOX[K[N] xor B]
endfor endfor

View File

@@ -163,7 +163,7 @@ void keyhash(char *pw, byte *hash) {
iv = kbox[(byte)pw[0]]; iv = kbox[(byte)pw[0]];
/* stretch pw */ /* stretch pw */
for(i=0; i<S_BOX_ROUNDS; i++) { for(i=0; i<K_HASH_ROUNDS; i++) {
if((size_t)i < pwlen) if((size_t)i < pwlen)
hash[i] = iv ^ pw[i]; hash[i] = iv ^ pw[i];
else else
@@ -175,7 +175,7 @@ void keyhash(char *pw, byte *hash) {
/* diffuse and confuse hash */ /* diffuse and confuse hash */
for(round=0; round<K_HASH_ROUNDS; round++) { for(round=0; round<K_HASH_ROUNDS; round++) {
for(i=0; i<S_BOX_ROUNDS; i++) { for(i=0; i<K_HASH_ROUNDS; i++) {
hash[i] = iv ^ (rot8left(hash[i], 3) ^ kbox[rcon(iv)]); hash[i] = iv ^ (rot8left(hash[i], 3) ^ kbox[rcon(iv)]);
iv = hash[i]; iv = hash[i];
} }
@@ -283,7 +283,7 @@ int cbc_handleio(byte *key, int encrypt) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
byte key[S_BOX_ROUNDS]; byte key[K_HASH_ROUNDS];
int encrypt; int encrypt;
if(argc != 3) { if(argc != 3) {