linux/crypto/serpent_generic.c
<<
>>
Prefs
   1/*
   2 * Cryptographic API.
   3 *
   4 * Serpent Cipher Algorithm.
   5 *
   6 * Copyright (C) 2002 Dag Arne Osvik <osvik@ii.uib.no>
   7 *               2003 Herbert Valerio Riedel <hvr@gnu.org>
   8 *
   9 * Added tnepres support:
  10 *              Ruben Jesus Garcia Hernandez <ruben@ugr.es>, 18.10.2004
  11 *              Based on code by hvr
  12 *
  13 * This program is free software; you can redistribute it and/or modify
  14 * it under the terms of the GNU General Public License as published by
  15 * the Free Software Foundation; either version 2 of the License, or
  16 * (at your option) any later version.
  17 */
  18
  19#include <linux/init.h>
  20#include <linux/module.h>
  21#include <linux/errno.h>
  22#include <asm/byteorder.h>
  23#include <linux/crypto.h>
  24#include <linux/types.h>
  25#include <crypto/serpent.h>
  26
  27/* Key is padded to the maximum of 256 bits before round key generation.
  28 * Any key length <= 256 bits (32 bytes) is allowed by the algorithm.
  29 */
  30
  31#define PHI 0x9e3779b9UL
  32
  33#define keyiter(a, b, c, d, i, j) \
  34        ({ b ^= d; b ^= c; b ^= a; b ^= PHI ^ i; b = rol32(b, 11); k[j] = b; })
  35
  36#define loadkeys(x0, x1, x2, x3, i) \
  37        ({ x0 = k[i]; x1 = k[i+1]; x2 = k[i+2]; x3 = k[i+3]; })
  38
  39#define storekeys(x0, x1, x2, x3, i) \
  40        ({ k[i] = x0; k[i+1] = x1; k[i+2] = x2; k[i+3] = x3; })
  41
  42#define store_and_load_keys(x0, x1, x2, x3, s, l) \
  43        ({ storekeys(x0, x1, x2, x3, s); loadkeys(x0, x1, x2, x3, l); })
  44
  45#define K(x0, x1, x2, x3, i) ({                         \
  46        x3 ^= k[4*(i)+3];        x2 ^= k[4*(i)+2];      \
  47        x1 ^= k[4*(i)+1];        x0 ^= k[4*(i)+0];      \
  48        })
  49
  50#define LK(x0, x1, x2, x3, x4, i) ({                                       \
  51                                                        x0 = rol32(x0, 13);\
  52        x2 = rol32(x2, 3);      x1 ^= x0;               x4  = x0 << 3;     \
  53        x3 ^= x2;               x1 ^= x2;                                  \
  54        x1 = rol32(x1, 1);      x3 ^= x4;                                  \
  55        x3 = rol32(x3, 7);      x4  = x1;                                  \
  56        x0 ^= x1;               x4 <<= 7;               x2 ^= x3;          \
  57        x0 ^= x3;               x2 ^= x4;               x3 ^= k[4*i+3];    \
  58        x1 ^= k[4*i+1];         x0 = rol32(x0, 5);      x2 = rol32(x2, 22);\
  59        x0 ^= k[4*i+0];         x2 ^= k[4*i+2];                            \
  60        })
  61
  62#define KL(x0, x1, x2, x3, x4, i) ({                                       \
  63        x0 ^= k[4*i+0];         x1 ^= k[4*i+1];         x2 ^= k[4*i+2];    \
  64        x3 ^= k[4*i+3];         x0 = ror32(x0, 5);      x2 = ror32(x2, 22);\
  65        x4 =  x1;               x2 ^= x3;               x0 ^= x3;          \
  66        x4 <<= 7;               x0 ^= x1;               x1 = ror32(x1, 1); \
  67        x2 ^= x4;               x3 = ror32(x3, 7);      x4 = x0 << 3;      \
  68        x1 ^= x0;               x3 ^= x4;               x0 = ror32(x0, 13);\
  69        x1 ^= x2;               x3 ^= x2;               x2 = ror32(x2, 3); \
  70        })
  71
  72#define S0(x0, x1, x2, x3, x4) ({                       \
  73                                        x4  = x3;       \
  74        x3 |= x0;       x0 ^= x4;       x4 ^= x2;       \
  75        x4 = ~x4;       x3 ^= x1;       x1 &= x0;       \
  76        x1 ^= x4;       x2 ^= x0;       x0 ^= x3;       \
  77        x4 |= x0;       x0 ^= x2;       x2 &= x1;       \
  78        x3 ^= x2;       x1 = ~x1;       x2 ^= x4;       \
  79        x1 ^= x2;                                       \
  80        })
  81
  82#define S1(x0, x1, x2, x3, x4) ({                       \
  83                                        x4  = x1;       \
  84        x1 ^= x0;       x0 ^= x3;       x3 = ~x3;       \
  85        x4 &= x1;       x0 |= x1;       x3 ^= x2;       \
  86        x0 ^= x3;       x1 ^= x3;       x3 ^= x4;       \
  87        x1 |= x4;       x4 ^= x2;       x2 &= x0;       \
  88        x2 ^= x1;       x1 |= x0;       x0 = ~x0;       \
  89        x0 ^= x2;       x4 ^= x1;                       \
  90        })
  91
  92#define S2(x0, x1, x2, x3, x4) ({                       \
  93                                        x3 = ~x3;       \
  94        x1 ^= x0;       x4  = x0;       x0 &= x2;       \
  95        x0 ^= x3;       x3 |= x4;       x2 ^= x1;       \
  96        x3 ^= x1;       x1 &= x0;       x0 ^= x2;       \
  97        x2 &= x3;       x3 |= x1;       x0 = ~x0;       \
  98        x3 ^= x0;       x4 ^= x0;       x0 ^= x2;       \
  99        x1 |= x2;                                       \
 100        })
 101
 102#define S3(x0, x1, x2, x3, x4) ({                       \
 103                                        x4  = x1;       \
 104        x1 ^= x3;       x3 |= x0;       x4 &= x0;       \
 105        x0 ^= x2;       x2 ^= x1;       x1 &= x3;       \
 106        x2 ^= x3;       x0 |= x4;       x4 ^= x3;       \
 107        x1 ^= x0;       x0 &= x3;       x3 &= x4;       \
 108        x3 ^= x2;       x4 |= x1;       x2 &= x1;       \
 109        x4 ^= x3;       x0 ^= x3;       x3 ^= x2;       \
 110        })
 111
 112#define S4(x0, x1, x2, x3, x4) ({                       \
 113                                        x4  = x3;       \
 114        x3 &= x0;       x0 ^= x4;                       \
 115        x3 ^= x2;       x2 |= x4;       x0 ^= x1;       \
 116        x4 ^= x3;       x2 |= x0;                       \
 117        x2 ^= x1;       x1 &= x0;                       \
 118        x1 ^= x4;       x4 &= x2;       x2 ^= x3;       \
 119        x4 ^= x0;       x3 |= x1;       x1 = ~x1;       \
 120        x3 ^= x0;                                       \
 121        })
 122
 123#define S5(x0, x1, x2, x3, x4) ({                       \
 124        x4  = x1;       x1 |= x0;                       \
 125        x2 ^= x1;       x3 = ~x3;       x4 ^= x0;       \
 126        x0 ^= x2;       x1 &= x4;       x4 |= x3;       \
 127        x4 ^= x0;       x0 &= x3;       x1 ^= x3;       \
 128        x3 ^= x2;       x0 ^= x1;       x2 &= x4;       \
 129        x1 ^= x2;       x2 &= x0;                       \
 130        x3 ^= x2;                                       \
 131        })
 132
 133#define S6(x0, x1, x2, x3, x4) ({                       \
 134                                        x4  = x1;       \
 135        x3 ^= x0;       x1 ^= x2;       x2 ^= x0;       \
 136        x0 &= x3;       x1 |= x3;       x4 = ~x4;       \
 137        x0 ^= x1;       x1 ^= x2;                       \
 138        x3 ^= x4;       x4 ^= x0;       x2 &= x0;       \
 139        x4 ^= x1;       x2 ^= x3;       x3 &= x1;       \
 140        x3 ^= x0;       x1 ^= x2;                       \
 141        })
 142
 143#define S7(x0, x1, x2, x3, x4) ({                       \
 144                                        x1 = ~x1;       \
 145        x4  = x1;       x0 = ~x0;       x1 &= x2;       \
 146        x1 ^= x3;       x3 |= x4;       x4 ^= x2;       \
 147        x2 ^= x3;       x3 ^= x0;       x0 |= x1;       \
 148        x2 &= x0;       x0 ^= x4;       x4 ^= x3;       \
 149        x3 &= x0;       x4 ^= x1;                       \
 150        x2 ^= x4;       x3 ^= x1;       x4 |= x0;       \
 151        x4 ^= x1;                                       \
 152        })
 153
 154#define SI0(x0, x1, x2, x3, x4) ({                      \
 155                        x4  = x3;       x1 ^= x0;       \
 156        x3 |= x1;       x4 ^= x1;       x0 = ~x0;       \
 157        x2 ^= x3;       x3 ^= x0;       x0 &= x1;       \
 158        x0 ^= x2;       x2 &= x3;       x3 ^= x4;       \
 159        x2 ^= x3;       x1 ^= x3;       x3 &= x0;       \
 160        x1 ^= x0;       x0 ^= x2;       x4 ^= x3;       \
 161        })
 162
 163#define SI1(x0, x1, x2, x3, x4) ({                      \
 164        x1 ^= x3;       x4  = x0;                       \
 165        x0 ^= x2;       x2 = ~x2;       x4 |= x1;       \
 166        x4 ^= x3;       x3 &= x1;       x1 ^= x2;       \
 167        x2 &= x4;       x4 ^= x1;       x1 |= x3;       \
 168        x3 ^= x0;       x2 ^= x0;       x0 |= x4;       \
 169        x2 ^= x4;       x1 ^= x0;                       \
 170        x4 ^= x1;                                       \
 171        })
 172
 173#define SI2(x0, x1, x2, x3, x4) ({                      \
 174        x2 ^= x1;       x4  = x3;       x3 = ~x3;       \
 175        x3 |= x2;       x2 ^= x4;       x4 ^= x0;       \
 176        x3 ^= x1;       x1 |= x2;       x2 ^= x0;       \
 177        x1 ^= x4;       x4 |= x3;       x2 ^= x3;       \
 178        x4 ^= x2;       x2 &= x1;                       \
 179        x2 ^= x3;       x3 ^= x4;       x4 ^= x0;       \
 180        })
 181
 182#define SI3(x0, x1, x2, x3, x4) ({                      \
 183                                        x2 ^= x1;       \
 184        x4  = x1;       x1 &= x2;                       \
 185        x1 ^= x0;       x0 |= x4;       x4 ^= x3;       \
 186        x0 ^= x3;       x3 |= x1;       x1 ^= x2;       \
 187        x1 ^= x3;       x0 ^= x2;       x2 ^= x3;       \
 188        x3 &= x1;       x1 ^= x0;       x0 &= x2;       \
 189        x4 ^= x3;       x3 ^= x0;       x0 ^= x1;       \
 190        })
 191
 192#define SI4(x0, x1, x2, x3, x4) ({                      \
 193        x2 ^= x3;       x4  = x0;       x0 &= x1;       \
 194        x0 ^= x2;       x2 |= x3;       x4 = ~x4;       \
 195        x1 ^= x0;       x0 ^= x2;       x2 &= x4;       \
 196        x2 ^= x0;       x0 |= x4;                       \
 197        x0 ^= x3;       x3 &= x2;                       \
 198        x4 ^= x3;       x3 ^= x1;       x1 &= x0;       \
 199        x4 ^= x1;       x0 ^= x3;                       \
 200        })
 201
 202#define SI5(x0, x1, x2, x3, x4) ({                      \
 203                        x4  = x1;       x1 |= x2;       \
 204        x2 ^= x4;       x1 ^= x3;       x3 &= x4;       \
 205        x2 ^= x3;       x3 |= x0;       x0 = ~x0;       \
 206        x3 ^= x2;       x2 |= x0;       x4 ^= x1;       \
 207        x2 ^= x4;       x4 &= x0;       x0 ^= x1;       \
 208        x1 ^= x3;       x0 &= x2;       x2 ^= x3;       \
 209        x0 ^= x2;       x2 ^= x4;       x4 ^= x3;       \
 210        })
 211
 212#define SI6(x0, x1, x2, x3, x4) ({                      \
 213                        x0 ^= x2;                       \
 214        x4  = x0;       x0 &= x3;       x2 ^= x3;       \
 215        x0 ^= x2;       x3 ^= x1;       x2 |= x4;       \
 216        x2 ^= x3;       x3 &= x0;       x0 = ~x0;       \
 217        x3 ^= x1;       x1 &= x2;       x4 ^= x0;       \
 218        x3 ^= x4;       x4 ^= x2;       x0 ^= x1;       \
 219        x2 ^= x0;                                       \
 220        })
 221
 222#define SI7(x0, x1, x2, x3, x4) ({                      \
 223        x4  = x3;       x3 &= x0;       x0 ^= x2;       \
 224        x2 |= x4;       x4 ^= x1;       x0 = ~x0;       \
 225        x1 |= x3;       x4 ^= x0;       x0 &= x2;       \
 226        x0 ^= x1;       x1 &= x2;       x3 ^= x2;       \
 227        x4 ^= x3;       x2 &= x3;       x3 |= x0;       \
 228        x1 ^= x4;       x3 ^= x4;       x4 &= x0;       \
 229        x4 ^= x2;                                       \
 230        })
 231
 232int __serpent_setkey(struct serpent_ctx *ctx, const u8 *key,
 233                     unsigned int keylen)
 234{
 235        u32 *k = ctx->expkey;
 236        u8  *k8 = (u8 *)k;
 237        u32 r0, r1, r2, r3, r4;
 238        int i;
 239
 240        /* Copy key, add padding */
 241
 242        for (i = 0; i < keylen; ++i)
 243                k8[i] = key[i];
 244        if (i < SERPENT_MAX_KEY_SIZE)
 245                k8[i++] = 1;
 246        while (i < SERPENT_MAX_KEY_SIZE)
 247                k8[i++] = 0;
 248
 249        /* Expand key using polynomial */
 250
 251        r0 = le32_to_cpu(k[3]);
 252        r1 = le32_to_cpu(k[4]);
 253        r2 = le32_to_cpu(k[5]);
 254        r3 = le32_to_cpu(k[6]);
 255        r4 = le32_to_cpu(k[7]);
 256
 257        keyiter(le32_to_cpu(k[0]), r0, r4, r2, 0, 0);
 258        keyiter(le32_to_cpu(k[1]), r1, r0, r3, 1, 1);
 259        keyiter(le32_to_cpu(k[2]), r2, r1, r4, 2, 2);
 260        keyiter(le32_to_cpu(k[3]), r3, r2, r0, 3, 3);
 261        keyiter(le32_to_cpu(k[4]), r4, r3, r1, 4, 4);
 262        keyiter(le32_to_cpu(k[5]), r0, r4, r2, 5, 5);
 263        keyiter(le32_to_cpu(k[6]), r1, r0, r3, 6, 6);
 264        keyiter(le32_to_cpu(k[7]), r2, r1, r4, 7, 7);
 265
 266        keyiter(k[0], r3, r2, r0, 8, 8);
 267        keyiter(k[1], r4, r3, r1, 9, 9);
 268        keyiter(k[2], r0, r4, r2, 10, 10);
 269        keyiter(k[3], r1, r0, r3, 11, 11);
 270        keyiter(k[4], r2, r1, r4, 12, 12);
 271        keyiter(k[5], r3, r2, r0, 13, 13);
 272        keyiter(k[6], r4, r3, r1, 14, 14);
 273        keyiter(k[7], r0, r4, r2, 15, 15);
 274        keyiter(k[8], r1, r0, r3, 16, 16);
 275        keyiter(k[9], r2, r1, r4, 17, 17);
 276        keyiter(k[10], r3, r2, r0, 18, 18);
 277        keyiter(k[11], r4, r3, r1, 19, 19);
 278        keyiter(k[12], r0, r4, r2, 20, 20);
 279        keyiter(k[13], r1, r0, r3, 21, 21);
 280        keyiter(k[14], r2, r1, r4, 22, 22);
 281        keyiter(k[15], r3, r2, r0, 23, 23);
 282        keyiter(k[16], r4, r3, r1, 24, 24);
 283        keyiter(k[17], r0, r4, r2, 25, 25);
 284        keyiter(k[18], r1, r0, r3, 26, 26);
 285        keyiter(k[19], r2, r1, r4, 27, 27);
 286        keyiter(k[20], r3, r2, r0, 28, 28);
 287        keyiter(k[21], r4, r3, r1, 29, 29);
 288        keyiter(k[22], r0, r4, r2, 30, 30);
 289        keyiter(k[23], r1, r0, r3, 31, 31);
 290
 291        k += 50;
 292
 293        keyiter(k[-26], r2, r1, r4, 32, -18);
 294        keyiter(k[-25], r3, r2, r0, 33, -17);
 295        keyiter(k[-24], r4, r3, r1, 34, -16);
 296        keyiter(k[-23], r0, r4, r2, 35, -15);
 297        keyiter(k[-22], r1, r0, r3, 36, -14);
 298        keyiter(k[-21], r2, r1, r4, 37, -13);
 299        keyiter(k[-20], r3, r2, r0, 38, -12);
 300        keyiter(k[-19], r4, r3, r1, 39, -11);
 301        keyiter(k[-18], r0, r4, r2, 40, -10);
 302        keyiter(k[-17], r1, r0, r3, 41, -9);
 303        keyiter(k[-16], r2, r1, r4, 42, -8);
 304        keyiter(k[-15], r3, r2, r0, 43, -7);
 305        keyiter(k[-14], r4, r3, r1, 44, -6);
 306        keyiter(k[-13], r0, r4, r2, 45, -5);
 307        keyiter(k[-12], r1, r0, r3, 46, -4);
 308        keyiter(k[-11], r2, r1, r4, 47, -3);
 309        keyiter(k[-10], r3, r2, r0, 48, -2);
 310        keyiter(k[-9], r4, r3, r1, 49, -1);
 311        keyiter(k[-8], r0, r4, r2, 50, 0);
 312        keyiter(k[-7], r1, r0, r3, 51, 1);
 313        keyiter(k[-6], r2, r1, r4, 52, 2);
 314        keyiter(k[-5], r3, r2, r0, 53, 3);
 315        keyiter(k[-4], r4, r3, r1, 54, 4);
 316        keyiter(k[-3], r0, r4, r2, 55, 5);
 317        keyiter(k[-2], r1, r0, r3, 56, 6);
 318        keyiter(k[-1], r2, r1, r4, 57, 7);
 319        keyiter(k[0], r3, r2, r0, 58, 8);
 320        keyiter(k[1], r4, r3, r1, 59, 9);
 321        keyiter(k[2], r0, r4, r2, 60, 10);
 322        keyiter(k[3], r1, r0, r3, 61, 11);
 323        keyiter(k[4], r2, r1, r4, 62, 12);
 324        keyiter(k[5], r3, r2, r0, 63, 13);
 325        keyiter(k[6], r4, r3, r1, 64, 14);
 326        keyiter(k[7], r0, r4, r2, 65, 15);
 327        keyiter(k[8], r1, r0, r3, 66, 16);
 328        keyiter(k[9], r2, r1, r4, 67, 17);
 329        keyiter(k[10], r3, r2, r0, 68, 18);
 330        keyiter(k[11], r4, r3, r1, 69, 19);
 331        keyiter(k[12], r0, r4, r2, 70, 20);
 332        keyiter(k[13], r1, r0, r3, 71, 21);
 333        keyiter(k[14], r2, r1, r4, 72, 22);
 334        keyiter(k[15], r3, r2, r0, 73, 23);
 335        keyiter(k[16], r4, r3, r1, 74, 24);
 336        keyiter(k[17], r0, r4, r2, 75, 25);
 337        keyiter(k[18], r1, r0, r3, 76, 26);
 338        keyiter(k[19], r2, r1, r4, 77, 27);
 339        keyiter(k[20], r3, r2, r0, 78, 28);
 340        keyiter(k[21], r4, r3, r1, 79, 29);
 341        keyiter(k[22], r0, r4, r2, 80, 30);
 342        keyiter(k[23], r1, r0, r3, 81, 31);
 343
 344        k += 50;
 345
 346        keyiter(k[-26], r2, r1, r4, 82, -18);
 347        keyiter(k[-25], r3, r2, r0, 83, -17);
 348        keyiter(k[-24], r4, r3, r1, 84, -16);
 349        keyiter(k[-23], r0, r4, r2, 85, -15);
 350        keyiter(k[-22], r1, r0, r3, 86, -14);
 351        keyiter(k[-21], r2, r1, r4, 87, -13);
 352        keyiter(k[-20], r3, r2, r0, 88, -12);
 353        keyiter(k[-19], r4, r3, r1, 89, -11);
 354        keyiter(k[-18], r0, r4, r2, 90, -10);
 355        keyiter(k[-17], r1, r0, r3, 91, -9);
 356        keyiter(k[-16], r2, r1, r4, 92, -8);
 357        keyiter(k[-15], r3, r2, r0, 93, -7);
 358        keyiter(k[-14], r4, r3, r1, 94, -6);
 359        keyiter(k[-13], r0, r4, r2, 95, -5);
 360        keyiter(k[-12], r1, r0, r3, 96, -4);
 361        keyiter(k[-11], r2, r1, r4, 97, -3);
 362        keyiter(k[-10], r3, r2, r0, 98, -2);
 363        keyiter(k[-9], r4, r3, r1, 99, -1);
 364        keyiter(k[-8], r0, r4, r2, 100, 0);
 365        keyiter(k[-7], r1, r0, r3, 101, 1);
 366        keyiter(k[-6], r2, r1, r4, 102, 2);
 367        keyiter(k[-5], r3, r2, r0, 103, 3);
 368        keyiter(k[-4], r4, r3, r1, 104, 4);
 369        keyiter(k[-3], r0, r4, r2, 105, 5);
 370        keyiter(k[-2], r1, r0, r3, 106, 6);
 371        keyiter(k[-1], r2, r1, r4, 107, 7);
 372        keyiter(k[0], r3, r2, r0, 108, 8);
 373        keyiter(k[1], r4, r3, r1, 109, 9);
 374        keyiter(k[2], r0, r4, r2, 110, 10);
 375        keyiter(k[3], r1, r0, r3, 111, 11);
 376        keyiter(k[4], r2, r1, r4, 112, 12);
 377        keyiter(k[5], r3, r2, r0, 113, 13);
 378        keyiter(k[6], r4, r3, r1, 114, 14);
 379        keyiter(k[7], r0, r4, r2, 115, 15);
 380        keyiter(k[8], r1, r0, r3, 116, 16);
 381        keyiter(k[9], r2, r1, r4, 117, 17);
 382        keyiter(k[10], r3, r2, r0, 118, 18);
 383        keyiter(k[11], r4, r3, r1, 119, 19);
 384        keyiter(k[12], r0, r4, r2, 120, 20);
 385        keyiter(k[13], r1, r0, r3, 121, 21);
 386        keyiter(k[14], r2, r1, r4, 122, 22);
 387        keyiter(k[15], r3, r2, r0, 123, 23);
 388        keyiter(k[16], r4, r3, r1, 124, 24);
 389        keyiter(k[17], r0, r4, r2, 125, 25);
 390        keyiter(k[18], r1, r0, r3, 126, 26);
 391        keyiter(k[19], r2, r1, r4, 127, 27);
 392        keyiter(k[20], r3, r2, r0, 128, 28);
 393        keyiter(k[21], r4, r3, r1, 129, 29);
 394        keyiter(k[22], r0, r4, r2, 130, 30);
 395        keyiter(k[23], r1, r0, r3, 131, 31);
 396
 397        /* Apply S-boxes */
 398
 399        S3(r3, r4, r0, r1, r2); store_and_load_keys(r1, r2, r4, r3, 28, 24);
 400        S4(r1, r2, r4, r3, r0); store_and_load_keys(r2, r4, r3, r0, 24, 20);
 401        S5(r2, r4, r3, r0, r1); store_and_load_keys(r1, r2, r4, r0, 20, 16);
 402        S6(r1, r2, r4, r0, r3); store_and_load_keys(r4, r3, r2, r0, 16, 12);
 403        S7(r4, r3, r2, r0, r1); store_and_load_keys(r1, r2, r0, r4, 12, 8);
 404        S0(r1, r2, r0, r4, r3); store_and_load_keys(r0, r2, r4, r1, 8, 4);
 405        S1(r0, r2, r4, r1, r3); store_and_load_keys(r3, r4, r1, r0, 4, 0);
 406        S2(r3, r4, r1, r0, r2); store_and_load_keys(r2, r4, r3, r0, 0, -4);
 407        S3(r2, r4, r3, r0, r1); store_and_load_keys(r0, r1, r4, r2, -4, -8);
 408        S4(r0, r1, r4, r2, r3); store_and_load_keys(r1, r4, r2, r3, -8, -12);
 409        S5(r1, r4, r2, r3, r0); store_and_load_keys(r0, r1, r4, r3, -12, -16);
 410        S6(r0, r1, r4, r3, r2); store_and_load_keys(r4, r2, r1, r3, -16, -20);
 411        S7(r4, r2, r1, r3, r0); store_and_load_keys(r0, r1, r3, r4, -20, -24);
 412        S0(r0, r1, r3, r4, r2); store_and_load_keys(r3, r1, r4, r0, -24, -28);
 413        k -= 50;
 414        S1(r3, r1, r4, r0, r2); store_and_load_keys(r2, r4, r0, r3, 22, 18);
 415        S2(r2, r4, r0, r3, r1); store_and_load_keys(r1, r4, r2, r3, 18, 14);
 416        S3(r1, r4, r2, r3, r0); store_and_load_keys(r3, r0, r4, r1, 14, 10);
 417        S4(r3, r0, r4, r1, r2); store_and_load_keys(r0, r4, r1, r2, 10, 6);
 418        S5(r0, r4, r1, r2, r3); store_and_load_keys(r3, r0, r4, r2, 6, 2);
 419        S6(r3, r0, r4, r2, r1); store_and_load_keys(r4, r1, r0, r2, 2, -2);
 420        S7(r4, r1, r0, r2, r3); store_and_load_keys(r3, r0, r2, r4, -2, -6);
 421        S0(r3, r0, r2, r4, r1); store_and_load_keys(r2, r0, r4, r3, -6, -10);
 422        S1(r2, r0, r4, r3, r1); store_and_load_keys(r1, r4, r3, r2, -10, -14);
 423        S2(r1, r4, r3, r2, r0); store_and_load_keys(r0, r4, r1, r2, -14, -18);
 424        S3(r0, r4, r1, r2, r3); store_and_load_keys(r2, r3, r4, r0, -18, -22);
 425        k -= 50;
 426        S4(r2, r3, r4, r0, r1); store_and_load_keys(r3, r4, r0, r1, 28, 24);
 427        S5(r3, r4, r0, r1, r2); store_and_load_keys(r2, r3, r4, r1, 24, 20);
 428        S6(r2, r3, r4, r1, r0); store_and_load_keys(r4, r0, r3, r1, 20, 16);
 429        S7(r4, r0, r3, r1, r2); store_and_load_keys(r2, r3, r1, r4, 16, 12);
 430        S0(r2, r3, r1, r4, r0); store_and_load_keys(r1, r3, r4, r2, 12, 8);
 431        S1(r1, r3, r4, r2, r0); store_and_load_keys(r0, r4, r2, r1, 8, 4);
 432        S2(r0, r4, r2, r1, r3); store_and_load_keys(r3, r4, r0, r1, 4, 0);
 433        S3(r3, r4, r0, r1, r2); storekeys(r1, r2, r4, r3, 0);
 434
 435        return 0;
 436}
 437EXPORT_SYMBOL_GPL(__serpent_setkey);
 438
 439int serpent_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
 440{
 441        return __serpent_setkey(crypto_tfm_ctx(tfm), key, keylen);
 442}
 443EXPORT_SYMBOL_GPL(serpent_setkey);
 444
 445void __serpent_encrypt(struct serpent_ctx *ctx, u8 *dst, const u8 *src)
 446{
 447        const u32 *k = ctx->expkey;
 448        const __le32 *s = (const __le32 *)src;
 449        __le32  *d = (__le32 *)dst;
 450        u32     r0, r1, r2, r3, r4;
 451
 452/*
 453 * Note: The conversions between u8* and u32* might cause trouble
 454 * on architectures with stricter alignment rules than x86
 455 */
 456
 457        r0 = le32_to_cpu(s[0]);
 458        r1 = le32_to_cpu(s[1]);
 459        r2 = le32_to_cpu(s[2]);
 460        r3 = le32_to_cpu(s[3]);
 461
 462                                        K(r0, r1, r2, r3, 0);
 463        S0(r0, r1, r2, r3, r4);         LK(r2, r1, r3, r0, r4, 1);
 464        S1(r2, r1, r3, r0, r4);         LK(r4, r3, r0, r2, r1, 2);
 465        S2(r4, r3, r0, r2, r1);         LK(r1, r3, r4, r2, r0, 3);
 466        S3(r1, r3, r4, r2, r0);         LK(r2, r0, r3, r1, r4, 4);
 467        S4(r2, r0, r3, r1, r4);         LK(r0, r3, r1, r4, r2, 5);
 468        S5(r0, r3, r1, r4, r2);         LK(r2, r0, r3, r4, r1, 6);
 469        S6(r2, r0, r3, r4, r1);         LK(r3, r1, r0, r4, r2, 7);
 470        S7(r3, r1, r0, r4, r2);         LK(r2, r0, r4, r3, r1, 8);
 471        S0(r2, r0, r4, r3, r1);         LK(r4, r0, r3, r2, r1, 9);
 472        S1(r4, r0, r3, r2, r1);         LK(r1, r3, r2, r4, r0, 10);
 473        S2(r1, r3, r2, r4, r0);         LK(r0, r3, r1, r4, r2, 11);
 474        S3(r0, r3, r1, r4, r2);         LK(r4, r2, r3, r0, r1, 12);
 475        S4(r4, r2, r3, r0, r1);         LK(r2, r3, r0, r1, r4, 13);
 476        S5(r2, r3, r0, r1, r4);         LK(r4, r2, r3, r1, r0, 14);
 477        S6(r4, r2, r3, r1, r0);         LK(r3, r0, r2, r1, r4, 15);
 478        S7(r3, r0, r2, r1, r4);         LK(r4, r2, r1, r3, r0, 16);
 479        S0(r4, r2, r1, r3, r0);         LK(r1, r2, r3, r4, r0, 17);
 480        S1(r1, r2, r3, r4, r0);         LK(r0, r3, r4, r1, r2, 18);
 481        S2(r0, r3, r4, r1, r2);         LK(r2, r3, r0, r1, r4, 19);
 482        S3(r2, r3, r0, r1, r4);         LK(r1, r4, r3, r2, r0, 20);
 483        S4(r1, r4, r3, r2, r0);         LK(r4, r3, r2, r0, r1, 21);
 484        S5(r4, r3, r2, r0, r1);         LK(r1, r4, r3, r0, r2, 22);
 485        S6(r1, r4, r3, r0, r2);         LK(r3, r2, r4, r0, r1, 23);
 486        S7(r3, r2, r4, r0, r1);         LK(r1, r4, r0, r3, r2, 24);
 487        S0(r1, r4, r0, r3, r2);         LK(r0, r4, r3, r1, r2, 25);
 488        S1(r0, r4, r3, r1, r2);         LK(r2, r3, r1, r0, r4, 26);
 489        S2(r2, r3, r1, r0, r4);         LK(r4, r3, r2, r0, r1, 27);
 490        S3(r4, r3, r2, r0, r1);         LK(r0, r1, r3, r4, r2, 28);
 491        S4(r0, r1, r3, r4, r2);         LK(r1, r3, r4, r2, r0, 29);
 492        S5(r1, r3, r4, r2, r0);         LK(r0, r1, r3, r2, r4, 30);
 493        S6(r0, r1, r3, r2, r4);         LK(r3, r4, r1, r2, r0, 31);
 494        S7(r3, r4, r1, r2, r0);         K(r0, r1, r2, r3, 32);
 495
 496        d[0] = cpu_to_le32(r0);
 497        d[1] = cpu_to_le32(r1);
 498        d[2] = cpu_to_le32(r2);
 499        d[3] = cpu_to_le32(r3);
 500}
 501EXPORT_SYMBOL_GPL(__serpent_encrypt);
 502
 503static void serpent_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
 504{
 505        struct serpent_ctx *ctx = crypto_tfm_ctx(tfm);
 506
 507        __serpent_encrypt(ctx, dst, src);
 508}
 509
 510void __serpent_decrypt(struct serpent_ctx *ctx, u8 *dst, const u8 *src)
 511{
 512        const u32 *k = ctx->expkey;
 513        const __le32 *s = (const __le32 *)src;
 514        __le32  *d = (__le32 *)dst;
 515        u32     r0, r1, r2, r3, r4;
 516
 51o/serpent_generic.c#L457" id="L457" class="line" name="L457"> 457        r0 = le32_to_cpu(r0, r0, r3derpent_generic.c#L516" id="L516" cla2f="+code=r0" class="sref">r0, r3,  = le32_to_cpu(s[2]);
 46052="sref">u2 *u8 *s[3]);
 461
 462                                        K(u32<2a> *r3, r2, 
 462                                        S6( 464        S1( 462              " class="sref">r3, 2lass="sref">r1, r0, r2, 22);
 464        S1( 462            r0" class=generic.c#L461" serpent_generic.K" class="line" name=" href="crypto/serpent_generic.c#L478" id="L478" class="line" name="L478"> 478href="crypto/serpent_generic.c#L494" id="L494" class="line" name="L494"> 494          r0, __le32<2a>  *r3, r4, r2, 5);
 478href="crypto/serpent_generic.c#L494" id="L494" class="line" name="L494"> 494          r4, 19);
 482href="crypto/serpent_generic.c#L494" id="L494" class="line" name" class="sref">r1, r1, r4, r1, r4, 4);
 482href="crypto/serpent_generic.c#L494" id="L494" class="line" nar0" class=generic.c#L461" serpent_generic.K" class="line" name=" "+code=r4" class="sref">r4, 19);
r2);         LK(r0, r3, r0, r1, r4, 19);
r2);         LK( 480        S1(r4, r3, r4, r0, 10);
 480        S1(r4, 19);
r2); href="crypto/serpent_generic.c#L488" id="L488" class="line" name="L488"> 488        r2, r1, r0, r4, 1);
r2); href="crypto/serpent_generic.c#L488" id="L488" class="line" name="L488"> 488        r2); href="crypto/serpent_generic.c#L488" id="L488" class="line" name="L488"> 488LK(r0, r2, r3, r2, 24);
r2); href="crypto/serpent_generic.c#L488" id="L488" class="line" name="L488"> 488LK(r2);         LK( 494          r1, u3 *r3, r2, r2);         LK( 494          r4, 19);
r2, 22);
 485        r3, u8 *r3, r0, r4, 19);
r2, 22);
 485        r2); href="crypto/serpent_generic.c#L472" id="L472" class="line" name="L472"> 472        S1(r1, u32<3a> *r3, r4, r2); href="crypto/serpent_generic.c#L472" id="L472" class="line" name="L472"> 472        S1(r0, 20);
 483        r4, 3lass="sref">r1, r1, r0, 20);
 483        r0, 14);
 477        r1, __le32<3a>  *r3, r1, r0, 14);
 477        r4, 19);
r2); "+code=r0" class="sref">r0, 29);
r2, r1, r4, r4, r4, 19);
r2); "+code=r0" class="sref">r0, 29);
r0, 14);
r2);         LK(r0, r3, r0, r0, r0, 14);
r2);         LK(r4, 19);
r0, 14);
r2);         LK(r1, r3, r3, r4, 19);
r0, 14);
r2);         LK( 464        S1( 462            s="sref">r2);         r4, r1, r2,  464        S1( 462            s="sref">r2);          478href="crypto/serpent_generic.c#L474" id="L474" class="line" name="L474"> 474        r3, r2, r0,  478href="crypto/serpent_generic.c#L474" id="L474" class="line" name="L474"> 474         464href="crypto/serpent_generic.c#L494" id="L494" class="line" name="L494"> 494href="crypto/serpent_generic.c#L478" id="L478" class="line" name" class="sref">r4, u4 *r3, r4,  464href="crypto/serpent_generic.c#L494" id="L494" class="line" name="L494"> 494href="crypto/serpent_generic.c#L478" id="L478" class="line" nar0" class=generic.c#L461" serpent_generic.K" class="line" name=" a href="+code=r2" class="sref">r2);         a href="+code=r2" class="sref">r2);         LK(r3, u8 *r3, r1, r2);         a href="+code=r2" class="sref">r2);         LK(r2); href="crypto/serpent_generic.c#L482" id="L482" class="line" name="L482"> 482        "L478" class="line" name" class="sref">r1, u32<4a> *r3, r1, r2); href="crypto/serpent_generic.c#L482" id="L482" class="line" name="L482"> 482        "L478" class="line" nar0" class=generic.c#L461" serpent_generic.K" class="line" name=" href="crypto/serpent_generic.c#L478" id="+code=r0" class="sref">r0, 14);
 479        r0, 4lass="sref">r1, r4, r0, 14);
 479        r2); href="crypto/serpent_generic.c#L482" id=a href="+code=r4" class="sref">r4);         LK(r1, __le32<4a>  *r3, r0, r2); href="crypto/serpent_generic.c#L482" id=a href="+code=r4" class="sref">r4);         LK(r4);         a href="+code=r2" class= class="sref">r2, r1, r4, r3, r4);         a href="+code=r2" clasr0" class=generic.c#L461" serpent_generic.K" class="line" name=" href="crypto/serpent_generic.c#L464" id=href="crypto/serpent_generic.c#L485" id="L485" class="line" name="L485"> 485        S6(r0, r3, r0, r2,  485        S6(r2); href="crypto/serpent_generic.c#L472" id="+code=r0" class="sref">r0, 10);
