diff --git a/sys/crypto/rc5.c b/sys/crypto/rc5.c index 294f3369c6..0463e9c2e5 100644 --- a/sys/crypto/rc5.c +++ b/sys/crypto/rc5.c @@ -63,7 +63,8 @@ int rc5_encrypt(cipher_context_t *context, uint8_t *block, { register uint32_t l; register uint32_t r; - register uint32_t *s = ((rc5_context_t *) context->context)->skey; + rc5_context_t *rc5_context = (rc5_context_t *) context->context; + register uint32_t *s = rc5_context->skey; uint8_t i, tmp; c2l(block, l); block += 4; @@ -95,8 +96,8 @@ int rc5_decrypt(cipher_context_t *context, uint8_t *cipherBlock, { register uint32_t l; register uint32_t r; - register uint32_t *s = ((rc5_context_t *) context->context)->skey + - (2 * RC5_ROUNDS) + 1; + rc5_context_t *rc5_context = (rc5_context_t *) context->context; + register uint32_t *s = rc5_context->skey + (2 * RC5_ROUNDS) + 1; uint8_t i, tmp; c2l(cipherBlock, l); @@ -131,7 +132,8 @@ int rc5_setup_key(cipher_context_t *context, uint8_t *key, uint8_t keysize) uint8_t ii, jj, m; int8_t i; uint8_t tmp[8]; - S = ((rc5_context_t *)context->context)->skey; + rc5_context_t *rc5_context = (rc5_context_t *) context->context; + S = rc5_context->skey; //dumpBuffer ("RC5M:setupKey K", (uint8_t *)key, 8); c2l(key, l); @@ -154,7 +156,7 @@ int rc5_setup_key(cipher_context_t *context, uint8_t *key, uint8_t keysize) //dumpBuffer ("RC5M: setupKey S", (uint8_t *)S, 2 * (RC5_ROUNDS +1) * 4); ii = jj = 0; A = B = 0; - S = ((rc5_context_t *)context->context)->skey; + S = rc5_context->skey; for (i = 3 * (2 * RC5_ROUNDS + 2) - 1; i >= 0; i--) { k = (*S + A + B)&RC5_32_MASK; @@ -168,7 +170,7 @@ int rc5_setup_key(cipher_context_t *context, uint8_t *key, uint8_t keysize) if (++ii >= 2 * RC5_ROUNDS + 2) { ii = 0; - S = ((rc5_context_t *)context->context)->skey; + S = rc5_context->skey; } jj ^= 4; diff --git a/sys/crypto/skipjack.c b/sys/crypto/skipjack.c index 7acc770c41..fea74652d8 100644 --- a/sys/crypto/skipjack.c +++ b/sys/crypto/skipjack.c @@ -137,7 +137,8 @@ int skipjack_encrypt(cipher_context_t *context, uint8_t *plainBlock, // prologue 10 pushs = 20 cycles /*register*/ uint8_t counter = 1; - /*register*/ uint8_t *skey = ((skipjack_context_t *)context->context)->skey; + skipjack_context_t *skipjack_context = (skipjack_context_t *)context->context; + /*register*/ uint8_t *skey = skipjack_context->skey; /*register*/ uint16_t w1, w2, w3, w4, tmp; /*register*/ uint8_t bLeft, bRight; @@ -172,7 +173,7 @@ int skipjack_encrypt(cipher_context_t *context, uint8_t *plainBlock, RULE_A(skey, w1, w2, w3, w4, counter, tmp, bLeft, bRight); } - skey = ((skipjack_context_t *)context->context)->skey; + skey = skipjack_context->skey; while (counter < 9) { // 3x RULE_A(skey, w1, w2, w3, w4, counter, tmp, bLeft, bRight); @@ -182,13 +183,13 @@ int skipjack_encrypt(cipher_context_t *context, uint8_t *plainBlock, RULE_B(skey, w1, w2, w3, w4, counter, tmp, bLeft, bRight); } - skey = ((skipjack_context_t *)context->context)->skey; + skey = skipjack_context->skey; while (counter < 16) { // 5x RULE_B(skey, w1, w2, w3, w4, counter, tmp, bLeft, bRight); } - skey = ((skipjack_context_t *)context->context)->skey; + skey = skipjack_context->skey; // 1x RULE_B(skey, w1, w2, w3, w4, counter, tmp, bLeft, bRight); @@ -196,7 +197,7 @@ int skipjack_encrypt(cipher_context_t *context, uint8_t *plainBlock, RULE_A(skey, w1, w2, w3, w4, counter, tmp, bLeft, bRight); } - skey = ((skipjack_context_t *)context->context)->skey; + skey = skipjack_context->skey; while (counter < 25) { // 4x RULE_A(skey, w1, w2, w3, w4, counter, tmp, bLeft, bRight); @@ -204,13 +205,13 @@ int skipjack_encrypt(cipher_context_t *context, uint8_t *plainBlock, // 1x RULE_B(skey, w1, w2, w3, w4, counter, tmp, bLeft, bRight); - skey = ((skipjack_context_t *)context->context)->skey; + skey = skipjack_context->skey; while (counter < 31) { // 5x RULE_B(skey, w1, w2, w3, w4, counter, tmp, bLeft, bRight); } - skey = ((skipjack_context_t *)context->context)->skey; + skey = skipjack_context->skey; while (counter < 33) { // 2x RULE_B(skey, w1, w2, w3, w4, counter, tmp, bLeft, bRight); @@ -233,7 +234,8 @@ int skipjack_decrypt(cipher_context_t *context, uint8_t *cipherBlock, uint8_t *plainBlock) { /*register*/ uint8_t counter = 32; - /*register*/ uint8_t *skey = ((skipjack_context_t *)context->context)->skey + 4; + skipjack_context_t *skipjack_context = (skipjack_context_t *)context->context; + /*register*/ uint8_t *skey = skipjack_context->skey + 4; /*register*/ uint16_t w1, w2, w3, w4, tmp; /*register*/ uint8_t bLeft, bRight; @@ -267,13 +269,13 @@ int skipjack_decrypt(cipher_context_t *context, uint8_t *cipherBlock, RULE_B_INV(skey, w1, w2, w3, w4, counter, tmp, bLeft, bRight); } - skey = ((skipjack_context_t *)context->context)->skey + 16; + skey = skipjack_context->skey + 16; while (counter > 25) { //5x RULE_B_INV(skey, w1, w2, w3, w4, counter, tmp, bLeft, bRight); } - skey = ((skipjack_context_t *)context->context)->skey + 16; + skey = skipjack_context->skey + 16; //1x RULE_B_INV(skey, w1, w2, w3, w4, counter, tmp, bLeft, bRight); @@ -281,7 +283,7 @@ int skipjack_decrypt(cipher_context_t *context, uint8_t *cipherBlock, RULE_A_INV(skey, w1, w2, w3, w4, counter, tmp, bLeft, bRight); } - skey = ((skipjack_context_t *)context->context)->skey + 16; + skey = skipjack_context->skey + 16; while (counter > 16) { //4x RULE_A_INV(skey, w1, w2, w3, w4, counter, tmp, bLeft, bRight); @@ -289,13 +291,13 @@ int skipjack_decrypt(cipher_context_t *context, uint8_t *cipherBlock, //1x RULE_B_INV(skey, w1, w2, w3, w4, counter, tmp, bLeft, bRight); - skey = ((skipjack_context_t *)context->context)->skey + 16; + skey = skipjack_context->skey + 16; while (counter > 10) { //5x RULE_B_INV(skey, w1, w2, w3, w4, counter, tmp, bLeft, bRight); } - skey = ((skipjack_context_t *)context->context)->skey + 16; + skey = skipjack_context->skey + 16; while (counter > 8) { // 2x RULE_B_INV(skey, w1, w2, w3, w4, counter, tmp, bLeft, bRight); @@ -305,7 +307,7 @@ int skipjack_decrypt(cipher_context_t *context, uint8_t *cipherBlock, RULE_A_INV(skey, w1, w2, w3, w4, counter, tmp, bLeft, bRight); } - skey = ((skipjack_context_t *)context->context)->skey + 16; + skey = skipjack_context->skey + 16; while (counter > 0) { // 5x RULE_A_INV(skey, w1, w2, w3, w4, counter, tmp, bLeft, bRight); @@ -326,7 +328,8 @@ int skipjack_decrypt(cipher_context_t *context, uint8_t *cipherBlock, int skipjack_setup_key(cipher_context_t *context, uint8_t *key, uint8_t keysize) { int i = 0; - uint8_t *skey = ((skipjack_context_t *)context->context)->skey; + skipjack_context_t *skipjack_context = (skipjack_context_t *)context->context; + uint8_t *skey = skipjack_context->skey; // for keys which are smaller than 160 bits, concatenate until they reach // 160 bits in size. Note that key expansion is just concatenation.