/*
* Cryptographic API.
*
* DES & Triple DES EDE Cipher Algorithms.
*
* Copyright (c) 2005 Dag Arne Osvik <da@osvik.no>
*
* 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.
*
*/
#include <asm/byteorder.h>
#include <linux/bitops.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/crypto.h>
#include <linux/types.h>
#define DES_KEY_SIZE 8
#define DES_EXPKEY_WORDS 32
#define DES_BLOCK_SIZE 8
#define DES3_EDE_KEY_SIZE (3 * DES_KEY_SIZE)
#define DES3_EDE_EXPKEY_WORDS (3 * DES_EXPKEY_WORDS)
#define DES3_EDE_BLOCK_SIZE DES_BLOCK_SIZE
#define ROL(x, r) ((x) = rol32((x), (r)))
#define ROR(x, r) ((x) = ror32((x), (r)))
struct des_ctx {
u32 expkey[DES_EXPKEY_WORDS];
};
struct des3_ede_ctx {
u32 expkey[DES3_EDE_EXPKEY_WORDS];
};
/* Lookup tables for key expansion */
static const u8 pc1[256] = {
0x00, 0x00, 0x40, 0x04, 0x10, 0x10, 0x50, 0x14,
0x04, 0x40, 0x44, 0x44, 0x14, 0x50, 0x54, 0x54,
0x02, 0x02, 0x42, 0x06, 0x12, 0x12, 0x52, 0x16,
0x06, 0x42, 0x46, 0x46, 0x16, 0x52, 0x56, 0x56,
0x80, 0x08, 0xc0, 0x0c, 0x90, 0x18, 0xd0, 0x1c,
0x84, 0x48, 0xc4, 0x4c, 0x94, 0x58, 0xd4, 0x5c,
0x82, 0x0a, 0xc2, 0x0e, 0x92, 0x1a, 0xd2, 0x1e,
0x86, 0x4a, 0xc6, 0x4e, 0x96, 0x5a, 0xd6, 0x5e,
0x20, 0x20, 0x60, 0x24, 0x30, 0x30, 0x70, 0x34,
0x24, 0x60, 0x64, 0x64, 0x34, 0x70, 0x74, 0x74,
0x22, 0x22, 0x62, 0x26, 0x32, 0x32, 0x72, 0x36,
0x26, 0x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