r1, r3, r0, r2); href="crypto/serpent_generic.c#L472" id="+code=r0" class="sref">r0, 10);
 464href="crypto/serpent_generic.c#L486" id="L486" class="line" name="L486"> 486        r4, r1, r4,  464href="crypto/serpent_generic.c#L486" id="L486" class="line" name="L486"> 486         464        a href="+code=r4" class="sref">r4);         a href="+code=r2" class= class="sref">r3, r2, r1,  464        a href="+code=r4" class="sref">r4);         a href="+code=r2" clasr0" class=generic.c#L461" serpent_generic.K" class="line" name=" "L464" class="line" name="L464"> 464href="crypto/serpent_generic.c#L464" id=href="crypto/serpent_generic.c#L485" id=        LK(r4, u5 *r3, r1,  464href="crypto/serpent_generic.c#L464" id=href="crypto/serpent_generic.c#L485" id=        LK(r2); href="crypto/serpent_generic.c#L482" id=href="crypto/serpent_generic.c#L478" id="L478" class="line" name="L478"> 478        r3, u8 *r3, r4, r2); href="crypto/serpent_generic.c#L482" id=href="crypto/serpent_generic.c#L478" id="L478" class="line" name="L478"> 478         464href="crypto/serpent_generic.c#L464" id=="+code=r4" class="sref">r4, 1);
r2); href="crypto/serpent_gen class="sref">r1, u32<5a> *r3, r0,  464href="crypto/serpent_generic.c#L464" id=="+code=r4" class="sref">r4, 1);
r2); href="crypto/serpent_gr0" class=generic.c#L461" serpent_generic.K" class="line" name=" a href="+code=r2" class="sref">r2); href="crypto/serpent_generic.c#L464" id=="+code=r4" class="sref">r4, 1);
r2);         r1, 5lass="sref">r1, r3, r2); href="crypto/serpent_generic.c#L464" id=="+code=r4" class="sref">r4, 1);
r2);         r3,  478href="crypto/serpent_generic.c#L474" id="L474" class="line" name="L474"> 474        r1, __le32<5a>  *r1, r1, r3, 32);
 495
 49855 class="s5ef">r3, [0] = cpu_to_le32(r0);
 499 5nt_generi5.c#L457" id="L457" class5"line5>[1] = cpu_to_le32(r1);
 49755"+code=r45 class=".c#L494" id="L495"t_en5>[2] = cpu_to_le32(r2);
 49756_generic.6#L508" id="L508" class="6ine" 6>[3] = u6 *r3);
 500o/serpent_generic.c#L509" id="L509" class="r07" class="line" name="L497"> 49756ass="sref6>u8 *EXPORT_SYMBOL_GPL(u32<6a> * 509<
 503static void serpent_encrypt(struct crypto_tfm *t>EXPORT_SYMBOL_GPL( *6a href="+code=s" class="6ref">6="sref">dst, const __le32<6a>  *src)
 504{
 505        struct serpent_ctxr1, r2, r3, tfm);
 504{
 507        __6nt_generi6.c#L457" id="L457" class6"line6ass="sref">ctx, src);
 tnepres9" tiness="line" name="L509"> 509<
 503crypto_tfm * iness=",ref">src);
u7 *rrrrrrrrrrrrrrrrrrrunsignedyin)
 inelenss="sref">t>EXPORT_SYMBOL_GPL(u8 *dst, const u32<7a> *r3, cr="crypto/serpentev_ine" name="L512"> tev_inef">cp1, c]ode=__serpent_encrypt" class="sref">__7e32 *7a href="+code=s" class="7ref">7lass="sref">rin)
__7">__le32<7a>  *r1, r1, r3;
 inelenss="; ++t>EXPORT_SYMBOL_GPL(r3, rrrrrrrrr="crypto/serpentev_ine" name="L512"> tev_inef">cp1,  inelenss=" -
( iness="p1, __7nt_generi7.c#L457" id="L457" class7"line78ass="sref">r1, [2] =  /serpent" tine> 505        struct  474ev_ine" name="L512"> tev_inef">cme="L474"> 474 inelenss="sode=__serpent_encrypt" class="sref">__8_generic.8#L508" id="L508" class="8ine" 8>[3] = u8 *u8 *);
 509<
 503static void serpent_encrypt(struct crypto_tfm *t>EXPORT_SYMBOL_GPL(u32<8a> *dst, const  *8a href="+code=s" class="8ref">8lass="sref">rc)
)
expkey;
"line" name="L513"> 513        const __8">__le32<8a>  *d = (__leirc)
src;
"line" name="L51" name="L514"> 514        r1, r2, r3, tfm);
 474ass="sref">expker0" id=4]me="L474"> 474=src" class="srerd" id=4]     r1, r0, expker0" id=ic.c#L495" id="L495"swab/serpent_generic.swab/s> 505        strnt_generic.c#L460" id="L460" class="line" name="L460"> 46059_generic.9#L508" id="L508" class="9ine" 9/a> = expker0" id=u_to_le32( 505        strnt_generic.c#L460" id=, r3, u9 *r3, expker0" id=u_to_le32( 505        strnt_generic.c#L460" id="L56" class="line"7"sref">r0, r3, expker0" id=u_to_le32( 505        strnt_generic.c#L460" id="L517" class="line" name="L517"> 51o/serp9ref">u32<9a> *r1, r4, r1,  503;
cry"line" name="L51>=src" class="srerd" id/aa>;
cry"line" name="L51>ass="sref">expker0" id517" class="line" name="L517"> 51o/serp9">__le32r0, r1, , r3, 32);
 505        str>=src" class="srerd" id="L460" class="line" name="L460"> 46059 class="shref="+code=d" class="sr5f">d<5a>[0] = cpu_to_le32( 505        str>=src" class="srerd" id=, r3, d<5a>[1] = cpu_to_le32( 505        str>=src" class="srerd" id="L56" class="line"7"sref">r0, d<5a>[2] = cpu_to_le32( 505        str>=src" class="srerd" id="L517" class="line" name="L517"> 51o/ser6       d<6a>[3] = cpu_6o_le32( = );
 509<
 503static void serpent_encrypt(struct crypto_tfm *t>EXPORT_SYMBOL_GPL(_603"sref">dst, const 68 *rc)
)
expkey;
"line" name="L513"> 513        const _6lass="sre6">u8 *d = (__leirc)
src;
"line" name="L51" name="L514"> 514        ctx6/a> =6tfm);
 474ass="sref">expker0" id=4]me="L474"> 474=src" class="srerd" id=4]     r1, , r0, expker0" id=ic.c#L495" id="L495"swab/serpent_generic.swab/s> 505        strnt_generic.c#L460" id="L460" class="line" name="L460"> 4606t_generic6c#L508" id="L508" class=6line"61/a> = expker0" id=u_to_le32( 505        strnt_generic.c#L460" id=, r3, 68 *r3, expker0" id=u_to_le32( 505        strnt_generic.c#L460" id="L56" class="line"7"sref">r0, u8 *r3, expker0" id=u_to_le32( 505        strnt_generic.c#L460" id="L517" class="line" name="L517"> 51o/ser6sref">u326/a> *r1,  6 = (const  503;
