diff --git a/serpentsboxes.h b/serpentsboxes.h index ea3222521cf8f982ef7cff58989e020a5613612e..6a082b7eed006b738575953d06540ce9df00213d 100644 --- a/serpentsboxes.h +++ b/serpentsboxes.h @@ -1,48 +1,37 @@ -/* Copyright (C) 1998 Ross Anderson, Eli Biham, Lars Knudsen - * All rights reserved. +/* serpentsboxes.h * - * This code is freely distributed for AES selection process. - * No other use is allowed. - * - * Copyright remains of the copyright holders, and as such any Copyright - * notices in the code are not to be removed. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted only for the AES selection process, provided - * that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed without the authors permission. - * i.e. this code cannot simply be copied and put under another distribution - * licence [including the GNU Public Licence.] + * $Id$ * - * Contrary to these statements, all Serpent code available from the authors - * (including this file) is now covered under LGPL, according to the Serpent - * website. For more details on this algorithm, see the Serpent website at + * For more details on this algorithm, see the Serpent website at * http://www.cl.cam.ac.uk/~rja14/serpent.html + */ + +/* Copyright (C) 1998 Ross Anderson, Eli Biham, Lars Knudsen * - * I've modified this code a bit so that it interoperates with lsh properly. - * 2000-9-5, Rafael R. Sevilla <dido@pacific.net.ph> + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* I've modified this code a bit so that it interoperates with lsh + * properly. 2000-9-5, Rafael R. Sevilla <dido@pacific.net.ph> */ +/* NOTE: The copyright notice for the original version of this code + * said "All rights reserved. This code is freely distributed for AES + * selection process. No other use is allowed." However, the authors + * later decided to GPL the code. /nisse */ + #if !defined(SERPENTSBOXES_H) #define SERPENTSBOXES_H @@ -50,7 +39,7 @@ /* depth = 5,7,4,2, Total gates=18 */ #define RND00(a,b,c,d,w,x,y,z) \ - { register unsigned long t02, t03, t05, t06, t07, t08, t09, t11, t12, t13, t14, t15, t17, t01;\ + { register UINT32 t02, t03, t05, t06, t07, t08, t09, t11, t12, t13, t14, t15, t17, t01;\ t01 = b ^ c ; \ t02 = a | d ; \ t03 = a ^ b ; \ @@ -74,7 +63,7 @@ /* depth = 8,4,3,6, Total gates=19 */ #define InvRND00(a,b,c,d,w,x,y,z) \ - { register unsigned long t02, t03, t04, t05, t06, t08, t09, t10, t12, t13, t14, t15, t17, t18, t01;\ + { register UINT32 t02, t03, t04, t05, t06, t08, t09, t10, t12, t13, t14, t15, t17, t18, t01;\ t01 = c ^ d ; \ t02 = a | b ; \ t03 = b | c ; \ @@ -99,7 +88,7 @@ /* depth = 10,7,3,5, Total gates=18 */ #define RND01(a,b,c,d,w,x,y,z) \ - { register unsigned long t02, t03, t04, t05, t06, t07, t08, t10, t11, t12, t13, t16, t17, t01;\ + { register UINT32 t02, t03, t04, t05, t06, t07, t08, t10, t11, t12, t13, t16, t17, t01;\ t01 = a | d ; \ t02 = c ^ d ; \ t03 = ~ b ; \ @@ -123,7 +112,7 @@ /* depth = 7,4,5,3, Total gates=18 */ #define InvRND01(a,b,c,d,w,x,y,z) \ - { register unsigned long t02, t03, t04, t05, t06, t07, t08, t09, t10, t11, t14, t15, t17, t01;\ + { register UINT32 t02, t03, t04, t05, t06, t07, t08, t09, t10, t11, t14, t15, t17, t01;\ t01 = a ^ b ; \ t02 = b | d ; \ t03 = a & c ; \ @@ -147,7 +136,7 @@ /* depth = 3,8,11,7, Total gates=16 */ #define RND02(a,b,c,d,w,x,y,z) \ - { register unsigned long t02, t03, t05, t06, t07, t08, t09, t10, t12, t13, t14, t01;\ + { register UINT32 t02, t03, t05, t06, t07, t08, t09, t10, t12, t13, t14, t01;\ t01 = a | c ; \ t02 = a ^ b ; \ t03 = d ^ t01; \ @@ -169,7 +158,7 @@ /* depth = 3,6,8,3, Total gates=18 */ #define InvRND02(a,b,c,d,w,x,y,z) \ - { register unsigned long t02, t03, t04, t06, t07, t08, t09, t10, t11, t12, t15, t16, t17, t01;\ + { register UINT32 t02, t03, t04, t06, t07, t08, t09, t10, t11, t12, t15, t16, t17, t01;\ t01 = a ^ d ; \ t02 = c ^ d ; \ t03 = a & c ; \ @@ -193,7 +182,7 @@ /* depth = 8,3,5,5, Total gates=18 */ #define RND03(a,b,c,d,w,x,y,z) \ - { register unsigned long t02, t03, t04, t05, t06, t07, t08, t09, t10, t11, t13, t14, t15, t01;\ + { register UINT32 t02, t03, t04, t05, t06, t07, t08, t09, t10, t11, t13, t14, t15, t01;\ t01 = a ^ c ; \ t02 = a | d ; \ t03 = a & d ; \ @@ -217,7 +206,7 @@ /* depth = 3,6,4,4, Total gates=17 */ #define InvRND03(a,b,c,d,w,x,y,z) \ - { register unsigned long t02, t03, t04, t05, t06, t07, t09, t11, t12, t13, t14, t16, t01;\ + { register UINT32 t02, t03, t04, t05, t06, t07, t09, t11, t12, t13, t14, t16, t01;\ t01 = c | d ; \ t02 = a | d ; \ t03 = c ^ t02; \ @@ -240,7 +229,7 @@ /* depth = 6,7,5,3, Total gates=19 */ #define RND04(a,b,c,d,w,x,y,z) \ - { register unsigned long t02, t03, t04, t05, t06, t08, t09, t10, t11, t12, t13, t14, t15, t16, t01;\ + { register UINT32 t02, t03, t04, t05, t06, t08, t09, t10, t11, t12, t13, t14, t15, t16, t01;\ t01 = a | b ; \ t02 = b | c ; \ t03 = a ^ t02; \ @@ -265,7 +254,7 @@ /* depth = 6,4,7,3, Total gates=17 */ #define InvRND04(a,b,c,d,w,x,y,z) \ - { register unsigned long t02, t03, t04, t05, t06, t07, t09, t10, t11, t12, t13, t15, t01;\ + { register UINT32 t02, t03, t04, t05, t06, t07, t09, t10, t11, t12, t13, t15, t01;\ t01 = b | d ; \ t02 = c | d ; \ t03 = a & t01; \ @@ -288,7 +277,7 @@ /* depth = 4,6,8,6, Total gates=17 */ #define RND05(a,b,c,d,w,x,y,z) \ - { register unsigned long t02, t03, t04, t05, t07, t08, t09, t10, t11, t12, t13, t14, t01;\ + { register UINT32 t02, t03, t04, t05, t07, t08, t09, t10, t11, t12, t13, t14, t01;\ t01 = b ^ d ; \ t02 = b | d ; \ t03 = a & t01; \ @@ -311,7 +300,7 @@ /* depth = 4,6,9,7, Total gates=17 */ #define InvRND05(a,b,c,d,w,x,y,z) \ - { register unsigned long t02, t03, t04, t05, t07, t08, t09, t10, t12, t13, t15, t16, t01;\ + { register UINT32 t02, t03, t04, t05, t07, t08, t09, t10, t12, t13, t15, t16, t01;\ t01 = a & d ; \ t02 = c ^ t01; \ t03 = a ^ d ; \ @@ -334,7 +323,7 @@ /* depth = 8,3,6,3, Total gates=19 */ #define RND06(a,b,c,d,w,x,y,z) \ - { register unsigned long t02, t03, t04, t05, t07, t08, t09, t10, t11, t12, t13, t15, t17, t18, t01;\ + { register UINT32 t02, t03, t04, t05, t07, t08, t09, t10, t11, t12, t13, t15, t17, t18, t01;\ t01 = a & d ; \ t02 = b ^ c ; \ t03 = a ^ d ; \ @@ -359,7 +348,7 @@ /* depth = 5,3,8,6, Total gates=19 */ #define InvRND06(a,b,c,d,w,x,y,z) \ - { register unsigned long t02, t03, t04, t05, t06, t07, t08, t09, t12, t13, t14, t15, t16, t17, t01;\ + { register UINT32 t02, t03, t04, t05, t06, t07, t08, t09, t12, t13, t14, t15, t16, t17, t01;\ t01 = a ^ c ; \ t02 = ~ c ; \ t03 = b & t01; \ @@ -384,7 +373,7 @@ /* depth = 10,7,10,4, Total gates=19 */ #define RND07(a,b,c,d,w,x,y,z) \ - { register unsigned long t02, t03, t04, t05, t06, t08, t09, t10, t11, t13, t14, t15, t16, t17, t01;\ + { register UINT32 t02, t03, t04, t05, t06, t08, t09, t10, t11, t13, t14, t15, t16, t17, t01;\ t01 = a & c ; \ t02 = ~ d ; \ t03 = a & t02; \ @@ -409,7 +398,7 @@ /* depth = 9,7,3,3, Total gates=18 */ #define InvRND07(a,b,c,d,w,x,y,z) \ - { register unsigned long t02, t03, t04, t06, t07, t08, t09, t10, t11, t13, t14, t15, t16, t01;\ + { register UINT32 t02, t03, t04, t06, t07, t08, t09, t10, t11, t13, t14, t15, t16, t01;\ t01 = a & b ; \ t02 = a | b ; \ t03 = c | t01; \ @@ -481,31 +470,31 @@ /* Linear transformations and key mixing: */ -#define ROL(x,n) ((((unsigned long)(x))<<(n))| \ - (((unsigned long)(x))>>(32-(n)))) -#define ROR(x,n) ((((unsigned long)(x))<<(32-(n)))| \ - (((unsigned long)(x))>>(n))) +#define ROL(x,n) ((((UINT32)(x))<<(n))| \ + (((UINT32)(x))>>(32-(n)))) +#define ROR(x,n) ((((UINT32)(x))<<(32-(n)))| \ + (((UINT32)(x))>>(n))) #define transform(x0, x1, x2, x3, y0, y1, y2, y3) \ y0 = ROL(x0, 13); \ y2 = ROL(x2, 3); \ y1 = x1 ^ y0 ^ y2; \ - y3 = x3 ^ y2 ^ ((unsigned long)y0)<<3; \ + y3 = x3 ^ y2 ^ ((UINT32)y0)<<3; \ y1 = ROL(y1, 1); \ y3 = ROL(y3, 7); \ y0 = y0 ^ y1 ^ y3; \ - y2 = y2 ^ y3 ^ ((unsigned long)y1<<7); \ + y2 = y2 ^ y3 ^ ((UINT32)y1<<7); \ y0 = ROL(y0, 5); \ y2 = ROL(y2, 22) #define inv_transform(x0, x1, x2, x3, y0, y1, y2, y3) \ y2 = ROR(x2, 22);\ y0 = ROR(x0, 5); \ - y2 = y2 ^ x3 ^ ((unsigned long)x1<<7); \ + y2 = y2 ^ x3 ^ ((UINT32)x1<<7); \ y0 = y0 ^ x1 ^ x3; \ y3 = ROR(x3, 7); \ y1 = ROR(x1, 1); \ - y3 = y3 ^ y2 ^ ((unsigned long)y0)<<3; \ + y3 = y3 ^ y2 ^ ((UINT32)y0)<<3; \ y1 = y1 ^ y0 ^ y2; \ y2 = ROR(y2, 3); \ y0 = ROR(y0, 13)