X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilccrypt%2Fciphers_def.h;h=98e445c400c605055e0cd7a625685c1a1e559777;hb=a818c5b5411bbc4436d1c5f011236985c96bb787;hp=3db98254a3d5f880e997b2ed99768ef6f4cb2032;hpb=62f89b2886bbe9df82d9b2fdabfe707509d9e0fc;p=silc.git diff --git a/lib/silccrypt/ciphers_def.h b/lib/silccrypt/ciphers_def.h index 3db98254..98e445c4 100644 --- a/lib/silccrypt/ciphers_def.h +++ b/lib/silccrypt/ciphers_def.h @@ -23,11 +23,85 @@ /* General definitions for algorithms */ typedef unsigned char u1byte; -typedef unsigned int u4byte; -typedef unsigned int u32; +typedef SilcUInt32 u4byte; +typedef SilcUInt32 u32; #define rotr(x, nr) (((x) >> ((int)(nr))) | ((x) << (32 - (int)(nr)))) #define rotl(x, nr) (((x) << ((int)(nr))) | ((x) >> (32 - (int)(nr)))) #define byte(x, nr) ((x) >> (nr * 8) & 255) +/* Byte key to words */ +#define SILC_GET_WORD_KEY(s, d, len) \ +do { \ + int _i; \ + for (_i = 0; _i < (len / 8) / 4; _i++) \ + SILC_GET32_LSB(d[_i], s + (_i * 4)); \ +} while(0); + +/* CBC mode macros. */ + +#define SILC_CBC_GET_IV(d, s) \ +do { \ + SILC_GET32_LSB(d[0], &s[0]); \ + SILC_GET32_LSB(d[1], &s[4]); \ + SILC_GET32_LSB(d[2], &s[8]); \ + SILC_GET32_LSB(d[3], &s[12]); \ +} while(0); + +#define SILC_CBC_PUT_IV(s, d) \ +do { \ + SILC_PUT32_LSB(s[0], &d[0]); \ + SILC_PUT32_LSB(s[1], &d[4]); \ + SILC_PUT32_LSB(s[2], &d[8]); \ + SILC_PUT32_LSB(s[3], &d[12]); \ +} while(0); + +#define SILC_CBC_ENC_PRE(d, s) \ +do { \ + SILC_GET32_X_LSB(d[0], &s[0]); \ + SILC_GET32_X_LSB(d[1], &s[4]); \ + SILC_GET32_X_LSB(d[2], &s[8]); \ + SILC_GET32_X_LSB(d[3], &s[12]); \ +} while(0); + +#define SILC_CBC_ENC_POST(s, d, t) \ +do { \ + SILC_PUT32_LSB(s[0], &d[0]); \ + SILC_PUT32_LSB(s[1], &d[4]); \ + SILC_PUT32_LSB(s[2], &d[8]); \ + SILC_PUT32_LSB(s[3], &d[12]); \ + \ + d += 16; \ + t += 16; \ +} while(0); + +#define SILC_CBC_DEC_PRE(d, s) \ +do { \ + SILC_GET32_LSB(d[0], &s[0]); \ + SILC_GET32_LSB(d[1], &s[4]); \ + SILC_GET32_LSB(d[2], &s[8]); \ + SILC_GET32_LSB(d[3], &s[12]); \ +} while(0); + +#define SILC_CBC_DEC_POST(s, d, p, t, siv) \ +do { \ + s[0] ^= siv[0]; \ + s[1] ^= siv[1]; \ + s[2] ^= siv[2]; \ + s[3] ^= siv[3]; \ + \ + SILC_PUT32_LSB(s[0], &d[0]); \ + SILC_PUT32_LSB(s[1], &d[4]); \ + SILC_PUT32_LSB(s[2], &d[8]); \ + SILC_PUT32_LSB(s[3], &d[12]); \ + \ + siv[0] = t[0]; \ + siv[1] = t[1]; \ + siv[2] = t[2]; \ + siv[3] = t[3]; \ + \ + d += 16; \ + p += 16; \ +} while(0); + #endif