YAARX: Yet Another ARX Toolkit  0.1
 All Data Structures Files Functions Variables Macros Pages
rc5-ref.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2014 Luxembourg University,
3  * Laboratory of Algorithmics, Cryptology and Security (LACS).
4  *
5  * This file is part of the YAARX toolkit. YAARX stands for
6  * Yet Another ARX toolkit for analysis of ARX cryptographic algorithms.
7  *
8  * YAARX is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * YAARX is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with YAARX. If not, see <http://www.gnu.org/licenses/>.
20  */
27 #ifndef RC5_REF_H
28 #define RC5_REF_H
29 
30 #define RC5_ROT_MASK (WORD_SIZE - 1) // mask that selects the log2(2^{WORD_SIZE}) LS bits
31 
32 #define RC5_ROTL(x,y) (((x)<<(y & (WORD_SIZE-1))) | ((x)>>(WORD_SIZE - (y & (WORD_SIZE-1)))))
33 #define RC5_ROTR(x,y) (((x)>>(y & (WORD_SIZE-1))) | ((x)<<(WORD_SIZE - (y & (WORD_SIZE-1)))))
34 
35 #if ((WORD_SIZE == 16) || (WORD_SIZE == 32) || (WORD_SIZE == 64))
36 
37 #define RC5_NROUNDS_R NROUNDS//12 /* r: number of rounds */
38 #define RC5_KEY_NBYTES_B 16 /* b: number of bytes in key */
39 #define RC5_STAB_LEN_T 26 /* t: size of table S = 2*(r+1) words */
40 //#define RC5_STAB_LEN_T (2 * (RC5_NROUNDS_R + 1)) /* t: size of table S = 2*(r+1) words */
41 
42 #if (WORD_SIZE == 64)
43 #define RC5_KEY_NWORDS_C 2 /* c: number words in key = ceil(8*b/w)*/
44 #endif // #if (WORD_SIZE == 64)
45 #if (WORD_SIZE == 32)
46 #define RC5_KEY_NWORDS_C 4 /* c: number words in key = ceil(8*b/w)*/
47 #endif // #if (WORD_SIZE == 32)
48 #if (WORD_SIZE == 16)
49 #define RC5_KEY_NWORDS_C 8 /* c: number words in key = ceil(8*b/w)*/
50 #endif // #if (WORD_SIZE == 16)
51 
52 extern WORD_T RC5_CONST_P; /* magic constant P: defined in rc5-ref.cc */
53 extern WORD_T RC5_CONST_Q; /* magic constant Q: defined in rc5-ref.cc */
54 
55 void rc5_encrypt(uint32_t nrounds, const WORD_T S[RC5_STAB_LEN_T], WORD_T *pt, WORD_T *ct); /* 2 WORD_T input pt/output ct */
56 void rc5_decrypt(uint32_t nrounds, const WORD_T S[RC5_STAB_LEN_T], WORD_T *ct, WORD_T *pt); /* 2 WORD_T input pt/output ct */
57 void rc5_xor_encrypt(uint32_t nrounds, const WORD_T S[RC5_STAB_LEN_T], WORD_T *pt, WORD_T *ct);
58 //void rc5_setup(unsigned char *K, WORD_T S[RC5_STAB_LEN_T]); /* secret input key K[0...b-1] */
59 void rc5_setup(const unsigned char *K, WORD_T S[RC5_STAB_LEN_T]); /* secret input key K[0...b-1] */
60 
61 #endif // #if ((WORD_SIZE == 16) || (WORD_SIZE == 32) || (WORD_SIZE == 64))
62 #endif // #ifndef RC5_REF_H