Skip to content
Snippets Groups Projects
Commit a7bd5fa7 authored by Niels Möller's avatar Niels Möller
Browse files

Use ROTL32 in the cast128 code.

parent 94de4dd9
Branches
Tags
No related merge requests found
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
(ROL128): ... old name. (ROL128): ... old name.
* camellia-crypt-internal.c: Updated for renamed rotation macros. * camellia-crypt-internal.c: Updated for renamed rotation macros.
* camellia-set-encrypt-key.c: Likewise. * camellia-set-encrypt-key.c: Likewise.
* cast128.c (ROL): Deleted macro.
(F1, F2, F3): Updated to use ROTL32 (reversed order of arguments).
Also added proper do { ... } while (0) wrappers.
2012-03-30 Niels Möller <nisse@lysator.liu.se> 2012-03-30 Niels Möller <nisse@lysator.liu.se>
......
...@@ -50,22 +50,22 @@ ...@@ -50,22 +50,22 @@
#define U8c(x) ( (uint8_t) ((x>>8)&0xff) ) #define U8c(x) ( (uint8_t) ((x>>8)&0xff) )
#define U8d(x) ( (uint8_t) ((x)&0xff) ) #define U8d(x) ( (uint8_t) ((x)&0xff) )
/* Circular left shift */
#define ROL(x, n) ( ((x)<<(n)) | ((x)>>(32-(n))) )
/* CAST-128 uses three different round functions */ /* CAST-128 uses three different round functions */
#define F1(l, r, i) \ #define F1(l, r, i) do { \
t = ROL(ctx->keys[i] + r, ctx->keys[i+16]); \ t = ROTL32(ctx->keys[i+16], ctx->keys[i] + r); \
l ^= ((cast_sbox1[U8a(t)] ^ cast_sbox2[U8b(t)]) \ l ^= ((cast_sbox1[U8a(t)] ^ cast_sbox2[U8b(t)]) \
- cast_sbox3[U8c(t)]) + cast_sbox4[U8d(t)]; - cast_sbox3[U8c(t)]) + cast_sbox4[U8d(t)]; \
#define F2(l, r, i) \ } while (0)
t = ROL(ctx->keys[i] ^ r, ctx->keys[i+16]); \ #define F2(l, r, i) do { \
t = ROTL32( ctx->keys[i+16], ctx->keys[i] ^ r); \
l ^= ((cast_sbox1[U8a(t)] - cast_sbox2[U8b(t)]) \ l ^= ((cast_sbox1[U8a(t)] - cast_sbox2[U8b(t)]) \
+ cast_sbox3[U8c(t)]) ^ cast_sbox4[U8d(t)]; + cast_sbox3[U8c(t)]) ^ cast_sbox4[U8d(t)]; \
#define F3(l, r, i) \ } while (0)
t = ROL(ctx->keys[i] - r, ctx->keys[i+16]); \ #define F3(l, r, i) do { \
t = ROTL32(ctx->keys[i+16], ctx->keys[i] - r); \
l ^= ((cast_sbox1[U8a(t)] + cast_sbox2[U8b(t)]) \ l ^= ((cast_sbox1[U8a(t)] + cast_sbox2[U8b(t)]) \
^ cast_sbox3[U8c(t)]) - cast_sbox4[U8d(t)]; ^ cast_sbox3[U8c(t)]) - cast_sbox4[U8d(t)]; \
} while (0)
/***** Encryption Function *****/ /***** Encryption Function *****/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment