12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 2c5a511f1SSebastian Siewior /* 3c5a511f1SSebastian Siewior * Cryptographic API. 4c5a511f1SSebastian Siewior * 5c5a511f1SSebastian Siewior * DES & Triple DES EDE Cipher Algorithms. 6c5a511f1SSebastian Siewior * 7c5a511f1SSebastian Siewior * Copyright (c) 2005 Dag Arne Osvik <da@osvik.no> 8c5a511f1SSebastian Siewior */ 9c5a511f1SSebastian Siewior 10c5a511f1SSebastian Siewior #include <asm/byteorder.h> 11c5a511f1SSebastian Siewior #include <linux/bitops.h> 12c5a511f1SSebastian Siewior #include <linux/init.h> 13c5a511f1SSebastian Siewior #include <linux/module.h> 14c5a511f1SSebastian Siewior #include <linux/errno.h> 15c5a511f1SSebastian Siewior #include <linux/crypto.h> 16c5a511f1SSebastian Siewior #include <linux/types.h> 17c5a511f1SSebastian Siewior 1816d004a2SEvgeniy Polyakov #include <crypto/des.h> 19c5a511f1SSebastian Siewior 20c5a511f1SSebastian Siewior #define ROL(x, r) ((x) = rol32((x), (r))) 21c5a511f1SSebastian Siewior #define ROR(x, r) ((x) = ror32((x), (r))) 22c5a511f1SSebastian Siewior 23c5a511f1SSebastian Siewior struct des_ctx { 24c5a511f1SSebastian Siewior u32 expkey[DES_EXPKEY_WORDS]; 25c5a511f1SSebastian Siewior }; 26c5a511f1SSebastian Siewior 27c5a511f1SSebastian Siewior struct des3_ede_ctx { 28c5a511f1SSebastian Siewior u32 expkey[DES3_EDE_EXPKEY_WORDS]; 29c5a511f1SSebastian Siewior }; 30c5a511f1SSebastian Siewior 31c5a511f1SSebastian Siewior /* Lookup tables for key expansion */ 32c5a511f1SSebastian Siewior 33c5a511f1SSebastian Siewior static const u8 pc1[256] = { 34c5a511f1SSebastian Siewior 0x00, 0x00, 0x40, 0x04, 0x10, 0x10, 0x50, 0x14, 35c5a511f1SSebastian Siewior 0x04, 0x40, 0x44, 0x44, 0x14, 0x50, 0x54, 0x54, 36c5a511f1SSebastian Siewior 0x02, 0x02, 0x42, 0x06, 0x12, 0x12, 0x52, 0x16, 37c5a511f1SSebastian Siewior 0x06, 0x42, 0x46, 0x46, 0x16, 0x52, 0x56, 0x56, 38c5a511f1SSebastian Siewior 0x80, 0x08, 0xc0, 0x0c, 0x90, 0x18, 0xd0, 0x1c, 39c5a511f1SSebastian Siewior 0x84, 0x48, 0xc4, 0x4c, 0x94, 0x58, 0xd4, 0x5c, 40c5a511f1SSebastian Siewior 0x82, 0x0a, 0xc2, 0x0e, 0x92, 0x1a, 0xd2, 0x1e, 41c5a511f1SSebastian Siewior 0x86, 0x4a, 0xc6, 0x4e, 0x96, 0x5a, 0xd6, 0x5e, 42c5a511f1SSebastian Siewior 0x20, 0x20, 0x60, 0x24, 0x30, 0x30, 0x70, 0x34, 43c5a511f1SSebastian Siewior 0x24, 0x60, 0x64, 0x64, 0x34, 0x70, 0x74, 0x74, 44c5a511f1SSebastian Siewior 0x22, 0x22, 0x62, 0x26, 0x32, 0x32, 0x72, 0x36, 45c5a511f1SSebastian Siewior 0x26, 0x62, 0x66, 0x66, 0x36, 0x72, 0x76, 0x76, 46c5a511f1SSebastian Siewior 0xa0, 0x28, 0xe0, 0x2c, 0xb0, 0x38, 0xf0, 0x3c, 47c5a511f1SSebastian Siewior 0xa4, 0x68, 0xe4, 0x6c, 0xb4, 0x78, 0xf4, 0x7c, 48c5a511f1SSebastian Siewior 0xa2, 0x2a, 0xe2, 0x2e, 0xb2, 0x3a, 0xf2, 0x3e, 49c5a511f1SSebastian Siewior 0xa6, 0x6a, 0xe6, 0x6e, 0xb6, 0x7a, 0xf6, 0x7e, 50c5a511f1SSebastian Siewior 0x08, 0x80, 0x48, 0x84, 0x18, 0x90, 0x58, 0x94, 51c5a511f1SSebastian Siewior 0x0c, 0xc0, 0x4c, 0xc4, 0x1c, 0xd0, 0x5c, 0xd4, 52c5a511f1SSebastian Siewior 0x0a, 0x82, 0x4a, 0x86, 0x1a, 0x92, 0x5a, 0x96, 53c5a511f1SSebastian Siewior 0x0e, 0xc2, 0x4e, 0xc6, 0x1e, 0xd2, 0x5e, 0xd6, 54c5a511f1SSebastian Siewior 0x88, 0x88, 0xc8, 0x8c, 0x98, 0x98, 0xd8, 0x9c, 55c5a511f1SSebastian Siewior 0x8c, 0xc8, 0xcc, 0xcc, 0x9c, 0xd8, 0xdc, 0xdc, 56c5a511f1SSebastian Siewior 0x8a, 0x8a, 0xca, 0x8e, 0x9a, 0x9a, 0xda, 0x9e, 57c5a511f1SSebastian Siewior 0x8e, 0xca, 0xce, 0xce, 0x9e, 0xda, 0xde, 0xde, 58c5a511f1SSebastian Siewior 0x28, 0xa0, 0x68, 0xa4, 0x38, 0xb0, 0x78, 0xb4, 59c5a511f1SSebastian Siewior 0x2c, 0xe0, 0x6c, 0xe4, 0x3c, 0xf0, 0x7c, 0xf4, 60c5a511f1SSebastian Siewior 0x2a, 0xa2, 0x6a, 0xa6, 0x3a, 0xb2, 0x7a, 0xb6, 61c5a511f1SSebastian Siewior 0x2e, 0xe2, 0x6e, 0xe6, 0x3e, 0xf2, 0x7e, 0xf6, 62c5a511f1SSebastian Siewior 0xa8, 0xa8, 0xe8, 0xac, 0xb8, 0xb8, 0xf8, 0xbc, 63c5a511f1SSebastian Siewior 0xac, 0xe8, 0xec, 0xec, 0xbc, 0xf8, 0xfc, 0xfc, 64c5a511f1SSebastian Siewior 0xaa, 0xaa, 0xea, 0xae, 0xba, 0xba, 0xfa, 0xbe, 65c5a511f1SSebastian Siewior 0xae, 0xea, 0xee, 0xee, 0xbe, 0xfa, 0xfe, 0xfe 66c5a511f1SSebastian Siewior }; 67c5a511f1SSebastian Siewior 68c5a511f1SSebastian Siewior static const u8 rs[256] = { 69c5a511f1SSebastian Siewior 0x00, 0x00, 0x80, 0x80, 0x02, 0x02, 0x82, 0x82, 70c5a511f1SSebastian Siewior 0x04, 0x04, 0x84, 0x84, 0x06, 0x06, 0x86, 0x86, 71c5a511f1SSebastian Siewior 0x08, 0x08, 0x88, 0x88, 0x0a, 0x0a, 0x8a, 0x8a, 72c5a511f1SSebastian Siewior 0x0c, 0x0c, 0x8c, 0x8c, 0x0e, 0x0e, 0x8e, 0x8e, 73c5a511f1SSebastian Siewior 0x10, 0x10, 0x90, 0x90, 0x12, 0x12, 0x92, 0x92, 74c5a511f1SSebastian Siewior 0x14, 0x14, 0x94, 0x94, 0x16, 0x16, 0x96, 0x96, 75c5a511f1SSebastian Siewior 0x18, 0x18, 0x98, 0x98, 0x1a, 0x1a, 0x9a, 0x9a, 76c5a511f1SSebastian Siewior 0x1c, 0x1c, 0x9c, 0x9c, 0x1e, 0x1e, 0x9e, 0x9e, 77c5a511f1SSebastian Siewior 0x20, 0x20, 0xa0, 0xa0, 0x22, 0x22, 0xa2, 0xa2, 78c5a511f1SSebastian Siewior 0x24, 0x24, 0xa4, 0xa4, 0x26, 0x26, 0xa6, 0xa6, 79c5a511f1SSebastian Siewior 0x28, 0x28, 0xa8, 0xa8, 0x2a, 0x2a, 0xaa, 0xaa, 80c5a511f1SSebastian Siewior 0x2c, 0x2c, 0xac, 0xac, 0x2e, 0x2e, 0xae, 0xae, 81c5a511f1SSebastian Siewior 0x30, 0x30, 0xb0, 0xb0, 0x32, 0x32, 0xb2, 0xb2, 82c5a511f1SSebastian Siewior 0x34, 0x34, 0xb4, 0xb4, 0x36, 0x36, 0xb6, 0xb6, 83c5a511f1SSebastian Siewior 0x38, 0x38, 0xb8, 0xb8, 0x3a, 0x3a, 0xba, 0xba, 84c5a511f1SSebastian Siewior 0x3c, 0x3c, 0xbc, 0xbc, 0x3e, 0x3e, 0xbe, 0xbe, 85c5a511f1SSebastian Siewior 0x40, 0x40, 0xc0, 0xc0, 0x42, 0x42, 0xc2, 0xc2, 86c5a511f1SSebastian Siewior 0x44, 0x44, 0xc4, 0xc4, 0x46, 0x46, 0xc6, 0xc6, 87c5a511f1SSebastian Siewior 0x48, 0x48, 0xc8, 0xc8, 0x4a, 0x4a, 0xca, 0xca, 88c5a511f1SSebastian Siewior 0x4c, 0x4c, 0xcc, 0xcc, 0x4e, 0x4e, 0xce, 0xce, 89c5a511f1SSebastian Siewior 0x50, 0x50, 0xd0, 0xd0, 0x52, 0x52, 0xd2, 0xd2, 90c5a511f1SSebastian Siewior 0x54, 0x54, 0xd4, 0xd4, 0x56, 0x56, 0xd6, 0xd6, 91c5a511f1SSebastian Siewior 0x58, 0x58, 0xd8, 0xd8, 0x5a, 0x5a, 0xda, 0xda, 92c5a511f1SSebastian Siewior 0x5c, 0x5c, 0xdc, 0xdc, 0x5e, 0x5e, 0xde, 0xde, 93c5a511f1SSebastian Siewior 0x60, 0x60, 0xe0, 0xe0, 0x62, 0x62, 0xe2, 0xe2, 94c5a511f1SSebastian Siewior 0x64, 0x64, 0xe4, 0xe4, 0x66, 0x66, 0xe6, 0xe6, 95c5a511f1SSebastian Siewior 0x68, 0x68, 0xe8, 0xe8, 0x6a, 0x6a, 0xea, 0xea, 96c5a511f1SSebastian Siewior 0x6c, 0x6c, 0xec, 0xec, 0x6e, 0x6e, 0xee, 0xee, 97c5a511f1SSebastian Siewior 0x70, 0x70, 0xf0, 0xf0, 0x72, 0x72, 0xf2, 0xf2, 98c5a511f1SSebastian Siewior 0x74, 0x74, 0xf4, 0xf4, 0x76, 0x76, 0xf6, 0xf6, 99c5a511f1SSebastian Siewior 0x78, 0x78, 0xf8, 0xf8, 0x7a, 0x7a, 0xfa, 0xfa, 100c5a511f1SSebastian Siewior 0x7c, 0x7c, 0xfc, 0xfc, 0x7e, 0x7e, 0xfe, 0xfe 101c5a511f1SSebastian Siewior }; 102c5a511f1SSebastian Siewior 103c5a511f1SSebastian Siewior static const u32 pc2[1024] = { 104c5a511f1SSebastian Siewior 0x00000000, 0x00000000, 0x00000000, 0x00000000, 105c5a511f1SSebastian Siewior 0x00040000, 0x00000000, 0x04000000, 0x00100000, 106c5a511f1SSebastian Siewior 0x00400000, 0x00000008, 0x00000800, 0x40000000, 107c5a511f1SSebastian Siewior 0x00440000, 0x00000008, 0x04000800, 0x40100000, 108c5a511f1SSebastian Siewior 0x00000400, 0x00000020, 0x08000000, 0x00000100, 109c5a511f1SSebastian Siewior 0x00040400, 0x00000020, 0x0c000000, 0x00100100, 110c5a511f1SSebastian Siewior 0x00400400, 0x00000028, 0x08000800, 0x40000100, 111c5a511f1SSebastian Siewior 0x00440400, 0x00000028, 0x0c000800, 0x40100100, 112c5a511f1SSebastian Siewior 0x80000000, 0x00000010, 0x00000000, 0x00800000, 113c5a511f1SSebastian Siewior 0x80040000, 0x00000010, 0x04000000, 0x00900000, 114c5a511f1SSebastian Siewior 0x80400000, 0x00000018, 0x00000800, 0x40800000, 115c5a511f1SSebastian Siewior 0x80440000, 0x00000018, 0x04000800, 0x40900000, 116c5a511f1SSebastian Siewior 0x80000400, 0x00000030, 0x08000000, 0x00800100, 117c5a511f1SSebastian Siewior 0x80040400, 0x00000030, 0x0c000000, 0x00900100, 118c5a511f1SSebastian Siewior 0x80400400, 0x00000038, 0x08000800, 0x40800100, 119c5a511f1SSebastian Siewior 0x80440400, 0x00000038, 0x0c000800, 0x40900100, 120c5a511f1SSebastian Siewior 0x10000000, 0x00000000, 0x00200000, 0x00001000, 121c5a511f1SSebastian Siewior 0x10040000, 0x00000000, 0x04200000, 0x00101000, 122c5a511f1SSebastian Siewior 0x10400000, 0x00000008, 0x00200800, 0x40001000, 123c5a511f1SSebastian Siewior 0x10440000, 0x00000008, 0x04200800, 0x40101000, 124c5a511f1SSebastian Siewior 0x10000400, 0x00000020, 0x08200000, 0x00001100, 125c5a511f1SSebastian Siewior 0x10040400, 0x00000020, 0x0c200000, 0x00101100, 126c5a511f1SSebastian Siewior 0x10400400, 0x00000028, 0x08200800, 0x40001100, 127c5a511f1SSebastian Siewior 0x10440400, 0x00000028, 0x0c200800, 0x40101100, 128c5a511f1SSebastian Siewior 0x90000000, 0x00000010, 0x00200000, 0x00801000, 129c5a511f1SSebastian Siewior 0x90040000, 0x00000010, 0x04200000, 0x00901000, 130c5a511f1SSebastian Siewior 0x90400000, 0x00000018, 0x00200800, 0x40801000, 131c5a511f1SSebastian Siewior 0x90440000, 0x00000018, 0x04200800, 0x40901000, 132c5a511f1SSebastian Siewior 0x90000400, 0x00000030, 0x08200000, 0x00801100, 133c5a511f1SSebastian Siewior 0x90040400, 0x00000030, 0x0c200000, 0x00901100, 134c5a511f1SSebastian Siewior 0x90400400, 0x00000038, 0x08200800, 0x40801100, 135c5a511f1SSebastian Siewior 0x90440400, 0x00000038, 0x0c200800, 0x40901100, 136c5a511f1SSebastian Siewior 0x00000200, 0x00080000, 0x00000000, 0x00000004, 137c5a511f1SSebastian Siewior 0x00040200, 0x00080000, 0x04000000, 0x00100004, 138c5a511f1SSebastian Siewior 0x00400200, 0x00080008, 0x00000800, 0x40000004, 139c5a511f1SSebastian Siewior 0x00440200, 0x00080008, 0x04000800, 0x40100004, 140c5a511f1SSebastian Siewior 0x00000600, 0x00080020, 0x08000000, 0x00000104, 141c5a511f1SSebastian Siewior 0x00040600, 0x00080020, 0x0c000000, 0x00100104, 142c5a511f1SSebastian Siewior 0x00400600, 0x00080028, 0x08000800, 0x40000104, 143c5a511f1SSebastian Siewior 0x00440600, 0x00080028, 0x0c000800, 0x40100104, 144c5a511f1SSebastian Siewior 0x80000200, 0x00080010, 0x00000000, 0x00800004, 145c5a511f1SSebastian Siewior 0x80040200, 0x00080010, 0x04000000, 0x00900004, 146c5a511f1SSebastian Siewior 0x80400200, 0x00080018, 0x00000800, 0x40800004, 147c5a511f1SSebastian Siewior 0x80440200, 0x00080018, 0x04000800, 0x40900004, 148c5a511f1SSebastian Siewior 0x80000600, 0x00080030, 0x08000000, 0x00800104, 149c5a511f1SSebastian Siewior 0x80040600, 0x00080030, 0x0c000000, 0x00900104, 150c5a511f1SSebastian Siewior 0x80400600, 0x00080038, 0x08000800, 0x40800104, 151c5a511f1SSebastian Siewior 0x80440600, 0x00080038, 0x0c000800, 0x40900104, 152c5a511f1SSebastian Siewior 0x10000200, 0x00080000, 0x00200000, 0x00001004, 153c5a511f1SSebastian Siewior 0x10040200, 0x00080000, 0x04200000, 0x00101004, 154c5a511f1SSebastian Siewior 0x10400200, 0x00080008, 0x00200800, 0x40001004, 155c5a511f1SSebastian Siewior 0x10440200, 0x00080008, 0x04200800, 0x40101004, 156c5a511f1SSebastian Siewior 0x10000600, 0x00080020, 0x08200000, 0x00001104, 157c5a511f1SSebastian Siewior 0x10040600, 0x00080020, 0x0c200000, 0x00101104, 158c5a511f1SSebastian Siewior 0x10400600, 0x00080028, 0x08200800, 0x40001104, 159c5a511f1SSebastian Siewior 0x10440600, 0x00080028, 0x0c200800, 0x40101104, 160c5a511f1SSebastian Siewior 0x90000200, 0x00080010, 0x00200000, 0x00801004, 161c5a511f1SSebastian Siewior 0x90040200, 0x00080010, 0x04200000, 0x00901004, 162c5a511f1SSebastian Siewior 0x90400200, 0x00080018, 0x00200800, 0x40801004, 163c5a511f1SSebastian Siewior 0x90440200, 0x00080018, 0x04200800, 0x40901004, 164c5a511f1SSebastian Siewior 0x90000600, 0x00080030, 0x08200000, 0x00801104, 165c5a511f1SSebastian Siewior 0x90040600, 0x00080030, 0x0c200000, 0x00901104, 166c5a511f1SSebastian Siewior 0x90400600, 0x00080038, 0x08200800, 0x40801104, 167c5a511f1SSebastian Siewior 0x90440600, 0x00080038, 0x0c200800, 0x40901104, 168c5a511f1SSebastian Siewior 0x00000002, 0x00002000, 0x20000000, 0x00000001, 169c5a511f1SSebastian Siewior 0x00040002, 0x00002000, 0x24000000, 0x00100001, 170c5a511f1SSebastian Siewior 0x00400002, 0x00002008, 0x20000800, 0x40000001, 171c5a511f1SSebastian Siewior 0x00440002, 0x00002008, 0x24000800, 0x40100001, 172c5a511f1SSebastian Siewior 0x00000402, 0x00002020, 0x28000000, 0x00000101, 173c5a511f1SSebastian Siewior 0x00040402, 0x00002020, 0x2c000000, 0x00100101, 174c5a511f1SSebastian Siewior 0x00400402, 0x00002028, 0x28000800, 0x40000101, 175c5a511f1SSebastian Siewior 0x00440402, 0x00002028, 0x2c000800, 0x40100101, 176c5a511f1SSebastian Siewior 0x80000002, 0x00002010, 0x20000000, 0x00800001, 177c5a511f1SSebastian Siewior 0x80040002, 0x00002010, 0x24000000, 0x00900001, 178c5a511f1SSebastian Siewior 0x80400002, 0x00002018, 0x20000800, 0x40800001, 179c5a511f1SSebastian Siewior 0x80440002, 0x00002018, 0x24000800, 0x40900001, 180c5a511f1SSebastian Siewior 0x80000402, 0x00002030, 0x28000000, 0x00800101, 181c5a511f1SSebastian Siewior 0x80040402, 0x00002030, 0x2c000000, 0x00900101, 182c5a511f1SSebastian Siewior 0x80400402, 0x00002038, 0x28000800, 0x40800101, 183c5a511f1SSebastian Siewior 0x80440402, 0x00002038, 0x2c000800, 0x40900101, 184c5a511f1SSebastian Siewior 0x10000002, 0x00002000, 0x20200000, 0x00001001, 185c5a511f1SSebastian Siewior 0x10040002, 0x00002000, 0x24200000, 0x00101001, 186c5a511f1SSebastian Siewior 0x10400002, 0x00002008, 0x20200800, 0x40001001, 187c5a511f1SSebastian Siewior 0x10440002, 0x00002008, 0x24200800, 0x40101001, 188c5a511f1SSebastian Siewior 0x10000402, 0x00002020, 0x28200000, 0x00001101, 189c5a511f1SSebastian Siewior 0x10040402, 0x00002020, 0x2c200000, 0x00101101, 190c5a511f1SSebastian Siewior 0x10400402, 0x00002028, 0x28200800, 0x40001101, 191c5a511f1SSebastian Siewior 0x10440402, 0x00002028, 0x2c200800, 0x40101101, 192c5a511f1SSebastian Siewior 0x90000002, 0x00002010, 0x20200000, 0x00801001, 193c5a511f1SSebastian Siewior 0x90040002, 0x00002010, 0x24200000, 0x00901001, 194c5a511f1SSebastian Siewior 0x90400002, 0x00002018, 0x20200800, 0x40801001, 195c5a511f1SSebastian Siewior 0x90440002, 0x00002018, 0x24200800, 0x40901001, 196c5a511f1SSebastian Siewior 0x90000402, 0x00002030, 0x28200000, 0x00801101, 197c5a511f1SSebastian Siewior 0x90040402, 0x00002030, 0x2c200000, 0x00901101, 198c5a511f1SSebastian Siewior 0x90400402, 0x00002038, 0x28200800, 0x40801101, 199c5a511f1SSebastian Siewior 0x90440402, 0x00002038, 0x2c200800, 0x40901101, 200c5a511f1SSebastian Siewior 0x00000202, 0x00082000, 0x20000000, 0x00000005, 201c5a511f1SSebastian Siewior 0x00040202, 0x00082000, 0x24000000, 0x00100005, 202c5a511f1SSebastian Siewior 0x00400202, 0x00082008, 0x20000800, 0x40000005, 203c5a511f1SSebastian Siewior 0x00440202, 0x00082008, 0x24000800, 0x40100005, 204c5a511f1SSebastian Siewior 0x00000602, 0x00082020, 0x28000000, 0x00000105, 205c5a511f1SSebastian Siewior 0x00040602, 0x00082020, 0x2c000000, 0x00100105, 206c5a511f1SSebastian Siewior 0x00400602, 0x00082028, 0x28000800, 0x40000105, 207c5a511f1SSebastian Siewior 0x00440602, 0x00082028, 0x2c000800, 0x40100105, 208c5a511f1SSebastian Siewior 0x80000202, 0x00082010, 0x20000000, 0x00800005, 209c5a511f1SSebastian Siewior 0x80040202, 0x00082010, 0x24000000, 0x00900005, 210c5a511f1SSebastian Siewior 0x80400202, 0x00082018, 0x20000800, 0x40800005, 211c5a511f1SSebastian Siewior 0x80440202, 0x00082018, 0x24000800, 0x40900005, 212c5a511f1SSebastian Siewior 0x80000602, 0x00082030, 0x28000000, 0x00800105, 213c5a511f1SSebastian Siewior 0x80040602, 0x00082030, 0x2c000000, 0x00900105, 214c5a511f1SSebastian Siewior 0x80400602, 0x00082038, 0x28000800, 0x40800105, 215c5a511f1SSebastian Siewior 0x80440602, 0x00082038, 0x2c000800, 0x40900105, 216c5a511f1SSebastian Siewior 0x10000202, 0x00082000, 0x20200000, 0x00001005, 217c5a511f1SSebastian Siewior 0x10040202, 0x00082000, 0x24200000, 0x00101005, 218c5a511f1SSebastian Siewior 0x10400202, 0x00082008, 0x20200800, 0x40001005, 219c5a511f1SSebastian Siewior 0x10440202, 0x00082008, 0x24200800, 0x40101005, 220c5a511f1SSebastian Siewior 0x10000602, 0x00082020, 0x28200000, 0x00001105, 221c5a511f1SSebastian Siewior 0x10040602, 0x00082020, 0x2c200000, 0x00101105, 222c5a511f1SSebastian Siewior 0x10400602, 0x00082028, 0x28200800, 0x40001105, 223c5a511f1SSebastian Siewior 0x10440602, 0x00082028, 0x2c200800, 0x40101105, 224c5a511f1SSebastian Siewior 0x90000202, 0x00082010, 0x20200000, 0x00801005, 225c5a511f1SSebastian Siewior 0x90040202, 0x00082010, 0x24200000, 0x00901005, 226c5a511f1SSebastian Siewior 0x90400202, 0x00082018, 0x20200800, 0x40801005, 227c5a511f1SSebastian Siewior 0x90440202, 0x00082018, 0x24200800, 0x40901005, 228c5a511f1SSebastian Siewior 0x90000602, 0x00082030, 0x28200000, 0x00801105, 229c5a511f1SSebastian Siewior 0x90040602, 0x00082030, 0x2c200000, 0x00901105, 230c5a511f1SSebastian Siewior 0x90400602, 0x00082038, 0x28200800, 0x40801105, 231c5a511f1SSebastian Siewior 0x90440602, 0x00082038, 0x2c200800, 0x40901105, 232c5a511f1SSebastian Siewior 233c5a511f1SSebastian Siewior 0x00000000, 0x00000000, 0x00000000, 0x00000000, 234c5a511f1SSebastian Siewior 0x00000000, 0x00000008, 0x00080000, 0x10000000, 235c5a511f1SSebastian Siewior 0x02000000, 0x00000000, 0x00000080, 0x00001000, 236c5a511f1SSebastian Siewior 0x02000000, 0x00000008, 0x00080080, 0x10001000, 237c5a511f1SSebastian Siewior 0x00004000, 0x00000000, 0x00000040, 0x00040000, 238c5a511f1SSebastian Siewior 0x00004000, 0x00000008, 0x00080040, 0x10040000, 239c5a511f1SSebastian Siewior 0x02004000, 0x00000000, 0x000000c0, 0x00041000, 240c5a511f1SSebastian Siewior 0x02004000, 0x00000008, 0x000800c0, 0x10041000, 241c5a511f1SSebastian Siewior 0x00020000, 0x00008000, 0x08000000, 0x00200000, 242c5a511f1SSebastian Siewior 0x00020000, 0x00008008, 0x08080000, 0x10200000, 243c5a511f1SSebastian Siewior 0x02020000, 0x00008000, 0x08000080, 0x00201000, 244c5a511f1SSebastian Siewior 0x02020000, 0x00008008, 0x08080080, 0x10201000, 245c5a511f1SSebastian Siewior 0x00024000, 0x00008000, 0x08000040, 0x00240000, 246c5a511f1SSebastian Siewior 0x00024000, 0x00008008, 0x08080040, 0x10240000, 247c5a511f1SSebastian Siewior 0x02024000, 0x00008000, 0x080000c0, 0x00241000, 248c5a511f1SSebastian Siewior 0x02024000, 0x00008008, 0x080800c0, 0x10241000, 249c5a511f1SSebastian Siewior 0x00000000, 0x01000000, 0x00002000, 0x00000020, 250c5a511f1SSebastian Siewior 0x00000000, 0x01000008, 0x00082000, 0x10000020, 251c5a511f1SSebastian Siewior 0x02000000, 0x01000000, 0x00002080, 0x00001020, 252c5a511f1SSebastian Siewior 0x02000000, 0x01000008, 0x00082080, 0x10001020, 253c5a511f1SSebastian Siewior 0x00004000, 0x01000000, 0x00002040, 0x00040020, 254c5a511f1SSebastian Siewior 0x00004000, 0x01000008, 0x00082040, 0x10040020, 255c5a511f1SSebastian Siewior 0x02004000, 0x01000000, 0x000020c0, 0x00041020, 256c5a511f1SSebastian Siewior 0x02004000, 0x01000008, 0x000820c0, 0x10041020, 257c5a511f1SSebastian Siewior 0x00020000, 0x01008000, 0x08002000, 0x00200020, 258c5a511f1SSebastian Siewior 0x00020000, 0x01008008, 0x08082000, 0x10200020, 259c5a511f1SSebastian Siewior 0x02020000, 0x01008000, 0x08002080, 0x00201020, 260c5a511f1SSebastian Siewior 0x02020000, 0x01008008, 0x08082080, 0x10201020, 261c5a511f1SSebastian Siewior 0x00024000, 0x01008000, 0x08002040, 0x00240020, 262c5a511f1SSebastian Siewior 0x00024000, 0x01008008, 0x08082040, 0x10240020, 263c5a511f1SSebastian Siewior 0x02024000, 0x01008000, 0x080020c0, 0x00241020, 264c5a511f1SSebastian Siewior 0x02024000, 0x01008008, 0x080820c0, 0x10241020, 265c5a511f1SSebastian Siewior 0x00000400, 0x04000000, 0x00100000, 0x00000004, 266c5a511f1SSebastian Siewior 0x00000400, 0x04000008, 0x00180000, 0x10000004, 267c5a511f1SSebastian Siewior 0x02000400, 0x04000000, 0x00100080, 0x00001004, 268c5a511f1SSebastian Siewior 0x02000400, 0x04000008, 0x00180080, 0x10001004, 269c5a511f1SSebastian Siewior 0x00004400, 0x04000000, 0x00100040, 0x00040004, 270c5a511f1SSebastian Siewior 0x00004400, 0x04000008, 0x00180040, 0x10040004, 271c5a511f1SSebastian Siewior 0x02004400, 0x04000000, 0x001000c0, 0x00041004, 272c5a511f1SSebastian Siewior 0x02004400, 0x04000008, 0x001800c0, 0x10041004, 273c5a511f1SSebastian Siewior 0x00020400, 0x04008000, 0x08100000, 0x00200004, 274c5a511f1SSebastian Siewior 0x00020400, 0x04008008, 0x08180000, 0x10200004, 275c5a511f1SSebastian Siewior 0x02020400, 0x04008000, 0x08100080, 0x00201004, 276c5a511f1SSebastian Siewior 0x02020400, 0x04008008, 0x08180080, 0x10201004, 277c5a511f1SSebastian Siewior 0x00024400, 0x04008000, 0x08100040, 0x00240004, 278c5a511f1SSebastian Siewior 0x00024400, 0x04008008, 0x08180040, 0x10240004, 279c5a511f1SSebastian Siewior 0x02024400, 0x04008000, 0x081000c0, 0x00241004, 280c5a511f1SSebastian Siewior 0x02024400, 0x04008008, 0x081800c0, 0x10241004, 281c5a511f1SSebastian Siewior 0x00000400, 0x05000000, 0x00102000, 0x00000024, 282c5a511f1SSebastian Siewior 0x00000400, 0x05000008, 0x00182000, 0x10000024, 283c5a511f1SSebastian Siewior 0x02000400, 0x05000000, 0x00102080, 0x00001024, 284c5a511f1SSebastian Siewior 0x02000400, 0x05000008, 0x00182080, 0x10001024, 285c5a511f1SSebastian Siewior 0x00004400, 0x05000000, 0x00102040, 0x00040024, 286c5a511f1SSebastian Siewior 0x00004400, 0x05000008, 0x00182040, 0x10040024, 287c5a511f1SSebastian Siewior 0x02004400, 0x05000000, 0x001020c0, 0x00041024, 288c5a511f1SSebastian Siewior 0x02004400, 0x05000008, 0x001820c0, 0x10041024, 289c5a511f1SSebastian Siewior 0x00020400, 0x05008000, 0x08102000, 0x00200024, 290c5a511f1SSebastian Siewior 0x00020400, 0x05008008, 0x08182000, 0x10200024, 291c5a511f1SSebastian Siewior 0x02020400, 0x05008000, 0x08102080, 0x00201024, 292c5a511f1SSebastian Siewior 0x02020400, 0x05008008, 0x08182080, 0x10201024, 293c5a511f1SSebastian Siewior 0x00024400, 0x05008000, 0x08102040, 0x00240024, 294c5a511f1SSebastian Siewior 0x00024400, 0x05008008, 0x08182040, 0x10240024, 295c5a511f1SSebastian Siewior 0x02024400, 0x05008000, 0x081020c0, 0x00241024, 296c5a511f1SSebastian Siewior 0x02024400, 0x05008008, 0x081820c0, 0x10241024, 297c5a511f1SSebastian Siewior 0x00000800, 0x00010000, 0x20000000, 0x00000010, 298c5a511f1SSebastian Siewior 0x00000800, 0x00010008, 0x20080000, 0x10000010, 299c5a511f1SSebastian Siewior 0x02000800, 0x00010000, 0x20000080, 0x00001010, 300c5a511f1SSebastian Siewior 0x02000800, 0x00010008, 0x20080080, 0x10001010, 301c5a511f1SSebastian Siewior 0x00004800, 0x00010000, 0x20000040, 0x00040010, 302c5a511f1SSebastian Siewior 0x00004800, 0x00010008, 0x20080040, 0x10040010, 303c5a511f1SSebastian Siewior 0x02004800, 0x00010000, 0x200000c0, 0x00041010, 304c5a511f1SSebastian Siewior 0x02004800, 0x00010008, 0x200800c0, 0x10041010, 305c5a511f1SSebastian Siewior 0x00020800, 0x00018000, 0x28000000, 0x00200010, 306c5a511f1SSebastian Siewior 0x00020800, 0x00018008, 0x28080000, 0x10200010, 307c5a511f1SSebastian Siewior 0x02020800, 0x00018000, 0x28000080, 0x00201010, 308c5a511f1SSebastian Siewior 0x02020800, 0x00018008, 0x28080080, 0x10201010, 309c5a511f1SSebastian Siewior 0x00024800, 0x00018000, 0x28000040, 0x00240010, 310c5a511f1SSebastian Siewior 0x00024800, 0x00018008, 0x28080040, 0x10240010, 311c5a511f1SSebastian Siewior 0x02024800, 0x00018000, 0x280000c0, 0x00241010, 312c5a511f1SSebastian Siewior 0x02024800, 0x00018008, 0x280800c0, 0x10241010, 313c5a511f1SSebastian Siewior 0x00000800, 0x01010000, 0x20002000, 0x00000030, 314c5a511f1SSebastian Siewior 0x00000800, 0x01010008, 0x20082000, 0x10000030, 315c5a511f1SSebastian Siewior 0x02000800, 0x01010000, 0x20002080, 0x00001030, 316c5a511f1SSebastian Siewior 0x02000800, 0x01010008, 0x20082080, 0x10001030, 317c5a511f1SSebastian Siewior 0x00004800, 0x01010000, 0x20002040, 0x00040030, 318c5a511f1SSebastian Siewior 0x00004800, 0x01010008, 0x20082040, 0x10040030, 319c5a511f1SSebastian Siewior 0x02004800, 0x01010000, 0x200020c0, 0x00041030, 320c5a511f1SSebastian Siewior 0x02004800, 0x01010008, 0x200820c0, 0x10041030, 321c5a511f1SSebastian Siewior 0x00020800, 0x01018000, 0x28002000, 0x00200030, 322c5a511f1SSebastian Siewior 0x00020800, 0x01018008, 0x28082000, 0x10200030, 323c5a511f1SSebastian Siewior 0x02020800, 0x01018000, 0x28002080, 0x00201030, 324c5a511f1SSebastian Siewior 0x02020800, 0x01018008, 0x28082080, 0x10201030, 325c5a511f1SSebastian Siewior 0x00024800, 0x01018000, 0x28002040, 0x00240030, 326c5a511f1SSebastian Siewior 0x00024800, 0x01018008, 0x28082040, 0x10240030, 327c5a511f1SSebastian Siewior 0x02024800, 0x01018000, 0x280020c0, 0x00241030, 328c5a511f1SSebastian Siewior 0x02024800, 0x01018008, 0x280820c0, 0x10241030, 329c5a511f1SSebastian Siewior 0x00000c00, 0x04010000, 0x20100000, 0x00000014, 330c5a511f1SSebastian Siewior 0x00000c00, 0x04010008, 0x20180000, 0x10000014, 331c5a511f1SSebastian Siewior 0x02000c00, 0x04010000, 0x20100080, 0x00001014, 332c5a511f1SSebastian Siewior 0x02000c00, 0x04010008, 0x20180080, 0x10001014, 333c5a511f1SSebastian Siewior 0x00004c00, 0x04010000, 0x20100040, 0x00040014, 334c5a511f1SSebastian Siewior 0x00004c00, 0x04010008, 0x20180040, 0x10040014, 335c5a511f1SSebastian Siewior 0x02004c00, 0x04010000, 0x201000c0, 0x00041014, 336c5a511f1SSebastian Siewior 0x02004c00, 0x04010008, 0x201800c0, 0x10041014, 337c5a511f1SSebastian Siewior 0x00020c00, 0x04018000, 0x28100000, 0x00200014, 338c5a511f1SSebastian Siewior 0x00020c00, 0x04018008, 0x28180000, 0x10200014, 339c5a511f1SSebastian Siewior 0x02020c00, 0x04018000, 0x28100080, 0x00201014, 340c5a511f1SSebastian Siewior 0x02020c00, 0x04018008, 0x28180080, 0x10201014, 341c5a511f1SSebastian Siewior 0x00024c00, 0x04018000, 0x28100040, 0x00240014, 342c5a511f1SSebastian Siewior 0x00024c00, 0x04018008, 0x28180040, 0x10240014, 343c5a511f1SSebastian Siewior 0x02024c00, 0x04018000, 0x281000c0, 0x00241014, 344c5a511f1SSebastian Siewior 0x02024c00, 0x04018008, 0x281800c0, 0x10241014, 345c5a511f1SSebastian Siewior 0x00000c00, 0x05010000, 0x20102000, 0x00000034, 346c5a511f1SSebastian Siewior 0x00000c00, 0x05010008, 0x20182000, 0x10000034, 347c5a511f1SSebastian Siewior 0x02000c00, 0x05010000, 0x20102080, 0x00001034, 348c5a511f1SSebastian Siewior 0x02000c00, 0x05010008, 0x20182080, 0x10001034, 349c5a511f1SSebastian Siewior 0x00004c00, 0x05010000, 0x20102040, 0x00040034, 350c5a511f1SSebastian Siewior 0x00004c00, 0x05010008, 0x20182040, 0x10040034, 351c5a511f1SSebastian Siewior 0x02004c00, 0x05010000, 0x201020c0, 0x00041034, 352c5a511f1SSebastian Siewior 0x02004c00, 0x05010008, 0x201820c0, 0x10041034, 353c5a511f1SSebastian Siewior 0x00020c00, 0x05018000, 0x28102000, 0x00200034, 354c5a511f1SSebastian Siewior 0x00020c00, 0x05018008, 0x28182000, 0x10200034, 355c5a511f1SSebastian Siewior 0x02020c00, 0x05018000, 0x28102080, 0x00201034, 356c5a511f1SSebastian Siewior 0x02020c00, 0x05018008, 0x28182080, 0x10201034, 357c5a511f1SSebastian Siewior 0x00024c00, 0x05018000, 0x28102040, 0x00240034, 358c5a511f1SSebastian Siewior 0x00024c00, 0x05018008, 0x28182040, 0x10240034, 359c5a511f1SSebastian Siewior 0x02024c00, 0x05018000, 0x281020c0, 0x00241034, 360c5a511f1SSebastian Siewior 0x02024c00, 0x05018008, 0x281820c0, 0x10241034 361c5a511f1SSebastian Siewior }; 362c5a511f1SSebastian Siewior 363c5a511f1SSebastian Siewior /* S-box lookup tables */ 364c5a511f1SSebastian Siewior 365c5a511f1SSebastian Siewior static const u32 S1[64] = { 366c5a511f1SSebastian Siewior 0x01010400, 0x00000000, 0x00010000, 0x01010404, 367c5a511f1SSebastian Siewior 0x01010004, 0x00010404, 0x00000004, 0x00010000, 368c5a511f1SSebastian Siewior 0x00000400, 0x01010400, 0x01010404, 0x00000400, 369c5a511f1SSebastian Siewior 0x01000404, 0x01010004, 0x01000000, 0x00000004, 370c5a511f1SSebastian Siewior 0x00000404, 0x01000400, 0x01000400, 0x00010400, 371c5a511f1SSebastian Siewior 0x00010400, 0x01010000, 0x01010000, 0x01000404, 372c5a511f1SSebastian Siewior 0x00010004, 0x01000004, 0x01000004, 0x00010004, 373c5a511f1SSebastian Siewior 0x00000000, 0x00000404, 0x00010404, 0x01000000, 374c5a511f1SSebastian Siewior 0x00010000, 0x01010404, 0x00000004, 0x01010000, 375c5a511f1SSebastian Siewior 0x01010400, 0x01000000, 0x01000000, 0x00000400, 376c5a511f1SSebastian Siewior 0x01010004, 0x00010000, 0x00010400, 0x01000004, 377c5a511f1SSebastian Siewior 0x00000400, 0x00000004, 0x01000404, 0x00010404, 378c5a511f1SSebastian Siewior 0x01010404, 0x00010004, 0x01010000, 0x01000404, 379c5a511f1SSebastian Siewior 0x01000004, 0x00000404, 0x00010404, 0x01010400, 380c5a511f1SSebastian Siewior 0x00000404, 0x01000400, 0x01000400, 0x00000000, 381c5a511f1SSebastian Siewior 0x00010004, 0x00010400, 0x00000000, 0x01010004 382c5a511f1SSebastian Siewior }; 383c5a511f1SSebastian Siewior 384c5a511f1SSebastian Siewior static const u32 S2[64] = { 385c5a511f1SSebastian Siewior 0x80108020, 0x80008000, 0x00008000, 0x00108020, 386c5a511f1SSebastian Siewior 0x00100000, 0x00000020, 0x80100020, 0x80008020, 387c5a511f1SSebastian Siewior 0x80000020, 0x80108020, 0x80108000, 0x80000000, 388c5a511f1SSebastian Siewior 0x80008000, 0x00100000, 0x00000020, 0x80100020, 389c5a511f1SSebastian Siewior 0x00108000, 0x00100020, 0x80008020, 0x00000000, 390c5a511f1SSebastian Siewior 0x80000000, 0x00008000, 0x00108020, 0x80100000, 391c5a511f1SSebastian Siewior 0x00100020, 0x80000020, 0x00000000, 0x00108000, 392c5a511f1SSebastian Siewior 0x00008020, 0x80108000, 0x80100000, 0x00008020, 393c5a511f1SSebastian Siewior 0x00000000, 0x00108020, 0x80100020, 0x00100000, 394c5a511f1SSebastian Siewior 0x80008020, 0x80100000, 0x80108000, 0x00008000, 395c5a511f1SSebastian Siewior 0x80100000, 0x80008000, 0x00000020, 0x80108020, 396c5a511f1SSebastian Siewior 0x00108020, 0x00000020, 0x00008000, 0x80000000, 397c5a511f1SSebastian Siewior 0x00008020, 0x80108000, 0x00100000, 0x80000020, 398c5a511f1SSebastian Siewior 0x00100020, 0x80008020, 0x80000020, 0x00100020, 399c5a511f1SSebastian Siewior 0x00108000, 0x00000000, 0x80008000, 0x00008020, 400c5a511f1SSebastian Siewior 0x80000000, 0x80100020, 0x80108020, 0x00108000 401c5a511f1SSebastian Siewior }; 402c5a511f1SSebastian Siewior 403c5a511f1SSebastian Siewior static const u32 S3[64] = { 404c5a511f1SSebastian Siewior 0x00000208, 0x08020200, 0x00000000, 0x08020008, 405c5a511f1SSebastian Siewior 0x08000200, 0x00000000, 0x00020208, 0x08000200, 406c5a511f1SSebastian Siewior 0x00020008, 0x08000008, 0x08000008, 0x00020000, 407c5a511f1SSebastian Siewior 0x08020208, 0x00020008, 0x08020000, 0x00000208, 408c5a511f1SSebastian Siewior 0x08000000, 0x00000008, 0x08020200, 0x00000200, 409c5a511f1SSebastian Siewior 0x00020200, 0x08020000, 0x08020008, 0x00020208, 410c5a511f1SSebastian Siewior 0x08000208, 0x00020200, 0x00020000, 0x08000208, 411c5a511f1SSebastian Siewior 0x00000008, 0x08020208, 0x00000200, 0x08000000, 412c5a511f1SSebastian Siewior 0x08020200, 0x08000000, 0x00020008, 0x00000208, 413c5a511f1SSebastian Siewior 0x00020000, 0x08020200, 0x08000200, 0x00000000, 414c5a511f1SSebastian Siewior 0x00000200, 0x00020008, 0x08020208, 0x08000200, 415c5a511f1SSebastian Siewior 0x08000008, 0x00000200, 0x00000000, 0x08020008, 416c5a511f1SSebastian Siewior 0x08000208, 0x00020000, 0x08000000, 0x08020208, 417c5a511f1SSebastian Siewior 0x00000008, 0x00020208, 0x00020200, 0x08000008, 418c5a511f1SSebastian Siewior 0x08020000, 0x08000208, 0x00000208, 0x08020000, 419c5a511f1SSebastian Siewior 0x00020208, 0x00000008, 0x08020008, 0x00020200 420c5a511f1SSebastian Siewior }; 421c5a511f1SSebastian Siewior 422c5a511f1SSebastian Siewior static const u32 S4[64] = { 423c5a511f1SSebastian Siewior 0x00802001, 0x00002081, 0x00002081, 0x00000080, 424c5a511f1SSebastian Siewior 0x00802080, 0x00800081, 0x00800001, 0x00002001, 425c5a511f1SSebastian Siewior 0x00000000, 0x00802000, 0x00802000, 0x00802081, 426c5a511f1SSebastian Siewior 0x00000081, 0x00000000, 0x00800080, 0x00800001, 427c5a511f1SSebastian Siewior 0x00000001, 0x00002000, 0x00800000, 0x00802001, 428c5a511f1SSebastian Siewior 0x00000080, 0x00800000, 0x00002001, 0x00002080, 429c5a511f1SSebastian Siewior 0x00800081, 0x00000001, 0x00002080, 0x00800080, 430c5a511f1SSebastian Siewior 0x00002000, 0x00802080, 0x00802081, 0x00000081, 431c5a511f1SSebastian Siewior 0x00800080, 0x00800001, 0x00802000, 0x00802081, 432c5a511f1SSebastian Siewior 0x00000081, 0x00000000, 0x00000000, 0x00802000, 433c5a511f1SSebastian Siewior 0x00002080, 0x00800080, 0x00800081, 0x00000001, 434c5a511f1SSebastian Siewior 0x00802001, 0x00002081, 0x00002081, 0x00000080, 435c5a511f1SSebastian Siewior 0x00802081, 0x00000081, 0x00000001, 0x00002000, 436c5a511f1SSebastian Siewior 0x00800001, 0x00002001, 0x00802080, 0x00800081, 437c5a511f1SSebastian Siewior 0x00002001, 0x00002080, 0x00800000, 0x00802001, 438c5a511f1SSebastian Siewior 0x00000080, 0x00800000, 0x00002000, 0x00802080 439c5a511f1SSebastian Siewior }; 440c5a511f1SSebastian Siewior 441c5a511f1SSebastian Siewior static const u32 S5[64] = { 442c5a511f1SSebastian Siewior 0x00000100, 0x02080100, 0x02080000, 0x42000100, 443c5a511f1SSebastian Siewior 0x00080000, 0x00000100, 0x40000000, 0x02080000, 444c5a511f1SSebastian Siewior 0x40080100, 0x00080000, 0x02000100, 0x40080100, 445c5a511f1SSebastian Siewior 0x42000100, 0x42080000, 0x00080100, 0x40000000, 446c5a511f1SSebastian Siewior 0x02000000, 0x40080000, 0x40080000, 0x00000000, 447c5a511f1SSebastian Siewior 0x40000100, 0x42080100, 0x42080100, 0x02000100, 448c5a511f1SSebastian Siewior 0x42080000, 0x40000100, 0x00000000, 0x42000000, 449c5a511f1SSebastian Siewior 0x02080100, 0x02000000, 0x42000000, 0x00080100, 450c5a511f1SSebastian Siewior 0x00080000, 0x42000100, 0x00000100, 0x02000000, 451c5a511f1SSebastian Siewior 0x40000000, 0x02080000, 0x42000100, 0x40080100, 452c5a511f1SSebastian Siewior 0x02000100, 0x40000000, 0x42080000, 0x02080100, 453c5a511f1SSebastian Siewior 0x40080100, 0x00000100, 0x02000000, 0x42080000, 454c5a511f1SSebastian Siewior 0x42080100, 0x00080100, 0x42000000, 0x42080100, 455c5a511f1SSebastian Siewior 0x02080000, 0x00000000, 0x40080000, 0x42000000, 456c5a511f1SSebastian Siewior 0x00080100, 0x02000100, 0x40000100, 0x00080000, 457c5a511f1SSebastian Siewior 0x00000000, 0x40080000, 0x02080100, 0x40000100 458c5a511f1SSebastian Siewior }; 459c5a511f1SSebastian Siewior 460c5a511f1SSebastian Siewior static const u32 S6[64] = { 461c5a511f1SSebastian Siewior 0x20000010, 0x20400000, 0x00004000, 0x20404010, 462c5a511f1SSebastian Siewior 0x20400000, 0x00000010, 0x20404010, 0x00400000, 463c5a511f1SSebastian Siewior 0x20004000, 0x00404010, 0x00400000, 0x20000010, 464c5a511f1SSebastian Siewior 0x00400010, 0x20004000, 0x20000000, 0x00004010, 465c5a511f1SSebastian Siewior 0x00000000, 0x00400010, 0x20004010, 0x00004000, 466c5a511f1SSebastian Siewior 0x00404000, 0x20004010, 0x00000010, 0x20400010, 467c5a511f1SSebastian Siewior 0x20400010, 0x00000000, 0x00404010, 0x20404000, 468c5a511f1SSebastian Siewior 0x00004010, 0x00404000, 0x20404000, 0x20000000, 469c5a511f1SSebastian Siewior 0x20004000, 0x00000010, 0x20400010, 0x00404000, 470c5a511f1SSebastian Siewior 0x20404010, 0x00400000, 0x00004010, 0x20000010, 471c5a511f1SSebastian Siewior 0x00400000, 0x20004000, 0x20000000, 0x00004010, 472c5a511f1SSebastian Siewior 0x20000010, 0x20404010, 0x00404000, 0x20400000, 473c5a511f1SSebastian Siewior 0x00404010, 0x20404000, 0x00000000, 0x20400010, 474c5a511f1SSebastian Siewior 0x00000010, 0x00004000, 0x20400000, 0x00404010, 475c5a511f1SSebastian Siewior 0x00004000, 0x00400010, 0x20004010, 0x00000000, 476c5a511f1SSebastian Siewior 0x20404000, 0x20000000, 0x00400010, 0x20004010 477c5a511f1SSebastian Siewior }; 478c5a511f1SSebastian Siewior 479c5a511f1SSebastian Siewior static const u32 S7[64] = { 480c5a511f1SSebastian Siewior 0x00200000, 0x04200002, 0x04000802, 0x00000000, 481c5a511f1SSebastian Siewior 0x00000800, 0x04000802, 0x00200802, 0x04200800, 482c5a511f1SSebastian Siewior 0x04200802, 0x00200000, 0x00000000, 0x04000002, 483c5a511f1SSebastian Siewior 0x00000002, 0x04000000, 0x04200002, 0x00000802, 484c5a511f1SSebastian Siewior 0x04000800, 0x00200802, 0x00200002, 0x04000800, 485c5a511f1SSebastian Siewior 0x04000002, 0x04200000, 0x04200800, 0x00200002, 486c5a511f1SSebastian Siewior 0x04200000, 0x00000800, 0x00000802, 0x04200802, 487c5a511f1SSebastian Siewior 0x00200800, 0x00000002, 0x04000000, 0x00200800, 488c5a511f1SSebastian Siewior 0x04000000, 0x00200800, 0x00200000, 0x04000802, 489c5a511f1SSebastian Siewior 0x04000802, 0x04200002, 0x04200002, 0x00000002, 490c5a511f1SSebastian Siewior 0x00200002, 0x04000000, 0x04000800, 0x00200000, 491c5a511f1SSebastian Siewior 0x04200800, 0x00000802, 0x00200802, 0x04200800, 492c5a511f1SSebastian Siewior 0x00000802, 0x04000002, 0x04200802, 0x04200000, 493c5a511f1SSebastian Siewior 0x00200800, 0x00000000, 0x00000002, 0x04200802, 494c5a511f1SSebastian Siewior 0x00000000, 0x00200802, 0x04200000, 0x00000800, 495c5a511f1SSebastian Siewior 0x04000002, 0x04000800, 0x00000800, 0x00200002 496c5a511f1SSebastian Siewior }; 497c5a511f1SSebastian Siewior 498c5a511f1SSebastian Siewior static const u32 S8[64] = { 499c5a511f1SSebastian Siewior 0x10001040, 0x00001000, 0x00040000, 0x10041040, 500c5a511f1SSebastian Siewior 0x10000000, 0x10001040, 0x00000040, 0x10000000, 501c5a511f1SSebastian Siewior 0x00040040, 0x10040000, 0x10041040, 0x00041000, 502c5a511f1SSebastian Siewior 0x10041000, 0x00041040, 0x00001000, 0x00000040, 503c5a511f1SSebastian Siewior 0x10040000, 0x10000040, 0x10001000, 0x00001040, 504c5a511f1SSebastian Siewior 0x00041000, 0x00040040, 0x10040040, 0x10041000, 505c5a511f1SSebastian Siewior 0x00001040, 0x00000000, 0x00000000, 0x10040040, 506c5a511f1SSebastian Siewior 0x10000040, 0x10001000, 0x00041040, 0x00040000, 507c5a511f1SSebastian Siewior 0x00041040, 0x00040000, 0x10041000, 0x00001000, 508c5a511f1SSebastian Siewior 0x00000040, 0x10040040, 0x00001000, 0x00041040, 509c5a511f1SSebastian Siewior 0x10001000, 0x00000040, 0x10000040, 0x10040000, 510c5a511f1SSebastian Siewior 0x10040040, 0x10000000, 0x00040000, 0x10001040, 511c5a511f1SSebastian Siewior 0x00000000, 0x10041040, 0x00040040, 0x10000040, 512c5a511f1SSebastian Siewior 0x10040000, 0x10001000, 0x10001040, 0x00000000, 513c5a511f1SSebastian Siewior 0x10041040, 0x00041000, 0x00041000, 0x00001040, 514c5a511f1SSebastian Siewior 0x00001040, 0x00040040, 0x10000000, 0x10041000 515c5a511f1SSebastian Siewior }; 516c5a511f1SSebastian Siewior 517c5a511f1SSebastian Siewior /* Encryption components: IP, FP, and round function */ 518c5a511f1SSebastian Siewior 519c5a511f1SSebastian Siewior #define IP(L, R, T) \ 520c5a511f1SSebastian Siewior ROL(R, 4); \ 521c5a511f1SSebastian Siewior T = L; \ 522c5a511f1SSebastian Siewior L ^= R; \ 523c5a511f1SSebastian Siewior L &= 0xf0f0f0f0; \ 524c5a511f1SSebastian Siewior R ^= L; \ 525c5a511f1SSebastian Siewior L ^= T; \ 526c5a511f1SSebastian Siewior ROL(R, 12); \ 527c5a511f1SSebastian Siewior T = L; \ 528c5a511f1SSebastian Siewior L ^= R; \ 529c5a511f1SSebastian Siewior L &= 0xffff0000; \ 530c5a511f1SSebastian Siewior R ^= L; \ 531c5a511f1SSebastian Siewior L ^= T; \ 532c5a511f1SSebastian Siewior ROR(R, 14); \ 533c5a511f1SSebastian Siewior T = L; \ 534c5a511f1SSebastian Siewior L ^= R; \ 535c5a511f1SSebastian Siewior L &= 0xcccccccc; \ 536c5a511f1SSebastian Siewior R ^= L; \ 537c5a511f1SSebastian Siewior L ^= T; \ 538c5a511f1SSebastian Siewior ROL(R, 6); \ 539c5a511f1SSebastian Siewior T = L; \ 540c5a511f1SSebastian Siewior L ^= R; \ 541c5a511f1SSebastian Siewior L &= 0xff00ff00; \ 542c5a511f1SSebastian Siewior R ^= L; \ 543c5a511f1SSebastian Siewior L ^= T; \ 544c5a511f1SSebastian Siewior ROR(R, 7); \ 545c5a511f1SSebastian Siewior T = L; \ 546c5a511f1SSebastian Siewior L ^= R; \ 547c5a511f1SSebastian Siewior L &= 0xaaaaaaaa; \ 548c5a511f1SSebastian Siewior R ^= L; \ 549c5a511f1SSebastian Siewior L ^= T; \ 550c5a511f1SSebastian Siewior ROL(L, 1); 551c5a511f1SSebastian Siewior 552c5a511f1SSebastian Siewior #define FP(L, R, T) \ 553c5a511f1SSebastian Siewior ROR(L, 1); \ 554c5a511f1SSebastian Siewior T = L; \ 555c5a511f1SSebastian Siewior L ^= R; \ 556c5a511f1SSebastian Siewior L &= 0xaaaaaaaa; \ 557c5a511f1SSebastian Siewior R ^= L; \ 558c5a511f1SSebastian Siewior L ^= T; \ 559c5a511f1SSebastian Siewior ROL(R, 7); \ 560c5a511f1SSebastian Siewior T = L; \ 561c5a511f1SSebastian Siewior L ^= R; \ 562c5a511f1SSebastian Siewior L &= 0xff00ff00; \ 563c5a511f1SSebastian Siewior R ^= L; \ 564c5a511f1SSebastian Siewior L ^= T; \ 565c5a511f1SSebastian Siewior ROR(R, 6); \ 566c5a511f1SSebastian Siewior T = L; \ 567c5a511f1SSebastian Siewior L ^= R; \ 568c5a511f1SSebastian Siewior L &= 0xcccccccc; \ 569c5a511f1SSebastian Siewior R ^= L; \ 570c5a511f1SSebastian Siewior L ^= T; \ 571c5a511f1SSebastian Siewior ROL(R, 14); \ 572c5a511f1SSebastian Siewior T = L; \ 573c5a511f1SSebastian Siewior L ^= R; \ 574c5a511f1SSebastian Siewior L &= 0xffff0000; \ 575c5a511f1SSebastian Siewior R ^= L; \ 576c5a511f1SSebastian Siewior L ^= T; \ 577c5a511f1SSebastian Siewior ROR(R, 12); \ 578c5a511f1SSebastian Siewior T = L; \ 579c5a511f1SSebastian Siewior L ^= R; \ 580c5a511f1SSebastian Siewior L &= 0xf0f0f0f0; \ 581c5a511f1SSebastian Siewior R ^= L; \ 582c5a511f1SSebastian Siewior L ^= T; \ 583c5a511f1SSebastian Siewior ROR(R, 4); 584c5a511f1SSebastian Siewior 585c5a511f1SSebastian Siewior #define ROUND(L, R, A, B, K, d) \ 586c5a511f1SSebastian Siewior B = K[0]; A = K[1]; K += d; \ 587c5a511f1SSebastian Siewior B ^= R; A ^= R; \ 588c5a511f1SSebastian Siewior B &= 0x3f3f3f3f; ROR(A, 4); \ 589c5a511f1SSebastian Siewior L ^= S8[0xff & B]; A &= 0x3f3f3f3f; \ 590c5a511f1SSebastian Siewior L ^= S6[0xff & (B >> 8)]; B >>= 16; \ 591c5a511f1SSebastian Siewior L ^= S7[0xff & A]; \ 592c5a511f1SSebastian Siewior L ^= S5[0xff & (A >> 8)]; A >>= 16; \ 593c5a511f1SSebastian Siewior L ^= S4[0xff & B]; \ 594c5a511f1SSebastian Siewior L ^= S2[0xff & (B >> 8)]; \ 595c5a511f1SSebastian Siewior L ^= S3[0xff & A]; \ 596c5a511f1SSebastian Siewior L ^= S1[0xff & (A >> 8)]; 597c5a511f1SSebastian Siewior 598c5a511f1SSebastian Siewior /* 599c5a511f1SSebastian Siewior * PC2 lookup tables are organized as 2 consecutive sets of 4 interleaved 600c5a511f1SSebastian Siewior * tables of 128 elements. One set is for C_i and the other for D_i, while 601c5a511f1SSebastian Siewior * the 4 interleaved tables correspond to four 7-bit subsets of C_i or D_i. 602c5a511f1SSebastian Siewior * 603c5a511f1SSebastian Siewior * After PC1 each of the variables a,b,c,d contains a 7 bit subset of C_i 604c5a511f1SSebastian Siewior * or D_i in bits 7-1 (bit 0 being the least significant). 605c5a511f1SSebastian Siewior */ 606c5a511f1SSebastian Siewior 607c5a511f1SSebastian Siewior #define T1(x) pt[2 * (x) + 0] 608c5a511f1SSebastian Siewior #define T2(x) pt[2 * (x) + 1] 609c5a511f1SSebastian Siewior #define T3(x) pt[2 * (x) + 2] 610c5a511f1SSebastian Siewior #define T4(x) pt[2 * (x) + 3] 611c5a511f1SSebastian Siewior 612db36b906SDavid Howells #define DES_PC2(a, b, c, d) (T4(d) | T3(c) | T2(b) | T1(a)) 613c5a511f1SSebastian Siewior 614c5a511f1SSebastian Siewior /* 615c5a511f1SSebastian Siewior * Encryption key expansion 616c5a511f1SSebastian Siewior * 617c5a511f1SSebastian Siewior * RFC2451: Weak key checks SHOULD be performed. 618c5a511f1SSebastian Siewior * 619c5a511f1SSebastian Siewior * FIPS 74: 620c5a511f1SSebastian Siewior * 621c5a511f1SSebastian Siewior * Keys having duals are keys which produce all zeros, all ones, or 622c5a511f1SSebastian Siewior * alternating zero-one patterns in the C and D registers after Permuted 623c5a511f1SSebastian Siewior * Choice 1 has operated on the key. 624c5a511f1SSebastian Siewior * 625c5a511f1SSebastian Siewior */ 626c3041f9cSEvgeniy Polyakov unsigned long des_ekey(u32 *pe, const u8 *k) 627c5a511f1SSebastian Siewior { 628c5a511f1SSebastian Siewior /* K&R: long is at least 32 bits */ 629c5a511f1SSebastian Siewior unsigned long a, b, c, d, w; 630c5a511f1SSebastian Siewior const u32 *pt = pc2; 631c5a511f1SSebastian Siewior 632c5a511f1SSebastian Siewior d = k[4]; d &= 0x0e; d <<= 4; d |= k[0] & 0x1e; d = pc1[d]; 633c5a511f1SSebastian Siewior c = k[5]; c &= 0x0e; c <<= 4; c |= k[1] & 0x1e; c = pc1[c]; 634c5a511f1SSebastian Siewior b = k[6]; b &= 0x0e; b <<= 4; b |= k[2] & 0x1e; b = pc1[b]; 635c5a511f1SSebastian Siewior a = k[7]; a &= 0x0e; a <<= 4; a |= k[3] & 0x1e; a = pc1[a]; 636c5a511f1SSebastian Siewior 637db36b906SDavid Howells pe[15 * 2 + 0] = DES_PC2(a, b, c, d); d = rs[d]; 638db36b906SDavid Howells pe[14 * 2 + 0] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; 639db36b906SDavid Howells pe[13 * 2 + 0] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; 640db36b906SDavid Howells pe[12 * 2 + 0] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; 641db36b906SDavid Howells pe[11 * 2 + 0] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; 642db36b906SDavid Howells pe[10 * 2 + 0] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; 643db36b906SDavid Howells pe[ 9 * 2 + 0] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; 644db36b906SDavid Howells pe[ 8 * 2 + 0] = DES_PC2(d, a, b, c); c = rs[c]; 645db36b906SDavid Howells pe[ 7 * 2 + 0] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; 646db36b906SDavid Howells pe[ 6 * 2 + 0] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; 647db36b906SDavid Howells pe[ 5 * 2 + 0] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; 648db36b906SDavid Howells pe[ 4 * 2 + 0] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; 649db36b906SDavid Howells pe[ 3 * 2 + 0] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; 650db36b906SDavid Howells pe[ 2 * 2 + 0] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; 651db36b906SDavid Howells pe[ 1 * 2 + 0] = DES_PC2(c, d, a, b); b = rs[b]; 652db36b906SDavid Howells pe[ 0 * 2 + 0] = DES_PC2(b, c, d, a); 653c5a511f1SSebastian Siewior 654c5a511f1SSebastian Siewior /* Check if first half is weak */ 655c5a511f1SSebastian Siewior w = (a ^ c) | (b ^ d) | (rs[a] ^ c) | (b ^ rs[d]); 656c5a511f1SSebastian Siewior 657c5a511f1SSebastian Siewior /* Skip to next table set */ 658c5a511f1SSebastian Siewior pt += 512; 659c5a511f1SSebastian Siewior 660c5a511f1SSebastian Siewior d = k[0]; d &= 0xe0; d >>= 4; d |= k[4] & 0xf0; d = pc1[d + 1]; 661c5a511f1SSebastian Siewior c = k[1]; c &= 0xe0; c >>= 4; c |= k[5] & 0xf0; c = pc1[c + 1]; 662c5a511f1SSebastian Siewior b = k[2]; b &= 0xe0; b >>= 4; b |= k[6] & 0xf0; b = pc1[b + 1]; 663c5a511f1SSebastian Siewior a = k[3]; a &= 0xe0; a >>= 4; a |= k[7] & 0xf0; a = pc1[a + 1]; 664c5a511f1SSebastian Siewior 665c5a511f1SSebastian Siewior /* Check if second half is weak */ 666c5a511f1SSebastian Siewior w |= (a ^ c) | (b ^ d) | (rs[a] ^ c) | (b ^ rs[d]); 667c5a511f1SSebastian Siewior 668db36b906SDavid Howells pe[15 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; 669db36b906SDavid Howells pe[14 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; 670db36b906SDavid Howells pe[13 * 2 + 1] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; 671db36b906SDavid Howells pe[12 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; 672db36b906SDavid Howells pe[11 * 2 + 1] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; 673db36b906SDavid Howells pe[10 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; 674db36b906SDavid Howells pe[ 9 * 2 + 1] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; 675db36b906SDavid Howells pe[ 8 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; 676db36b906SDavid Howells pe[ 7 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; 677db36b906SDavid Howells pe[ 6 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; 678db36b906SDavid Howells pe[ 5 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; 679db36b906SDavid Howells pe[ 4 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; 680db36b906SDavid Howells pe[ 3 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; 681db36b906SDavid Howells pe[ 2 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; 682db36b906SDavid Howells pe[ 1 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; 683db36b906SDavid Howells pe[ 0 * 2 + 1] = DES_PC2(b, c, d, a); 684c5a511f1SSebastian Siewior 685c5a511f1SSebastian Siewior /* Fixup: 2413 5768 -> 1357 2468 */ 686c5a511f1SSebastian Siewior for (d = 0; d < 16; ++d) { 687c5a511f1SSebastian Siewior a = pe[2 * d]; 688c5a511f1SSebastian Siewior b = pe[2 * d + 1]; 689c5a511f1SSebastian Siewior c = a ^ b; 690c5a511f1SSebastian Siewior c &= 0xffff0000; 691c5a511f1SSebastian Siewior a ^= c; 692c5a511f1SSebastian Siewior b ^= c; 693c5a511f1SSebastian Siewior ROL(b, 18); 694c5a511f1SSebastian Siewior pe[2 * d] = a; 695c5a511f1SSebastian Siewior pe[2 * d + 1] = b; 696c5a511f1SSebastian Siewior } 697c5a511f1SSebastian Siewior 698c5a511f1SSebastian Siewior /* Zero if weak key */ 699c5a511f1SSebastian Siewior return w; 700c5a511f1SSebastian Siewior } 701c3041f9cSEvgeniy Polyakov EXPORT_SYMBOL_GPL(des_ekey); 702c5a511f1SSebastian Siewior 703c5a511f1SSebastian Siewior /* 704c5a511f1SSebastian Siewior * Decryption key expansion 705c5a511f1SSebastian Siewior * 706c5a511f1SSebastian Siewior * No weak key checking is performed, as this is only used by triple DES 707c5a511f1SSebastian Siewior * 708c5a511f1SSebastian Siewior */ 709c5a511f1SSebastian Siewior static void dkey(u32 *pe, const u8 *k) 710c5a511f1SSebastian Siewior { 711c5a511f1SSebastian Siewior /* K&R: long is at least 32 bits */ 712c5a511f1SSebastian Siewior unsigned long a, b, c, d; 713c5a511f1SSebastian Siewior const u32 *pt = pc2; 714c5a511f1SSebastian Siewior 715c5a511f1SSebastian Siewior d = k[4]; d &= 0x0e; d <<= 4; d |= k[0] & 0x1e; d = pc1[d]; 716c5a511f1SSebastian Siewior c = k[5]; c &= 0x0e; c <<= 4; c |= k[1] & 0x1e; c = pc1[c]; 717c5a511f1SSebastian Siewior b = k[6]; b &= 0x0e; b <<= 4; b |= k[2] & 0x1e; b = pc1[b]; 718c5a511f1SSebastian Siewior a = k[7]; a &= 0x0e; a <<= 4; a |= k[3] & 0x1e; a = pc1[a]; 719c5a511f1SSebastian Siewior 720db36b906SDavid Howells pe[ 0 * 2] = DES_PC2(a, b, c, d); d = rs[d]; 721db36b906SDavid Howells pe[ 1 * 2] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; 722db36b906SDavid Howells pe[ 2 * 2] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; 723db36b906SDavid Howells pe[ 3 * 2] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; 724db36b906SDavid Howells pe[ 4 * 2] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; 725db36b906SDavid Howells pe[ 5 * 2] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; 726db36b906SDavid Howells pe[ 6 * 2] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; 727db36b906SDavid Howells pe[ 7 * 2] = DES_PC2(d, a, b, c); c = rs[c]; 728db36b906SDavid Howells pe[ 8 * 2] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; 729db36b906SDavid Howells pe[ 9 * 2] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; 730db36b906SDavid Howells pe[10 * 2] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; 731db36b906SDavid Howells pe[11 * 2] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; 732db36b906SDavid Howells pe[12 * 2] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; 733db36b906SDavid Howells pe[13 * 2] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; 734db36b906SDavid Howells pe[14 * 2] = DES_PC2(c, d, a, b); b = rs[b]; 735db36b906SDavid Howells pe[15 * 2] = DES_PC2(b, c, d, a); 736c5a511f1SSebastian Siewior 737c5a511f1SSebastian Siewior /* Skip to next table set */ 738c5a511f1SSebastian Siewior pt += 512; 739c5a511f1SSebastian Siewior 740c5a511f1SSebastian Siewior d = k[0]; d &= 0xe0; d >>= 4; d |= k[4] & 0xf0; d = pc1[d + 1]; 741c5a511f1SSebastian Siewior c = k[1]; c &= 0xe0; c >>= 4; c |= k[5] & 0xf0; c = pc1[c + 1]; 742c5a511f1SSebastian Siewior b = k[2]; b &= 0xe0; b >>= 4; b |= k[6] & 0xf0; b = pc1[b + 1]; 743c5a511f1SSebastian Siewior a = k[3]; a &= 0xe0; a >>= 4; a |= k[7] & 0xf0; a = pc1[a + 1]; 744c5a511f1SSebastian Siewior 745db36b906SDavid Howells pe[ 0 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; 746db36b906SDavid Howells pe[ 1 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; 747db36b906SDavid Howells pe[ 2 * 2 + 1] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; 748db36b906SDavid Howells pe[ 3 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; 749db36b906SDavid Howells pe[ 4 * 2 + 1] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; 750db36b906SDavid Howells pe[ 5 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; b = rs[b]; 751db36b906SDavid Howells pe[ 6 * 2 + 1] = DES_PC2(b, c, d, a); a = rs[a]; d = rs[d]; 752db36b906SDavid Howells pe[ 7 * 2 + 1] = DES_PC2(d, a, b, c); c = rs[c]; 753db36b906SDavid Howells pe[ 8 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; 754db36b906SDavid Howells pe[ 9 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; 755db36b906SDavid Howells pe[10 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; 756db36b906SDavid Howells pe[11 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; 757db36b906SDavid Howells pe[12 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; a = rs[a]; 758db36b906SDavid Howells pe[13 * 2 + 1] = DES_PC2(a, b, c, d); d = rs[d]; c = rs[c]; 759db36b906SDavid Howells pe[14 * 2 + 1] = DES_PC2(c, d, a, b); b = rs[b]; 760db36b906SDavid Howells pe[15 * 2 + 1] = DES_PC2(b, c, d, a); 761c5a511f1SSebastian Siewior 762c5a511f1SSebastian Siewior /* Fixup: 2413 5768 -> 1357 2468 */ 763c5a511f1SSebastian Siewior for (d = 0; d < 16; ++d) { 764c5a511f1SSebastian Siewior a = pe[2 * d]; 765c5a511f1SSebastian Siewior b = pe[2 * d + 1]; 766c5a511f1SSebastian Siewior c = a ^ b; 767c5a511f1SSebastian Siewior c &= 0xffff0000; 768c5a511f1SSebastian Siewior a ^= c; 769c5a511f1SSebastian Siewior b ^= c; 770c5a511f1SSebastian Siewior ROL(b, 18); 771c5a511f1SSebastian Siewior pe[2 * d] = a; 772c5a511f1SSebastian Siewior pe[2 * d + 1] = b; 773c5a511f1SSebastian Siewior } 774c5a511f1SSebastian Siewior } 775c5a511f1SSebastian Siewior 776c5a511f1SSebastian Siewior static int des_setkey(struct crypto_tfm *tfm, const u8 *key, 777c5a511f1SSebastian Siewior unsigned int keylen) 778c5a511f1SSebastian Siewior { 779c5a511f1SSebastian Siewior struct des_ctx *dctx = crypto_tfm_ctx(tfm); 780c5a511f1SSebastian Siewior u32 *flags = &tfm->crt_flags; 781c5a511f1SSebastian Siewior u32 tmp[DES_EXPKEY_WORDS]; 782c5a511f1SSebastian Siewior int ret; 783c5a511f1SSebastian Siewior 784c5a511f1SSebastian Siewior /* Expand to tmp */ 785c3041f9cSEvgeniy Polyakov ret = des_ekey(tmp, key); 786c5a511f1SSebastian Siewior 787231baecdSEric Biggers if (unlikely(ret == 0) && (*flags & CRYPTO_TFM_REQ_FORBID_WEAK_KEYS)) { 788c5a511f1SSebastian Siewior *flags |= CRYPTO_TFM_RES_WEAK_KEY; 789c5a511f1SSebastian Siewior return -EINVAL; 790c5a511f1SSebastian Siewior } 791c5a511f1SSebastian Siewior 792c5a511f1SSebastian Siewior /* Copy to output */ 793c5a511f1SSebastian Siewior memcpy(dctx->expkey, tmp, sizeof(dctx->expkey)); 794c5a511f1SSebastian Siewior 795c5a511f1SSebastian Siewior return 0; 796c5a511f1SSebastian Siewior } 797c5a511f1SSebastian Siewior 798c5a511f1SSebastian Siewior static void des_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 799c5a511f1SSebastian Siewior { 800c5a511f1SSebastian Siewior struct des_ctx *ctx = crypto_tfm_ctx(tfm); 801c5a511f1SSebastian Siewior const u32 *K = ctx->expkey; 802c5a511f1SSebastian Siewior const __le32 *s = (const __le32 *)src; 803c5a511f1SSebastian Siewior __le32 *d = (__le32 *)dst; 804c5a511f1SSebastian Siewior u32 L, R, A, B; 805c5a511f1SSebastian Siewior int i; 806c5a511f1SSebastian Siewior 807c5a511f1SSebastian Siewior L = le32_to_cpu(s[0]); 808c5a511f1SSebastian Siewior R = le32_to_cpu(s[1]); 809c5a511f1SSebastian Siewior 810c5a511f1SSebastian Siewior IP(L, R, A); 811c5a511f1SSebastian Siewior for (i = 0; i < 8; i++) { 812c5a511f1SSebastian Siewior ROUND(L, R, A, B, K, 2); 813c5a511f1SSebastian Siewior ROUND(R, L, A, B, K, 2); 814c5a511f1SSebastian Siewior } 815c5a511f1SSebastian Siewior FP(R, L, A); 816c5a511f1SSebastian Siewior 817c5a511f1SSebastian Siewior d[0] = cpu_to_le32(R); 818c5a511f1SSebastian Siewior d[1] = cpu_to_le32(L); 819c5a511f1SSebastian Siewior } 820c5a511f1SSebastian Siewior 821c5a511f1SSebastian Siewior static void des_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 822c5a511f1SSebastian Siewior { 823c5a511f1SSebastian Siewior struct des_ctx *ctx = crypto_tfm_ctx(tfm); 824c5a511f1SSebastian Siewior const u32 *K = ctx->expkey + DES_EXPKEY_WORDS - 2; 825c5a511f1SSebastian Siewior const __le32 *s = (const __le32 *)src; 826c5a511f1SSebastian Siewior __le32 *d = (__le32 *)dst; 827c5a511f1SSebastian Siewior u32 L, R, A, B; 828c5a511f1SSebastian Siewior int i; 829c5a511f1SSebastian Siewior 830c5a511f1SSebastian Siewior L = le32_to_cpu(s[0]); 831c5a511f1SSebastian Siewior R = le32_to_cpu(s[1]); 832c5a511f1SSebastian Siewior 833c5a511f1SSebastian Siewior IP(L, R, A); 834c5a511f1SSebastian Siewior for (i = 0; i < 8; i++) { 835c5a511f1SSebastian Siewior ROUND(L, R, A, B, K, -2); 836c5a511f1SSebastian Siewior ROUND(R, L, A, B, K, -2); 837c5a511f1SSebastian Siewior } 838c5a511f1SSebastian Siewior FP(R, L, A); 839c5a511f1SSebastian Siewior 840c5a511f1SSebastian Siewior d[0] = cpu_to_le32(R); 841c5a511f1SSebastian Siewior d[1] = cpu_to_le32(L); 842c5a511f1SSebastian Siewior } 843c5a511f1SSebastian Siewior 8446574e6c6SJussi Kivilinna int __des3_ede_setkey(u32 *expkey, u32 *flags, const u8 *key, 845c5a511f1SSebastian Siewior unsigned int keylen) 846c5a511f1SSebastian Siewior { 847d7198ce4SHerbert Xu int err; 848c5a511f1SSebastian Siewior 849c3041f9cSEvgeniy Polyakov des_ekey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE; 850c5a511f1SSebastian Siewior dkey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE; 851c3041f9cSEvgeniy Polyakov des_ekey(expkey, key); 852c5a511f1SSebastian Siewior 853c5a511f1SSebastian Siewior return 0; 854c5a511f1SSebastian Siewior } 8556574e6c6SJussi Kivilinna EXPORT_SYMBOL_GPL(__des3_ede_setkey); 8566574e6c6SJussi Kivilinna 8576574e6c6SJussi Kivilinna static int des3_ede_setkey(struct crypto_tfm *tfm, const u8 *key, 8586574e6c6SJussi Kivilinna unsigned int keylen) 8596574e6c6SJussi Kivilinna { 8606574e6c6SJussi Kivilinna struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm); 8616574e6c6SJussi Kivilinna u32 *expkey = dctx->expkey; 862*4fd4be05SArd Biesheuvel int err; 863*4fd4be05SArd Biesheuvel 864*4fd4be05SArd Biesheuvel err = crypto_des3_ede_verify_key(tfm, key); 865*4fd4be05SArd Biesheuvel if (err) 866*4fd4be05SArd Biesheuvel return err; 8676574e6c6SJussi Kivilinna 8686574e6c6SJussi Kivilinna return __des3_ede_setkey(expkey, flags, key, keylen); 8696574e6c6SJussi Kivilinna } 870c5a511f1SSebastian Siewior 871c5a511f1SSebastian Siewior static void des3_ede_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 872c5a511f1SSebastian Siewior { 873c5a511f1SSebastian Siewior struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm); 874c5a511f1SSebastian Siewior const u32 *K = dctx->expkey; 875c5a511f1SSebastian Siewior const __le32 *s = (const __le32 *)src; 876c5a511f1SSebastian Siewior __le32 *d = (__le32 *)dst; 877c5a511f1SSebastian Siewior u32 L, R, A, B; 878c5a511f1SSebastian Siewior int i; 879c5a511f1SSebastian Siewior 880c5a511f1SSebastian Siewior L = le32_to_cpu(s[0]); 881c5a511f1SSebastian Siewior R = le32_to_cpu(s[1]); 882c5a511f1SSebastian Siewior 883c5a511f1SSebastian Siewior IP(L, R, A); 884c5a511f1SSebastian Siewior for (i = 0; i < 8; i++) { 885c5a511f1SSebastian Siewior ROUND(L, R, A, B, K, 2); 886c5a511f1SSebastian Siewior ROUND(R, L, A, B, K, 2); 887c5a511f1SSebastian Siewior } 888c5a511f1SSebastian Siewior for (i = 0; i < 8; i++) { 889c5a511f1SSebastian Siewior ROUND(R, L, A, B, K, 2); 890c5a511f1SSebastian Siewior ROUND(L, R, A, B, K, 2); 891c5a511f1SSebastian Siewior } 892c5a511f1SSebastian Siewior for (i = 0; i < 8; i++) { 893c5a511f1SSebastian Siewior ROUND(L, R, A, B, K, 2); 894c5a511f1SSebastian Siewior ROUND(R, L, A, B, K, 2); 895c5a511f1SSebastian Siewior } 896c5a511f1SSebastian Siewior FP(R, L, A); 897c5a511f1SSebastian Siewior 898c5a511f1SSebastian Siewior d[0] = cpu_to_le32(R); 899c5a511f1SSebastian Siewior d[1] = cpu_to_le32(L); 900c5a511f1SSebastian Siewior } 901c5a511f1SSebastian Siewior 902c5a511f1SSebastian Siewior static void des3_ede_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 903c5a511f1SSebastian Siewior { 904c5a511f1SSebastian Siewior struct des3_ede_ctx *dctx = crypto_tfm_ctx(tfm); 905c5a511f1SSebastian Siewior const u32 *K = dctx->expkey + DES3_EDE_EXPKEY_WORDS - 2; 906c5a511f1SSebastian Siewior const __le32 *s = (const __le32 *)src; 907c5a511f1SSebastian Siewior __le32 *d = (__le32 *)dst; 908c5a511f1SSebastian Siewior u32 L, R, A, B; 909c5a511f1SSebastian Siewior int i; 910c5a511f1SSebastian Siewior 911c5a511f1SSebastian Siewior L = le32_to_cpu(s[0]); 912c5a511f1SSebastian Siewior R = le32_to_cpu(s[1]); 913c5a511f1SSebastian Siewior 914c5a511f1SSebastian Siewior IP(L, R, A); 915c5a511f1SSebastian Siewior for (i = 0; i < 8; i++) { 916c5a511f1SSebastian Siewior ROUND(L, R, A, B, K, -2); 917c5a511f1SSebastian Siewior ROUND(R, L, A, B, K, -2); 918c5a511f1SSebastian Siewior } 919c5a511f1SSebastian Siewior for (i = 0; i < 8; i++) { 920c5a511f1SSebastian Siewior ROUND(R, L, A, B, K, -2); 921c5a511f1SSebastian Siewior ROUND(L, R, A, B, K, -2); 922c5a511f1SSebastian Siewior } 923c5a511f1SSebastian Siewior for (i = 0; i < 8; i++) { 924c5a511f1SSebastian Siewior ROUND(L, R, A, B, K, -2); 925c5a511f1SSebastian Siewior ROUND(R, L, A, B, K, -2); 926c5a511f1SSebastian Siewior } 927c5a511f1SSebastian Siewior FP(R, L, A); 928c5a511f1SSebastian Siewior 929c5a511f1SSebastian Siewior d[0] = cpu_to_le32(R); 930c5a511f1SSebastian Siewior d[1] = cpu_to_le32(L); 931c5a511f1SSebastian Siewior } 932c5a511f1SSebastian Siewior 9339935e6d2SJussi Kivilinna static struct crypto_alg des_algs[2] = { { 934c5a511f1SSebastian Siewior .cra_name = "des", 9356574e6c6SJussi Kivilinna .cra_driver_name = "des-generic", 9366574e6c6SJussi Kivilinna .cra_priority = 100, 937c5a511f1SSebastian Siewior .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 938c5a511f1SSebastian Siewior .cra_blocksize = DES_BLOCK_SIZE, 939c5a511f1SSebastian Siewior .cra_ctxsize = sizeof(struct des_ctx), 940c5a511f1SSebastian Siewior .cra_module = THIS_MODULE, 941c5a511f1SSebastian Siewior .cra_alignmask = 3, 942c5a511f1SSebastian Siewior .cra_u = { .cipher = { 943c5a511f1SSebastian Siewior .cia_min_keysize = DES_KEY_SIZE, 944c5a511f1SSebastian Siewior .cia_max_keysize = DES_KEY_SIZE, 945c5a511f1SSebastian Siewior .cia_setkey = des_setkey, 946c5a511f1SSebastian Siewior .cia_encrypt = des_encrypt, 947c5a511f1SSebastian Siewior .cia_decrypt = des_decrypt } } 9489935e6d2SJussi Kivilinna }, { 949c5a511f1SSebastian Siewior .cra_name = "des3_ede", 9506574e6c6SJussi Kivilinna .cra_driver_name = "des3_ede-generic", 9516574e6c6SJussi Kivilinna .cra_priority = 100, 952c5a511f1SSebastian Siewior .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 953c5a511f1SSebastian Siewior .cra_blocksize = DES3_EDE_BLOCK_SIZE, 954c5a511f1SSebastian Siewior .cra_ctxsize = sizeof(struct des3_ede_ctx), 955c5a511f1SSebastian Siewior .cra_module = THIS_MODULE, 956c5a511f1SSebastian Siewior .cra_alignmask = 3, 957c5a511f1SSebastian Siewior .cra_u = { .cipher = { 958c5a511f1SSebastian Siewior .cia_min_keysize = DES3_EDE_KEY_SIZE, 959c5a511f1SSebastian Siewior .cia_max_keysize = DES3_EDE_KEY_SIZE, 960c5a511f1SSebastian Siewior .cia_setkey = des3_ede_setkey, 961c5a511f1SSebastian Siewior .cia_encrypt = des3_ede_encrypt, 962c5a511f1SSebastian Siewior .cia_decrypt = des3_ede_decrypt } } 9639935e6d2SJussi Kivilinna } }; 964c5a511f1SSebastian Siewior 9653af5b90bSKamalesh Babulal static int __init des_generic_mod_init(void) 966c5a511f1SSebastian Siewior { 9679935e6d2SJussi Kivilinna return crypto_register_algs(des_algs, ARRAY_SIZE(des_algs)); 968c5a511f1SSebastian Siewior } 969c5a511f1SSebastian Siewior 9703af5b90bSKamalesh Babulal static void __exit des_generic_mod_fini(void) 971c5a511f1SSebastian Siewior { 9729935e6d2SJussi Kivilinna crypto_unregister_algs(des_algs, ARRAY_SIZE(des_algs)); 973c5a511f1SSebastian Siewior } 974c5a511f1SSebastian Siewior 975c4741b23SEric Biggers subsys_initcall(des_generic_mod_init); 9763af5b90bSKamalesh Babulal module_exit(des_generic_mod_fini); 977c5a511f1SSebastian Siewior 978c5a511f1SSebastian Siewior MODULE_LICENSE("GPL"); 979c5a511f1SSebastian Siewior MODULE_DESCRIPTION("DES & Triple DES EDE Cipher Algorithms"); 980c5a511f1SSebastian Siewior MODULE_AUTHOR("Dag Arne Osvik <da@osvik.no>"); 9813e14dcf7SMathias Krause MODULE_ALIAS_CRYPTO("des"); 9823e14dcf7SMathias Krause MODULE_ALIAS_CRYPTO("des-generic"); 9833e14dcf7SMathias Krause MODULE_ALIAS_CRYPTO("des3_ede"); 9843e14dcf7SMathias Krause MODULE_ALIAS_CRYPTO("des3_ede-generic"); 985