cry"line" name="L51>=src" class="srerd" id/aa>;
cry"line" name="L51>ass="sref">expker0" id517" class="line" name="L517"> 51o/ser6f">__le326/a>  *r1, r1, r3, 32);
 505        str>=src" class="srerd" id="L460" class="line" name="L460"> 4606" class="6ref">r3, r4;
cpu_to_le32( 505        str>=src" class="srerd" id=, r3,  457       _le32" class="sref">cpu_to_le32( 505        str>=src" class="srerd" id="L56" class="line"7"sref">r0, r0, cpu_to_le32( 505        str>=src" class="srerd" id="L517" class="line" name="L517"> 51o/ser62_generic62#L508" id="L508" class=62ine"62>[3] = 62 *u8 * 509<
 474cpu_to_{ f">dst, const u3262a> *r.me="L509"> 509<
rrrrrrrr=class=respanrypto/sertring">"src);
r.me="L509"> 509<
r.me="L509"> 50_de=kcrypto/serpent_gea_class="srerass="srid="L508" class=62ine"62>[3] = 62 *[3] = r1, t>EXPORT_SYMBOL_GPL(riorit8ine" 8>[3] = riorit8ef"62lass="sref+code=ds100 href="+codt"sr6 href="+c6de=ctx" clane      strrypto/serpent_generic.c#6482" 6d="L482" classL(r+code=ds6/a>(626;         ((serpent_        struct 626; href="cryptoL(626; href="cryptoL(+code=ds6/a>(LK((r.f">+code=ds{rL(rrrrrrrr=class=respanrypto/sertring"r2,622);
6a href="cryptoL(((r0,620);
638" class=62ine"62>[3] =  inei="elen" ef"62lass="sref">+code=ds6/a>( inelenss="sode=__serdhref="+codt"sr6 href="+c6de=ctx" clan)ric47 hrer0" class="sref">r0,614);
63ORT_SYMBOL_GPL(;
(;
6263="L482" classL(;
(;
r0,614);
6a a hr},a">rrrrrrrr=class=respanrypto/sertring"<      strr0" class="sref">r0,614);
63="L480" classL(r.me="L509"> 509<
r1,       6 (r+code=ds6/a>(href="6rypto/serpent_generic.c#6494" 64>LK((serpent_        struct (+code=ds6/a>(r0,614);
648" class=62ine"62>[3] = r.f">+code=ds{rL(rrrrrrrr=class=respanrypto/sertring"); href="6rypto/serpent_generic.c#6482" 64ORT_SYMBOL_GPL((((( inei="elen" ef"62lass="sref">+code=ds6/a>(dhref="+codt"sr6 href="+c6de=ctx" clani      strrypto/serpent_generic.c#6472" 64="L480" classL(;
(static void       6class="line" name="L464"6 464<64 href="cryptoL(;
(static void a hr} =+code=ds62 cla62/a> =  474r.me="L509"> 50asrpcalmod_ini   rc)
href="6rypto/serpent_generic.c#6464" 65/a>)
expkey;
<); href="6rypto/serpent_generic.c#6464" 6d=="+code=r4" tev_inef">cme="L474"> ="62lasregister
 = ass="sref">expker0" id=4]me="L474"> 4 href="cr6pto/serpent_generic.c#L469" id6"L499" class="line" name="L503"> __exi   r.me="L509"> 50asrpcalmod_fini  rc)
expkey;
<)a>      6pto/serpenthref="crypto/6erpen6_gr07" class="line" name="L49="62lasunregister
 =  500o/serpe6t_generic6c#L509" id="L509" class=6r07" 66calg511" ="L474"> 474 =  =  = r1,  = r1,  = static void  509<
, r1,  =  509<
r1,  =  509<



The original LXR software by the ode=ds62 http://sourceforge.net/=sojects/lxr">LXR communit8ef"6, this exp="+mlxr@nerux.noef"6.
lxr.nerux.no kindly hosted by ode=ds62 http://www.redpill-ner=so.no">Redpill Ler=so ASref=, =sovider of Leruxfm_ctultr_d and op="las_ct > =vicer since 1995.