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

* src/symmetric/serpent.c: Replaced the AES "All rights reserved"

copyright blurb with the vanilla GPL blurb, after confirming with
the authors that the code really is GPL:ed.
* src/symmetric/serpentsboxes.h: Likewise.

* src/symmetric/serpentsboxes.h: Replaced unsigned long with
UINT32.

Rev: src/symmetric/serpentsboxes.h:1.2
parent f59011a4
No related branches found
No related tags found
No related merge requests found
/* Copyright (C) 1998 Ross Anderson, Eli Biham, Lars Knudsen /* serpentsboxes.h
* All rights reserved.
* *
* This code is freely distributed for AES selection process. * $Id$
* 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.]
* *
* Contrary to these statements, all Serpent code available from the authors * For more details on this algorithm, see the Serpent website at
* (including this file) is now covered under LGPL, according to the Serpent
* website. For more details on this algorithm, see the Serpent website at
* http://www.cl.cam.ac.uk/~rja14/serpent.html * 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. * This program is free software; you can redistribute it and/or
* 2000-9-5, Rafael R. Sevilla <dido@pacific.net.ph> * 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) #if !defined(SERPENTSBOXES_H)
#define SERPENTSBOXES_H #define SERPENTSBOXES_H
...@@ -50,7 +39,7 @@ ...@@ -50,7 +39,7 @@
/* depth = 5,7,4,2, Total gates=18 */ /* depth = 5,7,4,2, Total gates=18 */
#define RND00(a,b,c,d,w,x,y,z) \ #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 ; \ t01 = b ^ c ; \
t02 = a | d ; \ t02 = a | d ; \
t03 = a ^ b ; \ t03 = a ^ b ; \
...@@ -74,7 +63,7 @@ ...@@ -74,7 +63,7 @@
/* depth = 8,4,3,6, Total gates=19 */ /* depth = 8,4,3,6, Total gates=19 */
#define InvRND00(a,b,c,d,w,x,y,z) \ #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 ; \ t01 = c ^ d ; \
t02 = a | b ; \ t02 = a | b ; \
t03 = b | c ; \ t03 = b | c ; \
...@@ -99,7 +88,7 @@ ...@@ -99,7 +88,7 @@
/* depth = 10,7,3,5, Total gates=18 */ /* depth = 10,7,3,5, Total gates=18 */
#define RND01(a,b,c,d,w,x,y,z) \ #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 ; \ t01 = a | d ; \
t02 = c ^ d ; \ t02 = c ^ d ; \
t03 = ~ b ; \ t03 = ~ b ; \
...@@ -123,7 +112,7 @@ ...@@ -123,7 +112,7 @@
/* depth = 7,4,5,3, Total gates=18 */ /* depth = 7,4,5,3, Total gates=18 */
#define InvRND01(a,b,c,d,w,x,y,z) \ #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 ; \ t01 = a ^ b ; \
t02 = b | d ; \ t02 = b | d ; \
t03 = a & c ; \ t03 = a & c ; \
...@@ -147,7 +136,7 @@ ...@@ -147,7 +136,7 @@
/* depth = 3,8,11,7, Total gates=16 */ /* depth = 3,8,11,7, Total gates=16 */
#define RND02(a,b,c,d,w,x,y,z) \ #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 ; \ t01 = a | c ; \
t02 = a ^ b ; \ t02 = a ^ b ; \
t03 = d ^ t01; \ t03 = d ^ t01; \
...@@ -169,7 +158,7 @@ ...@@ -169,7 +158,7 @@
/* depth = 3,6,8,3, Total gates=18 */ /* depth = 3,6,8,3, Total gates=18 */
#define InvRND02(a,b,c,d,w,x,y,z) \ #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 ; \ t01 = a ^ d ; \
t02 = c ^ d ; \ t02 = c ^ d ; \
t03 = a & c ; \ t03 = a & c ; \
...@@ -193,7 +182,7 @@ ...@@ -193,7 +182,7 @@
/* depth = 8,3,5,5, Total gates=18 */ /* depth = 8,3,5,5, Total gates=18 */
#define RND03(a,b,c,d,w,x,y,z) \ #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 ; \ t01 = a ^ c ; \
t02 = a | d ; \ t02 = a | d ; \
t03 = a & d ; \ t03 = a & d ; \
...@@ -217,7 +206,7 @@ ...@@ -217,7 +206,7 @@
/* depth = 3,6,4,4, Total gates=17 */ /* depth = 3,6,4,4, Total gates=17 */
#define InvRND03(a,b,c,d,w,x,y,z) \ #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 ; \ t01 = c | d ; \
t02 = a | d ; \ t02 = a | d ; \
t03 = c ^ t02; \ t03 = c ^ t02; \
...@@ -240,7 +229,7 @@ ...@@ -240,7 +229,7 @@
/* depth = 6,7,5,3, Total gates=19 */ /* depth = 6,7,5,3, Total gates=19 */
#define RND04(a,b,c,d,w,x,y,z) \ #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 ; \ t01 = a | b ; \
t02 = b | c ; \ t02 = b | c ; \
t03 = a ^ t02; \ t03 = a ^ t02; \
...@@ -265,7 +254,7 @@ ...@@ -265,7 +254,7 @@
/* depth = 6,4,7,3, Total gates=17 */ /* depth = 6,4,7,3, Total gates=17 */
#define InvRND04(a,b,c,d,w,x,y,z) \ #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 ; \ t01 = b | d ; \
t02 = c | d ; \ t02 = c | d ; \
t03 = a & t01; \ t03 = a & t01; \
...@@ -288,7 +277,7 @@ ...@@ -288,7 +277,7 @@
/* depth = 4,6,8,6, Total gates=17 */ /* depth = 4,6,8,6, Total gates=17 */
#define RND05(a,b,c,d,w,x,y,z) \ #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 ; \ t01 = b ^ d ; \
t02 = b | d ; \ t02 = b | d ; \
t03 = a & t01; \ t03 = a & t01; \
...@@ -311,7 +300,7 @@ ...@@ -311,7 +300,7 @@
/* depth = 4,6,9,7, Total gates=17 */ /* depth = 4,6,9,7, Total gates=17 */
#define InvRND05(a,b,c,d,w,x,y,z) \ #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 ; \ t01 = a & d ; \
t02 = c ^ t01; \ t02 = c ^ t01; \
t03 = a ^ d ; \ t03 = a ^ d ; \
...@@ -334,7 +323,7 @@ ...@@ -334,7 +323,7 @@
/* depth = 8,3,6,3, Total gates=19 */ /* depth = 8,3,6,3, Total gates=19 */
#define RND06(a,b,c,d,w,x,y,z) \ #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 ; \ t01 = a & d ; \
t02 = b ^ c ; \ t02 = b ^ c ; \
t03 = a ^ d ; \ t03 = a ^ d ; \
...@@ -359,7 +348,7 @@ ...@@ -359,7 +348,7 @@
/* depth = 5,3,8,6, Total gates=19 */ /* depth = 5,3,8,6, Total gates=19 */
#define InvRND06(a,b,c,d,w,x,y,z) \ #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 ; \ t01 = a ^ c ; \
t02 = ~ c ; \ t02 = ~ c ; \
t03 = b & t01; \ t03 = b & t01; \
...@@ -384,7 +373,7 @@ ...@@ -384,7 +373,7 @@
/* depth = 10,7,10,4, Total gates=19 */ /* depth = 10,7,10,4, Total gates=19 */
#define RND07(a,b,c,d,w,x,y,z) \ #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 ; \ t01 = a & c ; \
t02 = ~ d ; \ t02 = ~ d ; \
t03 = a & t02; \ t03 = a & t02; \
...@@ -409,7 +398,7 @@ ...@@ -409,7 +398,7 @@
/* depth = 9,7,3,3, Total gates=18 */ /* depth = 9,7,3,3, Total gates=18 */
#define InvRND07(a,b,c,d,w,x,y,z) \ #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 ; \ t01 = a & b ; \
t02 = a | b ; \ t02 = a | b ; \
t03 = c | t01; \ t03 = c | t01; \
...@@ -481,31 +470,31 @@ ...@@ -481,31 +470,31 @@
/* Linear transformations and key mixing: */ /* Linear transformations and key mixing: */
#define ROL(x,n) ((((unsigned long)(x))<<(n))| \ #define ROL(x,n) ((((UINT32)(x))<<(n))| \
(((unsigned long)(x))>>(32-(n)))) (((UINT32)(x))>>(32-(n))))
#define ROR(x,n) ((((unsigned long)(x))<<(32-(n)))| \ #define ROR(x,n) ((((UINT32)(x))<<(32-(n)))| \
(((unsigned long)(x))>>(n))) (((UINT32)(x))>>(n)))
#define transform(x0, x1, x2, x3, y0, y1, y2, y3) \ #define transform(x0, x1, x2, x3, y0, y1, y2, y3) \
y0 = ROL(x0, 13); \ y0 = ROL(x0, 13); \
y2 = ROL(x2, 3); \ y2 = ROL(x2, 3); \
y1 = x1 ^ y0 ^ y2; \ y1 = x1 ^ y0 ^ y2; \
y3 = x3 ^ y2 ^ ((unsigned long)y0)<<3; \ y3 = x3 ^ y2 ^ ((UINT32)y0)<<3; \
y1 = ROL(y1, 1); \ y1 = ROL(y1, 1); \
y3 = ROL(y3, 7); \ y3 = ROL(y3, 7); \
y0 = y0 ^ y1 ^ y3; \ y0 = y0 ^ y1 ^ y3; \
y2 = y2 ^ y3 ^ ((unsigned long)y1<<7); \ y2 = y2 ^ y3 ^ ((UINT32)y1<<7); \
y0 = ROL(y0, 5); \ y0 = ROL(y0, 5); \
y2 = ROL(y2, 22) y2 = ROL(y2, 22)
#define inv_transform(x0, x1, x2, x3, y0, y1, y2, y3) \ #define inv_transform(x0, x1, x2, x3, y0, y1, y2, y3) \
y2 = ROR(x2, 22);\ y2 = ROR(x2, 22);\
y0 = ROR(x0, 5); \ y0 = ROR(x0, 5); \
y2 = y2 ^ x3 ^ ((unsigned long)x1<<7); \ y2 = y2 ^ x3 ^ ((UINT32)x1<<7); \
y0 = y0 ^ x1 ^ x3; \ y0 = y0 ^ x1 ^ x3; \
y3 = ROR(x3, 7); \ y3 = ROR(x3, 7); \
y1 = ROR(x1, 1); \ y1 = ROR(x1, 1); \
y3 = y3 ^ y2 ^ ((unsigned long)y0)<<3; \ y3 = y3 ^ y2 ^ ((UINT32)y0)<<3; \
y1 = y1 ^ y0 ^ y2; \ y1 = y1 ^ y0 ^ y2; \
y2 = ROR(y2, 3); \ y2 = ROR(y2, 3); \
y0 = ROR(y0, 13) y0 = ROR(y0, 13)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment