aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--MAINTAINERS2
-rw-r--r--arch/arm/kernel/armksyms.c3
-rw-r--r--arch/arm/mach-ixp4xx/common-pci.c4
-rw-r--r--arch/arm/mach-ixp4xx/coyote-setup.c27
-rw-r--r--arch/arm/mach-ixp4xx/ixdp425-setup.c3
-rw-r--r--arch/arm/mm/proc-v6.S2
-rw-r--r--arch/ppc/syslib/of_device.c15
-rw-r--r--arch/ppc64/kernel/of_device.c15
-rw-r--r--arch/sparc64/kernel/irq.c7
-rw-r--r--arch/x86_64/Makefile4
-rw-r--r--arch/x86_64/crypto/Makefile9
-rw-r--r--arch/x86_64/crypto/aes-x86_64-asm.S186
-rw-r--r--arch/x86_64/crypto/aes.c324
-rw-r--r--crypto/Kconfig22
-rw-r--r--crypto/api.c60
-rw-r--r--crypto/cipher.c312
-rw-r--r--crypto/des.c2005
-rw-r--r--crypto/hmac.c3
-rw-r--r--crypto/internal.h43
-rw-r--r--crypto/scatterwalk.c4
-rw-r--r--crypto/scatterwalk.h12
-rw-r--r--crypto/serpent.c1
-rw-r--r--drivers/crypto/padlock-aes.c153
-rw-r--r--drivers/crypto/padlock.h22
-rw-r--r--drivers/i2c/busses/i2c-keywest.c7
-rw-r--r--drivers/ide/ppc/pmac.c12
-rw-r--r--drivers/ieee1394/ieee1394_core.h4
-rw-r--r--drivers/macintosh/Makefile2
-rw-r--r--drivers/macintosh/macio_asic.c78
-rw-r--r--drivers/macintosh/macio_sysfs.c50
-rw-r--r--drivers/macintosh/mediabay.c7
-rw-r--r--drivers/macintosh/therm_pm72.c9
-rw-r--r--drivers/macintosh/therm_windtunnel.c6
-rw-r--r--drivers/media/dvb/frontends/tda80xx.c1
-rw-r--r--drivers/net/bmac.c7
-rw-r--r--drivers/net/mace.c6
-rw-r--r--drivers/net/wireless/airport.c8
-rw-r--r--drivers/pci/setup-bus.c1
-rw-r--r--drivers/scsi/mac53c94.c7
-rw-r--r--drivers/scsi/mesh.c8
-rw-r--r--drivers/serial/pmac_zilog.c9
-rw-r--r--drivers/video/platinumfb.c6
-rw-r--r--include/asm-arm/arch-ixp4xx/io.h176
-rw-r--r--include/asm-ppc/macio.h5
-rw-r--r--include/asm-ppc/of_device.h20
-rw-r--r--include/asm-sparc64/parport.h4
-rw-r--r--include/linux/crypto.h34
-rw-r--r--include/linux/mod_devicetable.h11
-rw-r--r--scripts/mod/file2alias.c22
49 files changed, 2270 insertions, 1468 deletions
diff --git a/MAINTAINERS b/MAINTAINERS
index 19a9a1c53037..302b31960008 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2161,7 +2161,7 @@ UltraSPARC (sparc64):
2161P: David S. Miller 2161P: David S. Miller
2162M: davem@davemloft.net 2162M: davem@davemloft.net
2163P: Eddie C. Dost 2163P: Eddie C. Dost
2164M: ecd@skynet.be 2164M: ecd@brainaid.de
2165P: Jakub Jelinek 2165P: Jakub Jelinek
2166M: jj@sunsite.ms.mff.cuni.cz 2166M: jj@sunsite.ms.mff.cuni.cz
2167P: Anton Blanchard 2167P: Anton Blanchard
diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
index b713c44c6fb4..835d450797a1 100644
--- a/arch/arm/kernel/armksyms.c
+++ b/arch/arm/kernel/armksyms.c
@@ -41,7 +41,10 @@ extern void fp_enter(void);
41 * This has a special calling convention; it doesn't 41 * This has a special calling convention; it doesn't
42 * modify any of the usual registers, except for LR. 42 * modify any of the usual registers, except for LR.
43 */ 43 */
44#define EXPORT_CRC_ALIAS(sym) __CRC_SYMBOL(sym, "")
45
44#define EXPORT_SYMBOL_ALIAS(sym,orig) \ 46#define EXPORT_SYMBOL_ALIAS(sym,orig) \
47 EXPORT_CRC_ALIAS(sym) \
45 const struct kernel_symbol __ksymtab_##sym \ 48 const struct kernel_symbol __ksymtab_##sym \
46 __attribute__((section("__ksymtab"))) = \ 49 __attribute__((section("__ksymtab"))) = \
47 { (unsigned long)&orig, #sym }; 50 { (unsigned long)&orig, #sym };
diff --git a/arch/arm/mach-ixp4xx/common-pci.c b/arch/arm/mach-ixp4xx/common-pci.c
index aa92e3708838..2b544363c078 100644
--- a/arch/arm/mach-ixp4xx/common-pci.c
+++ b/arch/arm/mach-ixp4xx/common-pci.c
@@ -453,8 +453,8 @@ int ixp4xx_setup(int nr, struct pci_sys_data *sys)
453 local_write_config(PCI_COMMAND, 2, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY); 453 local_write_config(PCI_COMMAND, 2, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
454 454
455 res[0].name = "PCI I/O Space"; 455 res[0].name = "PCI I/O Space";
456 res[0].start = 0x00001000; 456 res[0].start = 0x00000000;
457 res[0].end = 0xffff0000; 457 res[0].end = 0x0000ffff;
458 res[0].flags = IORESOURCE_IO; 458 res[0].flags = IORESOURCE_IO;
459 459
460 res[1].name = "PCI Memory Space"; 460 res[1].name = "PCI Memory Space";
diff --git a/arch/arm/mach-ixp4xx/coyote-setup.c b/arch/arm/mach-ixp4xx/coyote-setup.c
index c6335f51907d..4ff4393ef0ea 100644
--- a/arch/arm/mach-ixp4xx/coyote-setup.c
+++ b/arch/arm/mach-ixp4xx/coyote-setup.c
@@ -56,21 +56,24 @@ static struct resource coyote_uart_resource = {
56 .flags = IORESOURCE_MEM, 56 .flags = IORESOURCE_MEM,
57}; 57};
58 58
59static struct plat_serial8250_port coyote_uart_data = { 59static struct plat_serial8250_port coyote_uart_data[] = {
60 .mapbase = IXP4XX_UART2_BASE_PHYS, 60 {
61 .membase = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET, 61 .mapbase = IXP4XX_UART2_BASE_PHYS,
62 .irq = IRQ_IXP4XX_UART2, 62 .membase = (char *)IXP4XX_UART2_BASE_VIRT + REG_OFFSET,
63 .flags = UPF_BOOT_AUTOCONF, 63 .irq = IRQ_IXP4XX_UART2,
64 .iotype = UPIO_MEM, 64 .flags = UPF_BOOT_AUTOCONF,
65 .regshift = 2, 65 .iotype = UPIO_MEM,
66 .uartclk = IXP4XX_UART_XTAL, 66 .regshift = 2,
67 .uartclk = IXP4XX_UART_XTAL,
68 },
69 { },
67}; 70};
68 71
69static struct platform_device coyote_uart = { 72static struct platform_device coyote_uart = {
70 .name = "serial8250", 73 .name = "serial8250",
71 .id = 0, 74 .id = 0,
72 .dev = { 75 .dev = {
73 .platform_data = &coyote_uart_data, 76 .platform_data = coyote_uart_data,
74 }, 77 },
75 .num_resources = 1, 78 .num_resources = 1,
76 .resource = &coyote_uart_resource, 79 .resource = &coyote_uart_resource,
@@ -87,10 +90,10 @@ static void __init coyote_init(void)
87 *IXP4XX_EXP_CS1 = *IXP4XX_EXP_CS0; 90 *IXP4XX_EXP_CS1 = *IXP4XX_EXP_CS0;
88 91
89 if (machine_is_ixdpg425()) { 92 if (machine_is_ixdpg425()) {
90 coyote_uart_data.membase = 93 coyote_uart_data[0].membase =
91 (char*)(IXP4XX_UART1_BASE_VIRT + REG_OFFSET); 94 (char*)(IXP4XX_UART1_BASE_VIRT + REG_OFFSET);
92 coyote_uart_data.mapbase = IXP4XX_UART1_BASE_PHYS; 95 coyote_uart_data[0].mapbase = IXP4XX_UART1_BASE_PHYS;
93 coyote_uart_data.irq = IRQ_IXP4XX_UART1; 96 coyote_uart_data[0].irq = IRQ_IXP4XX_UART1;
94 } 97 }
95 98
96 99
diff --git a/arch/arm/mach-ixp4xx/ixdp425-setup.c b/arch/arm/mach-ixp4xx/ixdp425-setup.c
index f2e9c0ea0501..c2ba759e9946 100644
--- a/arch/arm/mach-ixp4xx/ixdp425-setup.c
+++ b/arch/arm/mach-ixp4xx/ixdp425-setup.c
@@ -95,7 +95,8 @@ static struct plat_serial8250_port ixdp425_uart_data[] = {
95 .iotype = UPIO_MEM, 95 .iotype = UPIO_MEM,
96 .regshift = 2, 96 .regshift = 2,
97 .uartclk = IXP4XX_UART_XTAL, 97 .uartclk = IXP4XX_UART_XTAL,
98 } 98 },
99 { },
99}; 100};
100 101
101static struct platform_device ixdp425_uart = { 102static struct platform_device ixdp425_uart = {
diff --git a/arch/arm/mm/proc-v6.S b/arch/arm/mm/proc-v6.S
index e3d8510f4340..352db98ee269 100644
--- a/arch/arm/mm/proc-v6.S
+++ b/arch/arm/mm/proc-v6.S
@@ -200,7 +200,7 @@ __v6_setup:
200 mcr p15, 0, r4, c2, c0, 1 @ load TTB1 200 mcr p15, 0, r4, c2, c0, 1 @ load TTB1
201#ifdef CONFIG_VFP 201#ifdef CONFIG_VFP
202 mrc p15, 0, r0, c1, c0, 2 202 mrc p15, 0, r0, c1, c0, 2
203 orr r0, r0, #(3 << 20) 203 orr r0, r0, #(0xf << 20)
204 mcr p15, 0, r0, c1, c0, 2 @ Enable full access to VFP 204 mcr p15, 0, r0, c1, c0, 2 @ Enable full access to VFP
205#endif 205#endif
206 mrc p15, 0, r0, c1, c0, 0 @ read control register 206 mrc p15, 0, r0, c1, c0, 0 @ read control register
diff --git a/arch/ppc/syslib/of_device.c b/arch/ppc/syslib/of_device.c
index 49c0e34e2d6b..1eb4f726ca9f 100644
--- a/arch/ppc/syslib/of_device.c
+++ b/arch/ppc/syslib/of_device.c
@@ -3,6 +3,7 @@
3#include <linux/kernel.h> 3#include <linux/kernel.h>
4#include <linux/init.h> 4#include <linux/init.h>
5#include <linux/module.h> 5#include <linux/module.h>
6#include <linux/mod_devicetable.h>
6#include <asm/errno.h> 7#include <asm/errno.h>
7#include <asm/of_device.h> 8#include <asm/of_device.h>
8 9
@@ -15,20 +16,20 @@
15 * Used by a driver to check whether an of_device present in the 16 * Used by a driver to check whether an of_device present in the
16 * system is in its list of supported devices. 17 * system is in its list of supported devices.
17 */ 18 */
18const struct of_match * of_match_device(const struct of_match *matches, 19const struct of_device_id * of_match_device(const struct of_device_id *matches,
19 const struct of_device *dev) 20 const struct of_device *dev)
20{ 21{
21 if (!dev->node) 22 if (!dev->node)
22 return NULL; 23 return NULL;
23 while (matches->name || matches->type || matches->compatible) { 24 while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
24 int match = 1; 25 int match = 1;
25 if (matches->name && matches->name != OF_ANY_MATCH) 26 if (matches->name[0])
26 match &= dev->node->name 27 match &= dev->node->name
27 && !strcmp(matches->name, dev->node->name); 28 && !strcmp(matches->name, dev->node->name);
28 if (matches->type && matches->type != OF_ANY_MATCH) 29 if (matches->type[0])
29 match &= dev->node->type 30 match &= dev->node->type
30 && !strcmp(matches->type, dev->node->type); 31 && !strcmp(matches->type, dev->node->type);
31 if (matches->compatible && matches->compatible != OF_ANY_MATCH) 32 if (matches->compatible[0])
32 match &= device_is_compatible(dev->node, 33 match &= device_is_compatible(dev->node,
33 matches->compatible); 34 matches->compatible);
34 if (match) 35 if (match)
@@ -42,7 +43,7 @@ static int of_platform_bus_match(struct device *dev, struct device_driver *drv)
42{ 43{
43 struct of_device * of_dev = to_of_device(dev); 44 struct of_device * of_dev = to_of_device(dev);
44 struct of_platform_driver * of_drv = to_of_platform_driver(drv); 45 struct of_platform_driver * of_drv = to_of_platform_driver(drv);
45 const struct of_match * matches = of_drv->match_table; 46 const struct of_device_id * matches = of_drv->match_table;
46 47
47 if (!matches) 48 if (!matches)
48 return 0; 49 return 0;
@@ -75,7 +76,7 @@ static int of_device_probe(struct device *dev)
75 int error = -ENODEV; 76 int error = -ENODEV;
76 struct of_platform_driver *drv; 77 struct of_platform_driver *drv;
77 struct of_device *of_dev; 78 struct of_device *of_dev;
78 const struct of_match *match; 79 const struct of_device_id *match;
79 80
80 drv = to_of_platform_driver(dev->driver); 81 drv = to_of_platform_driver(dev->driver);
81 of_dev = to_of_device(dev); 82 of_dev = to_of_device(dev);
diff --git a/arch/ppc64/kernel/of_device.c b/arch/ppc64/kernel/of_device.c
index 66bd5ab7c25a..b80e81984ba8 100644
--- a/arch/ppc64/kernel/of_device.c
+++ b/arch/ppc64/kernel/of_device.c
@@ -3,6 +3,7 @@
3#include <linux/kernel.h> 3#include <linux/kernel.h>
4#include <linux/init.h> 4#include <linux/init.h>
5#include <linux/module.h> 5#include <linux/module.h>
6#include <linux/mod_devicetable.h>
6#include <asm/errno.h> 7#include <asm/errno.h>
7#include <asm/of_device.h> 8#include <asm/of_device.h>
8 9
@@ -15,20 +16,20 @@
15 * Used by a driver to check whether an of_device present in the 16 * Used by a driver to check whether an of_device present in the
16 * system is in its list of supported devices. 17 * system is in its list of supported devices.
17 */ 18 */
18const struct of_match * of_match_device(const struct of_match *matches, 19const struct of_device_id *of_match_device(const struct of_device_id *matches,
19 const struct of_device *dev) 20 const struct of_device *dev)
20{ 21{
21 if (!dev->node) 22 if (!dev->node)
22 return NULL; 23 return NULL;
23 while (matches->name || matches->type || matches->compatible) { 24 while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
24 int match = 1; 25 int match = 1;
25 if (matches->name && matches->name != OF_ANY_MATCH) 26 if (matches->name[0])
26 match &= dev->node->name 27 match &= dev->node->name
27 && !strcmp(matches->name, dev->node->name); 28 && !strcmp(matches->name, dev->node->name);
28 if (matches->type && matches->type != OF_ANY_MATCH) 29 if (matches->type[0])
29 match &= dev->node->type 30 match &= dev->node->type
30 && !strcmp(matches->type, dev->node->type); 31 && !strcmp(matches->type, dev->node->type);
31 if (matches->compatible && matches->compatible != OF_ANY_MATCH) 32 if (matches->compatible[0])
32 match &= device_is_compatible(dev->node, 33 match &= device_is_compatible(dev->node,
33 matches->compatible); 34 matches->compatible);
34 if (match) 35 if (match)
@@ -42,7 +43,7 @@ static int of_platform_bus_match(struct device *dev, struct device_driver *drv)
42{ 43{
43 struct of_device * of_dev = to_of_device(dev); 44 struct of_device * of_dev = to_of_device(dev);
44 struct of_platform_driver * of_drv = to_of_platform_driver(drv); 45 struct of_platform_driver * of_drv = to_of_platform_driver(drv);
45 const struct of_match * matches = of_drv->match_table; 46 const struct of_device_id * matches = of_drv->match_table;
46 47
47 if (!matches) 48 if (!matches)
48 return 0; 49 return 0;
@@ -75,7 +76,7 @@ static int of_device_probe(struct device *dev)
75 int error = -ENODEV; 76 int error = -ENODEV;
76 struct of_platform_driver *drv; 77 struct of_platform_driver *drv;
77 struct of_device *of_dev; 78 struct of_device *of_dev;
78 const struct of_match *match; 79 const struct of_device_id *match;
79 80
80 drv = to_of_platform_driver(dev->driver); 81 drv = to_of_platform_driver(dev->driver);
81 of_dev = to_of_device(dev); 82 of_dev = to_of_device(dev);
diff --git a/arch/sparc64/kernel/irq.c b/arch/sparc64/kernel/irq.c
index 74a2e0808cbc..daa2fb93052c 100644
--- a/arch/sparc64/kernel/irq.c
+++ b/arch/sparc64/kernel/irq.c
@@ -917,7 +917,8 @@ static int irq_affinity_read_proc (char *page, char **start, off_t off,
917 int count, int *eof, void *data) 917 int count, int *eof, void *data)
918{ 918{
919 struct ino_bucket *bp = ivector_table + (long)data; 919 struct ino_bucket *bp = ivector_table + (long)data;
920 struct irqaction *ap = bp->irq_info; 920 struct irq_desc *desc = bp->irq_info;
921 struct irqaction *ap = desc->action;
921 cpumask_t mask; 922 cpumask_t mask;
922 int len; 923 int len;
923 924
@@ -935,11 +936,13 @@ static int irq_affinity_read_proc (char *page, char **start, off_t off,
935static inline void set_intr_affinity(int irq, cpumask_t hw_aff) 936static inline void set_intr_affinity(int irq, cpumask_t hw_aff)
936{ 937{
937 struct ino_bucket *bp = ivector_table + irq; 938 struct ino_bucket *bp = ivector_table + irq;
939 struct irq_desc *desc = bp->irq_info;
940 struct irqaction *ap = desc->action;
938 941
939 /* Users specify affinity in terms of hw cpu ids. 942 /* Users specify affinity in terms of hw cpu ids.
940 * As soon as we do this, handler_irq() might see and take action. 943 * As soon as we do this, handler_irq() might see and take action.
941 */ 944 */
942 put_smpaff_in_irqaction((struct irqaction *)bp->irq_info, hw_aff); 945 put_smpaff_in_irqaction(ap, hw_aff);
943 946
944 /* Migration is simply done by the next cpu to service this 947 /* Migration is simply done by the next cpu to service this
945 * interrupt. 948 * interrupt.
diff --git a/arch/x86_64/Makefile b/arch/x86_64/Makefile
index 8a73794f9b90..428915697675 100644
--- a/arch/x86_64/Makefile
+++ b/arch/x86_64/Makefile
@@ -65,7 +65,9 @@ CFLAGS += $(call cc-option,-mno-sse -mno-mmx -mno-sse2 -mno-3dnow,)
65head-y := arch/x86_64/kernel/head.o arch/x86_64/kernel/head64.o arch/x86_64/kernel/init_task.o 65head-y := arch/x86_64/kernel/head.o arch/x86_64/kernel/head64.o arch/x86_64/kernel/init_task.o
66 66
67libs-y += arch/x86_64/lib/ 67libs-y += arch/x86_64/lib/
68core-y += arch/x86_64/kernel/ arch/x86_64/mm/ 68core-y += arch/x86_64/kernel/ \
69 arch/x86_64/mm/ \
70 arch/x86_64/crypto/
69core-$(CONFIG_IA32_EMULATION) += arch/x86_64/ia32/ 71core-$(CONFIG_IA32_EMULATION) += arch/x86_64/ia32/
70drivers-$(CONFIG_PCI) += arch/x86_64/pci/ 72drivers-$(CONFIG_PCI) += arch/x86_64/pci/
71drivers-$(CONFIG_OPROFILE) += arch/x86_64/oprofile/ 73drivers-$(CONFIG_OPROFILE) += arch/x86_64/oprofile/
diff --git a/arch/x86_64/crypto/Makefile b/arch/x86_64/crypto/Makefile
new file mode 100644
index 000000000000..426d20f4b72e
--- /dev/null
+++ b/arch/x86_64/crypto/Makefile
@@ -0,0 +1,9 @@
1#
2# x86_64/crypto/Makefile
3#
4# Arch-specific CryptoAPI modules.
5#
6
7obj-$(CONFIG_CRYPTO_AES_X86_64) += aes-x86_64.o
8
9aes-x86_64-y := aes-x86_64-asm.o aes.o
diff --git a/arch/x86_64/crypto/aes-x86_64-asm.S b/arch/x86_64/crypto/aes-x86_64-asm.S
new file mode 100644
index 000000000000..483cbb23ab8d
--- /dev/null
+++ b/arch/x86_64/crypto/aes-x86_64-asm.S
@@ -0,0 +1,186 @@
1/* AES (Rijndael) implementation (FIPS PUB 197) for x86_64
2 *
3 * Copyright (C) 2005 Andreas Steinmetz, <ast@domdv.de>
4 *
5 * License:
6 * This code can be distributed under the terms of the GNU General Public
7 * License (GPL) Version 2 provided that the above header down to and
8 * including this sentence is retained in full.
9 */
10
11.extern aes_ft_tab
12.extern aes_it_tab
13.extern aes_fl_tab
14.extern aes_il_tab
15
16.text
17
18#define R1 %rax
19#define R1E %eax
20#define R1X %ax
21#define R1H %ah
22#define R1L %al
23#define R2 %rbx
24#define R2E %ebx
25#define R2X %bx
26#define R2H %bh
27#define R2L %bl
28#define R3 %rcx
29#define R3E %ecx
30#define R3X %cx
31#define R3H %ch
32#define R3L %cl
33#define R4 %rdx
34#define R4E %edx
35#define R4X %dx
36#define R4H %dh
37#define R4L %dl
38#define R5 %rsi
39#define R5E %esi
40#define R6 %rdi
41#define R6E %edi
42#define R7 %rbp
43#define R7E %ebp
44#define R8 %r8
45#define R9 %r9
46#define R10 %r10
47#define R11 %r11
48
49#define prologue(FUNC,BASE,B128,B192,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11) \
50 .global FUNC; \
51 .type FUNC,@function; \
52 .align 8; \
53FUNC: movq r1,r2; \
54 movq r3,r4; \
55 leaq BASE+52(r8),r9; \
56 movq r10,r11; \
57 movl (r7),r5 ## E; \
58 movl 4(r7),r1 ## E; \
59 movl 8(r7),r6 ## E; \
60 movl 12(r7),r7 ## E; \
61 movl (r8),r10 ## E; \
62 xorl -48(r9),r5 ## E; \
63 xorl -44(r9),r1 ## E; \
64 xorl -40(r9),r6 ## E; \
65 xorl -36(r9),r7 ## E; \
66 cmpl $24,r10 ## E; \
67 jb B128; \
68 leaq 32(r9),r9; \
69 je B192; \
70 leaq 32(r9),r9;
71
72#define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
73 movq r1,r2; \
74 movq r3,r4; \
75 movl r5 ## E,(r9); \
76 movl r6 ## E,4(r9); \
77 movl r7 ## E,8(r9); \
78 movl r8 ## E,12(r9); \
79 ret;
80
81#define round(TAB,OFFSET,r1,r2,r3,r4,r5,r6,r7,r8,ra,rb,rc,rd) \
82 movzbl r2 ## H,r5 ## E; \
83 movzbl r2 ## L,r6 ## E; \
84 movl TAB+1024(,r5,4),r5 ## E;\
85 movw r4 ## X,r2 ## X; \
86 movl TAB(,r6,4),r6 ## E; \
87 roll $16,r2 ## E; \
88 shrl $16,r4 ## E; \
89 movzbl r4 ## H,r7 ## E; \
90 movzbl r4 ## L,r4 ## E; \
91 xorl OFFSET(r8),ra ## E; \
92 xorl OFFSET+4(r8),rb ## E; \
93 xorl TAB+3072(,r7,4),r5 ## E;\
94 xorl TAB+2048(,r4,4),r6 ## E;\
95 movzbl r1 ## L,r7 ## E; \
96 movzbl r1 ## H,r4 ## E; \
97 movl TAB+1024(,r4,4),r4 ## E;\
98 movw r3 ## X,r1 ## X; \
99 roll $16,r1 ## E; \
100 shrl $16,r3 ## E; \
101 xorl TAB(,r7,4),r5 ## E; \
102 movzbl r3 ## H,r7 ## E; \
103 movzbl r3 ## L,r3 ## E; \
104 xorl TAB+3072(,r7,4),r4 ## E;\
105 xorl TAB+2048(,r3,4),r5 ## E;\
106 movzbl r1 ## H,r7 ## E; \
107 movzbl r1 ## L,r3 ## E; \
108 shrl $16,r1 ## E; \
109 xorl TAB+3072(,r7,4),r6 ## E;\
110 movl TAB+2048(,r3,4),r3 ## E;\
111 movzbl r1 ## H,r7 ## E; \
112 movzbl r1 ## L,r1 ## E; \
113 xorl TAB+1024(,r7,4),r6 ## E;\
114 xorl TAB(,r1,4),r3 ## E; \
115 movzbl r2 ## H,r1 ## E; \
116 movzbl r2 ## L,r7 ## E; \
117 shrl $16,r2 ## E; \
118 xorl TAB+3072(,r1,4),r3 ## E;\
119 xorl TAB+2048(,r7,4),r4 ## E;\
120 movzbl r2 ## H,r1 ## E; \
121 movzbl r2 ## L,r2 ## E; \
122 xorl OFFSET+8(r8),rc ## E; \
123 xorl OFFSET+12(r8),rd ## E; \
124 xorl TAB+1024(,r1,4),r3 ## E;\
125 xorl TAB(,r2,4),r4 ## E;
126
127#define move_regs(r1,r2,r3,r4) \
128 movl r3 ## E,r1 ## E; \
129 movl r4 ## E,r2 ## E;
130
131#define entry(FUNC,BASE,B128,B192) \
132 prologue(FUNC,BASE,B128,B192,R2,R8,R7,R9,R1,R3,R4,R6,R10,R5,R11)
133
134#define return epilogue(R8,R2,R9,R7,R5,R6,R3,R4,R11)
135
136#define encrypt_round(TAB,OFFSET) \
137 round(TAB,OFFSET,R1,R2,R3,R4,R5,R6,R7,R10,R5,R6,R3,R4) \
138 move_regs(R1,R2,R5,R6)
139
140#define encrypt_final(TAB,OFFSET) \
141 round(TAB,OFFSET,R1,R2,R3,R4,R5,R6,R7,R10,R5,R6,R3,R4)
142
143#define decrypt_round(TAB,OFFSET) \
144 round(TAB,OFFSET,R2,R1,R4,R3,R6,R5,R7,R10,R5,R6,R3,R4) \
145 move_regs(R1,R2,R5,R6)
146
147#define decrypt_final(TAB,OFFSET) \
148 round(TAB,OFFSET,R2,R1,R4,R3,R6,R5,R7,R10,R5,R6,R3,R4)
149
150/* void aes_encrypt(void *ctx, u8 *out, const u8 *in) */
151
152 entry(aes_encrypt,0,enc128,enc192)
153 encrypt_round(aes_ft_tab,-96)
154 encrypt_round(aes_ft_tab,-80)
155enc192: encrypt_round(aes_ft_tab,-64)
156 encrypt_round(aes_ft_tab,-48)
157enc128: encrypt_round(aes_ft_tab,-32)
158 encrypt_round(aes_ft_tab,-16)
159 encrypt_round(aes_ft_tab, 0)
160 encrypt_round(aes_ft_tab, 16)
161 encrypt_round(aes_ft_tab, 32)
162 encrypt_round(aes_ft_tab, 48)
163 encrypt_round(aes_ft_tab, 64)
164 encrypt_round(aes_ft_tab, 80)
165 encrypt_round(aes_ft_tab, 96)
166 encrypt_final(aes_fl_tab,112)
167 return
168
169/* void aes_decrypt(void *ctx, u8 *out, const u8 *in) */
170
171 entry(aes_decrypt,240,dec128,dec192)
172 decrypt_round(aes_it_tab,-96)
173 decrypt_round(aes_it_tab,-80)
174dec192: decrypt_round(aes_it_tab,-64)
175 decrypt_round(aes_it_tab,-48)
176dec128: decrypt_round(aes_it_tab,-32)
177 decrypt_round(aes_it_tab,-16)
178 decrypt_round(aes_it_tab, 0)
179 decrypt_round(aes_it_tab, 16)
180 decrypt_round(aes_it_tab, 32)
181 decrypt_round(aes_it_tab, 48)
182 decrypt_round(aes_it_tab, 64)
183 decrypt_round(aes_it_tab, 80)
184 decrypt_round(aes_it_tab, 96)
185 decrypt_final(aes_il_tab,112)
186 return
diff --git a/arch/x86_64/crypto/aes.c b/arch/x86_64/crypto/aes.c
new file mode 100644
index 000000000000..2b5c4010ce38
--- /dev/null
+++ b/arch/x86_64/crypto/aes.c
@@ -0,0 +1,324 @@
1/*
2 * Cryptographic API.
3 *
4 * AES Cipher Algorithm.
5 *
6 * Based on Brian Gladman's code.
7 *
8 * Linux developers:
9 * Alexander Kjeldaas <astor@fast.no>
10 * Herbert Valerio Riedel <hvr@hvrlab.org>
11 * Kyle McMartin <kyle@debian.org>
12 * Adam J. Richter <adam@yggdrasil.com> (conversion to 2.5 API).
13 * Andreas Steinmetz <ast@domdv.de> (adapted to x86_64 assembler)
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * ---------------------------------------------------------------------------
21 * Copyright (c) 2002, Dr Brian Gladman <brg@gladman.me.uk>, Worcester, UK.
22 * All rights reserved.
23 *
24 * LICENSE TERMS
25 *
26 * The free distribution and use of this software in both source and binary
27 * form is allowed (with or without changes) provided that:
28 *
29 * 1. distributions of this source code include the above copyright
30 * notice, this list of conditions and the following disclaimer;
31 *
32 * 2. distributions in binary form include the above copyright
33 * notice, this list of conditions and the following disclaimer
34 * in the documentation and/or other associated materials;
35 *
36 * 3. the copyright holder's name is not used to endorse products
37 * built using this software without specific written permission.
38 *
39 * ALTERNATIVELY, provided that this notice is retained in full, this product
40 * may be distributed under the terms of the GNU General Public License (GPL),
41 * in which case the provisions of the GPL apply INSTEAD OF those given above.
42 *
43 * DISCLAIMER
44 *
45 * This software is provided 'as is' with no explicit or implied warranties
46 * in respect of its properties, including, but not limited to, correctness
47 * and/or fitness for purpose.
48 * ---------------------------------------------------------------------------
49 */
50
51/* Some changes from the Gladman version:
52 s/RIJNDAEL(e_key)/E_KEY/g
53 s/RIJNDAEL(d_key)/D_KEY/g
54*/
55
56#include <asm/byteorder.h>
57#include <linux/bitops.h>
58#include <linux/crypto.h>
59#include <linux/errno.h>
60#include <linux/init.h>
61#include <linux/module.h>
62#include <linux/types.h>
63
64#define AES_MIN_KEY_SIZE 16
65#define AES_MAX_KEY_SIZE 32
66
67#define AES_BLOCK_SIZE 16
68
69/*
70 * #define byte(x, nr) ((unsigned char)((x) >> (nr*8)))
71 */
72static inline u8 byte(const u32 x, const unsigned n)
73{
74 return x >> (n << 3);
75}
76
77#define u32_in(x) le32_to_cpu(*(const __le32 *)(x))
78
79struct aes_ctx
80{
81 u32 key_length;
82 u32 E[60];
83 u32 D[60];
84};
85
86#define E_KEY ctx->E
87#define D_KEY ctx->D
88
89static u8 pow_tab[256] __initdata;
90static u8 log_tab[256] __initdata;
91static u8 sbx_tab[256] __initdata;
92static u8 isb_tab[256] __initdata;
93static u32 rco_tab[10];
94u32 aes_ft_tab[4][256];
95u32 aes_it_tab[4][256];
96
97u32 aes_fl_tab[4][256];
98u32 aes_il_tab[4][256];
99
100static inline u8 f_mult(u8 a, u8 b)
101{
102 u8 aa = log_tab[a], cc = aa + log_tab[b];
103
104 return pow_tab[cc + (cc < aa ? 1 : 0)];
105}
106
107#define ff_mult(a, b) (a && b ? f_mult(a, b) : 0)
108
109#define ls_box(x) \
110 (aes_fl_tab[0][byte(x, 0)] ^ \
111 aes_fl_tab[1][byte(x, 1)] ^ \
112 aes_fl_tab[2][byte(x, 2)] ^ \
113 aes_fl_tab[3][byte(x, 3)])
114
115static void __init gen_tabs(void)
116{
117 u32 i, t;
118 u8 p, q;
119
120 /* log and power tables for GF(2**8) finite field with
121 0x011b as modular polynomial - the simplest primitive
122 root is 0x03, used here to generate the tables */
123
124 for (i = 0, p = 1; i < 256; ++i) {
125 pow_tab[i] = (u8)p;
126 log_tab[p] = (u8)i;
127
128 p ^= (p << 1) ^ (p & 0x80 ? 0x01b : 0);
129 }
130
131 log_tab[1] = 0;
132
133 for (i = 0, p = 1; i < 10; ++i) {
134 rco_tab[i] = p;
135
136 p = (p << 1) ^ (p & 0x80 ? 0x01b : 0);
137 }
138
139 for (i = 0; i < 256; ++i) {
140 p = (i ? pow_tab[255 - log_tab[i]] : 0);
141 q = ((p >> 7) | (p << 1)) ^ ((p >> 6) | (p << 2));
142 p ^= 0x63 ^ q ^ ((q >> 6) | (q << 2));
143 sbx_tab[i] = p;
144 isb_tab[p] = (u8)i;
145 }
146
147 for (i = 0; i < 256; ++i) {
148 p = sbx_tab[i];
149
150 t = p;
151 aes_fl_tab[0][i] = t;
152 aes_fl_tab[1][i] = rol32(t, 8);
153 aes_fl_tab[2][i] = rol32(t, 16);
154 aes_fl_tab[3][i] = rol32(t, 24);
155
156 t = ((u32)ff_mult(2, p)) |
157 ((u32)p << 8) |
158 ((u32)p << 16) | ((u32)ff_mult(3, p) << 24);
159
160 aes_ft_tab[0][i] = t;
161 aes_ft_tab[1][i] = rol32(t, 8);
162 aes_ft_tab[2][i] = rol32(t, 16);
163 aes_ft_tab[3][i] = rol32(t, 24);
164
165 p = isb_tab[i];
166
167 t = p;
168 aes_il_tab[0][i] = t;
169 aes_il_tab[1][i] = rol32(t, 8);
170 aes_il_tab[2][i] = rol32(t, 16);
171 aes_il_tab[3][i] = rol32(t, 24);
172
173 t = ((u32)ff_mult(14, p)) |
174 ((u32)ff_mult(9, p) << 8) |
175 ((u32)ff_mult(13, p) << 16) |
176 ((u32)ff_mult(11, p) << 24);
177
178 aes_it_tab[0][i] = t;
179 aes_it_tab[1][i] = rol32(t, 8);
180 aes_it_tab[2][i] = rol32(t, 16);
181 aes_it_tab[3][i] = rol32(t, 24);
182 }
183}
184
185#define star_x(x) (((x) & 0x7f7f7f7f) << 1) ^ ((((x) & 0x80808080) >> 7) * 0x1b)
186
187#define imix_col(y, x) \
188 u = star_x(x); \
189 v = star_x(u); \
190 w = star_x(v); \
191 t = w ^ (x); \
192 (y) = u ^ v ^ w; \
193 (y) ^= ror32(u ^ t, 8) ^ \
194 ror32(v ^ t, 16) ^ \
195 ror32(t, 24)
196
197/* initialise the key schedule from the user supplied key */
198
199#define loop4(i) \
200{ \
201 t = ror32(t, 8); t = ls_box(t) ^ rco_tab[i]; \
202 t ^= E_KEY[4 * i]; E_KEY[4 * i + 4] = t; \
203 t ^= E_KEY[4 * i + 1]; E_KEY[4 * i + 5] = t; \
204 t ^= E_KEY[4 * i + 2]; E_KEY[4 * i + 6] = t; \
205 t ^= E_KEY[4 * i + 3]; E_KEY[4 * i + 7] = t; \
206}
207
208#define loop6(i) \
209{ \
210 t = ror32(t, 8); t = ls_box(t) ^ rco_tab[i]; \
211 t ^= E_KEY[6 * i]; E_KEY[6 * i + 6] = t; \
212 t ^= E_KEY[6 * i + 1]; E_KEY[6 * i + 7] = t; \
213 t ^= E_KEY[6 * i + 2]; E_KEY[6 * i + 8] = t; \
214 t ^= E_KEY[6 * i + 3]; E_KEY[6 * i + 9] = t; \
215 t ^= E_KEY[6 * i + 4]; E_KEY[6 * i + 10] = t; \
216 t ^= E_KEY[6 * i + 5]; E_KEY[6 * i + 11] = t; \
217}
218
219#define loop8(i) \
220{ \
221 t = ror32(t, 8); ; t = ls_box(t) ^ rco_tab[i]; \
222 t ^= E_KEY[8 * i]; E_KEY[8 * i + 8] = t; \
223 t ^= E_KEY[8 * i + 1]; E_KEY[8 * i + 9] = t; \
224 t ^= E_KEY[8 * i + 2]; E_KEY[8 * i + 10] = t; \
225 t ^= E_KEY[8 * i + 3]; E_KEY[8 * i + 11] = t; \
226 t = E_KEY[8 * i + 4] ^ ls_box(t); \
227 E_KEY[8 * i + 12] = t; \
228 t ^= E_KEY[8 * i + 5]; E_KEY[8 * i + 13] = t; \
229 t ^= E_KEY[8 * i + 6]; E_KEY[8 * i + 14] = t; \
230 t ^= E_KEY[8 * i + 7]; E_KEY[8 * i + 15] = t; \
231}
232
233static int aes_set_key(void *ctx_arg, const u8 *in_key, unsigned int key_len,
234 u32 *flags)
235{
236 struct aes_ctx *ctx = ctx_arg;
237 u32 i, j, t, u, v, w;
238
239 if (key_len != 16 && key_len != 24 && key_len != 32) {
240 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
241 return -EINVAL;
242 }
243
244 ctx->key_length = key_len;
245
246 D_KEY[key_len + 24] = E_KEY[0] = u32_in(in_key);
247 D_KEY[key_len + 25] = E_KEY[1] = u32_in(in_key + 4);
248 D_KEY[key_len + 26] = E_KEY[2] = u32_in(in_key + 8);
249 D_KEY[key_len + 27] = E_KEY[3] = u32_in(in_key + 12);
250
251 switch (key_len) {
252 case 16:
253 t = E_KEY[3];
254 for (i = 0; i < 10; ++i)
255 loop4(i);
256 break;
257
258 case 24:
259 E_KEY[4] = u32_in(in_key + 16);
260 t = E_KEY[5] = u32_in(in_key + 20);
261 for (i = 0; i < 8; ++i)
262 loop6 (i);
263 break;
264
265 case 32:
266 E_KEY[4] = u32_in(in_key + 16);
267 E_KEY[5] = u32_in(in_key + 20);
268 E_KEY[6] = u32_in(in_key + 24);
269 t = E_KEY[7] = u32_in(in_key + 28);
270 for (i = 0; i < 7; ++i)
271 loop8(i);
272 break;
273 }
274
275 D_KEY[0] = E_KEY[key_len + 24];
276 D_KEY[1] = E_KEY[key_len + 25];
277 D_KEY[2] = E_KEY[key_len + 26];
278 D_KEY[3] = E_KEY[key_len + 27];
279
280 for (i = 4; i < key_len + 24; ++i) {
281 j = key_len + 24 - (i & ~3) + (i & 3);
282 imix_col(D_KEY[j], E_KEY[i]);
283 }
284
285 return 0;
286}
287
288extern void aes_encrypt(void *ctx_arg, u8 *out, const u8 *in);
289extern void aes_decrypt(void *ctx_arg, u8 *out, const u8 *in);
290
291static struct crypto_alg aes_alg = {
292 .cra_name = "aes",
293 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
294 .cra_blocksize = AES_BLOCK_SIZE,
295 .cra_ctxsize = sizeof(struct aes_ctx),
296 .cra_module = THIS_MODULE,
297 .cra_list = LIST_HEAD_INIT(aes_alg.cra_list),
298 .cra_u = {
299 .cipher = {
300 .cia_min_keysize = AES_MIN_KEY_SIZE,
301 .cia_max_keysize = AES_MAX_KEY_SIZE,
302 .cia_setkey = aes_set_key,
303 .cia_encrypt = aes_encrypt,
304 .cia_decrypt = aes_decrypt
305 }
306 }
307};
308
309static int __init aes_init(void)
310{
311 gen_tabs();
312 return crypto_register_alg(&aes_alg);
313}
314
315static void __exit aes_fini(void)
316{
317 crypto_unregister_alg(&aes_alg);
318}
319
320module_init(aes_init);
321module_exit(aes_fini);
322
323MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm");
324MODULE_LICENSE("GPL");
diff --git a/crypto/Kconfig b/crypto/Kconfig
index 90d6089d60ed..256c0b1fed10 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -146,7 +146,7 @@ config CRYPTO_SERPENT
146 146
147config CRYPTO_AES 147config CRYPTO_AES
148 tristate "AES cipher algorithms" 148 tristate "AES cipher algorithms"
149 depends on CRYPTO && !((X86 || UML_X86) && !64BIT) 149 depends on CRYPTO && !(X86 || UML_X86)
150 help 150 help
151 AES cipher algorithms (FIPS-197). AES uses the Rijndael 151 AES cipher algorithms (FIPS-197). AES uses the Rijndael
152 algorithm. 152 algorithm.
@@ -184,6 +184,26 @@ config CRYPTO_AES_586
184 184
185 See <http://csrc.nist.gov/encryption/aes/> for more information. 185 See <http://csrc.nist.gov/encryption/aes/> for more information.
186 186
187config CRYPTO_AES_X86_64
188 tristate "AES cipher algorithms (x86_64)"
189 depends on CRYPTO && ((X86 || UML_X86) && 64BIT)
190 help
191 AES cipher algorithms (FIPS-197). AES uses the Rijndael
192 algorithm.
193
194 Rijndael appears to be consistently a very good performer in
195 both hardware and software across a wide range of computing
196 environments regardless of its use in feedback or non-feedback
197 modes. Its key setup time is excellent, and its key agility is
198 good. Rijndael's very low memory requirements make it very well
199 suited for restricted-space environments, in which it also
200 demonstrates excellent performance. Rijndael's operations are
201 among the easiest to defend against power and timing attacks.
202
203 The AES specifies three key sizes: 128, 192 and 256 bits
204
205 See <http://csrc.nist.gov/encryption/aes/> for more information.
206
187config CRYPTO_CAST5 207config CRYPTO_CAST5
188 tristate "CAST5 (CAST-128) cipher algorithm" 208 tristate "CAST5 (CAST-128) cipher algorithm"
189 depends on CRYPTO 209 depends on CRYPTO
diff --git a/crypto/api.c b/crypto/api.c
index 394169a8577d..b4728811ce3b 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -13,9 +13,12 @@
13 * any later version. 13 * any later version.
14 * 14 *
15 */ 15 */
16
17#include <linux/compiler.h>
16#include <linux/init.h> 18#include <linux/init.h>
17#include <linux/crypto.h> 19#include <linux/crypto.h>
18#include <linux/errno.h> 20#include <linux/errno.h>
21#include <linux/kmod.h>
19#include <linux/rwsem.h> 22#include <linux/rwsem.h>
20#include <linux/slab.h> 23#include <linux/slab.h>
21#include "internal.h" 24#include "internal.h"
@@ -33,7 +36,7 @@ static inline void crypto_alg_put(struct crypto_alg *alg)
33 module_put(alg->cra_module); 36 module_put(alg->cra_module);
34} 37}
35 38
36struct crypto_alg *crypto_alg_lookup(const char *name) 39static struct crypto_alg *crypto_alg_lookup(const char *name)
37{ 40{
38 struct crypto_alg *q, *alg = NULL; 41 struct crypto_alg *q, *alg = NULL;
39 42
@@ -54,6 +57,13 @@ struct crypto_alg *crypto_alg_lookup(const char *name)
54 return alg; 57 return alg;
55} 58}
56 59
60/* A far more intelligent version of this is planned. For now, just
61 * try an exact match on the name of the algorithm. */
62static inline struct crypto_alg *crypto_alg_mod_lookup(const char *name)
63{
64 return try_then_request_module(crypto_alg_lookup(name), name);
65}
66
57static int crypto_init_flags(struct crypto_tfm *tfm, u32 flags) 67static int crypto_init_flags(struct crypto_tfm *tfm, u32 flags)
58{ 68{
59 tfm->crt_flags = 0; 69 tfm->crt_flags = 0;
@@ -117,20 +127,46 @@ static void crypto_exit_ops(struct crypto_tfm *tfm)
117 } 127 }
118} 128}
119 129
130static unsigned int crypto_ctxsize(struct crypto_alg *alg, int flags)
131{
132 unsigned int len;
133
134 switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) {
135 default:
136 BUG();
137
138 case CRYPTO_ALG_TYPE_CIPHER:
139 len = crypto_cipher_ctxsize(alg, flags);
140 break;
141
142 case CRYPTO_ALG_TYPE_DIGEST:
143 len = crypto_digest_ctxsize(alg, flags);
144 break;
145
146 case CRYPTO_ALG_TYPE_COMPRESS:
147 len = crypto_compress_ctxsize(alg, flags);
148 break;
149 }
150
151 return len + alg->cra_alignmask;
152}
153
120struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags) 154struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags)
121{ 155{
122 struct crypto_tfm *tfm = NULL; 156 struct crypto_tfm *tfm = NULL;
123 struct crypto_alg *alg; 157 struct crypto_alg *alg;
158 unsigned int tfm_size;
124 159
125 alg = crypto_alg_mod_lookup(name); 160 alg = crypto_alg_mod_lookup(name);
126 if (alg == NULL) 161 if (alg == NULL)
127 goto out; 162 goto out;
128 163
129 tfm = kmalloc(sizeof(*tfm) + alg->cra_ctxsize, GFP_KERNEL); 164 tfm_size = sizeof(*tfm) + crypto_ctxsize(alg, flags);
165 tfm = kmalloc(tfm_size, GFP_KERNEL);
130 if (tfm == NULL) 166 if (tfm == NULL)
131 goto out_put; 167 goto out_put;
132 168
133 memset(tfm, 0, sizeof(*tfm) + alg->cra_ctxsize); 169 memset(tfm, 0, tfm_size);
134 170
135 tfm->__crt_alg = alg; 171 tfm->__crt_alg = alg;
136 172
@@ -155,8 +191,14 @@ out:
155 191
156void crypto_free_tfm(struct crypto_tfm *tfm) 192void crypto_free_tfm(struct crypto_tfm *tfm)
157{ 193{
158 struct crypto_alg *alg = tfm->__crt_alg; 194 struct crypto_alg *alg;
159 int size = sizeof(*tfm) + alg->cra_ctxsize; 195 int size;
196
197 if (unlikely(!tfm))
198 return;
199
200 alg = tfm->__crt_alg;
201 size = sizeof(*tfm) + alg->cra_ctxsize;
160 202
161 crypto_exit_ops(tfm); 203 crypto_exit_ops(tfm);
162 crypto_alg_put(alg); 204 crypto_alg_put(alg);
@@ -168,6 +210,12 @@ int crypto_register_alg(struct crypto_alg *alg)
168{ 210{
169 int ret = 0; 211 int ret = 0;
170 struct crypto_alg *q; 212 struct crypto_alg *q;
213
214 if (alg->cra_alignmask & (alg->cra_alignmask + 1))
215 return -EINVAL;
216
217 if (alg->cra_alignmask > PAGE_SIZE)
218 return -EINVAL;
171 219
172 down_write(&crypto_alg_sem); 220 down_write(&crypto_alg_sem);
173 221
diff --git a/crypto/cipher.c b/crypto/cipher.c
index f434ce7c2d0b..1c92c6bb138b 100644
--- a/crypto/cipher.c
+++ b/crypto/cipher.c
@@ -4,6 +4,7 @@
4 * Cipher operations. 4 * Cipher operations.
5 * 5 *
6 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> 6 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
7 * Copyright (c) 2005 Herbert Xu <herbert@gondor.apana.org.au>
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify it 9 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free 10 * under the terms of the GNU General Public License as published by the Free
@@ -22,10 +23,6 @@
22#include "internal.h" 23#include "internal.h"
23#include "scatterwalk.h" 24#include "scatterwalk.h"
24 25
25typedef void (cryptfn_t)(void *, u8 *, const u8 *);
26typedef void (procfn_t)(struct crypto_tfm *, u8 *,
27 u8*, cryptfn_t, void *);
28
29static inline void xor_64(u8 *a, const u8 *b) 26static inline void xor_64(u8 *a, const u8 *b)
30{ 27{
31 ((u32 *)a)[0] ^= ((u32 *)b)[0]; 28 ((u32 *)a)[0] ^= ((u32 *)b)[0];
@@ -39,63 +36,70 @@ static inline void xor_128(u8 *a, const u8 *b)
39 ((u32 *)a)[2] ^= ((u32 *)b)[2]; 36 ((u32 *)a)[2] ^= ((u32 *)b)[2];
40 ((u32 *)a)[3] ^= ((u32 *)b)[3]; 37 ((u32 *)a)[3] ^= ((u32 *)b)[3];
41} 38}
42 39
43static inline void *prepare_src(struct scatter_walk *walk, int bsize, 40static unsigned int crypt_slow(const struct cipher_desc *desc,
44 void *tmp, int in_place) 41 struct scatter_walk *in,
42 struct scatter_walk *out, unsigned int bsize)
45{ 43{
46 void *src = walk->data; 44 unsigned int alignmask = crypto_tfm_alg_alignmask(desc->tfm);
47 int n = bsize; 45 u8 buffer[bsize * 2 + alignmask];
46 u8 *src = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
47 u8 *dst = src + bsize;
48 unsigned int n;
48 49
49 if (unlikely(scatterwalk_across_pages(walk, bsize))) { 50 n = scatterwalk_copychunks(src, in, bsize, 0);
50 src = tmp; 51 scatterwalk_advance(in, n);
51 n = scatterwalk_copychunks(src, walk, bsize, 0); 52
52 } 53 desc->prfn(desc, dst, src, bsize);
53 scatterwalk_advance(walk, n); 54
54 return src; 55 n = scatterwalk_copychunks(dst, out, bsize, 1);
56 scatterwalk_advance(out, n);
57
58 return bsize;
55} 59}
56 60
57static inline void *prepare_dst(struct scatter_walk *walk, int bsize, 61static inline unsigned int crypt_fast(const struct cipher_desc *desc,
58 void *tmp, int in_place) 62 struct scatter_walk *in,
63 struct scatter_walk *out,
64 unsigned int nbytes, u8 *tmp)
59{ 65{
60 void *dst = walk->data; 66 u8 *src, *dst;
61 67
62 if (unlikely(scatterwalk_across_pages(walk, bsize)) || in_place) 68 src = in->data;
69 dst = scatterwalk_samebuf(in, out) ? src : out->data;
70
71 if (tmp) {
72 memcpy(tmp, in->data, nbytes);
73 src = tmp;
63 dst = tmp; 74 dst = tmp;
64 return dst; 75 }
65}
66 76
67static inline void complete_src(struct scatter_walk *walk, int bsize, 77 nbytes = desc->prfn(desc, dst, src, nbytes);
68 void *src, int in_place)
69{
70}
71 78
72static inline void complete_dst(struct scatter_walk *walk, int bsize, 79 if (tmp)
73 void *dst, int in_place) 80 memcpy(out->data, tmp, nbytes);
74{ 81
75 int n = bsize; 82 scatterwalk_advance(in, nbytes);
83 scatterwalk_advance(out, nbytes);
76 84
77 if (unlikely(scatterwalk_across_pages(walk, bsize))) 85 return nbytes;
78 n = scatterwalk_copychunks(dst, walk, bsize, 1);
79 else if (in_place)
80 memcpy(walk->data, dst, bsize);
81 scatterwalk_advance(walk, n);
82} 86}
83 87
84/* 88/*
85 * Generic encrypt/decrypt wrapper for ciphers, handles operations across 89 * Generic encrypt/decrypt wrapper for ciphers, handles operations across
86 * multiple page boundaries by using temporary blocks. In user context, 90 * multiple page boundaries by using temporary blocks. In user context,
87 * the kernel is given a chance to schedule us once per block. 91 * the kernel is given a chance to schedule us once per page.
88 */ 92 */
89static int crypt(struct crypto_tfm *tfm, 93static int crypt(const struct cipher_desc *desc,
90 struct scatterlist *dst, 94 struct scatterlist *dst,
91 struct scatterlist *src, 95 struct scatterlist *src,
92 unsigned int nbytes, cryptfn_t crfn, 96 unsigned int nbytes)
93 procfn_t prfn, void *info)
94{ 97{
95 struct scatter_walk walk_in, walk_out; 98 struct scatter_walk walk_in, walk_out;
99 struct crypto_tfm *tfm = desc->tfm;
96 const unsigned int bsize = crypto_tfm_alg_blocksize(tfm); 100 const unsigned int bsize = crypto_tfm_alg_blocksize(tfm);
97 u8 tmp_src[bsize]; 101 unsigned int alignmask = crypto_tfm_alg_alignmask(tfm);
98 u8 tmp_dst[bsize]; 102 unsigned long buffer = 0;
99 103
100 if (!nbytes) 104 if (!nbytes)
101 return 0; 105 return 0;
@@ -109,64 +113,144 @@ static int crypt(struct crypto_tfm *tfm,
109 scatterwalk_start(&walk_out, dst); 113 scatterwalk_start(&walk_out, dst);
110 114
111 for(;;) { 115 for(;;) {
112 u8 *src_p, *dst_p; 116 unsigned int n = nbytes;
113 int in_place; 117 u8 *tmp = NULL;
118
119 if (!scatterwalk_aligned(&walk_in, alignmask) ||
120 !scatterwalk_aligned(&walk_out, alignmask)) {
121 if (!buffer) {
122 buffer = __get_free_page(GFP_ATOMIC);
123 if (!buffer)
124 n = 0;
125 }
126 tmp = (u8 *)buffer;
127 }
114 128
115 scatterwalk_map(&walk_in, 0); 129 scatterwalk_map(&walk_in, 0);
116 scatterwalk_map(&walk_out, 1); 130 scatterwalk_map(&walk_out, 1);
117 131
118 in_place = scatterwalk_samebuf(&walk_in, &walk_out); 132 n = scatterwalk_clamp(&walk_in, n);
119 133 n = scatterwalk_clamp(&walk_out, n);
120 do {
121 src_p = prepare_src(&walk_in, bsize, tmp_src,
122 in_place);
123 dst_p = prepare_dst(&walk_out, bsize, tmp_dst,
124 in_place);
125
126 prfn(tfm, dst_p, src_p, crfn, info);
127 134
128 complete_src(&walk_in, bsize, src_p, in_place); 135 if (likely(n >= bsize))
129 complete_dst(&walk_out, bsize, dst_p, in_place); 136 n = crypt_fast(desc, &walk_in, &walk_out, n, tmp);
137 else
138 n = crypt_slow(desc, &walk_in, &walk_out, bsize);
130 139
131 nbytes -= bsize; 140 nbytes -= n;
132 } while (nbytes &&
133 !scatterwalk_across_pages(&walk_in, bsize) &&
134 !scatterwalk_across_pages(&walk_out, bsize));
135 141
136 scatterwalk_done(&walk_in, 0, nbytes); 142 scatterwalk_done(&walk_in, 0, nbytes);
137 scatterwalk_done(&walk_out, 1, nbytes); 143 scatterwalk_done(&walk_out, 1, nbytes);
138 144
139 if (!nbytes) 145 if (!nbytes)
140 return 0; 146 break;
141 147
142 crypto_yield(tfm); 148 crypto_yield(tfm);
143 } 149 }
150
151 if (buffer)
152 free_page(buffer);
153
154 return 0;
144} 155}
145 156
146static void cbc_process_encrypt(struct crypto_tfm *tfm, u8 *dst, u8 *src, 157static int crypt_iv_unaligned(struct cipher_desc *desc,
147 cryptfn_t fn, void *info) 158 struct scatterlist *dst,
159 struct scatterlist *src,
160 unsigned int nbytes)
148{ 161{
149 u8 *iv = info; 162 struct crypto_tfm *tfm = desc->tfm;
163 unsigned int alignmask = crypto_tfm_alg_alignmask(tfm);
164 u8 *iv = desc->info;
150 165
151 tfm->crt_u.cipher.cit_xor_block(iv, src); 166 if (unlikely(((unsigned long)iv & alignmask))) {
152 fn(crypto_tfm_ctx(tfm), dst, iv); 167 unsigned int ivsize = tfm->crt_cipher.cit_ivsize;
153 memcpy(iv, dst, crypto_tfm_alg_blocksize(tfm)); 168 u8 buffer[ivsize + alignmask];
169 u8 *tmp = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
170 int err;
171
172 desc->info = memcpy(tmp, iv, ivsize);
173 err = crypt(desc, dst, src, nbytes);
174 memcpy(iv, tmp, ivsize);
175
176 return err;
177 }
178
179 return crypt(desc, dst, src, nbytes);
154} 180}
155 181
156static void cbc_process_decrypt(struct crypto_tfm *tfm, u8 *dst, u8 *src, 182static unsigned int cbc_process_encrypt(const struct cipher_desc *desc,
157 cryptfn_t fn, void *info) 183 u8 *dst, const u8 *src,
184 unsigned int nbytes)
158{ 185{
159 u8 *iv = info; 186 struct crypto_tfm *tfm = desc->tfm;
187 void (*xor)(u8 *, const u8 *) = tfm->crt_u.cipher.cit_xor_block;
188 int bsize = crypto_tfm_alg_blocksize(tfm);
189
190 void (*fn)(void *, u8 *, const u8 *) = desc->crfn;
191 u8 *iv = desc->info;
192 unsigned int done = 0;
193
194 do {
195 xor(iv, src);
196 fn(crypto_tfm_ctx(tfm), dst, iv);
197 memcpy(iv, dst, bsize);
160 198
161 fn(crypto_tfm_ctx(tfm), dst, src); 199 src += bsize;
162 tfm->crt_u.cipher.cit_xor_block(dst, iv); 200 dst += bsize;
163 memcpy(iv, src, crypto_tfm_alg_blocksize(tfm)); 201 } while ((done += bsize) < nbytes);
202
203 return done;
164} 204}
165 205
166static void ecb_process(struct crypto_tfm *tfm, u8 *dst, u8 *src, 206static unsigned int cbc_process_decrypt(const struct cipher_desc *desc,
167 cryptfn_t fn, void *info) 207 u8 *dst, const u8 *src,
208 unsigned int nbytes)
168{ 209{
169 fn(crypto_tfm_ctx(tfm), dst, src); 210 struct crypto_tfm *tfm = desc->tfm;
211 void (*xor)(u8 *, const u8 *) = tfm->crt_u.cipher.cit_xor_block;
212 int bsize = crypto_tfm_alg_blocksize(tfm);
213
214 u8 stack[src == dst ? bsize : 0];
215 u8 *buf = stack;
216 u8 **dst_p = src == dst ? &buf : &dst;
217
218 void (*fn)(void *, u8 *, const u8 *) = desc->crfn;
219 u8 *iv = desc->info;
220 unsigned int done = 0;
221
222 do {
223 u8 *tmp_dst = *dst_p;
224
225 fn(crypto_tfm_ctx(tfm), tmp_dst, src);
226 xor(tmp_dst, iv);
227 memcpy(iv, src, bsize);
228 if (tmp_dst != dst)
229 memcpy(dst, tmp_dst, bsize);
230
231 src += bsize;
232 dst += bsize;
233 } while ((done += bsize) < nbytes);
234
235 return done;
236}
237
238static unsigned int ecb_process(const struct cipher_desc *desc, u8 *dst,
239 const u8 *src, unsigned int nbytes)
240{
241 struct crypto_tfm *tfm = desc->tfm;
242 int bsize = crypto_tfm_alg_blocksize(tfm);
243 void (*fn)(void *, u8 *, const u8 *) = desc->crfn;
244 unsigned int done = 0;
245
246 do {
247 fn(crypto_tfm_ctx(tfm), dst, src);
248
249 src += bsize;
250 dst += bsize;
251 } while ((done += bsize) < nbytes);
252
253 return done;
170} 254}
171 255
172static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) 256static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
@@ -185,9 +269,14 @@ static int ecb_encrypt(struct crypto_tfm *tfm,
185 struct scatterlist *dst, 269 struct scatterlist *dst,
186 struct scatterlist *src, unsigned int nbytes) 270 struct scatterlist *src, unsigned int nbytes)
187{ 271{
188 return crypt(tfm, dst, src, nbytes, 272 struct cipher_desc desc;
189 tfm->__crt_alg->cra_cipher.cia_encrypt, 273 struct cipher_alg *cipher = &tfm->__crt_alg->cra_cipher;
190 ecb_process, NULL); 274
275 desc.tfm = tfm;
276 desc.crfn = cipher->cia_encrypt;
277 desc.prfn = cipher->cia_encrypt_ecb ?: ecb_process;
278
279 return crypt(&desc, dst, src, nbytes);
191} 280}
192 281
193static int ecb_decrypt(struct crypto_tfm *tfm, 282static int ecb_decrypt(struct crypto_tfm *tfm,
@@ -195,9 +284,14 @@ static int ecb_decrypt(struct crypto_tfm *tfm,
195 struct scatterlist *src, 284 struct scatterlist *src,
196 unsigned int nbytes) 285 unsigned int nbytes)
197{ 286{
198 return crypt(tfm, dst, src, nbytes, 287 struct cipher_desc desc;
199 tfm->__crt_alg->cra_cipher.cia_decrypt, 288 struct cipher_alg *cipher = &tfm->__crt_alg->cra_cipher;
200 ecb_process, NULL); 289
290 desc.tfm = tfm;
291 desc.crfn = cipher->cia_decrypt;
292 desc.prfn = cipher->cia_decrypt_ecb ?: ecb_process;
293
294 return crypt(&desc, dst, src, nbytes);
201} 295}
202 296
203static int cbc_encrypt(struct crypto_tfm *tfm, 297static int cbc_encrypt(struct crypto_tfm *tfm,
@@ -205,9 +299,15 @@ static int cbc_encrypt(struct crypto_tfm *tfm,
205 struct scatterlist *src, 299 struct scatterlist *src,
206 unsigned int nbytes) 300 unsigned int nbytes)
207{ 301{
208 return crypt(tfm, dst, src, nbytes, 302 struct cipher_desc desc;
209 tfm->__crt_alg->cra_cipher.cia_encrypt, 303 struct cipher_alg *cipher = &tfm->__crt_alg->cra_cipher;
210 cbc_process_encrypt, tfm->crt_cipher.cit_iv); 304
305 desc.tfm = tfm;
306 desc.crfn = cipher->cia_encrypt;
307 desc.prfn = cipher->cia_encrypt_cbc ?: cbc_process_encrypt;
308 desc.info = tfm->crt_cipher.cit_iv;
309
310 return crypt(&desc, dst, src, nbytes);
211} 311}
212 312
213static int cbc_encrypt_iv(struct crypto_tfm *tfm, 313static int cbc_encrypt_iv(struct crypto_tfm *tfm,
@@ -215,9 +315,15 @@ static int cbc_encrypt_iv(struct crypto_tfm *tfm,
215 struct scatterlist *src, 315 struct scatterlist *src,
216 unsigned int nbytes, u8 *iv) 316 unsigned int nbytes, u8 *iv)
217{ 317{
218 return crypt(tfm, dst, src, nbytes, 318 struct cipher_desc desc;
219 tfm->__crt_alg->cra_cipher.cia_encrypt, 319 struct cipher_alg *cipher = &tfm->__crt_alg->cra_cipher;
220 cbc_process_encrypt, iv); 320
321 desc.tfm = tfm;
322 desc.crfn = cipher->cia_encrypt;
323 desc.prfn = cipher->cia_encrypt_cbc ?: cbc_process_encrypt;
324 desc.info = iv;
325
326 return crypt_iv_unaligned(&desc, dst, src, nbytes);
221} 327}
222 328
223static int cbc_decrypt(struct crypto_tfm *tfm, 329static int cbc_decrypt(struct crypto_tfm *tfm,
@@ -225,9 +331,15 @@ static int cbc_decrypt(struct crypto_tfm *tfm,
225 struct scatterlist *src, 331 struct scatterlist *src,
226 unsigned int nbytes) 332 unsigned int nbytes)
227{ 333{
228 return crypt(tfm, dst, src, nbytes, 334 struct cipher_desc desc;
229 tfm->__crt_alg->cra_cipher.cia_decrypt, 335 struct cipher_alg *cipher = &tfm->__crt_alg->cra_cipher;
230 cbc_process_decrypt, tfm->crt_cipher.cit_iv); 336
337 desc.tfm = tfm;
338 desc.crfn = cipher->cia_decrypt;
339 desc.prfn = cipher->cia_decrypt_cbc ?: cbc_process_decrypt;
340 desc.info = tfm->crt_cipher.cit_iv;
341
342 return crypt(&desc, dst, src, nbytes);
231} 343}
232 344
233static int cbc_decrypt_iv(struct crypto_tfm *tfm, 345static int cbc_decrypt_iv(struct crypto_tfm *tfm,
@@ -235,9 +347,15 @@ static int cbc_decrypt_iv(struct crypto_tfm *tfm,
235 struct scatterlist *src, 347 struct scatterlist *src,
236 unsigned int nbytes, u8 *iv) 348 unsigned int nbytes, u8 *iv)
237{ 349{
238 return crypt(tfm, dst, src, nbytes, 350 struct cipher_desc desc;
239 tfm->__crt_alg->cra_cipher.cia_decrypt, 351 struct cipher_alg *cipher = &tfm->__crt_alg->cra_cipher;
240 cbc_process_decrypt, iv); 352
353 desc.tfm = tfm;
354 desc.crfn = cipher->cia_decrypt;
355 desc.prfn = cipher->cia_decrypt_cbc ?: cbc_process_decrypt;
356 desc.info = iv;
357
358 return crypt_iv_unaligned(&desc, dst, src, nbytes);
241} 359}
242 360
243static int nocrypt(struct crypto_tfm *tfm, 361static int nocrypt(struct crypto_tfm *tfm,
@@ -306,6 +424,8 @@ int crypto_init_cipher_ops(struct crypto_tfm *tfm)
306 } 424 }
307 425
308 if (ops->cit_mode == CRYPTO_TFM_MODE_CBC) { 426 if (ops->cit_mode == CRYPTO_TFM_MODE_CBC) {
427 unsigned int align;
428 unsigned long addr;
309 429
310 switch (crypto_tfm_alg_blocksize(tfm)) { 430 switch (crypto_tfm_alg_blocksize(tfm)) {
311 case 8: 431 case 8:
@@ -325,9 +445,11 @@ int crypto_init_cipher_ops(struct crypto_tfm *tfm)
325 } 445 }
326 446
327 ops->cit_ivsize = crypto_tfm_alg_blocksize(tfm); 447 ops->cit_ivsize = crypto_tfm_alg_blocksize(tfm);
328 ops->cit_iv = kmalloc(ops->cit_ivsize, GFP_KERNEL); 448 align = crypto_tfm_alg_alignmask(tfm) + 1;
329 if (ops->cit_iv == NULL) 449 addr = (unsigned long)crypto_tfm_ctx(tfm);
330 ret = -ENOMEM; 450 addr = ALIGN(addr, align);
451 addr += ALIGN(tfm->__crt_alg->cra_ctxsize, align);
452 ops->cit_iv = (void *)addr;
331 } 453 }
332 454
333out: 455out:
@@ -336,6 +458,4 @@ out:
336 458
337void crypto_exit_cipher_ops(struct crypto_tfm *tfm) 459void crypto_exit_cipher_ops(struct crypto_tfm *tfm)
338{ 460{
339 if (tfm->crt_cipher.cit_iv)
340 kfree(tfm->crt_cipher.cit_iv);
341} 461}
diff --git a/crypto/des.c b/crypto/des.c
index 1c7e6de9356c..a3c863dddded 100644
--- a/crypto/des.c
+++ b/crypto/des.c
@@ -1,18 +1,9 @@
1/* 1/*
2 * Cryptographic API. 2 * Cryptographic API.
3 * 3 *
4 * DES & Triple DES EDE Cipher Algorithms. 4 * DES & Triple DES EDE Cipher Algorithms.
5 * 5 *
6 * Originally released as descore by Dana L. How <how@isl.stanford.edu>. 6 * Copyright (c) 2005 Dag Arne Osvik <da@osvik.no>
7 * Modified by Raimar Falke <rf13@inf.tu-dresden.de> for the Linux-Kernel.
8 * Derived from Cryptoapi and Nettle implementations, adapted for in-place
9 * scatterlist interface. Changed LGPL to GPL per section 3 of the LGPL.
10 *
11 * Copyright (c) 1992 Dana L. How.
12 * Copyright (c) Raimar Falke <rf13@inf.tu-dresden.de>
13 * Copyright (c) Gisle Sælensminde <gisle@ii.uib.no>
14 * Copyright (C) 2001 Niels Möller.
15 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
16 * 7 *
17 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
@@ -20,11 +11,11 @@
20 * (at your option) any later version. 11 * (at your option) any later version.
21 * 12 *
22 */ 13 */
14
15#include <linux/bitops.h>
23#include <linux/init.h> 16#include <linux/init.h>
24#include <linux/module.h> 17#include <linux/module.h>
25#include <linux/mm.h>
26#include <linux/errno.h> 18#include <linux/errno.h>
27#include <asm/scatterlist.h>
28#include <linux/crypto.h> 19#include <linux/crypto.h>
29 20
30#define DES_KEY_SIZE 8 21#define DES_KEY_SIZE 8
@@ -35,1157 +26,826 @@
35#define DES3_EDE_EXPKEY_WORDS (3 * DES_EXPKEY_WORDS) 26#define DES3_EDE_EXPKEY_WORDS (3 * DES_EXPKEY_WORDS)
36#define DES3_EDE_BLOCK_SIZE DES_BLOCK_SIZE 27#define DES3_EDE_BLOCK_SIZE DES_BLOCK_SIZE
37 28
38#define ROR(d,c,o) ((d) = (d) >> (c) | (d) << (o)) 29#define ROL(x, r) ((x) = rol32((x), (r)))
30#define ROR(x, r) ((x) = ror32((x), (r)))
39 31
40struct des_ctx { 32struct des_ctx {
41 u8 iv[DES_BLOCK_SIZE];
42 u32 expkey[DES_EXPKEY_WORDS]; 33 u32 expkey[DES_EXPKEY_WORDS];
43}; 34};
44 35
45struct des3_ede_ctx { 36struct des3_ede_ctx {
46 u8 iv[DES_BLOCK_SIZE];
47 u32 expkey[DES3_EDE_EXPKEY_WORDS]; 37 u32 expkey[DES3_EDE_EXPKEY_WORDS];
48}; 38};
49 39
50static const u32 des_keymap[] = { 40/* Lookup tables for key expansion */
51 0x02080008, 0x02082000, 0x00002008, 0x00000000, 41
52 0x02002000, 0x00080008, 0x02080000, 0x02082008, 42static const u8 pc1[256] = {
53 0x00000008, 0x02000000, 0x00082000, 0x00002008, 43 0x00, 0x00, 0x40, 0x04, 0x10, 0x10, 0x50, 0x14,
54 0x00082008, 0x02002008, 0x02000008, 0x02080000, 44 0x04, 0x40, 0x44, 0x44, 0x14, 0x50, 0x54, 0x54,
55 0x00002000, 0x00082008, 0x00080008, 0x02002000, 45 0x02, 0x02, 0x42, 0x06, 0x12, 0x12, 0x52, 0x16,
56 0x02082008, 0x02000008, 0x00000000, 0x00082000, 46 0x06, 0x42, 0x46, 0x46, 0x16, 0x52, 0x56, 0x56,
57 0x02000000, 0x00080000, 0x02002008, 0x02080008, 47 0x80, 0x08, 0xc0, 0x0c, 0x90, 0x18, 0xd0, 0x1c,
58 0x00080000, 0x00002000, 0x02082000, 0x00000008, 48 0x84, 0x48, 0xc4, 0x4c, 0x94, 0x58, 0xd4, 0x5c,
59 0x00080000, 0x00002000, 0x02000008, 0x02082008, 49 0x82, 0x0a, 0xc2, 0x0e, 0x92, 0x1a, 0xd2, 0x1e,
60 0x00002008, 0x02000000, 0x00000000, 0x00082000, 50 0x86, 0x4a, 0xc6, 0x4e, 0x96, 0x5a, 0xd6, 0x5e,
61 0x02080008, 0x02002008, 0x02002000, 0x00080008, 51 0x20, 0x20, 0x60, 0x24, 0x30, 0x30, 0x70, 0x34,
62 0x02082000, 0x00000008, 0x00080008, 0x02002000, 52 0x24, 0x60, 0x64, 0x64, 0x34, 0x70, 0x74, 0x74,
63 0x02082008, 0x00080000, 0x02080000, 0x02000008, 53 0x22, 0x22, 0x62, 0x26, 0x32, 0x32, 0x72, 0x36,
64 0x00082000, 0x00002008, 0x02002008, 0x02080000, 54 0x26, 0x62, 0x66, 0x66, 0x36, 0x72, 0x76, 0x76,
65 0x00000008, 0x02082000, 0x00082008, 0x00000000, 55 0xa0, 0x28, 0xe0, 0x2c, 0xb0, 0x38, 0xf0, 0x3c,
66 0x02000000, 0x02080008, 0x00002000, 0x00082008, 56 0xa4, 0x68, 0xe4, 0x6c, 0xb4, 0x78, 0xf4, 0x7c,
67 57 0xa2, 0x2a, 0xe2, 0x2e, 0xb2, 0x3a, 0xf2, 0x3e,
68 0x08000004, 0x00020004, 0x00000000, 0x08020200, 58 0xa6, 0x6a, 0xe6, 0x6e, 0xb6, 0x7a, 0xf6, 0x7e,
69 0x00020004, 0x00000200, 0x08000204, 0x00020000, 59 0x08, 0x80, 0x48, 0x84, 0x18, 0x90, 0x58, 0x94,
70 0x00000204, 0x08020204, 0x00020200, 0x08000000, 60 0x0c, 0xc0, 0x4c, 0xc4, 0x1c, 0xd0, 0x5c, 0xd4,
71 0x08000200, 0x08000004, 0x08020000, 0x00020204, 61 0x0a, 0x82, 0x4a, 0x86, 0x1a, 0x92, 0x5a, 0x96,
72 0x00020000, 0x08000204, 0x08020004, 0x00000000, 62 0x0e, 0xc2, 0x4e, 0xc6, 0x1e, 0xd2, 0x5e, 0xd6,
73 0x00000200, 0x00000004, 0x08020200, 0x08020004, 63 0x88, 0x88, 0xc8, 0x8c, 0x98, 0x98, 0xd8, 0x9c,
74 0x08020204, 0x08020000, 0x08000000, 0x00000204, 64 0x8c, 0xc8, 0xcc, 0xcc, 0x9c, 0xd8, 0xdc, 0xdc,
75 0x00000004, 0x00020200, 0x00020204, 0x08000200, 65 0x8a, 0x8a, 0xca, 0x8e, 0x9a, 0x9a, 0xda, 0x9e,
76 0x00000204, 0x08000000, 0x08000200, 0x00020204, 66 0x8e, 0xca, 0xce, 0xce, 0x9e, 0xda, 0xde, 0xde,
77 0x08020200, 0x00020004, 0x00000000, 0x08000200, 67 0x28, 0xa0, 0x68, 0xa4, 0x38, 0xb0, 0x78, 0xb4,
78 0x08000000, 0x00000200, 0x08020004, 0x00020000, 68 0x2c, 0xe0, 0x6c, 0xe4, 0x3c, 0xf0, 0x7c, 0xf4,
79 0x00020004, 0x08020204, 0x00020200, 0x00000004, 69 0x2a, 0xa2, 0x6a, 0xa6, 0x3a, 0xb2, 0x7a, 0xb6,
80 0x08020204, 0x00020200, 0x00020000, 0x08000204, 70 0x2e, 0xe2, 0x6e, 0xe6, 0x3e, 0xf2, 0x7e, 0xf6,
81 0x08000004, 0x08020000, 0x00020204, 0x00000000, 71 0xa8, 0xa8, 0xe8, 0xac, 0xb8, 0xb8, 0xf8, 0xbc,
82 0x00000200, 0x08000004, 0x08000204, 0x08020200, 72 0xac, 0xe8, 0xec, 0xec, 0xbc, 0xf8, 0xfc, 0xfc,
83 0x08020000, 0x00000204, 0x00000004, 0x08020004, 73 0xaa, 0xaa, 0xea, 0xae, 0xba, 0xba, 0xfa, 0xbe,
84 74 0xae, 0xea, 0xee, 0xee, 0xbe, 0xfa, 0xfe, 0xfe
85 0x80040100, 0x01000100, 0x80000000, 0x81040100,
86 0x00000000, 0x01040000, 0x81000100, 0x80040000,
87 0x01040100, 0x81000000, 0x01000000, 0x80000100,
88 0x81000000, 0x80040100, 0x00040000, 0x01000000,
89 0x81040000, 0x00040100, 0x00000100, 0x80000000,
90 0x00040100, 0x81000100, 0x01040000, 0x00000100,
91 0x80000100, 0x00000000, 0x80040000, 0x01040100,
92 0x01000100, 0x81040000, 0x81040100, 0x00040000,
93 0x81040000, 0x80000100, 0x00040000, 0x81000000,
94 0x00040100, 0x01000100, 0x80000000, 0x01040000,
95 0x81000100, 0x00000000, 0x00000100, 0x80040000,
96 0x00000000, 0x81040000, 0x01040100, 0x00000100,
97 0x01000000, 0x81040100, 0x80040100, 0x00040000,
98 0x81040100, 0x80000000, 0x01000100, 0x80040100,
99 0x80040000, 0x00040100, 0x01040000, 0x81000100,
100 0x80000100, 0x01000000, 0x81000000, 0x01040100,
101
102 0x04010801, 0x00000000, 0x00010800, 0x04010000,
103 0x04000001, 0x00000801, 0x04000800, 0x00010800,
104 0x00000800, 0x04010001, 0x00000001, 0x04000800,
105 0x00010001, 0x04010800, 0x04010000, 0x00000001,
106 0x00010000, 0x04000801, 0x04010001, 0x00000800,
107 0x00010801, 0x04000000, 0x00000000, 0x00010001,
108 0x04000801, 0x00010801, 0x04010800, 0x04000001,
109 0x04000000, 0x00010000, 0x00000801, 0x04010801,
110 0x00010001, 0x04010800, 0x04000800, 0x00010801,
111 0x04010801, 0x00010001, 0x04000001, 0x00000000,
112 0x04000000, 0x00000801, 0x00010000, 0x04010001,
113 0x00000800, 0x04000000, 0x00010801, 0x04000801,
114 0x04010800, 0x00000800, 0x00000000, 0x04000001,
115 0x00000001, 0x04010801, 0x00010800, 0x04010000,
116 0x04010001, 0x00010000, 0x00000801, 0x04000800,
117 0x04000801, 0x00000001, 0x04010000, 0x00010800,
118
119 0x00000400, 0x00000020, 0x00100020, 0x40100000,
120 0x40100420, 0x40000400, 0x00000420, 0x00000000,
121 0x00100000, 0x40100020, 0x40000020, 0x00100400,
122 0x40000000, 0x00100420, 0x00100400, 0x40000020,
123 0x40100020, 0x00000400, 0x40000400, 0x40100420,
124 0x00000000, 0x00100020, 0x40100000, 0x00000420,
125 0x40100400, 0x40000420, 0x00100420, 0x40000000,
126 0x40000420, 0x40100400, 0x00000020, 0x00100000,
127 0x40000420, 0x00100400, 0x40100400, 0x40000020,
128 0x00000400, 0x00000020, 0x00100000, 0x40100400,
129 0x40100020, 0x40000420, 0x00000420, 0x00000000,
130 0x00000020, 0x40100000, 0x40000000, 0x00100020,
131 0x00000000, 0x40100020, 0x00100020, 0x00000420,
132 0x40000020, 0x00000400, 0x40100420, 0x00100000,
133 0x00100420, 0x40000000, 0x40000400, 0x40100420,
134 0x40100000, 0x00100420, 0x00100400, 0x40000400,
135
136 0x00800000, 0x00001000, 0x00000040, 0x00801042,
137 0x00801002, 0x00800040, 0x00001042, 0x00801000,
138 0x00001000, 0x00000002, 0x00800002, 0x00001040,
139 0x00800042, 0x00801002, 0x00801040, 0x00000000,
140 0x00001040, 0x00800000, 0x00001002, 0x00000042,
141 0x00800040, 0x00001042, 0x00000000, 0x00800002,
142 0x00000002, 0x00800042, 0x00801042, 0x00001002,
143 0x00801000, 0x00000040, 0x00000042, 0x00801040,
144 0x00801040, 0x00800042, 0x00001002, 0x00801000,
145 0x00001000, 0x00000002, 0x00800002, 0x00800040,
146 0x00800000, 0x00001040, 0x00801042, 0x00000000,
147 0x00001042, 0x00800000, 0x00000040, 0x00001002,
148 0x00800042, 0x00000040, 0x00000000, 0x00801042,
149 0x00801002, 0x00801040, 0x00000042, 0x00001000,
150 0x00001040, 0x00801002, 0x00800040, 0x00000042,
151 0x00000002, 0x00001042, 0x00801000, 0x00800002,
152
153 0x10400000, 0x00404010, 0x00000010, 0x10400010,
154 0x10004000, 0x00400000, 0x10400010, 0x00004010,
155 0x00400010, 0x00004000, 0x00404000, 0x10000000,
156 0x10404010, 0x10000010, 0x10000000, 0x10404000,
157 0x00000000, 0x10004000, 0x00404010, 0x00000010,
158 0x10000010, 0x10404010, 0x00004000, 0x10400000,
159 0x10404000, 0x00400010, 0x10004010, 0x00404000,
160 0x00004010, 0x00000000, 0x00400000, 0x10004010,
161 0x00404010, 0x00000010, 0x10000000, 0x00004000,
162 0x10000010, 0x10004000, 0x00404000, 0x10400010,
163 0x00000000, 0x00404010, 0x00004010, 0x10404000,
164 0x10004000, 0x00400000, 0x10404010, 0x10000000,
165 0x10004010, 0x10400000, 0x00400000, 0x10404010,
166 0x00004000, 0x00400010, 0x10400010, 0x00004010,
167 0x00400010, 0x00000000, 0x10404000, 0x10000010,
168 0x10400000, 0x10004010, 0x00000010, 0x00404000,
169
170 0x00208080, 0x00008000, 0x20200000, 0x20208080,
171 0x00200000, 0x20008080, 0x20008000, 0x20200000,
172 0x20008080, 0x00208080, 0x00208000, 0x20000080,
173 0x20200080, 0x00200000, 0x00000000, 0x20008000,
174 0x00008000, 0x20000000, 0x00200080, 0x00008080,
175 0x20208080, 0x00208000, 0x20000080, 0x00200080,
176 0x20000000, 0x00000080, 0x00008080, 0x20208000,
177 0x00000080, 0x20200080, 0x20208000, 0x00000000,
178 0x00000000, 0x20208080, 0x00200080, 0x20008000,
179 0x00208080, 0x00008000, 0x20000080, 0x00200080,
180 0x20208000, 0x00000080, 0x00008080, 0x20200000,
181 0x20008080, 0x20000000, 0x20200000, 0x00208000,
182 0x20208080, 0x00008080, 0x00208000, 0x20200080,
183 0x00200000, 0x20000080, 0x20008000, 0x00000000,
184 0x00008000, 0x00200000, 0x20200080, 0x00208080,
185 0x20000000, 0x20208000, 0x00000080, 0x20008080,
186}; 75};
187 76
188static const u8 rotors[] = { 77static const u8 rs[256] = {
189 34, 13, 5, 46, 47, 18, 32, 41, 11, 53, 33, 20, 78 0x00, 0x00, 0x80, 0x80, 0x02, 0x02, 0x82, 0x82,
190 14, 36, 30, 24, 49, 2, 15, 37, 42, 50, 0, 21, 79 0x04, 0x04, 0x84, 0x84, 0x06, 0x06, 0x86, 0x86,
191 38, 48, 6, 26, 39, 4, 52, 25, 12, 27, 31, 40, 80 0x08, 0x08, 0x88, 0x88, 0x0a, 0x0a, 0x8a, 0x8a,
192 1, 17, 28, 29, 23, 51, 35, 7, 3, 22, 9, 43, 81 0x0c, 0x0c, 0x8c, 0x8c, 0x0e, 0x0e, 0x8e, 0x8e,
193 82 0x10, 0x10, 0x90, 0x90, 0x12, 0x12, 0x92, 0x92,
194 41, 20, 12, 53, 54, 25, 39, 48, 18, 31, 40, 27, 83 0x14, 0x14, 0x94, 0x94, 0x16, 0x16, 0x96, 0x96,
195 21, 43, 37, 0, 1, 9, 22, 44, 49, 2, 7, 28, 84 0x18, 0x18, 0x98, 0x98, 0x1a, 0x1a, 0x9a, 0x9a,
196 45, 55, 13, 33, 46, 11, 6, 32, 19, 34, 38, 47, 85 0x1c, 0x1c, 0x9c, 0x9c, 0x1e, 0x1e, 0x9e, 0x9e,
197 8, 24, 35, 36, 30, 3, 42, 14, 10, 29, 16, 50, 86 0x20, 0x20, 0xa0, 0xa0, 0x22, 0x22, 0xa2, 0xa2,
198 87 0x24, 0x24, 0xa4, 0xa4, 0x26, 0x26, 0xa6, 0xa6,
199 55, 34, 26, 38, 11, 39, 53, 5, 32, 45, 54, 41, 88 0x28, 0x28, 0xa8, 0xa8, 0x2a, 0x2a, 0xaa, 0xaa,
200 35, 2, 51, 14, 15, 23, 36, 3, 8, 16, 21, 42, 89 0x2c, 0x2c, 0xac, 0xac, 0x2e, 0x2e, 0xae, 0xae,
201 6, 12, 27, 47, 31, 25, 20, 46, 33, 48, 52, 4, 90 0x30, 0x30, 0xb0, 0xb0, 0x32, 0x32, 0xb2, 0xb2,
202 22, 7, 49, 50, 44, 17, 1, 28, 24, 43, 30, 9, 91 0x34, 0x34, 0xb4, 0xb4, 0x36, 0x36, 0xb6, 0xb6,
203 92 0x38, 0x38, 0xb8, 0xb8, 0x3a, 0x3a, 0xba, 0xba,
204 12, 48, 40, 52, 25, 53, 38, 19, 46, 6, 11, 55, 93 0x3c, 0x3c, 0xbc, 0xbc, 0x3e, 0x3e, 0xbe, 0xbe,
205 49, 16, 10, 28, 29, 37, 50, 17, 22, 30, 35, 1, 94 0x40, 0x40, 0xc0, 0xc0, 0x42, 0x42, 0xc2, 0xc2,
206 20, 26, 41, 4, 45, 39, 34, 31, 47, 5, 13, 18, 95 0x44, 0x44, 0xc4, 0xc4, 0x46, 0x46, 0xc6, 0xc6,
207 36, 21, 8, 9, 3, 0, 15, 42, 7, 2, 44, 23, 96 0x48, 0x48, 0xc8, 0xc8, 0x4a, 0x4a, 0xca, 0xca,
208 97 0x4c, 0x4c, 0xcc, 0xcc, 0x4e, 0x4e, 0xce, 0xce,
209 26, 5, 54, 13, 39, 38, 52, 33, 31, 20, 25, 12, 98 0x50, 0x50, 0xd0, 0xd0, 0x52, 0x52, 0xd2, 0xd2,
210 8, 30, 24, 42, 43, 51, 9, 0, 36, 44, 49, 15, 99 0x54, 0x54, 0xd4, 0xd4, 0x56, 0x56, 0xd6, 0xd6,
211 34, 40, 55, 18, 6, 53, 48, 45, 4, 19, 27, 32, 100 0x58, 0x58, 0xd8, 0xd8, 0x5a, 0x5a, 0xda, 0xda,
212 50, 35, 22, 23, 17, 14, 29, 1, 21, 16, 3, 37, 101 0x5c, 0x5c, 0xdc, 0xdc, 0x5e, 0x5e, 0xde, 0xde,
213 102 0x60, 0x60, 0xe0, 0xe0, 0x62, 0x62, 0xe2, 0xe2,
214 40, 19, 11, 27, 53, 52, 13, 47, 45, 34, 39, 26, 103 0x64, 0x64, 0xe4, 0xe4, 0x66, 0x66, 0xe6, 0xe6,
215 22, 44, 7, 1, 2, 10, 23, 14, 50, 3, 8, 29, 104 0x68, 0x68, 0xe8, 0xe8, 0x6a, 0x6a, 0xea, 0xea,
216 48, 54, 12, 32, 20, 38, 5, 6, 18, 33, 41, 46, 105 0x6c, 0x6c, 0xec, 0xec, 0x6e, 0x6e, 0xee, 0xee,
217 9, 49, 36, 37, 0, 28, 43, 15, 35, 30, 17, 51, 106 0x70, 0x70, 0xf0, 0xf0, 0x72, 0x72, 0xf2, 0xf2,
218 107 0x74, 0x74, 0xf4, 0xf4, 0x76, 0x76, 0xf6, 0xf6,
219 54, 33, 25, 41, 38, 13, 27, 4, 6, 48, 53, 40, 108 0x78, 0x78, 0xf8, 0xf8, 0x7a, 0x7a, 0xfa, 0xfa,
220 36, 3, 21, 15, 16, 24, 37, 28, 9, 17, 22, 43, 109 0x7c, 0x7c, 0xfc, 0xfc, 0x7e, 0x7e, 0xfe, 0xfe
221 5, 11, 26, 46, 34, 52, 19, 20, 32, 47, 55, 31,
222 23, 8, 50, 51, 14, 42, 2, 29, 49, 44, 0, 10,
223
224 11, 47, 39, 55, 52, 27, 41, 18, 20, 5, 38, 54,
225 50, 17, 35, 29, 30, 7, 51, 42, 23, 0, 36, 2,
226 19, 25, 40, 31, 48, 13, 33, 34, 46, 4, 12, 45,
227 37, 22, 9, 10, 28, 1, 16, 43, 8, 3, 14, 24,
228
229 18, 54, 46, 5, 6, 34, 48, 25, 27, 12, 45, 4,
230 2, 24, 42, 36, 37, 14, 3, 49, 30, 7, 43, 9,
231 26, 32, 47, 38, 55, 20, 40, 41, 53, 11, 19, 52,
232 44, 29, 16, 17, 35, 8, 23, 50, 15, 10, 21, 0,
233
234 32, 11, 31, 19, 20, 48, 5, 39, 41, 26, 6, 18,
235 16, 7, 1, 50, 51, 28, 17, 8, 44, 21, 2, 23,
236 40, 46, 4, 52, 12, 34, 54, 55, 38, 25, 33, 13,
237 3, 43, 30, 0, 49, 22, 37, 9, 29, 24, 35, 14,
238
239 46, 25, 45, 33, 34, 5, 19, 53, 55, 40, 20, 32,
240 30, 21, 15, 9, 10, 42, 0, 22, 3, 35, 16, 37,
241 54, 31, 18, 13, 26, 48, 11, 12, 52, 39, 47, 27,
242 17, 2, 44, 14, 8, 36, 51, 23, 43, 7, 49, 28,
243
244 31, 39, 6, 47, 48, 19, 33, 38, 12, 54, 34, 46,
245 44, 35, 29, 23, 24, 1, 14, 36, 17, 49, 30, 51,
246 11, 45, 32, 27, 40, 5, 25, 26, 13, 53, 4, 41,
247 0, 16, 3, 28, 22, 50, 10, 37, 2, 21, 8, 42,
248
249 45, 53, 20, 4, 5, 33, 47, 52, 26, 11, 48, 31,
250 3, 49, 43, 37, 7, 15, 28, 50, 0, 8, 44, 10,
251 25, 6, 46, 41, 54, 19, 39, 40, 27, 38, 18, 55,
252 14, 30, 17, 42, 36, 9, 24, 51, 16, 35, 22, 1,
253
254 6, 38, 34, 18, 19, 47, 4, 13, 40, 25, 5, 45,
255 17, 8, 2, 51, 21, 29, 42, 9, 14, 22, 3, 24,
256 39, 20, 31, 55, 11, 33, 53, 54, 41, 52, 32, 12,
257 28, 44, 0, 1, 50, 23, 7, 10, 30, 49, 36, 15,
258
259 20, 52, 48, 32, 33, 4, 18, 27, 54, 39, 19, 6,
260 0, 22, 16, 10, 35, 43, 1, 23, 28, 36, 17, 7,
261 53, 34, 45, 12, 25, 47, 38, 11, 55, 13, 46, 26,
262 42, 3, 14, 15, 9, 37, 21, 24, 44, 8, 50, 29,
263
264 27, 6, 55, 39, 40, 11, 25, 34, 4, 46, 26, 13,
265 7, 29, 23, 17, 42, 50, 8, 30, 35, 43, 24, 14,
266 31, 41, 52, 19, 32, 54, 45, 18, 5, 20, 53, 33,
267 49, 10, 21, 22, 16, 44, 28, 0, 51, 15, 2, 36,
268}; 110};
269 111
270static const u8 parity[] = { 112static const u32 pc2[1024] = {
271 8,1,0,8,0,8,8,0,0,8,8,0,8,0,2,8,0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,3, 113 0x00000000, 0x00000000, 0x00000000, 0x00000000,
272 0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8, 114 0x00040000, 0x00000000, 0x04000000, 0x00100000,
273 0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8, 115 0x00400000, 0x00000008, 0x00000800, 0x40000000,
274 8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8,0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0, 116 0x00440000, 0x00000008, 0x04000800, 0x40100000,
275 0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8, 117 0x00000400, 0x00000020, 0x08000000, 0x00000100,
276 8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8,0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0, 118 0x00040400, 0x00000020, 0x0c000000, 0x00100100,
277 8,0,0,8,0,8,8,0,0,8,8,0,8,0,0,8,0,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0, 119 0x00400400, 0x00000028, 0x08000800, 0x40000100,
278 4,8,8,0,8,0,0,8,8,0,0,8,0,8,8,0,8,5,0,8,0,8,8,0,0,8,8,0,8,0,6,8, 120 0x00440400, 0x00000028, 0x0c000800, 0x40100100,
121 0x80000000, 0x00000010, 0x00000000, 0x00800000,
122 0x80040000, 0x00000010, 0x04000000, 0x00900000,
123 0x80400000, 0x00000018, 0x00000800, 0x40800000,
124 0x80440000, 0x00000018, 0x04000800, 0x40900000,
125 0x80000400, 0x00000030, 0x08000000, 0x00800100,
126 0x80040400, 0x00000030, 0x0c000000, 0x00900100,
127 0x80400400, 0x00000038, 0x08000800, 0x40800100,
128 0x80440400, 0x00000038, 0x0c000800, 0x40900100,
129 0x10000000, 0x00000000, 0x00200000, 0x00001000,
130 0x10040000, 0x00000000, 0x04200000, 0x00101000,
131 0x10400000, 0x00000008, 0x00200800, 0x40001000,
132 0x10440000, 0x00000008, 0x04200800, 0x40101000,
133 0x10000400, 0x00000020, 0x08200000, 0x00001100,
134 0x10040400, 0x00000020, 0x0c200000, 0x00101100,
135 0x10400400, 0x00000028, 0x08200800, 0x40001100,
136 0x10440400, 0x00000028, 0x0c200800, 0x40101100,
137 0x90000000, 0x00000010, 0x00200000, 0x00801000,
138 0x90040000, 0x00000010, 0x04200000, 0x00901000,
139 0x90400000, 0x00000018, 0x00200800, 0x40801000,
140 0x90440000, 0x00000018, 0x04200800, 0x40901000,
141 0x90000400, 0x00000030, 0x08200000, 0x00801100,
142 0x90040400, 0x00000030, 0x0c200000, 0x00901100,
143 0x90400400, 0x00000038, 0x08200800, 0x40801100,
144 0x90440400, 0x00000038, 0x0c200800, 0x40901100,
145 0x00000200, 0x00080000, 0x00000000, 0x00000004,
146 0x00040200, 0x00080000, 0x04000000, 0x00100004,
147 0x00400200, 0x00080008, 0x00000800, 0x40000004,
148 0x00440200, 0x00080008, 0x04000800, 0x40100004,
149 0x00000600, 0x00080020, 0x08000000, 0x00000104,
150 0x00040600, 0x00080020, 0x0c000000, 0x00100104,
151 0x00400600, 0x00080028, 0x08000800, 0x40000104,
152 0x00440600, 0x00080028, 0x0c000800, 0x40100104,
153 0x80000200, 0x00080010, 0x00000000, 0x00800004,
154 0x80040200, 0x00080010, 0x04000000, 0x00900004,
155 0x80400200, 0x00080018, 0x00000800, 0x40800004,
156 0x80440200, 0x00080018, 0x04000800, 0x40900004,
157 0x80000600, 0x00080030, 0x08000000, 0x00800104,
158 0x80040600, 0x00080030, 0x0c000000, 0x00900104,
159 0x80400600, 0x00080038, 0x08000800, 0x40800104,
160 0x80440600, 0x00080038, 0x0c000800, 0x40900104,
161 0x10000200, 0x00080000, 0x00200000, 0x00001004,
162 0x10040200, 0x00080000, 0x04200000, 0x00101004,
163 0x10400200, 0x00080008, 0x00200800, 0x40001004,
164 0x10440200, 0x00080008, 0x04200800, 0x40101004,
165 0x10000600, 0x00080020, 0x08200000, 0x00001104,
166 0x10040600, 0x00080020, 0x0c200000, 0x00101104,
167 0x10400600, 0x00080028, 0x08200800, 0x40001104,
168 0x10440600, 0x00080028, 0x0c200800, 0x40101104,
169 0x90000200, 0x00080010, 0x00200000, 0x00801004,
170 0x90040200, 0x00080010, 0x04200000, 0x00901004,
171 0x90400200, 0x00080018, 0x00200800, 0x40801004,
172 0x90440200, 0x00080018, 0x04200800, 0x40901004,
173 0x90000600, 0x00080030, 0x08200000, 0x00801104,
174 0x90040600, 0x00080030, 0x0c200000, 0x00901104,
175 0x90400600, 0x00080038, 0x08200800, 0x40801104,
176 0x90440600, 0x00080038, 0x0c200800, 0x40901104,
177 0x00000002, 0x00002000, 0x20000000, 0x00000001,
178 0x00040002, 0x00002000, 0x24000000, 0x00100001,
179 0x00400002, 0x00002008, 0x20000800, 0x40000001,
180 0x00440002, 0x00002008, 0x24000800, 0x40100001,
181 0x00000402, 0x00002020, 0x28000000, 0x00000101,
182 0x00040402, 0x00002020, 0x2c000000, 0x00100101,
183 0x00400402, 0x00002028, 0x28000800, 0x40000101,
184 0x00440402, 0x00002028, 0x2c000800, 0x40100101,
185 0x80000002, 0x00002010, 0x20000000, 0x00800001,
186 0x80040002, 0x00002010, 0x24000000, 0x00900001,
187 0x80400002, 0x00002018, 0x20000800, 0x40800001,
188 0x80440002, 0x00002018, 0x24000800, 0x40900001,
189 0x80000402, 0x00002030, 0x28000000, 0x00800101,
190 0x80040402, 0x00002030, 0x2c000000, 0x00900101,
191 0x80400402, 0x00002038, 0x28000800, 0x40800101,
192 0x80440402, 0x00002038, 0x2c000800, 0x40900101,
193 0x10000002, 0x00002000, 0x20200000, 0x00001001,
194 0x10040002, 0x00002000, 0x24200000, 0x00101001,
195 0x10400002, 0x00002008, 0x20200800, 0x40001001,
196 0x10440002, 0x00002008, 0x24200800, 0x40101001,
197 0x10000402, 0x00002020, 0x28200000, 0x00001101,
198 0x10040402, 0x00002020, 0x2c200000, 0x00101101,
199 0x10400402, 0x00002028, 0x28200800, 0x40001101,
200 0x10440402, 0x00002028, 0x2c200800, 0x40101101,
201 0x90000002, 0x00002010, 0x20200000, 0x00801001,
202 0x90040002, 0x00002010, 0x24200000, 0x00901001,
203 0x90400002, 0x00002018, 0x20200800, 0x40801001,
204 0x90440002, 0x00002018, 0x24200800, 0x40901001,
205 0x90000402, 0x00002030, 0x28200000, 0x00801101,
206 0x90040402, 0x00002030, 0x2c200000, 0x00901101,
207 0x90400402, 0x00002038, 0x28200800, 0x40801101,
208 0x90440402, 0x00002038, 0x2c200800, 0x40901101,
209 0x00000202, 0x00082000, 0x20000000, 0x00000005,
210 0x00040202, 0x00082000, 0x24000000, 0x00100005,
211 0x00400202, 0x00082008, 0x20000800, 0x40000005,
212 0x00440202, 0x00082008, 0x24000800, 0x40100005,
213 0x00000602, 0x00082020, 0x28000000, 0x00000105,
214 0x00040602, 0x00082020, 0x2c000000, 0x00100105,
215 0x00400602, 0x00082028, 0x28000800, 0x40000105,
216 0x00440602, 0x00082028, 0x2c000800, 0x40100105,
217 0x80000202, 0x00082010, 0x20000000, 0x00800005,
218 0x80040202, 0x00082010, 0x24000000, 0x00900005,
219 0x80400202, 0x00082018, 0x20000800, 0x40800005,
220 0x80440202, 0x00082018, 0x24000800, 0x40900005,
221 0x80000602, 0x00082030, 0x28000000, 0x00800105,
222 0x80040602, 0x00082030, 0x2c000000, 0x00900105,
223 0x80400602, 0x00082038, 0x28000800, 0x40800105,
224 0x80440602, 0x00082038, 0x2c000800, 0x40900105,
225 0x10000202, 0x00082000, 0x20200000, 0x00001005,
226 0x10040202, 0x00082000, 0x24200000, 0x00101005,
227 0x10400202, 0x00082008, 0x20200800, 0x40001005,
228 0x10440202, 0x00082008, 0x24200800, 0x40101005,
229 0x10000602, 0x00082020, 0x28200000, 0x00001105,
230 0x10040602, 0x00082020, 0x2c200000, 0x00101105,
231 0x10400602, 0x00082028, 0x28200800, 0x40001105,
232 0x10440602, 0x00082028, 0x2c200800, 0x40101105,
233 0x90000202, 0x00082010, 0x20200000, 0x00801005,
234 0x90040202, 0x00082010, 0x24200000, 0x00901005,
235 0x90400202, 0x00082018, 0x20200800, 0x40801005,
236 0x90440202, 0x00082018, 0x24200800, 0x40901005,
237 0x90000602, 0x00082030, 0x28200000, 0x00801105,
238 0x90040602, 0x00082030, 0x2c200000, 0x00901105,
239 0x90400602, 0x00082038, 0x28200800, 0x40801105,
240 0x90440602, 0x00082038, 0x2c200800, 0x40901105,
241
242 0x00000000, 0x00000000, 0x00000000, 0x00000000,
243 0x00000000, 0x00000008, 0x00080000, 0x10000000,
244 0x02000000, 0x00000000, 0x00000080, 0x00001000,
245 0x02000000, 0x00000008, 0x00080080, 0x10001000,
246 0x00004000, 0x00000000, 0x00000040, 0x00040000,
247 0x00004000, 0x00000008, 0x00080040, 0x10040000,
248 0x02004000, 0x00000000, 0x000000c0, 0x00041000,
249 0x02004000, 0x00000008, 0x000800c0, 0x10041000,
250 0x00020000, 0x00008000, 0x08000000, 0x00200000,
251 0x00020000, 0x00008008, 0x08080000, 0x10200000,
252 0x02020000, 0x00008000, 0x08000080, 0x00201000,
253 0x02020000, 0x00008008, 0x08080080, 0x10201000,
254 0x00024000, 0x00008000, 0x08000040, 0x00240000,
255 0x00024000, 0x00008008, 0x08080040, 0x10240000,
256 0x02024000, 0x00008000, 0x080000c0, 0x00241000,
257 0x02024000, 0x00008008, 0x080800c0, 0x10241000,
258 0x00000000, 0x01000000, 0x00002000, 0x00000020,
259 0x00000000, 0x01000008, 0x00082000, 0x10000020,
260 0x02000000, 0x01000000, 0x00002080, 0x00001020,
261 0x02000000, 0x01000008, 0x00082080, 0x10001020,
262 0x00004000, 0x01000000, 0x00002040, 0x00040020,
263 0x00004000, 0x01000008, 0x00082040, 0x10040020,
264 0x02004000, 0x01000000, 0x000020c0, 0x00041020,
265 0x02004000, 0x01000008, 0x000820c0, 0x10041020,
266 0x00020000, 0x01008000, 0x08002000, 0x00200020,
267 0x00020000, 0x01008008, 0x08082000, 0x10200020,
268 0x02020000, 0x01008000, 0x08002080, 0x00201020,
269 0x02020000, 0x01008008, 0x08082080, 0x10201020,
270 0x00024000, 0x01008000, 0x08002040, 0x00240020,
271 0x00024000, 0x01008008, 0x08082040, 0x10240020,
272 0x02024000, 0x01008000, 0x080020c0, 0x00241020,
273 0x02024000, 0x01008008, 0x080820c0, 0x10241020,
274 0x00000400, 0x04000000, 0x00100000, 0x00000004,
275 0x00000400, 0x04000008, 0x00180000, 0x10000004,
276 0x02000400, 0x04000000, 0x00100080, 0x00001004,
277 0x02000400, 0x04000008, 0x00180080, 0x10001004,
278 0x00004400, 0x04000000, 0x00100040, 0x00040004,
279 0x00004400, 0x04000008, 0x00180040, 0x10040004,
280 0x02004400, 0x04000000, 0x001000c0, 0x00041004,
281 0x02004400, 0x04000008, 0x001800c0, 0x10041004,
282 0x00020400, 0x04008000, 0x08100000, 0x00200004,
283 0x00020400, 0x04008008, 0x08180000, 0x10200004,
284 0x02020400, 0x04008000, 0x08100080, 0x00201004,
285 0x02020400, 0x04008008, 0x08180080, 0x10201004,
286 0x00024400, 0x04008000, 0x08100040, 0x00240004,
287 0x00024400, 0x04008008, 0x08180040, 0x10240004,
288 0x02024400, 0x04008000, 0x081000c0, 0x00241004,
289 0x02024400, 0x04008008, 0x081800c0, 0x10241004,
290 0x00000400, 0x05000000, 0x00102000, 0x00000024,
291 0x00000400, 0x05000008, 0x00182000, 0x10000024,
292 0x02000400, 0x05000000, 0x00102080, 0x00001024,
293 0x02000400, 0x05000008, 0x00182080, 0x10001024,
294 0x00004400, 0x05000000, 0x00102040, 0x00040024,
295 0x00004400, 0x05000008, 0x00182040, 0x10040024,
296 0x02004400, 0x05000000, 0x001020c0, 0x00041024,
297 0x02004400, 0x05000008, 0x001820c0, 0x10041024,
298 0x00020400, 0x05008000, 0x08102000, 0x00200024,
299 0x00020400, 0x05008008, 0x08182000, 0x10200024,
300 0x02020400, 0x05008000, 0x08102080, 0x00201024,
301 0x02020400, 0x05008008, 0x08182080, 0x10201024,
302 0x00024400, 0x05008000, 0x08102040, 0x00240024,
303 0x00024400, 0x05008008, 0x08182040, 0x10240024,
304 0x02024400, 0x05008000, 0x081020c0, 0x00241024,
305 0x02024400, 0x05008008, 0x081820c0, 0x10241024,
306 0x00000800, 0x00010000, 0x20000000, 0x00000010,
307 0x00000800, 0x00010008, 0x20080000, 0x10000010,
308 0x02000800, 0x00010000, 0x20000080, 0x00001010,
309 0x02000800, 0x00010008, 0x20080080, 0x10001010,
310 0x00004800, 0x00010000, 0x20000040, 0x00040010,
311 0x00004800, 0x00010008, 0x20080040, 0x10040010,
312 0x02004800, 0x00010000, 0x200000c0, 0x00041010,
313 0x02004800, 0x00010008, 0x200800c0, 0x10041010,
314 0x00020800, 0x00018000, 0x28000000, 0x00200010,
315 0x00020800, 0x00018008, 0x28080000, 0x10200010,
316 0x02020800, 0x00018000, 0x28000080, 0x00201010,
317 0x02020800, 0x00018008, 0x28080080, 0x10201010,
318 0x00024800, 0x00018000, 0x28000040, 0x00240010,
319 0x00024800, 0x00018008, 0x28080040, 0x10240010,
320 0x02024800, 0x00018000, 0x280000c0, 0x00241010,
321 0x02024800, 0x00018008, 0x280800c0, 0x10241010,
322 0x00000800, 0x01010000, 0x20002000, 0x00000030,
323 0x00000800, 0x01010008, 0x20082000, 0x10000030,
324 0x02000800, 0x01010000, 0x20002080, 0x00001030,
325 0x02000800, 0x01010008, 0x20082080, 0x10001030,
326 0x00004800, 0x01010000, 0x20002040, 0x00040030,
327 0x00004800, 0x01010008, 0x20082040, 0x10040030,
328 0x02004800, 0x01010000, 0x200020c0, 0x00041030,
329 0x02004800, 0x01010008, 0x200820c0, 0x10041030,
330 0x00020800, 0x01018000, 0x28002000, 0x00200030,
331 0x00020800, 0x01018008, 0x28082000, 0x10200030,
332 0x02020800, 0x01018000, 0x28002080, 0x00201030,
333 0x02020800, 0x01018008, 0x28082080, 0x10201030,
334 0x00024800, 0x01018000, 0x28002040, 0x00240030,
335 0x00024800, 0x01018008, 0x28082040, 0x10240030,
336 0x02024800, 0x01018000, 0x280020c0, 0x00241030,
337 0x02024800, 0x01018008, 0x280820c0, 0x10241030,
338 0x00000c00, 0x04010000, 0x20100000, 0x00000014,
339 0x00000c00, 0x04010008, 0x20180000, 0x10000014,
340 0x02000c00, 0x04010000, 0x20100080, 0x00001014,
341 0x02000c00, 0x04010008, 0x20180080, 0x10001014,
342 0x00004c00, 0x04010000, 0x20100040, 0x00040014,
343 0x00004c00, 0x04010008, 0x20180040, 0x10040014,
344 0x02004c00, 0x04010000, 0x201000c0, 0x00041014,
345 0x02004c00, 0x04010008, 0x201800c0, 0x10041014,
346 0x00020c00, 0x04018000, 0x28100000, 0x00200014,
347 0x00020c00, 0x04018008, 0x28180000, 0x10200014,
348 0x02020c00, 0x04018000, 0x28100080, 0x00201014,
349 0x02020c00, 0x04018008, 0x28180080, 0x10201014,
350 0x00024c00, 0x04018000, 0x28100040, 0x00240014,
351 0x00024c00, 0x04018008, 0x28180040, 0x10240014,
352 0x02024c00, 0x04018000, 0x281000c0, 0x00241014,
353 0x02024c00, 0x04018008, 0x281800c0, 0x10241014,
354 0x00000c00, 0x05010000, 0x20102000, 0x00000034,
355 0x00000c00, 0x05010008, 0x20182000, 0x10000034,
356 0x02000c00, 0x05010000, 0x20102080, 0x00001034,
357 0x02000c00, 0x05010008, 0x20182080, 0x10001034,
358 0x00004c00, 0x05010000, 0x20102040, 0x00040034,
359 0x00004c00, 0x05010008, 0x20182040, 0x10040034,
360 0x02004c00, 0x05010000, 0x201020c0, 0x00041034,
361 0x02004c00, 0x05010008, 0x201820c0, 0x10041034,
362 0x00020c00, 0x05018000, 0x28102000, 0x00200034,
363 0x00020c00, 0x05018008, 0x28182000, 0x10200034,
364 0x02020c00, 0x05018000, 0x28102080, 0x00201034,
365 0x02020c00, 0x05018008, 0x28182080, 0x10201034,
366 0x00024c00, 0x05018000, 0x28102040, 0x00240034,
367 0x00024c00, 0x05018008, 0x28182040, 0x10240034,
368 0x02024c00, 0x05018000, 0x281020c0, 0x00241034,
369 0x02024c00, 0x05018008, 0x281820c0, 0x10241034
279}; 370};
280 371
372/* S-box lookup tables */
373
374static const u32 S1[64] = {
375 0x01010400, 0x00000000, 0x00010000, 0x01010404,
376 0x01010004, 0x00010404, 0x00000004, 0x00010000,
377 0x00000400, 0x01010400, 0x01010404, 0x00000400,
378 0x01000404, 0x01010004, 0x01000000, 0x00000004,
379 0x00000404, 0x01000400, 0x01000400, 0x00010400,
380 0x00010400, 0x01010000, 0x01010000, 0x01000404,
381 0x00010004, 0x01000004, 0x01000004, 0x00010004,
382 0x00000000, 0x00000404, 0x00010404, 0x01000000,
383 0x00010000, 0x01010404, 0x00000004, 0x01010000,
384 0x01010400, 0x01000000, 0x01000000, 0x00000400,
385 0x01010004, 0x00010000, 0x00010400, 0x01000004,
386 0x00000400, 0x00000004, 0x01000404, 0x00010404,
387 0x01010404, 0x00010004, 0x01010000, 0x01000404,
388 0x01000004, 0x00000404, 0x00010404, 0x01010400,
389 0x00000404, 0x01000400, 0x01000400, 0x00000000,
390 0x00010004, 0x00010400, 0x00000000, 0x01010004
391};
281 392
282static void des_small_fips_encrypt(u32 *expkey, u8 *dst, const u8 *src) 393static const u32 S2[64] = {
283{ 394 0x80108020, 0x80008000, 0x00008000, 0x00108020,
284 u32 x, y, z; 395 0x00100000, 0x00000020, 0x80100020, 0x80008020,
285 396 0x80000020, 0x80108020, 0x80108000, 0x80000000,
286 x = src[7]; 397 0x80008000, 0x00100000, 0x00000020, 0x80100020,
287 x <<= 8; 398 0x00108000, 0x00100020, 0x80008020, 0x00000000,
288 x |= src[6]; 399 0x80000000, 0x00008000, 0x00108020, 0x80100000,
289 x <<= 8; 400 0x00100020, 0x80000020, 0x00000000, 0x00108000,
290 x |= src[5]; 401 0x00008020, 0x80108000, 0x80100000, 0x00008020,
291 x <<= 8; 402 0x00000000, 0x00108020, 0x80100020, 0x00100000,
292 x |= src[4]; 403 0x80008020, 0x80100000, 0x80108000, 0x00008000,
293 y = src[3]; 404 0x80100000, 0x80008000, 0x00000020, 0x80108020,
294 y <<= 8; 405 0x00108020, 0x00000020, 0x00008000, 0x80000000,
295 y |= src[2]; 406 0x00008020, 0x80108000, 0x00100000, 0x80000020,
296 y <<= 8; 407 0x00100020, 0x80008020, 0x80000020, 0x00100020,
297 y |= src[1]; 408 0x00108000, 0x00000000, 0x80008000, 0x00008020,
298 y <<= 8; 409 0x80000000, 0x80100020, 0x80108020, 0x00108000
299 y |= src[0]; 410};
300 z = ((x >> 004) ^ y) & 0x0F0F0F0FL;
301 x ^= z << 004;
302 y ^= z;
303 z = ((y >> 020) ^ x) & 0x0000FFFFL;
304 y ^= z << 020;
305 x ^= z;
306 z = ((x >> 002) ^ y) & 0x33333333L;
307 x ^= z << 002;
308 y ^= z;
309 z = ((y >> 010) ^ x) & 0x00FF00FFL;
310 y ^= z << 010;
311 x ^= z;
312 x = x >> 1 | x << 31;
313 z = (x ^ y) & 0x55555555L;
314 y ^= z;
315 x ^= z;
316 y = y >> 1 | y << 31;
317 z = expkey[0];
318 z ^= y;
319 x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z));
320 z >>= 8;
321 x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z));
322 z >>= 8;
323 x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z));
324 z >>= 8;
325 x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z));
326 z = expkey[1];
327 z ^= y;
328 z = z << 4 | z >> 28;
329 x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z));
330 z >>= 8;
331 x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z));
332 z >>= 8;
333 x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z));
334 z >>= 8;
335 x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z));
336 z = expkey[2];
337 z ^= x;
338 y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z));
339 z >>= 8;
340 y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z));
341 z >>= 8;
342 y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z));
343 z >>= 8;
344 y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z));
345 z = expkey[3];
346 z ^= x;
347 z = z << 4 | z >> 28;
348 y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z));
349 z >>= 8;
350 y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z));
351 z >>= 8;
352 y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z));
353 z >>= 8;
354 y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z));
355 z = expkey[4];
356 z ^= y;
357 x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z));
358 z >>= 8;
359 x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z));
360 z >>= 8;
361 x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z));
362 z >>= 8;
363 x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z));
364 z = expkey[5];
365 z ^= y;
366 z = z << 4 | z >> 28;
367 x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z));
368 z >>= 8;
369 x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z));
370 z >>= 8;
371 x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z));
372 z >>= 8;
373 x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z));
374 z = expkey[6];
375 z ^= x;
376 y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z));
377 z >>= 8;
378 y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z));
379 z >>= 8;
380 y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z));
381 z >>= 8;
382 y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z));
383 z = expkey[7];
384 z ^= x;
385 z = z << 4 | z >> 28;
386 y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z));
387 z >>= 8;
388 y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z));
389 z >>= 8;
390 y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z));
391 z >>= 8;
392 y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z));
393 z = expkey[8];
394 z ^= y;
395 x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z));
396 z >>= 8;
397 x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z));
398 z >>= 8;
399 x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z));
400 z >>= 8;
401 x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z));
402 z = expkey[9];
403 z ^= y;
404 z = z << 4 | z >> 28;
405 x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z));
406 z >>= 8;
407 x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z));
408 z >>= 8;
409 x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z));
410 z >>= 8;
411 x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z));
412 z = expkey[10];
413 z ^= x;
414 y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z));
415 z >>= 8;
416 y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z));
417 z >>= 8;
418 y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z));
419 z >>= 8;
420 y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z));
421 z = expkey[11];
422 z ^= x;
423 z = z << 4 | z >> 28;
424 y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z));
425 z >>= 8;
426 y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z));
427 z >>= 8;
428 y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z));
429 z >>= 8;
430 y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z));
431 z = expkey[12];
432 z ^= y;
433 x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z));
434 z >>= 8;
435 x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z));
436 z >>= 8;
437 x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z));
438 z >>= 8;
439 x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z));
440 z = expkey[13];
441 z ^= y;
442 z = z << 4 | z >> 28;
443 x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z));
444 z >>= 8;
445 x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z));
446 z >>= 8;
447 x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z));
448 z >>= 8;
449 x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z));
450 z = expkey[14];
451 z ^= x;
452 y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z));
453 z >>= 8;
454 y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z));
455 z >>= 8;
456 y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z));
457 z >>= 8;
458 y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z));
459 z = expkey[15];
460 z ^= x;
461 z = z << 4 | z >> 28;
462 y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z));
463 z >>= 8;
464 y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z));
465 z >>= 8;
466 y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z));
467 z >>= 8;
468 y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z));
469 z = expkey[16];
470 z ^= y;
471 x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z));
472 z >>= 8;
473 x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z));
474 z >>= 8;
475 x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z));
476 z >>= 8;
477 x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z));
478 z = expkey[17];
479 z ^= y;
480 z = z << 4 | z >> 28;
481 x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z));
482 z >>= 8;
483 x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z));
484 z >>= 8;
485 x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z));
486 z >>= 8;
487 x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z));
488 z = expkey[18];
489 z ^= x;
490 y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z));
491 z >>= 8;
492 y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z));
493 z >>= 8;
494 y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z));
495 z >>= 8;
496 y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z));
497 z = expkey[19];
498 z ^= x;
499 z = z << 4 | z >> 28;
500 y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z));
501 z >>= 8;
502 y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z));
503 z >>= 8;
504 y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z));
505 z >>= 8;
506 y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z));
507 z = expkey[20];
508 z ^= y;
509 x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z));
510 z >>= 8;
511 x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z));
512 z >>= 8;
513 x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z));
514 z >>= 8;
515 x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z));
516 z = expkey[21];
517 z ^= y;
518 z = z << 4 | z >> 28;
519 x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z));
520 z >>= 8;
521 x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z));
522 z >>= 8;
523 x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z));
524 z >>= 8;
525 x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z));
526 z = expkey[22];
527 z ^= x;
528 y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z));
529 z >>= 8;
530 y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z));
531 z >>= 8;
532 y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z));
533 z >>= 8;
534 y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z));
535 z = expkey[23];
536 z ^= x;
537 z = z << 4 | z >> 28;
538 y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z));
539 z >>= 8;
540 y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z));
541 z >>= 8;
542 y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z));
543 z >>= 8;
544 y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z));
545 z = expkey[24];
546 z ^= y;
547 x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z));
548 z >>= 8;
549 x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z));
550 z >>= 8;
551 x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z));
552 z >>= 8;
553 x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z));
554 z = expkey[25];
555 z ^= y;
556 z = z << 4 | z >> 28;
557 x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z));
558 z >>= 8;
559 x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z));
560 z >>= 8;
561 x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z));
562 z >>= 8;
563 x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z));
564 z = expkey[26];
565 z ^= x;
566 y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z));
567 z >>= 8;
568 y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z));
569 z >>= 8;
570 y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z));
571 z >>= 8;
572 y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z));
573 z = expkey[27];
574 z ^= x;
575 z = z << 4 | z >> 28;
576 y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z));
577 z >>= 8;
578 y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z));
579 z >>= 8;
580 y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z));
581 z >>= 8;
582 y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z));
583 z = expkey[28];
584 z ^= y;
585 x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z));
586 z >>= 8;
587 x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z));
588 z >>= 8;
589 x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z));
590 z >>= 8;
591 x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z));
592 z = expkey[29];
593 z ^= y;
594 z = z << 4 | z >> 28;
595 x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z));
596 z >>= 8;
597 x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z));
598 z >>= 8;
599 x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z));
600 z >>= 8;
601 x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z));
602 z = expkey[30];
603 z ^= x;
604 y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z));
605 z >>= 8;
606 y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z));
607 z >>= 8;
608 y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z));
609 z >>= 8;
610 y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z));
611 z = expkey[31];
612 z ^= x;
613 z = z << 4 | z >> 28;
614 y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z));
615 z >>= 8;
616 y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z));
617 z >>= 8;
618 y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z));
619 z >>= 8;
620 y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z));
621 x = x << 1 | x >> 31;
622 z = (x ^ y) & 0x55555555L;
623 y ^= z;
624 x ^= z;
625 y = y << 1 | y >> 31;
626 z = ((x >> 010) ^ y) & 0x00FF00FFL;
627 x ^= z << 010;
628 y ^= z;
629 z = ((y >> 002) ^ x) & 0x33333333L;
630 y ^= z << 002;
631 x ^= z;
632 z = ((x >> 020) ^ y) & 0x0000FFFFL;
633 x ^= z << 020;
634 y ^= z;
635 z = ((y >> 004) ^ x) & 0x0F0F0F0FL;
636 y ^= z << 004;
637 x ^= z;
638 dst[0] = x;
639 x >>= 8;
640 dst[1] = x;
641 x >>= 8;
642 dst[2] = x;
643 x >>= 8;
644 dst[3] = x;
645 dst[4] = y;
646 y >>= 8;
647 dst[5] = y;
648 y >>= 8;
649 dst[6] = y;
650 y >>= 8;
651 dst[7] = y;
652}
653 411
654static void des_small_fips_decrypt(u32 *expkey, u8 *dst, const u8 *src) 412static const u32 S3[64] = {
655{ 413 0x00000208, 0x08020200, 0x00000000, 0x08020008,
656 u32 x, y, z; 414 0x08000200, 0x00000000, 0x00020208, 0x08000200,
657 415 0x00020008, 0x08000008, 0x08000008, 0x00020000,
658 x = src[7]; 416 0x08020208, 0x00020008, 0x08020000, 0x00000208,
659 x <<= 8; 417 0x08000000, 0x00000008, 0x08020200, 0x00000200,
660 x |= src[6]; 418 0x00020200, 0x08020000, 0x08020008, 0x00020208,
661 x <<= 8; 419 0x08000208, 0x00020200, 0x00020000, 0x08000208,
662 x |= src[5]; 420 0x00000008, 0x08020208, 0x00000200, 0x08000000,
663 x <<= 8; 421 0x08020200, 0x08000000, 0x00020008, 0x00000208,
664 x |= src[4]; 422 0x00020000, 0x08020200, 0x08000200, 0x00000000,
665 y = src[3]; 423 0x00000200, 0x00020008, 0x08020208, 0x08000200,
666 y <<= 8; 424 0x08000008, 0x00000200, 0x00000000, 0x08020008,
667 y |= src[2]; 425 0x08000208, 0x00020000, 0x08000000, 0x08020208,
668 y <<= 8; 426 0x00000008, 0x00020208, 0x00020200, 0x08000008,
669 y |= src[1]; 427 0x08020000, 0x08000208, 0x00000208, 0x08020000,
670 y <<= 8; 428 0x00020208, 0x00000008, 0x08020008, 0x00020200
671 y |= src[0]; 429};
672 z = ((x >> 004) ^ y) & 0x0F0F0F0FL; 430
673 x ^= z << 004; 431static const u32 S4[64] = {
674 y ^= z; 432 0x00802001, 0x00002081, 0x00002081, 0x00000080,
675 z = ((y >> 020) ^ x) & 0x0000FFFFL; 433 0x00802080, 0x00800081, 0x00800001, 0x00002001,
676 y ^= z << 020; 434 0x00000000, 0x00802000, 0x00802000, 0x00802081,
677 x ^= z; 435 0x00000081, 0x00000000, 0x00800080, 0x00800001,
678 z = ((x >> 002) ^ y) & 0x33333333L; 436 0x00000001, 0x00002000, 0x00800000, 0x00802001,
679 x ^= z << 002; 437 0x00000080, 0x00800000, 0x00002001, 0x00002080,
680 y ^= z; 438 0x00800081, 0x00000001, 0x00002080, 0x00800080,
681 z = ((y >> 010) ^ x) & 0x00FF00FFL; 439 0x00002000, 0x00802080, 0x00802081, 0x00000081,
682 y ^= z << 010; 440 0x00800080, 0x00800001, 0x00802000, 0x00802081,
683 x ^= z; 441 0x00000081, 0x00000000, 0x00000000, 0x00802000,
684 x = x >> 1 | x << 31; 442 0x00002080, 0x00800080, 0x00800081, 0x00000001,
685 z = (x ^ y) & 0x55555555L; 443 0x00802001, 0x00002081, 0x00002081, 0x00000080,
686 y ^= z; 444 0x00802081, 0x00000081, 0x00000001, 0x00002000,
687 x ^= z; 445 0x00800001, 0x00002001, 0x00802080, 0x00800081,
688 y = y >> 1 | y << 31; 446 0x00002001, 0x00002080, 0x00800000, 0x00802001,
689 z = expkey[31]; 447 0x00000080, 0x00800000, 0x00002000, 0x00802080
690 z ^= y; 448};
691 z = z << 4 | z >> 28; 449
692 x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); 450static const u32 S5[64] = {
693 z >>= 8; 451 0x00000100, 0x02080100, 0x02080000, 0x42000100,
694 x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); 452 0x00080000, 0x00000100, 0x40000000, 0x02080000,
695 z >>= 8; 453 0x40080100, 0x00080000, 0x02000100, 0x40080100,
696 x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); 454 0x42000100, 0x42080000, 0x00080100, 0x40000000,
697 z >>= 8; 455 0x02000000, 0x40080000, 0x40080000, 0x00000000,
698 x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); 456 0x40000100, 0x42080100, 0x42080100, 0x02000100,
699 z = expkey[30]; 457 0x42080000, 0x40000100, 0x00000000, 0x42000000,
700 z ^= y; 458 0x02080100, 0x02000000, 0x42000000, 0x00080100,
701 x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); 459 0x00080000, 0x42000100, 0x00000100, 0x02000000,
702 z >>= 8; 460 0x40000000, 0x02080000, 0x42000100, 0x40080100,
703 x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); 461 0x02000100, 0x40000000, 0x42080000, 0x02080100,
704 z >>= 8; 462 0x40080100, 0x00000100, 0x02000000, 0x42080000,
705 x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); 463 0x42080100, 0x00080100, 0x42000000, 0x42080100,
706 z >>= 8; 464 0x02080000, 0x00000000, 0x40080000, 0x42000000,
707 x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); 465 0x00080100, 0x02000100, 0x40000100, 0x00080000,
708 z = expkey[29]; 466 0x00000000, 0x40080000, 0x02080100, 0x40000100
709 z ^= x; 467};
710 z = z << 4 | z >> 28; 468
711 y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); 469static const u32 S6[64] = {
712 z >>= 8; 470 0x20000010, 0x20400000, 0x00004000, 0x20404010,
713 y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); 471 0x20400000, 0x00000010, 0x20404010, 0x00400000,
714 z >>= 8; 472 0x20004000, 0x00404010, 0x00400000, 0x20000010,
715 y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); 473 0x00400010, 0x20004000, 0x20000000, 0x00004010,
716 z >>= 8; 474 0x00000000, 0x00400010, 0x20004010, 0x00004000,
717 y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); 475 0x00404000, 0x20004010, 0x00000010, 0x20400010,
718 z = expkey[28]; 476 0x20400010, 0x00000000, 0x00404010, 0x20404000,
719 z ^= x; 477 0x00004010, 0x00404000, 0x20404000, 0x20000000,
720 y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); 478 0x20004000, 0x00000010, 0x20400010, 0x00404000,
721 z >>= 8; 479 0x20404010, 0x00400000, 0x00004010, 0x20000010,
722 y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); 480 0x00400000, 0x20004000, 0x20000000, 0x00004010,
723 z >>= 8; 481 0x20000010, 0x20404010, 0x00404000, 0x20400000,
724 y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); 482 0x00404010, 0x20404000, 0x00000000, 0x20400010,
725 z >>= 8; 483 0x00000010, 0x00004000, 0x20400000, 0x00404010,
726 y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); 484 0x00004000, 0x00400010, 0x20004010, 0x00000000,
727 z = expkey[27]; 485 0x20404000, 0x20000000, 0x00400010, 0x20004010
728 z ^= y; 486};
729 z = z << 4 | z >> 28; 487
730 x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); 488static const u32 S7[64] = {
731 z >>= 8; 489 0x00200000, 0x04200002, 0x04000802, 0x00000000,
732 x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); 490 0x00000800, 0x04000802, 0x00200802, 0x04200800,
733 z >>= 8; 491 0x04200802, 0x00200000, 0x00000000, 0x04000002,
734 x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); 492 0x00000002, 0x04000000, 0x04200002, 0x00000802,
735 z >>= 8; 493 0x04000800, 0x00200802, 0x00200002, 0x04000800,
736 x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); 494 0x04000002, 0x04200000, 0x04200800, 0x00200002,
737 z = expkey[26]; 495 0x04200000, 0x00000800, 0x00000802, 0x04200802,
738 z ^= y; 496 0x00200800, 0x00000002, 0x04000000, 0x00200800,
739 x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); 497 0x04000000, 0x00200800, 0x00200000, 0x04000802,
740 z >>= 8; 498 0x04000802, 0x04200002, 0x04200002, 0x00000002,
741 x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); 499 0x00200002, 0x04000000, 0x04000800, 0x00200000,
742 z >>= 8; 500 0x04200800, 0x00000802, 0x00200802, 0x04200800,
743 x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); 501 0x00000802, 0x04000002, 0x04200802, 0x04200000,
744 z >>= 8; 502 0x00200800, 0x00000000, 0x00000002, 0x04200802,
745 x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); 503 0x00000000, 0x00200802, 0x04200000, 0x00000800,
746 z = expkey[25]; 504 0x04000002, 0x04000800, 0x00000800, 0x00200002
747 z ^= x; 505};
748 z = z << 4 | z >> 28; 506
749 y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); 507static const u32 S8[64] = {
750 z >>= 8; 508 0x10001040, 0x00001000, 0x00040000, 0x10041040,
751 y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); 509 0x10000000, 0x10001040, 0x00000040, 0x10000000,
752 z >>= 8; 510 0x00040040, 0x10040000, 0x10041040, 0x00041000,
753 y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); 511 0x10041000, 0x00041040, 0x00001000, 0x00000040,
754 z >>= 8; 512 0x10040000, 0x10000040, 0x10001000, 0x00001040,
755 y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); 513 0x00041000, 0x00040040, 0x10040040, 0x10041000,
756 z = expkey[24]; 514 0x00001040, 0x00000000, 0x00000000, 0x10040040,
757 z ^= x; 515 0x10000040, 0x10001000, 0x00041040, 0x00040000,
758 y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); 516 0x00041040, 0x00040000, 0x10041000, 0x00001000,
759 z >>= 8; 517 0x00000040, 0x10040040, 0x00001000, 0x00041040,
760 y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); 518 0x10001000, 0x00000040, 0x10000040, 0x10040000,
761 z >>= 8; 519 0x10040040, 0x10000000, 0x00040000, 0x10001040,
762 y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); 520 0x00000000, 0x10041040, 0x00040040, 0x10000040,
763 z >>= 8; 521 0x10040000, 0x10001000, 0x10001040, 0x00000000,
764 y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); 522 0x10041040, 0x00041000, 0x00041000, 0x00001040,
765 z = expkey[23]; 523 0x00001040, 0x00040040, 0x10000000, 0x10041000
766 z ^= y; 524};
767 z = z << 4 | z >> 28; 525
768 x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); 526/* Encryption components: IP, FP, and round function */
769 z >>= 8; 527
770 x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); 528#define IP(L, R, T) \
771 z >>= 8; 529 ROL(R, 4); \
772 x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); 530 T = L; \
773 z >>= 8; 531 L ^= R; \
774 x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); 532 L &= 0xf0f0f0f0; \
775 z = expkey[22]; 533 R ^= L; \
776 z ^= y; 534 L ^= T; \
777 x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); 535 ROL(R, 12); \
778 z >>= 8; 536 T = L; \
779 x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); 537 L ^= R; \
780 z >>= 8; 538 L &= 0xffff0000; \
781 x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); 539 R ^= L; \
782 z >>= 8; 540 L ^= T; \
783 x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); 541 ROR(R, 14); \
784 z = expkey[21]; 542 T = L; \
785 z ^= x; 543 L ^= R; \
786 z = z << 4 | z >> 28; 544 L &= 0xcccccccc; \
787 y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); 545 R ^= L; \
788 z >>= 8; 546 L ^= T; \
789 y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); 547 ROL(R, 6); \
790 z >>= 8; 548 T = L; \
791 y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); 549 L ^= R; \
792 z >>= 8; 550 L &= 0xff00ff00; \
793 y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); 551 R ^= L; \
794 z = expkey[20]; 552 L ^= T; \
795 z ^= x; 553 ROR(R, 7); \
796 y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); 554 T = L; \
797 z >>= 8; 555 L ^= R; \
798 y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); 556 L &= 0xaaaaaaaa; \
799 z >>= 8; 557 R ^= L; \
800 y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); 558 L ^= T; \
801 z >>= 8; 559 ROL(L, 1);
802 y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); 560
803 z = expkey[19]; 561#define FP(L, R, T) \
804 z ^= y; 562 ROR(L, 1); \
805 z = z << 4 | z >> 28; 563 T = L; \
806 x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); 564 L ^= R; \
807 z >>= 8; 565 L &= 0xaaaaaaaa; \
808 x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); 566 R ^= L; \
809 z >>= 8; 567 L ^= T; \
810 x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); 568 ROL(R, 7); \
811 z >>= 8; 569 T = L; \
812 x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); 570 L ^= R; \
813 z = expkey[18]; 571 L &= 0xff00ff00; \
814 z ^= y; 572 R ^= L; \
815 x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); 573 L ^= T; \
816 z >>= 8; 574 ROR(R, 6); \
817 x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); 575 T = L; \
818 z >>= 8; 576 L ^= R; \
819 x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); 577 L &= 0xcccccccc; \
820 z >>= 8; 578 R ^= L; \
821 x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); 579 L ^= T; \
822 z = expkey[17]; 580 ROL(R, 14); \
823 z ^= x; 581 T = L; \
824 z = z << 4 | z >> 28; 582 L ^= R; \
825 y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); 583 L &= 0xffff0000; \
826 z >>= 8; 584 R ^= L; \
827 y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); 585 L ^= T; \
828 z >>= 8; 586 ROR(R, 12); \
829 y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); 587 T = L; \
830 z >>= 8; 588 L ^= R; \
831 y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); 589 L &= 0xf0f0f0f0; \
832 z = expkey[16]; 590 R ^= L; \
833 z ^= x; 591 L ^= T; \
834 y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); 592 ROR(R, 4);
835 z >>= 8; 593
836 y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); 594#define ROUND(L, R, A, B, K, d) \
837 z >>= 8; 595 B = K[0]; A = K[1]; K += d; \
838 y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); 596 B ^= R; A ^= R; \
839 z >>= 8; 597 B &= 0x3f3f3f3f; ROR(A, 4); \
840 y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); 598 L ^= S8[0xff & B]; A &= 0x3f3f3f3f; \
841 z = expkey[15]; 599 L ^= S6[0xff & (B >> 8)]; B >>= 16; \
842 z ^= y; 600 L ^= S7[0xff & A]; \
843 z = z << 4 | z >> 28; 601 L ^= S5[0xff & (A >> 8)]; A >>= 16; \
844 x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); 602 L ^= S4[0xff & B]; \
845 z >>= 8; 603 L ^= S2[0xff & (B >> 8)]; \
846 x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z)); 604 L ^= S3[0xff & A]; \
847 z >>= 8; 605 L ^= S1[0xff & (A >> 8)];
848 x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z)); 606
849 z >>= 8; 607/*
850 x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z)); 608 * PC2 lookup tables are organized as 2 consecutive sets of 4 interleaved
851 z = expkey[14]; 609 * tables of 128 elements. One set is for C_i and the other for D_i, while
852 z ^= y; 610 * the 4 interleaved tables correspond to four 7-bit subsets of C_i or D_i.
853 x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z)); 611 *
854 z >>= 8; 612 * After PC1 each of the variables a,b,c,d contains a 7 bit subset of C_i
855 x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z)); 613 * or D_i in bits 7-1 (bit 0 being the least significant).
856 z >>= 8; 614 */
857 x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z)); 615
858 z >>= 8; 616#define T1(x) pt[2 * (x) + 0]
859 x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z)); 617#define T2(x) pt[2 * (x) + 1]
860 z = expkey[13]; 618#define T3(x) pt[2 * (x) + 2]
861 z ^= x; 619#define T4(x) pt[2 * (x) + 3]
862 z = z << 4 | z >> 28; 620
863 y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z)); 621#define PC2(a, b, c, d) (T4(d) | T3(c) | T2(b) | T1(a))
864 z >>= 8;
865 y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z));
866 z >>= 8;
867 y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z));
868 z >>= 8;
869 y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z));
870 z = expkey[12];
871 z ^= x;
872 y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z));
873 z >>= 8;
874 y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z));
875 z >>= 8;
876 y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z));
877 z >>= 8;
878 y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z));
879 z = expkey[11];
880 z ^= y;
881 z = z << 4 | z >> 28;
882 x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z));
883 z >>= 8;
884 x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z));
885 z >>= 8;
886 x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z));
887 z >>= 8;
888 x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z));
889 z = expkey[10];
890 z ^= y;
891 x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z));
892 z >>= 8;
893 x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z));
894 z >>= 8;
895 x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z));
896 z >>= 8;
897 x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z));
898 z = expkey[9];
899 z ^= x;
900 z = z << 4 | z >> 28;
901 y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z));
902 z >>= 8;
903 y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z));
904 z >>= 8;
905 y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z));
906 z >>= 8;
907 y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z));
908 z = expkey[8];
909 z ^= x;
910 y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z));
911 z >>= 8;
912 y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z));
913 z >>= 8;
914 y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z));
915 z >>= 8;
916 y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z));
917 z = expkey[7];
918 z ^= y;
919 z = z << 4 | z >> 28;
920 x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z));
921 z >>= 8;
922 x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z));
923 z >>= 8;
924 x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z));
925 z >>= 8;
926 x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z));
927 z = expkey[6];
928 z ^= y;
929 x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z));
930 z >>= 8;
931 x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z));
932 z >>= 8;
933 x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z));
934 z >>= 8;
935 x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z));
936 z = expkey[5];
937 z ^= x;
938 z = z << 4 | z >> 28;
939 y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z));
940 z >>= 8;
941 y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z));
942 z >>= 8;
943 y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z));
944 z >>= 8;
945 y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z));
946 z = expkey[4];
947 z ^= x;
948 y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z));
949 z >>= 8;
950 y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z));
951 z >>= 8;
952 y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z));
953 z >>= 8;
954 y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z));
955 z = expkey[3];
956 z ^= y;
957 z = z << 4 | z >> 28;
958 x ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z));
959 z >>= 8;
960 x ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z));
961 z >>= 8;
962 x ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z));
963 z >>= 8;
964 x ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z));
965 z = expkey[2];
966 z ^= y;
967 x ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z));
968 z >>= 8;
969 x ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z));
970 z >>= 8;
971 x ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z));
972 z >>= 8;
973 x ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z));
974 z = expkey[1];
975 z ^= x;
976 z = z << 4 | z >> 28;
977 y ^= * (u32 *) ((u8 *) (des_keymap + 448) + (0xFC & z));
978 z >>= 8;
979 y ^= * (u32 *) ((u8 *) (des_keymap + 384) + (0xFC & z));
980 z >>= 8;
981 y ^= * (u32 *) ((u8 *) (des_keymap + 320) + (0xFC & z));
982 z >>= 8;
983 y ^= * (u32 *) ((u8 *) (des_keymap + 256) + (0xFC & z));
984 z = expkey[0];
985 z ^= x;
986 y ^= * (u32 *) ((u8 *) (des_keymap + 192) + (0xFC & z));
987 z >>= 8;
988 y ^= * (u32 *) ((u8 *) (des_keymap + 128) + (0xFC & z));
989 z >>= 8;
990 y ^= * (u32 *) ((u8 *) (des_keymap + 64) + (0xFC & z));
991 z >>= 8;
992 y ^= * (u32 *) ((u8 *) des_keymap + (0xFC & z));
993 x = x << 1 | x >> 31;
994 z = (x ^ y) & 0x55555555L;
995 y ^= z;
996 x ^= z;
997 y = y << 1 | y >> 31;
998 z = ((x >> 010) ^ y) & 0x00FF00FFL;
999 x ^= z << 010;
1000 y ^= z;
1001 z = ((y >> 002) ^ x) & 0x33333333L;
1002 y ^= z << 002;
1003 x ^= z;
1004 z = ((x >> 020) ^ y) & 0x0000FFFFL;
1005 x ^= z << 020;
1006 y ^= z;
1007 z = ((y >> 004) ^ x) & 0x0F0F0F0FL;
1008 y ^= z << 004;
1009 x ^= z;
1010 dst[0] = x;
1011 x >>= 8;
1012 dst[1] = x;
1013 x >>= 8;
1014 dst[2] = x;
1015 x >>= 8;
1016 dst[3] = x;
1017 dst[4] = y;
1018 y >>= 8;
1019 dst[5] = y;
1020 y >>= 8;
1021 dst[6] = y;
1022 y >>= 8;
1023 dst[7] = y;
1024}
1025 622
1026/* 623/*
624 * Encryption key expansion
625 *
1027 * RFC2451: Weak key checks SHOULD be performed. 626 * RFC2451: Weak key checks SHOULD be performed.
627 *
628 * FIPS 74:
629 *
630 * Keys having duals are keys which produce all zeros, all ones, or
631 * alternating zero-one patterns in the C and D registers after Permuted
632 * Choice 1 has operated on the key.
633 *
1028 */ 634 */
1029static int setkey(u32 *expkey, const u8 *key, unsigned int keylen, u32 *flags) 635static unsigned long ekey(u32 *pe, const u8 *k)
1030{ 636{
1031 const u8 *k; 637 /* K&R: long is at least 32 bits */
1032 u8 *b0, *b1; 638 unsigned long a, b, c, d, w;
1033 u32 n, w; 639 const u32 *pt = pc2;
1034 u8 bits0[56], bits1[56]; 640
1035 641 d = k[4]; d &= 0x0e; d <<= 4; d |= k[0] & 0x1e; d = pc1[d];
1036 n = parity[key[0]]; n <<= 4; 642 c = k[5]; c &= 0x0e; c <<= 4; c |= k[1] & 0x1e; c = pc1[c];
1037 n |= parity[key[1]]; n <<= 4; 643 b = k[6]; b &= 0x0e; b <<= 4; b |= k[2] & 0x1e; b = pc1[b];
1038 n |= parity[key[2]]; n <<= 4; 644 a = k[7]; a &= 0x0e; a <<= 4; a |= k[3] & 0x1e; a = pc1[a];
1039 n |= parity[key[3]]; n <<= 4; 645
1040 n |= parity[key[4]]; n <<= 4; 646 pe[15 * 2 + 0] = PC2(a, b, c, d); d = rs[d];
1041 n |= parity[key[5]]; n <<= 4; 647 pe[14 * 2 + 0] = PC2(d, a, b, c); c = rs[c]; b = rs[b];
1042 n |= parity[key[6]]; n <<= 4; 648 pe[13 * 2 + 0] = PC2(b, c, d, a); a = rs[a]; d = rs[d];
1043 n |= parity[key[7]]; 649 pe[12 * 2 + 0] = PC2(d, a, b, c); c = rs[c]; b = rs[b];
1044 w = 0x88888888L; 650 pe[11 * 2 + 0] = PC2(b, c, d, a); a = rs[a]; d = rs[d];
1045 651 pe[10 * 2 + 0] = PC2(d, a, b, c); c = rs[c]; b = rs[b];
1046 if ((*flags & CRYPTO_TFM_REQ_WEAK_KEY) 652 pe[ 9 * 2 + 0] = PC2(b, c, d, a); a = rs[a]; d = rs[d];
1047 && !((n - (w >> 3)) & w)) { /* 1 in 10^10 keys passes this test */ 653 pe[ 8 * 2 + 0] = PC2(d, a, b, c); c = rs[c];
1048 if (n < 0x41415151) { 654 pe[ 7 * 2 + 0] = PC2(c, d, a, b); b = rs[b]; a = rs[a];
1049 if (n < 0x31312121) { 655 pe[ 6 * 2 + 0] = PC2(a, b, c, d); d = rs[d]; c = rs[c];
1050 if (n < 0x14141515) { 656 pe[ 5 * 2 + 0] = PC2(c, d, a, b); b = rs[b]; a = rs[a];
1051 /* 01 01 01 01 01 01 01 01 */ 657 pe[ 4 * 2 + 0] = PC2(a, b, c, d); d = rs[d]; c = rs[c];
1052 if (n == 0x11111111) goto weak; 658 pe[ 3 * 2 + 0] = PC2(c, d, a, b); b = rs[b]; a = rs[a];
1053 /* 01 1F 01 1F 01 0E 01 0E */ 659 pe[ 2 * 2 + 0] = PC2(a, b, c, d); d = rs[d]; c = rs[c];
1054 if (n == 0x13131212) goto weak; 660 pe[ 1 * 2 + 0] = PC2(c, d, a, b); b = rs[b];
1055 } else { 661 pe[ 0 * 2 + 0] = PC2(b, c, d, a);
1056 /* 01 E0 01 E0 01 F1 01 F1 */ 662
1057 if (n == 0x14141515) goto weak; 663 /* Check if first half is weak */
1058 /* 01 FE 01 FE 01 FE 01 FE */ 664 w = (a ^ c) | (b ^ d) | (rs[a] ^ c) | (b ^ rs[d]);
1059 if (n == 0x16161616) goto weak; 665
1060 } 666 /* Skip to next table set */
1061 } else { 667 pt += 512;
1062 if (n < 0x34342525) { 668
1063 /* 1F 01 1F 01 0E 01 0E 01 */ 669 d = k[0]; d &= 0xe0; d >>= 4; d |= k[4] & 0xf0; d = pc1[d + 1];
1064 if (n == 0x31312121) goto weak; 670 c = k[1]; c &= 0xe0; c >>= 4; c |= k[5] & 0xf0; c = pc1[c + 1];
1065 /* 1F 1F 1F 1F 0E 0E 0E 0E (?) */ 671 b = k[2]; b &= 0xe0; b >>= 4; b |= k[6] & 0xf0; b = pc1[b + 1];
1066 if (n == 0x33332222) goto weak; 672 a = k[3]; a &= 0xe0; a >>= 4; a |= k[7] & 0xf0; a = pc1[a + 1];
1067 } else { 673
1068 /* 1F E0 1F E0 0E F1 0E F1 */ 674 /* Check if second half is weak */
1069 if (n == 0x34342525) goto weak; 675 w |= (a ^ c) | (b ^ d) | (rs[a] ^ c) | (b ^ rs[d]);
1070 /* 1F FE 1F FE 0E FE 0E FE */ 676
1071 if (n == 0x36362626) goto weak; 677 pe[15 * 2 + 1] = PC2(a, b, c, d); d = rs[d];
1072 } 678 pe[14 * 2 + 1] = PC2(d, a, b, c); c = rs[c]; b = rs[b];
1073 } 679 pe[13 * 2 + 1] = PC2(b, c, d, a); a = rs[a]; d = rs[d];
1074 } else { 680 pe[12 * 2 + 1] = PC2(d, a, b, c); c = rs[c]; b = rs[b];
1075 if (n < 0x61616161) { 681 pe[11 * 2 + 1] = PC2(b, c, d, a); a = rs[a]; d = rs[d];
1076 if (n < 0x44445555) { 682 pe[10 * 2 + 1] = PC2(d, a, b, c); c = rs[c]; b = rs[b];
1077 /* E0 01 E0 01 F1 01 F1 01 */ 683 pe[ 9 * 2 + 1] = PC2(b, c, d, a); a = rs[a]; d = rs[d];
1078 if (n == 0x41415151) goto weak; 684 pe[ 8 * 2 + 1] = PC2(d, a, b, c); c = rs[c];
1079 /* E0 1F E0 1F F1 0E F1 0E */ 685 pe[ 7 * 2 + 1] = PC2(c, d, a, b); b = rs[b]; a = rs[a];
1080 if (n == 0x43435252) goto weak; 686 pe[ 6 * 2 + 1] = PC2(a, b, c, d); d = rs[d]; c = rs[c];
1081 } else { 687 pe[ 5 * 2 + 1] = PC2(c, d, a, b); b = rs[b]; a = rs[a];
1082 /* E0 E0 E0 E0 F1 F1 F1 F1 (?) */ 688 pe[ 4 * 2 + 1] = PC2(a, b, c, d); d = rs[d]; c = rs[c];
1083 if (n == 0x44445555) goto weak; 689 pe[ 3 * 2 + 1] = PC2(c, d, a, b); b = rs[b]; a = rs[a];
1084 /* E0 FE E0 FE F1 FE F1 FE */ 690 pe[ 2 * 2 + 1] = PC2(a, b, c, d); d = rs[d]; c = rs[c];
1085 if (n == 0x46465656) goto weak; 691 pe[ 1 * 2 + 1] = PC2(c, d, a, b); b = rs[b];
1086 } 692 pe[ 0 * 2 + 1] = PC2(b, c, d, a);
1087 } else { 693
1088 if (n < 0x64646565) { 694 /* Fixup: 2413 5768 -> 1357 2468 */
1089 /* FE 01 FE 01 FE 01 FE 01 */ 695 for (d = 0; d < 16; ++d) {
1090 if (n == 0x61616161) goto weak; 696 a = pe[2 * d];
1091 /* FE 1F FE 1F FE 0E FE 0E */ 697 b = pe[2 * d + 1];
1092 if (n == 0x63636262) goto weak; 698 c = a ^ b;
1093 } else { 699 c &= 0xffff0000;
1094 /* FE E0 FE E0 FE F1 FE F1 */ 700 a ^= c;
1095 if (n == 0x64646565) goto weak; 701 b ^= c;
1096 /* FE FE FE FE FE FE FE FE */ 702 ROL(b, 18);
1097 if (n == 0x66666666) goto weak; 703 pe[2 * d] = a;
1098 } 704 pe[2 * d + 1] = b;
1099 }
1100 }
1101
1102 goto not_weak;
1103weak:
1104 *flags |= CRYPTO_TFM_RES_WEAK_KEY;
1105 return -EINVAL;
1106 } 705 }
1107 706
1108not_weak: 707 /* Zero if weak key */
1109 708 return w;
1110 /* explode the bits */ 709}
1111 n = 56;
1112 b0 = bits0;
1113 b1 = bits1;
1114
1115 do {
1116 w = (256 | *key++) << 2;
1117 do {
1118 --n;
1119 b1[n] = 8 & w;
1120 w >>= 1;
1121 b0[n] = 4 & w;
1122 } while ( w >= 16 );
1123 } while ( n );
1124
1125 /* put the bits in the correct places */
1126 n = 16;
1127 k = rotors;
1128
1129 do {
1130 w = (b1[k[ 0 ]] | b0[k[ 1 ]]) << 4;
1131 w |= (b1[k[ 2 ]] | b0[k[ 3 ]]) << 2;
1132 w |= b1[k[ 4 ]] | b0[k[ 5 ]];
1133 w <<= 8;
1134 w |= (b1[k[ 6 ]] | b0[k[ 7 ]]) << 4;
1135 w |= (b1[k[ 8 ]] | b0[k[ 9 ]]) << 2;
1136 w |= b1[k[10 ]] | b0[k[11 ]];
1137 w <<= 8;
1138 w |= (b1[k[12 ]] | b0[k[13 ]]) << 4;
1139 w |= (b1[k[14 ]] | b0[k[15 ]]) << 2;
1140 w |= b1[k[16 ]] | b0[k[17 ]];
1141 w <<= 8;
1142 w |= (b1[k[18 ]] | b0[k[19 ]]) << 4;
1143 w |= (b1[k[20 ]] | b0[k[21 ]]) << 2;
1144 w |= b1[k[22 ]] | b0[k[23 ]];
1145 expkey[0] = w;
1146
1147 w = (b1[k[ 0+24]] | b0[k[ 1+24]]) << 4;
1148 w |= (b1[k[ 2+24]] | b0[k[ 3+24]]) << 2;
1149 w |= b1[k[ 4+24]] | b0[k[ 5+24]];
1150 w <<= 8;
1151 w |= (b1[k[ 6+24]] | b0[k[ 7+24]]) << 4;
1152 w |= (b1[k[ 8+24]] | b0[k[ 9+24]]) << 2;
1153 w |= b1[k[10+24]] | b0[k[11+24]];
1154 w <<= 8;
1155 w |= (b1[k[12+24]] | b0[k[13+24]]) << 4;
1156 w |= (b1[k[14+24]] | b0[k[15+24]]) << 2;
1157 w |= b1[k[16+24]] | b0[k[17+24]];
1158 w <<= 8;
1159 w |= (b1[k[18+24]] | b0[k[19+24]]) << 4;
1160 w |= (b1[k[20+24]] | b0[k[21+24]]) << 2;
1161 w |= b1[k[22+24]] | b0[k[23+24]];
1162
1163 ROR(w, 4, 28); /* could be eliminated */
1164 expkey[1] = w;
1165
1166 k += 48;
1167 expkey += 2;
1168 } while (--n);
1169 710
1170 return 0; 711/*
712 * Decryption key expansion
713 *
714 * No weak key checking is performed, as this is only used by triple DES
715 *
716 */
717static void dkey(u32 *pe, const u8 *k)
718{
719 /* K&R: long is at least 32 bits */
720 unsigned long a, b, c, d;
721 const u32 *pt = pc2;
722
723 d = k[4]; d &= 0x0e; d <<= 4; d |= k[0] & 0x1e; d = pc1[d];
724 c = k[5]; c &= 0x0e; c <<= 4; c |= k[1] & 0x1e; c = pc1[c];
725 b = k[6]; b &= 0x0e; b <<= 4; b |= k[2] & 0x1e; b = pc1[b];
726 a = k[7]; a &= 0x0e; a <<= 4; a |= k[3] & 0x1e; a = pc1[a];
727
728 pe[ 0 * 2] = PC2(a, b, c, d); d = rs[d];
729 pe[ 1 * 2] = PC2(d, a, b, c); c = rs[c]; b = rs[b];
730 pe[ 2 * 2] = PC2(b, c, d, a); a = rs[a]; d = rs[d];
731 pe[ 3 * 2] = PC2(d, a, b, c); c = rs[c]; b = rs[b];
732 pe[ 4 * 2] = PC2(b, c, d, a); a = rs[a]; d = rs[d];
733 pe[ 5 * 2] = PC2(d, a, b, c); c = rs[c]; b = rs[b];
734 pe[ 6 * 2] = PC2(b, c, d, a); a = rs[a]; d = rs[d];
735 pe[ 7 * 2] = PC2(d, a, b, c); c = rs[c];
736 pe[ 8 * 2] = PC2(c, d, a, b); b = rs[b]; a = rs[a];
737 pe[ 9 * 2] = PC2(a, b, c, d); d = rs[d]; c = rs[c];
738 pe[10 * 2] = PC2(c, d, a, b); b = rs[b]; a = rs[a];
739 pe[11 * 2] = PC2(a, b, c, d); d = rs[d]; c = rs[c];
740 pe[12 * 2] = PC2(c, d, a, b); b = rs[b]; a = rs[a];
741 pe[13 * 2] = PC2(a, b, c, d); d = rs[d]; c = rs[c];
742 pe[14 * 2] = PC2(c, d, a, b); b = rs[b];
743 pe[15 * 2] = PC2(b, c, d, a);
744
745 /* Skip to next table set */
746 pt += 512;
747
748 d = k[0]; d &= 0xe0; d >>= 4; d |= k[4] & 0xf0; d = pc1[d + 1];
749 c = k[1]; c &= 0xe0; c >>= 4; c |= k[5] & 0xf0; c = pc1[c + 1];
750 b = k[2]; b &= 0xe0; b >>= 4; b |= k[6] & 0xf0; b = pc1[b + 1];
751 a = k[3]; a &= 0xe0; a >>= 4; a |= k[7] & 0xf0; a = pc1[a + 1];
752
753 pe[ 0 * 2 + 1] = PC2(a, b, c, d); d = rs[d];
754 pe[ 1 * 2 + 1] = PC2(d, a, b, c); c = rs[c]; b = rs[b];
755 pe[ 2 * 2 + 1] = PC2(b, c, d, a); a = rs[a]; d = rs[d];
756 pe[ 3 * 2 + 1] = PC2(d, a, b, c); c = rs[c]; b = rs[b];
757 pe[ 4 * 2 + 1] = PC2(b, c, d, a); a = rs[a]; d = rs[d];
758 pe[ 5 * 2 + 1] = PC2(d, a, b, c); c = rs[c]; b = rs[b];
759 pe[ 6 * 2 + 1] = PC2(b, c, d, a); a = rs[a]; d = rs[d];
760 pe[ 7 * 2 + 1] = PC2(d, a, b, c); c = rs[c];
761 pe[ 8 * 2 + 1] = PC2(c, d, a, b); b = rs[b]; a = rs[a];
762 pe[ 9 * 2 + 1] = PC2(a, b, c, d); d = rs[d]; c = rs[c];
763 pe[10 * 2 + 1] = PC2(c, d, a, b); b = rs[b]; a = rs[a];
764 pe[11 * 2 + 1] = PC2(a, b, c, d); d = rs[d]; c = rs[c];
765 pe[12 * 2 + 1] = PC2(c, d, a, b); b = rs[b]; a = rs[a];
766 pe[13 * 2 + 1] = PC2(a, b, c, d); d = rs[d]; c = rs[c];
767 pe[14 * 2 + 1] = PC2(c, d, a, b); b = rs[b];
768 pe[15 * 2 + 1] = PC2(b, c, d, a);
769
770 /* Fixup: 2413 5768 -> 1357 2468 */
771 for (d = 0; d < 16; ++d) {
772 a = pe[2 * d];
773 b = pe[2 * d + 1];
774 c = a ^ b;
775 c &= 0xffff0000;
776 a ^= c;
777 b ^= c;
778 ROL(b, 18);
779 pe[2 * d] = a;
780 pe[2 * d + 1] = b;
781 }
1171} 782}
1172 783
1173static int des_setkey(void *ctx, const u8 *key, unsigned int keylen, u32 *flags) 784static int des_setkey(void *ctx, const u8 *key, unsigned int keylen, u32 *flags)
1174{ 785{
1175 return setkey(((struct des_ctx *)ctx)->expkey, key, keylen, flags); 786 struct des_ctx *dctx = ctx;
787 u32 tmp[DES_EXPKEY_WORDS];
788 int ret;
789
790 /* Expand to tmp */
791 ret = ekey(tmp, key);
792
793 if (unlikely(ret == 0) && (*flags & CRYPTO_TFM_REQ_WEAK_KEY)) {
794 *flags |= CRYPTO_TFM_RES_WEAK_KEY;
795 return -EINVAL;
796 }
797
798 /* Copy to output */
799 memcpy(dctx->expkey, tmp, sizeof(dctx->expkey));
800
801 return 0;
1176} 802}
1177 803
1178static void des_encrypt(void *ctx, u8 *dst, const u8 *src) 804static void des_encrypt(void *ctx, u8 *dst, const u8 *src)
1179{ 805{
1180 des_small_fips_encrypt(((struct des_ctx *)ctx)->expkey, dst, src); 806 const u32 *K = ((struct des_ctx *)ctx)->expkey;
807 const __le32 *s = (const __le32 *)src;
808 __le32 *d = (__le32 *)dst;
809 u32 L, R, A, B;
810 int i;
811
812 L = le32_to_cpu(s[0]);
813 R = le32_to_cpu(s[1]);
814
815 IP(L, R, A);
816 for (i = 0; i < 8; i++) {
817 ROUND(L, R, A, B, K, 2);
818 ROUND(R, L, A, B, K, 2);
819 }
820 FP(R, L, A);
821
822 d[0] = cpu_to_le32(R);
823 d[1] = cpu_to_le32(L);
1181} 824}
1182 825
1183static void des_decrypt(void *ctx, u8 *dst, const u8 *src) 826static void des_decrypt(void *ctx, u8 *dst, const u8 *src)
1184{ 827{
1185 des_small_fips_decrypt(((struct des_ctx *)ctx)->expkey, dst, src); 828 const u32 *K = ((struct des_ctx *)ctx)->expkey + DES_EXPKEY_WORDS - 2;
829 const __le32 *s = (const __le32 *)src;
830 __le32 *d = (__le32 *)dst;
831 u32 L, R, A, B;
832 int i;
833
834 L = le32_to_cpu(s[0]);
835 R = le32_to_cpu(s[1]);
836
837 IP(L, R, A);
838 for (i = 0; i < 8; i++) {
839 ROUND(L, R, A, B, K, -2);
840 ROUND(R, L, A, B, K, -2);
841 }
842 FP(R, L, A);
843
844 d[0] = cpu_to_le32(R);
845 d[1] = cpu_to_le32(L);
1186} 846}
1187 847
1188/* 848/*
1189 * RFC2451: 849 * RFC2451:
1190 * 850 *
1191 * For DES-EDE3, there is no known need to reject weak or 851 * For DES-EDE3, there is no known need to reject weak or
@@ -1199,44 +859,86 @@ static void des_decrypt(void *ctx, u8 *dst, const u8 *src)
1199 * 859 *
1200 */ 860 */
1201static int des3_ede_setkey(void *ctx, const u8 *key, 861static int des3_ede_setkey(void *ctx, const u8 *key,
1202 unsigned int keylen, u32 *flags) 862 unsigned int keylen, u32 *flags)
1203{ 863{
1204 unsigned int i, off; 864 const u32 *K = (const u32 *)key;
1205 struct des3_ede_ctx *dctx = ctx; 865 struct des3_ede_ctx *dctx = ctx;
866 u32 *expkey = dctx->expkey;
1206 867
1207 if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) && 868 if (unlikely(!((K[0] ^ K[2]) | (K[1] ^ K[3])) ||
1208 memcmp(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2], 869 !((K[2] ^ K[4]) | (K[3] ^ K[5]))))
1209 DES_KEY_SIZE))) { 870 {
1210
1211 *flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED; 871 *flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED;
1212 return -EINVAL; 872 return -EINVAL;
1213 } 873 }
1214 874
1215 for (i = 0, off = 0; i < 3; i++, off += DES_EXPKEY_WORDS, 875 ekey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE;
1216 key += DES_KEY_SIZE) { 876 dkey(expkey, key); expkey += DES_EXPKEY_WORDS; key += DES_KEY_SIZE;
1217 int ret = setkey(&dctx->expkey[off], key, DES_KEY_SIZE, flags); 877 ekey(expkey, key);
1218 if (ret < 0) 878
1219 return ret;
1220 }
1221 return 0; 879 return 0;
1222} 880}
1223 881
1224static void des3_ede_encrypt(void *ctx, u8 *dst, const u8 *src) 882static void des3_ede_encrypt(void *ctx, u8 *dst, const u8 *src)
1225{ 883{
1226 struct des3_ede_ctx *dctx = ctx; 884 struct des3_ede_ctx *dctx = ctx;
1227 885 const u32 *K = dctx->expkey;
1228 des_small_fips_encrypt(dctx->expkey, dst, src); 886 const __le32 *s = (const __le32 *)src;
1229 des_small_fips_decrypt(&dctx->expkey[DES_EXPKEY_WORDS], dst, dst); 887 __le32 *d = (__le32 *)dst;
1230 des_small_fips_encrypt(&dctx->expkey[DES_EXPKEY_WORDS * 2], dst, dst); 888 u32 L, R, A, B;
889 int i;
890
891 L = le32_to_cpu(s[0]);
892 R = le32_to_cpu(s[1]);
893
894 IP(L, R, A);
895 for (i = 0; i < 8; i++) {
896 ROUND(L, R, A, B, K, 2);
897 ROUND(R, L, A, B, K, 2);
898 }
899 for (i = 0; i < 8; i++) {
900 ROUND(R, L, A, B, K, 2);
901 ROUND(L, R, A, B, K, 2);
902 }
903 for (i = 0; i < 8; i++) {
904 ROUND(L, R, A, B, K, 2);
905 ROUND(R, L, A, B, K, 2);
906 }
907 FP(R, L, A);
908
909 d[0] = cpu_to_le32(R);
910 d[1] = cpu_to_le32(L);
1231} 911}
1232 912
1233static void des3_ede_decrypt(void *ctx, u8 *dst, const u8 *src) 913static void des3_ede_decrypt(void *ctx, u8 *dst, const u8 *src)
1234{ 914{
1235 struct des3_ede_ctx *dctx = ctx; 915 struct des3_ede_ctx *dctx = ctx;
916 const u32 *K = dctx->expkey + DES3_EDE_EXPKEY_WORDS - 2;
917 const __le32 *s = (const __le32 *)src;
918 __le32 *d = (__le32 *)dst;
919 u32 L, R, A, B;
920 int i;
921
922 L = le32_to_cpu(s[0]);
923 R = le32_to_cpu(s[1]);
924
925 IP(L, R, A);
926 for (i = 0; i < 8; i++) {
927 ROUND(L, R, A, B, K, -2);
928 ROUND(R, L, A, B, K, -2);
929 }
930 for (i = 0; i < 8; i++) {
931 ROUND(R, L, A, B, K, -2);
932 ROUND(L, R, A, B, K, -2);
933 }
934 for (i = 0; i < 8; i++) {
935 ROUND(L, R, A, B, K, -2);
936 ROUND(R, L, A, B, K, -2);
937 }
938 FP(R, L, A);
1236 939
1237 des_small_fips_decrypt(&dctx->expkey[DES_EXPKEY_WORDS * 2], dst, src); 940 d[0] = cpu_to_le32(R);
1238 des_small_fips_encrypt(&dctx->expkey[DES_EXPKEY_WORDS], dst, dst); 941 d[1] = cpu_to_le32(L);
1239 des_small_fips_decrypt(dctx->expkey, dst, dst);
1240} 942}
1241 943
1242static struct crypto_alg des_alg = { 944static struct crypto_alg des_alg = {
@@ -1249,7 +951,7 @@ static struct crypto_alg des_alg = {
1249 .cra_u = { .cipher = { 951 .cra_u = { .cipher = {
1250 .cia_min_keysize = DES_KEY_SIZE, 952 .cia_min_keysize = DES_KEY_SIZE,
1251 .cia_max_keysize = DES_KEY_SIZE, 953 .cia_max_keysize = DES_KEY_SIZE,
1252 .cia_setkey = des_setkey, 954 .cia_setkey = des_setkey,
1253 .cia_encrypt = des_encrypt, 955 .cia_encrypt = des_encrypt,
1254 .cia_decrypt = des_decrypt } } 956 .cia_decrypt = des_decrypt } }
1255}; 957};
@@ -1264,9 +966,9 @@ static struct crypto_alg des3_ede_alg = {
1264 .cra_u = { .cipher = { 966 .cra_u = { .cipher = {
1265 .cia_min_keysize = DES3_EDE_KEY_SIZE, 967 .cia_min_keysize = DES3_EDE_KEY_SIZE,
1266 .cia_max_keysize = DES3_EDE_KEY_SIZE, 968 .cia_max_keysize = DES3_EDE_KEY_SIZE,
1267 .cia_setkey = des3_ede_setkey, 969 .cia_setkey = des3_ede_setkey,
1268 .cia_encrypt = des3_ede_encrypt, 970 .cia_encrypt = des3_ede_encrypt,
1269 .cia_decrypt = des3_ede_decrypt } } 971 .cia_decrypt = des3_ede_decrypt } }
1270}; 972};
1271 973
1272MODULE_ALIAS("des3_ede"); 974MODULE_ALIAS("des3_ede");
@@ -1274,7 +976,7 @@ MODULE_ALIAS("des3_ede");
1274static int __init init(void) 976static int __init init(void)
1275{ 977{
1276 int ret = 0; 978 int ret = 0;
1277 979
1278 ret = crypto_register_alg(&des_alg); 980 ret = crypto_register_alg(&des_alg);
1279 if (ret < 0) 981 if (ret < 0)
1280 goto out; 982 goto out;
@@ -1282,7 +984,7 @@ static int __init init(void)
1282 ret = crypto_register_alg(&des3_ede_alg); 984 ret = crypto_register_alg(&des3_ede_alg);
1283 if (ret < 0) 985 if (ret < 0)
1284 crypto_unregister_alg(&des_alg); 986 crypto_unregister_alg(&des_alg);
1285out: 987out:
1286 return ret; 988 return ret;
1287} 989}
1288 990
@@ -1297,3 +999,4 @@ module_exit(fini);
1297 999
1298MODULE_LICENSE("GPL"); 1000MODULE_LICENSE("GPL");
1299MODULE_DESCRIPTION("DES & Triple DES EDE Cipher Algorithms"); 1001MODULE_DESCRIPTION("DES & Triple DES EDE Cipher Algorithms");
1002MODULE_AUTHOR("Dag Arne Osvik <da@osvik.no>");
diff --git a/crypto/hmac.c b/crypto/hmac.c
index 847df9263e16..da0456b37109 100644
--- a/crypto/hmac.c
+++ b/crypto/hmac.c
@@ -49,8 +49,7 @@ int crypto_alloc_hmac_block(struct crypto_tfm *tfm)
49 49
50void crypto_free_hmac_block(struct crypto_tfm *tfm) 50void crypto_free_hmac_block(struct crypto_tfm *tfm)
51{ 51{
52 if (tfm->crt_digest.dit_hmac_block) 52 kfree(tfm->crt_digest.dit_hmac_block);
53 kfree(tfm->crt_digest.dit_hmac_block);
54} 53}
55 54
56void crypto_hmac_init(struct crypto_tfm *tfm, u8 *key, unsigned int *keylen) 55void crypto_hmac_init(struct crypto_tfm *tfm, u8 *key, unsigned int *keylen)
diff --git a/crypto/internal.h b/crypto/internal.h
index 964b9a60ca24..68612874b5fd 100644
--- a/crypto/internal.h
+++ b/crypto/internal.h
@@ -16,7 +16,7 @@
16#include <linux/highmem.h> 16#include <linux/highmem.h>
17#include <linux/interrupt.h> 17#include <linux/interrupt.h>
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/kmod.h> 19#include <linux/kernel.h>
20#include <asm/kmap_types.h> 20#include <asm/kmap_types.h>
21 21
22extern enum km_type crypto_km_types[]; 22extern enum km_type crypto_km_types[];
@@ -42,20 +42,6 @@ static inline void crypto_yield(struct crypto_tfm *tfm)
42 cond_resched(); 42 cond_resched();
43} 43}
44 44
45static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm)
46{
47 return (void *)&tfm[1];
48}
49
50struct crypto_alg *crypto_alg_lookup(const char *name);
51
52/* A far more intelligent version of this is planned. For now, just
53 * try an exact match on the name of the algorithm. */
54static inline struct crypto_alg *crypto_alg_mod_lookup(const char *name)
55{
56 return try_then_request_module(crypto_alg_lookup(name), name);
57}
58
59#ifdef CONFIG_CRYPTO_HMAC 45#ifdef CONFIG_CRYPTO_HMAC
60int crypto_alloc_hmac_block(struct crypto_tfm *tfm); 46int crypto_alloc_hmac_block(struct crypto_tfm *tfm);
61void crypto_free_hmac_block(struct crypto_tfm *tfm); 47void crypto_free_hmac_block(struct crypto_tfm *tfm);
@@ -76,6 +62,33 @@ static inline void crypto_init_proc(void)
76{ } 62{ }
77#endif 63#endif
78 64
65static inline unsigned int crypto_digest_ctxsize(struct crypto_alg *alg,
66 int flags)
67{
68 return alg->cra_ctxsize;
69}
70
71static inline unsigned int crypto_cipher_ctxsize(struct crypto_alg *alg,
72 int flags)
73{
74 unsigned int len = alg->cra_ctxsize;
75
76 switch (flags & CRYPTO_TFM_MODE_MASK) {
77 case CRYPTO_TFM_MODE_CBC:
78 len = ALIGN(len, alg->cra_alignmask + 1);
79 len += alg->cra_blocksize;
80 break;
81 }
82
83 return len;
84}
85
86static inline unsigned int crypto_compress_ctxsize(struct crypto_alg *alg,
87 int flags)
88{
89 return alg->cra_ctxsize;
90}
91
79int crypto_init_digest_flags(struct crypto_tfm *tfm, u32 flags); 92int crypto_init_digest_flags(struct crypto_tfm *tfm, u32 flags);
80int crypto_init_cipher_flags(struct crypto_tfm *tfm, u32 flags); 93int crypto_init_cipher_flags(struct crypto_tfm *tfm, u32 flags);
81int crypto_init_compress_flags(struct crypto_tfm *tfm, u32 flags); 94int crypto_init_compress_flags(struct crypto_tfm *tfm, u32 flags);
diff --git a/crypto/scatterwalk.c b/crypto/scatterwalk.c
index 50c9461e8cc6..47ac90e615f4 100644
--- a/crypto/scatterwalk.c
+++ b/crypto/scatterwalk.c
@@ -100,7 +100,7 @@ void scatterwalk_done(struct scatter_walk *walk, int out, int more)
100int scatterwalk_copychunks(void *buf, struct scatter_walk *walk, 100int scatterwalk_copychunks(void *buf, struct scatter_walk *walk,
101 size_t nbytes, int out) 101 size_t nbytes, int out)
102{ 102{
103 do { 103 while (nbytes > walk->len_this_page) {
104 memcpy_dir(buf, walk->data, walk->len_this_page, out); 104 memcpy_dir(buf, walk->data, walk->len_this_page, out);
105 buf += walk->len_this_page; 105 buf += walk->len_this_page;
106 nbytes -= walk->len_this_page; 106 nbytes -= walk->len_this_page;
@@ -108,7 +108,7 @@ int scatterwalk_copychunks(void *buf, struct scatter_walk *walk,
108 scatterwalk_unmap(walk, out); 108 scatterwalk_unmap(walk, out);
109 scatterwalk_pagedone(walk, out, 1); 109 scatterwalk_pagedone(walk, out, 1);
110 scatterwalk_map(walk, out); 110 scatterwalk_map(walk, out);
111 } while (nbytes > walk->len_this_page); 111 }
112 112
113 memcpy_dir(buf, walk->data, nbytes, out); 113 memcpy_dir(buf, walk->data, nbytes, out);
114 return nbytes; 114 return nbytes;
diff --git a/crypto/scatterwalk.h b/crypto/scatterwalk.h
index 02aa56c649b4..e79925c474a3 100644
--- a/crypto/scatterwalk.h
+++ b/crypto/scatterwalk.h
@@ -40,10 +40,10 @@ static inline int scatterwalk_samebuf(struct scatter_walk *walk_in,
40 walk_in->offset == walk_out->offset; 40 walk_in->offset == walk_out->offset;
41} 41}
42 42
43static inline int scatterwalk_across_pages(struct scatter_walk *walk, 43static inline unsigned int scatterwalk_clamp(struct scatter_walk *walk,
44 unsigned int nbytes) 44 unsigned int nbytes)
45{ 45{
46 return nbytes > walk->len_this_page; 46 return nbytes > walk->len_this_page ? walk->len_this_page : nbytes;
47} 47}
48 48
49static inline void scatterwalk_advance(struct scatter_walk *walk, 49static inline void scatterwalk_advance(struct scatter_walk *walk,
@@ -55,6 +55,12 @@ static inline void scatterwalk_advance(struct scatter_walk *walk,
55 walk->len_this_segment -= nbytes; 55 walk->len_this_segment -= nbytes;
56} 56}
57 57
58static inline unsigned int scatterwalk_aligned(struct scatter_walk *walk,
59 unsigned int alignmask)
60{
61 return !(walk->offset & alignmask);
62}
63
58void scatterwalk_start(struct scatter_walk *walk, struct scatterlist *sg); 64void scatterwalk_start(struct scatter_walk *walk, struct scatterlist *sg);
59int scatterwalk_copychunks(void *buf, struct scatter_walk *walk, size_t nbytes, int out); 65int scatterwalk_copychunks(void *buf, struct scatter_walk *walk, size_t nbytes, int out);
60void scatterwalk_map(struct scatter_walk *walk, int out); 66void scatterwalk_map(struct scatter_walk *walk, int out);
diff --git a/crypto/serpent.c b/crypto/serpent.c
index 7d152e89016f..3cf2c5067eea 100644
--- a/crypto/serpent.c
+++ b/crypto/serpent.c
@@ -210,7 +210,6 @@
210 x4 ^= x2; 210 x4 ^= x2;
211 211
212struct serpent_ctx { 212struct serpent_ctx {
213 u8 iv[SERPENT_BLOCK_SIZE];
214 u32 expkey[SERPENT_EXPKEY_WORDS]; 213 u32 expkey[SERPENT_EXPKEY_WORDS];
215}; 214};
216 215
diff --git a/drivers/crypto/padlock-aes.c b/drivers/crypto/padlock-aes.c
index ed708b4427b0..71407c578afe 100644
--- a/drivers/crypto/padlock-aes.c
+++ b/drivers/crypto/padlock-aes.c
@@ -49,6 +49,7 @@
49#include <linux/errno.h> 49#include <linux/errno.h>
50#include <linux/crypto.h> 50#include <linux/crypto.h>
51#include <linux/interrupt.h> 51#include <linux/interrupt.h>
52#include <linux/kernel.h>
52#include <asm/byteorder.h> 53#include <asm/byteorder.h>
53#include "padlock.h" 54#include "padlock.h"
54 55
@@ -59,8 +60,12 @@
59#define AES_EXTENDED_KEY_SIZE_B (AES_EXTENDED_KEY_SIZE * sizeof(uint32_t)) 60#define AES_EXTENDED_KEY_SIZE_B (AES_EXTENDED_KEY_SIZE * sizeof(uint32_t))
60 61
61struct aes_ctx { 62struct aes_ctx {
62 uint32_t e_data[AES_EXTENDED_KEY_SIZE+4]; 63 uint32_t e_data[AES_EXTENDED_KEY_SIZE];
63 uint32_t d_data[AES_EXTENDED_KEY_SIZE+4]; 64 uint32_t d_data[AES_EXTENDED_KEY_SIZE];
65 struct {
66 struct cword encrypt;
67 struct cword decrypt;
68 } cword;
64 uint32_t *E; 69 uint32_t *E;
65 uint32_t *D; 70 uint32_t *D;
66 int key_length; 71 int key_length;
@@ -280,10 +285,15 @@ aes_hw_extkey_available(uint8_t key_len)
280 return 0; 285 return 0;
281} 286}
282 287
288static inline struct aes_ctx *aes_ctx(void *ctx)
289{
290 return (struct aes_ctx *)ALIGN((unsigned long)ctx, PADLOCK_ALIGNMENT);
291}
292
283static int 293static int
284aes_set_key(void *ctx_arg, const uint8_t *in_key, unsigned int key_len, uint32_t *flags) 294aes_set_key(void *ctx_arg, const uint8_t *in_key, unsigned int key_len, uint32_t *flags)
285{ 295{
286 struct aes_ctx *ctx = ctx_arg; 296 struct aes_ctx *ctx = aes_ctx(ctx_arg);
287 uint32_t i, t, u, v, w; 297 uint32_t i, t, u, v, w;
288 uint32_t P[AES_EXTENDED_KEY_SIZE]; 298 uint32_t P[AES_EXTENDED_KEY_SIZE];
289 uint32_t rounds; 299 uint32_t rounds;
@@ -295,25 +305,36 @@ aes_set_key(void *ctx_arg, const uint8_t *in_key, unsigned int key_len, uint32_t
295 305
296 ctx->key_length = key_len; 306 ctx->key_length = key_len;
297 307
308 /*
309 * If the hardware is capable of generating the extended key
310 * itself we must supply the plain key for both encryption
311 * and decryption.
312 */
298 ctx->E = ctx->e_data; 313 ctx->E = ctx->e_data;
299 ctx->D = ctx->d_data; 314 ctx->D = ctx->e_data;
300
301 /* Ensure 16-Bytes alignmentation of keys for VIA PadLock. */
302 if ((int)(ctx->e_data) & 0x0F)
303 ctx->E += 4 - (((int)(ctx->e_data) & 0x0F) / sizeof (ctx->e_data[0]));
304
305 if ((int)(ctx->d_data) & 0x0F)
306 ctx->D += 4 - (((int)(ctx->d_data) & 0x0F) / sizeof (ctx->d_data[0]));
307 315
308 E_KEY[0] = uint32_t_in (in_key); 316 E_KEY[0] = uint32_t_in (in_key);
309 E_KEY[1] = uint32_t_in (in_key + 4); 317 E_KEY[1] = uint32_t_in (in_key + 4);
310 E_KEY[2] = uint32_t_in (in_key + 8); 318 E_KEY[2] = uint32_t_in (in_key + 8);
311 E_KEY[3] = uint32_t_in (in_key + 12); 319 E_KEY[3] = uint32_t_in (in_key + 12);
312 320
321 /* Prepare control words. */
322 memset(&ctx->cword, 0, sizeof(ctx->cword));
323
324 ctx->cword.decrypt.encdec = 1;
325 ctx->cword.encrypt.rounds = 10 + (key_len - 16) / 4;
326 ctx->cword.decrypt.rounds = ctx->cword.encrypt.rounds;
327 ctx->cword.encrypt.ksize = (key_len - 16) / 8;
328 ctx->cword.decrypt.ksize = ctx->cword.encrypt.ksize;
329
313 /* Don't generate extended keys if the hardware can do it. */ 330 /* Don't generate extended keys if the hardware can do it. */
314 if (aes_hw_extkey_available(key_len)) 331 if (aes_hw_extkey_available(key_len))
315 return 0; 332 return 0;
316 333
334 ctx->D = ctx->d_data;
335 ctx->cword.encrypt.keygen = 1;
336 ctx->cword.decrypt.keygen = 1;
337
317 switch (key_len) { 338 switch (key_len) {
318 case 16: 339 case 16:
319 t = E_KEY[3]; 340 t = E_KEY[3];
@@ -369,10 +390,9 @@ aes_set_key(void *ctx_arg, const uint8_t *in_key, unsigned int key_len, uint32_t
369 390
370/* ====== Encryption/decryption routines ====== */ 391/* ====== Encryption/decryption routines ====== */
371 392
372/* This is the real call to PadLock. */ 393/* These are the real call to PadLock. */
373static inline void 394static inline void padlock_xcrypt_ecb(const u8 *input, u8 *output, void *key,
374padlock_xcrypt_ecb(uint8_t *input, uint8_t *output, uint8_t *key, 395 void *control_word, u32 count)
375 void *control_word, uint32_t count)
376{ 396{
377 asm volatile ("pushfl; popfl"); /* enforce key reload. */ 397 asm volatile ("pushfl; popfl"); /* enforce key reload. */
378 asm volatile (".byte 0xf3,0x0f,0xa7,0xc8" /* rep xcryptecb */ 398 asm volatile (".byte 0xf3,0x0f,0xa7,0xc8" /* rep xcryptecb */
@@ -380,60 +400,70 @@ padlock_xcrypt_ecb(uint8_t *input, uint8_t *output, uint8_t *key,
380 : "d"(control_word), "b"(key), "c"(count)); 400 : "d"(control_word), "b"(key), "c"(count));
381} 401}
382 402
383static void 403static inline u8 *padlock_xcrypt_cbc(const u8 *input, u8 *output, void *key,
384aes_padlock(void *ctx_arg, uint8_t *out_arg, const uint8_t *in_arg, int encdec) 404 u8 *iv, void *control_word, u32 count)
385{ 405{
386 /* Don't blindly modify this structure - the items must 406 /* Enforce key reload. */
387 fit on 16-Bytes boundaries! */ 407 asm volatile ("pushfl; popfl");
388 struct padlock_xcrypt_data { 408 /* rep xcryptcbc */
389 uint8_t buf[AES_BLOCK_SIZE]; 409 asm volatile (".byte 0xf3,0x0f,0xa7,0xd0"
390 union cword cword; 410 : "+S" (input), "+D" (output), "+a" (iv)
391 }; 411 : "d" (control_word), "b" (key), "c" (count));
392 412 return iv;
393 struct aes_ctx *ctx = ctx_arg;
394 char bigbuf[sizeof(struct padlock_xcrypt_data) + 16];
395 struct padlock_xcrypt_data *data;
396 void *key;
397
398 /* Place 'data' at the first 16-Bytes aligned address in 'bigbuf'. */
399 if (((long)bigbuf) & 0x0F)
400 data = (void*)(bigbuf + 16 - ((long)bigbuf & 0x0F));
401 else
402 data = (void*)bigbuf;
403
404 /* Prepare Control word. */
405 memset (data, 0, sizeof(struct padlock_xcrypt_data));
406 data->cword.b.encdec = !encdec; /* in the rest of cryptoapi ENC=1/DEC=0 */
407 data->cword.b.rounds = 10 + (ctx->key_length - 16) / 4;
408 data->cword.b.ksize = (ctx->key_length - 16) / 8;
409
410 /* Is the hardware capable to generate the extended key? */
411 if (!aes_hw_extkey_available(ctx->key_length))
412 data->cword.b.keygen = 1;
413
414 /* ctx->E starts with a plain key - if the hardware is capable
415 to generate the extended key itself we must supply
416 the plain key for both Encryption and Decryption. */
417 if (encdec == CRYPTO_DIR_ENCRYPT || data->cword.b.keygen == 0)
418 key = ctx->E;
419 else
420 key = ctx->D;
421
422 memcpy(data->buf, in_arg, AES_BLOCK_SIZE);
423 padlock_xcrypt_ecb(data->buf, data->buf, key, &data->cword, 1);
424 memcpy(out_arg, data->buf, AES_BLOCK_SIZE);
425} 413}
426 414
427static void 415static void
428aes_encrypt(void *ctx_arg, uint8_t *out, const uint8_t *in) 416aes_encrypt(void *ctx_arg, uint8_t *out, const uint8_t *in)
429{ 417{
430 aes_padlock(ctx_arg, out, in, CRYPTO_DIR_ENCRYPT); 418 struct aes_ctx *ctx = aes_ctx(ctx_arg);
419 padlock_xcrypt_ecb(in, out, ctx->E, &ctx->cword.encrypt, 1);
431} 420}
432 421
433static void 422static void
434aes_decrypt(void *ctx_arg, uint8_t *out, const uint8_t *in) 423aes_decrypt(void *ctx_arg, uint8_t *out, const uint8_t *in)
435{ 424{
436 aes_padlock(ctx_arg, out, in, CRYPTO_DIR_DECRYPT); 425 struct aes_ctx *ctx = aes_ctx(ctx_arg);
426 padlock_xcrypt_ecb(in, out, ctx->D, &ctx->cword.decrypt, 1);
427}
428
429static unsigned int aes_encrypt_ecb(const struct cipher_desc *desc, u8 *out,
430 const u8 *in, unsigned int nbytes)
431{
432 struct aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(desc->tfm));
433 padlock_xcrypt_ecb(in, out, ctx->E, &ctx->cword.encrypt,
434 nbytes / AES_BLOCK_SIZE);
435 return nbytes & ~(AES_BLOCK_SIZE - 1);
436}
437
438static unsigned int aes_decrypt_ecb(const struct cipher_desc *desc, u8 *out,
439 const u8 *in, unsigned int nbytes)
440{
441 struct aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(desc->tfm));
442 padlock_xcrypt_ecb(in, out, ctx->D, &ctx->cword.decrypt,
443 nbytes / AES_BLOCK_SIZE);
444 return nbytes & ~(AES_BLOCK_SIZE - 1);
445}
446
447static unsigned int aes_encrypt_cbc(const struct cipher_desc *desc, u8 *out,
448 const u8 *in, unsigned int nbytes)
449{
450 struct aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(desc->tfm));
451 u8 *iv;
452
453 iv = padlock_xcrypt_cbc(in, out, ctx->E, desc->info,
454 &ctx->cword.encrypt, nbytes / AES_BLOCK_SIZE);
455 memcpy(desc->info, iv, AES_BLOCK_SIZE);
456
457 return nbytes & ~(AES_BLOCK_SIZE - 1);
458}
459
460static unsigned int aes_decrypt_cbc(const struct cipher_desc *desc, u8 *out,
461 const u8 *in, unsigned int nbytes)
462{
463 struct aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(desc->tfm));
464 padlock_xcrypt_cbc(in, out, ctx->D, desc->info, &ctx->cword.decrypt,
465 nbytes / AES_BLOCK_SIZE);
466 return nbytes & ~(AES_BLOCK_SIZE - 1);
437} 467}
438 468
439static struct crypto_alg aes_alg = { 469static struct crypto_alg aes_alg = {
@@ -441,6 +471,7 @@ static struct crypto_alg aes_alg = {
441 .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 471 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
442 .cra_blocksize = AES_BLOCK_SIZE, 472 .cra_blocksize = AES_BLOCK_SIZE,
443 .cra_ctxsize = sizeof(struct aes_ctx), 473 .cra_ctxsize = sizeof(struct aes_ctx),
474 .cra_alignmask = PADLOCK_ALIGNMENT - 1,
444 .cra_module = THIS_MODULE, 475 .cra_module = THIS_MODULE,
445 .cra_list = LIST_HEAD_INIT(aes_alg.cra_list), 476 .cra_list = LIST_HEAD_INIT(aes_alg.cra_list),
446 .cra_u = { 477 .cra_u = {
@@ -449,7 +480,11 @@ static struct crypto_alg aes_alg = {
449 .cia_max_keysize = AES_MAX_KEY_SIZE, 480 .cia_max_keysize = AES_MAX_KEY_SIZE,
450 .cia_setkey = aes_set_key, 481 .cia_setkey = aes_set_key,
451 .cia_encrypt = aes_encrypt, 482 .cia_encrypt = aes_encrypt,
452 .cia_decrypt = aes_decrypt 483 .cia_decrypt = aes_decrypt,
484 .cia_encrypt_ecb = aes_encrypt_ecb,
485 .cia_decrypt_ecb = aes_decrypt_ecb,
486 .cia_encrypt_cbc = aes_encrypt_cbc,
487 .cia_decrypt_cbc = aes_decrypt_cbc,
453 } 488 }
454 } 489 }
455}; 490};
diff --git a/drivers/crypto/padlock.h b/drivers/crypto/padlock.h
index 7a500605e449..3cf2b7a12348 100644
--- a/drivers/crypto/padlock.h
+++ b/drivers/crypto/padlock.h
@@ -13,18 +13,18 @@
13#ifndef _CRYPTO_PADLOCK_H 13#ifndef _CRYPTO_PADLOCK_H
14#define _CRYPTO_PADLOCK_H 14#define _CRYPTO_PADLOCK_H
15 15
16#define PADLOCK_ALIGNMENT 16
17
16/* Control word. */ 18/* Control word. */
17union cword { 19struct cword {
18 uint32_t cword[4]; 20 int __attribute__ ((__packed__))
19 struct { 21 rounds:4,
20 int rounds:4; 22 algo:3,
21 int algo:3; 23 keygen:1,
22 int keygen:1; 24 interm:1,
23 int interm:1; 25 encdec:1,
24 int encdec:1; 26 ksize:2;
25 int ksize:2; 27} __attribute__ ((__aligned__(PADLOCK_ALIGNMENT)));
26 } b;
27};
28 28
29#define PFX "padlock: " 29#define PFX "padlock: "
30 30
diff --git a/drivers/i2c/busses/i2c-keywest.c b/drivers/i2c/busses/i2c-keywest.c
index 363e545fc01f..94ae808314f7 100644
--- a/drivers/i2c/busses/i2c-keywest.c
+++ b/drivers/i2c/busses/i2c-keywest.c
@@ -698,7 +698,7 @@ dispose_iface(struct device *dev)
698} 698}
699 699
700static int 700static int
701create_iface_macio(struct macio_dev* dev, const struct of_match *match) 701create_iface_macio(struct macio_dev* dev, const struct of_device_id *match)
702{ 702{
703 return create_iface(dev->ofdev.node, &dev->ofdev.dev); 703 return create_iface(dev->ofdev.node, &dev->ofdev.dev);
704} 704}
@@ -710,7 +710,7 @@ dispose_iface_macio(struct macio_dev* dev)
710} 710}
711 711
712static int 712static int
713create_iface_of_platform(struct of_device* dev, const struct of_match *match) 713create_iface_of_platform(struct of_device* dev, const struct of_device_id *match)
714{ 714{
715 return create_iface(dev->node, &dev->dev); 715 return create_iface(dev->node, &dev->dev);
716} 716}
@@ -721,10 +721,9 @@ dispose_iface_of_platform(struct of_device* dev)
721 return dispose_iface(&dev->dev); 721 return dispose_iface(&dev->dev);
722} 722}
723 723
724static struct of_match i2c_keywest_match[] = 724static struct of_device_id i2c_keywest_match[] =
725{ 725{
726 { 726 {
727 .name = OF_ANY_MATCH,
728 .type = "i2c", 727 .type = "i2c",
729 .compatible = "keywest" 728 .compatible = "keywest"
730 }, 729 },
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c
index 818380b5fd27..be0fcc8f4b15 100644
--- a/drivers/ide/ppc/pmac.c
+++ b/drivers/ide/ppc/pmac.c
@@ -1419,7 +1419,7 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
1419 * Attach to a macio probed interface 1419 * Attach to a macio probed interface
1420 */ 1420 */
1421static int __devinit 1421static int __devinit
1422pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_match *match) 1422pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
1423{ 1423{
1424 void __iomem *base; 1424 void __iomem *base;
1425 unsigned long regbase; 1425 unsigned long regbase;
@@ -1637,27 +1637,19 @@ pmac_ide_pci_resume(struct pci_dev *pdev)
1637 return rc; 1637 return rc;
1638} 1638}
1639 1639
1640static struct of_match pmac_ide_macio_match[] = 1640static struct of_device_id pmac_ide_macio_match[] =
1641{ 1641{
1642 { 1642 {
1643 .name = "IDE", 1643 .name = "IDE",
1644 .type = OF_ANY_MATCH,
1645 .compatible = OF_ANY_MATCH
1646 }, 1644 },
1647 { 1645 {
1648 .name = "ATA", 1646 .name = "ATA",
1649 .type = OF_ANY_MATCH,
1650 .compatible = OF_ANY_MATCH
1651 }, 1647 },
1652 { 1648 {
1653 .name = OF_ANY_MATCH,
1654 .type = "ide", 1649 .type = "ide",
1655 .compatible = OF_ANY_MATCH
1656 }, 1650 },
1657 { 1651 {
1658 .name = OF_ANY_MATCH,
1659 .type = "ata", 1652 .type = "ata",
1660 .compatible = OF_ANY_MATCH
1661 }, 1653 },
1662 {}, 1654 {},
1663}; 1655};
diff --git a/drivers/ieee1394/ieee1394_core.h b/drivers/ieee1394/ieee1394_core.h
index 73bd8efd2b6c..0b31429d0a68 100644
--- a/drivers/ieee1394/ieee1394_core.h
+++ b/drivers/ieee1394/ieee1394_core.h
@@ -38,8 +38,8 @@ struct hpsb_packet {
38 38
39 /* These are core internal. */ 39 /* These are core internal. */
40 signed char tlabel; 40 signed char tlabel;
41 char ack_code; 41 signed char ack_code;
42 char tcode; 42 unsigned char tcode;
43 43
44 unsigned expect_response:1; 44 unsigned expect_response:1;
45 unsigned no_waiter:1; 45 unsigned no_waiter:1;
diff --git a/drivers/macintosh/Makefile b/drivers/macintosh/Makefile
index f5ae171dbfef..236291bd48a4 100644
--- a/drivers/macintosh/Makefile
+++ b/drivers/macintosh/Makefile
@@ -4,7 +4,7 @@
4 4
5# Each configuration option enables a list of files. 5# Each configuration option enables a list of files.
6 6
7obj-$(CONFIG_PPC_PMAC) += macio_asic.o 7obj-$(CONFIG_PPC_PMAC) += macio_asic.o macio_sysfs.o
8 8
9obj-$(CONFIG_PMAC_MEDIABAY) += mediabay.o 9obj-$(CONFIG_PMAC_MEDIABAY) += mediabay.o
10obj-$(CONFIG_MAC_EMUMOUSEBTN) += mac_hid.o 10obj-$(CONFIG_MAC_EMUMOUSEBTN) += mac_hid.o
diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
index d0bda7e3e6aa..1ee003346923 100644
--- a/drivers/macintosh/macio_asic.c
+++ b/drivers/macintosh/macio_asic.c
@@ -33,7 +33,7 @@ static int macio_bus_match(struct device *dev, struct device_driver *drv)
33{ 33{
34 struct macio_dev * macio_dev = to_macio_device(dev); 34 struct macio_dev * macio_dev = to_macio_device(dev);
35 struct macio_driver * macio_drv = to_macio_driver(drv); 35 struct macio_driver * macio_drv = to_macio_driver(drv);
36 const struct of_match * matches = macio_drv->match_table; 36 const struct of_device_id * matches = macio_drv->match_table;
37 37
38 if (!matches) 38 if (!matches)
39 return 0; 39 return 0;
@@ -66,7 +66,7 @@ static int macio_device_probe(struct device *dev)
66 int error = -ENODEV; 66 int error = -ENODEV;
67 struct macio_driver *drv; 67 struct macio_driver *drv;
68 struct macio_dev *macio_dev; 68 struct macio_dev *macio_dev;
69 const struct of_match *match; 69 const struct of_device_id *match;
70 70
71 drv = to_macio_driver(dev->driver); 71 drv = to_macio_driver(dev->driver);
72 macio_dev = to_macio_device(dev); 72 macio_dev = to_macio_device(dev);
@@ -126,11 +126,85 @@ static int macio_device_resume(struct device * dev)
126 return 0; 126 return 0;
127} 127}
128 128
129static int macio_hotplug (struct device *dev, char **envp, int num_envp,
130 char *buffer, int buffer_size)
131{
132 struct macio_dev * macio_dev;
133 struct of_device * of;
134 char *scratch, *compat;
135 int i = 0;
136 int length = 0;
137 int cplen, seen = 0;
138
139 if (!dev)
140 return -ENODEV;
141
142 macio_dev = to_macio_device(dev);
143 if (!macio_dev)
144 return -ENODEV;
145
146 of = &macio_dev->ofdev;
147 scratch = buffer;
148
149 /* stuff we want to pass to /sbin/hotplug */
150 envp[i++] = scratch;
151 length += scnprintf (scratch, buffer_size - length, "OF_NAME=%s",
152 of->node->name);
153 if ((buffer_size - length <= 0) || (i >= num_envp))
154 return -ENOMEM;
155 ++length;
156 scratch += length;
157
158 envp[i++] = scratch;
159 length += scnprintf (scratch, buffer_size - length, "OF_TYPE=%s",
160 of->node->type);
161 if ((buffer_size - length <= 0) || (i >= num_envp))
162 return -ENOMEM;
163 ++length;
164 scratch += length;
165
166 /* Since the compatible field can contain pretty much anything
167 * it's not really legal to split it out with commas. We split it
168 * up using a number of environment variables instead. */
169
170 compat = (char *) get_property(of->node, "compatible", &cplen);
171 while (compat && cplen > 0) {
172 int l;
173 envp[i++] = scratch;
174 length += scnprintf (scratch, buffer_size - length,
175 "OF_COMPATIBLE_%d=%s", seen, compat);
176 if ((buffer_size - length <= 0) || (i >= num_envp))
177 return -ENOMEM;
178 length++;
179 scratch += length;
180 l = strlen (compat) + 1;
181 compat += l;
182 cplen -= l;
183 seen++;
184 }
185
186 envp[i++] = scratch;
187 length += scnprintf (scratch, buffer_size - length,
188 "OF_COMPATIBLE_N=%d", seen);
189 if ((buffer_size - length <= 0) || (i >= num_envp))
190 return -ENOMEM;
191 ++length;
192 scratch += length;
193
194 envp[i] = NULL;
195
196 return 0;
197}
198
199extern struct device_attribute macio_dev_attrs[];
200
129struct bus_type macio_bus_type = { 201struct bus_type macio_bus_type = {
130 .name = "macio", 202 .name = "macio",
131 .match = macio_bus_match, 203 .match = macio_bus_match,
204 .hotplug = macio_hotplug,
132 .suspend = macio_device_suspend, 205 .suspend = macio_device_suspend,
133 .resume = macio_device_resume, 206 .resume = macio_device_resume,
207 .dev_attrs = macio_dev_attrs,
134}; 208};
135 209
136static int __init macio_bus_driver_init(void) 210static int __init macio_bus_driver_init(void)
diff --git a/drivers/macintosh/macio_sysfs.c b/drivers/macintosh/macio_sysfs.c
new file mode 100644
index 000000000000..97d22bb4516a
--- /dev/null
+++ b/drivers/macintosh/macio_sysfs.c
@@ -0,0 +1,50 @@
1#include <linux/config.h>
2#include <linux/kernel.h>
3#include <linux/stat.h>
4#include <asm/macio.h>
5
6
7#define macio_config_of_attr(field, format_string) \
8static ssize_t \
9field##_show (struct device *dev, struct device_attribute *attr, \
10 char *buf) \
11{ \
12 struct macio_dev *mdev = to_macio_device (dev); \
13 return sprintf (buf, format_string, mdev->ofdev.node->field); \
14}
15
16static ssize_t
17compatible_show (struct device *dev, struct device_attribute *attr, char *buf)
18{
19 struct of_device *of;
20 char *compat;
21 int cplen;
22 int length = 0;
23
24 of = &to_macio_device (dev)->ofdev;
25 compat = (char *) get_property(of->node, "compatible", &cplen);
26 if (!compat) {
27 *buf = '\0';
28 return 0;
29 }
30 while (cplen > 0) {
31 int l;
32 length += sprintf (buf, "%s\n", compat);
33 buf += length;
34 l = strlen (compat) + 1;
35 compat += l;
36 cplen -= l;
37 }
38
39 return length;
40}
41
42macio_config_of_attr (name, "%s\n");
43macio_config_of_attr (type, "%s\n");
44
45struct device_attribute macio_dev_attrs[] = {
46 __ATTR_RO(name),
47 __ATTR_RO(type),
48 __ATTR_RO(compatible),
49 __ATTR_NULL
50};
diff --git a/drivers/macintosh/mediabay.c b/drivers/macintosh/mediabay.c
index 4be709e13eec..7c16c25fc5d4 100644
--- a/drivers/macintosh/mediabay.c
+++ b/drivers/macintosh/mediabay.c
@@ -642,7 +642,7 @@ static int __pmac media_bay_task(void *x)
642 } 642 }
643} 643}
644 644
645static int __devinit media_bay_attach(struct macio_dev *mdev, const struct of_match *match) 645static int __devinit media_bay_attach(struct macio_dev *mdev, const struct of_device_id *match)
646{ 646{
647 struct media_bay_info* bay; 647 struct media_bay_info* bay;
648 u32 __iomem *regbase; 648 u32 __iomem *regbase;
@@ -797,23 +797,20 @@ static struct mb_ops keylargo_mb_ops __pmacdata = {
797 * Therefore we do it all by polling the media bay once each tick. 797 * Therefore we do it all by polling the media bay once each tick.
798 */ 798 */
799 799
800static struct of_match media_bay_match[] = 800static struct of_device_id media_bay_match[] =
801{ 801{
802 { 802 {
803 .name = "media-bay", 803 .name = "media-bay",
804 .type = OF_ANY_MATCH,
805 .compatible = "keylargo-media-bay", 804 .compatible = "keylargo-media-bay",
806 .data = &keylargo_mb_ops, 805 .data = &keylargo_mb_ops,
807 }, 806 },
808 { 807 {
809 .name = "media-bay", 808 .name = "media-bay",
810 .type = OF_ANY_MATCH,
811 .compatible = "heathrow-media-bay", 809 .compatible = "heathrow-media-bay",
812 .data = &heathrow_mb_ops, 810 .data = &heathrow_mb_ops,
813 }, 811 },
814 { 812 {
815 .name = "media-bay", 813 .name = "media-bay",
816 .type = OF_ANY_MATCH,
817 .compatible = "ohare-media-bay", 814 .compatible = "ohare-media-bay",
818 .data = &ohare_mb_ops, 815 .data = &ohare_mb_ops,
819 }, 816 },
diff --git a/drivers/macintosh/therm_pm72.c b/drivers/macintosh/therm_pm72.c
index feb4e2413858..703e31973314 100644
--- a/drivers/macintosh/therm_pm72.c
+++ b/drivers/macintosh/therm_pm72.c
@@ -120,6 +120,7 @@
120#include <asm/system.h> 120#include <asm/system.h>
121#include <asm/sections.h> 121#include <asm/sections.h>
122#include <asm/of_device.h> 122#include <asm/of_device.h>
123#include <asm/macio.h>
123 124
124#include "therm_pm72.h" 125#include "therm_pm72.h"
125 126
@@ -1986,7 +1987,7 @@ static void fcu_lookup_fans(struct device_node *fcu_node)
1986 } 1987 }
1987} 1988}
1988 1989
1989static int fcu_of_probe(struct of_device* dev, const struct of_match *match) 1990static int fcu_of_probe(struct of_device* dev, const struct of_device_id *match)
1990{ 1991{
1991 int rc; 1992 int rc;
1992 1993
@@ -2009,12 +2010,10 @@ static int fcu_of_remove(struct of_device* dev)
2009 return 0; 2010 return 0;
2010} 2011}
2011 2012
2012static struct of_match fcu_of_match[] = 2013static struct of_device_id fcu_match[] =
2013{ 2014{
2014 { 2015 {
2015 .name = OF_ANY_MATCH,
2016 .type = "fcu", 2016 .type = "fcu",
2017 .compatible = OF_ANY_MATCH
2018 }, 2017 },
2019 {}, 2018 {},
2020}; 2019};
@@ -2022,7 +2021,7 @@ static struct of_match fcu_of_match[] =
2022static struct of_platform_driver fcu_of_platform_driver = 2021static struct of_platform_driver fcu_of_platform_driver =
2023{ 2022{
2024 .name = "temperature", 2023 .name = "temperature",
2025 .match_table = fcu_of_match, 2024 .match_table = fcu_match,
2026 .probe = fcu_of_probe, 2025 .probe = fcu_of_probe,
2027 .remove = fcu_of_remove 2026 .remove = fcu_of_remove
2028}; 2027};
diff --git a/drivers/macintosh/therm_windtunnel.c b/drivers/macintosh/therm_windtunnel.c
index 61400f04015e..cbb72eb0426d 100644
--- a/drivers/macintosh/therm_windtunnel.c
+++ b/drivers/macintosh/therm_windtunnel.c
@@ -43,6 +43,7 @@
43#include <asm/system.h> 43#include <asm/system.h>
44#include <asm/sections.h> 44#include <asm/sections.h>
45#include <asm/of_device.h> 45#include <asm/of_device.h>
46#include <asm/macio.h>
46 47
47#define LOG_TEMP 0 /* continously log temperature */ 48#define LOG_TEMP 0 /* continously log temperature */
48 49
@@ -450,7 +451,7 @@ do_probe( struct i2c_adapter *adapter, int addr, int kind )
450/************************************************************************/ 451/************************************************************************/
451 452
452static int 453static int
453therm_of_probe( struct of_device *dev, const struct of_match *match ) 454therm_of_probe( struct of_device *dev, const struct of_device_id *match )
454{ 455{
455 return i2c_add_driver( &g4fan_driver ); 456 return i2c_add_driver( &g4fan_driver );
456} 457}
@@ -461,9 +462,8 @@ therm_of_remove( struct of_device *dev )
461 return i2c_del_driver( &g4fan_driver ); 462 return i2c_del_driver( &g4fan_driver );
462} 463}
463 464
464static struct of_match therm_of_match[] = {{ 465static struct of_device_id therm_of_match[] = {{
465 .name = "fan", 466 .name = "fan",
466 .type = OF_ANY_MATCH,
467 .compatible = "adm1030" 467 .compatible = "adm1030"
468 }, {} 468 }, {}
469}; 469};
diff --git a/drivers/media/dvb/frontends/tda80xx.c b/drivers/media/dvb/frontends/tda80xx.c
index 032d348dafb7..88e125079ca1 100644
--- a/drivers/media/dvb/frontends/tda80xx.c
+++ b/drivers/media/dvb/frontends/tda80xx.c
@@ -27,7 +27,6 @@
27#include <linux/spinlock.h> 27#include <linux/spinlock.h>
28#include <linux/threads.h> 28#include <linux/threads.h>
29#include <linux/interrupt.h> 29#include <linux/interrupt.h>
30#include <linux/irq.h>
31#include <linux/kernel.h> 30#include <linux/kernel.h>
32#include <linux/module.h> 31#include <linux/module.h>
33#include <linux/slab.h> 32#include <linux/slab.h>
diff --git a/drivers/net/bmac.c b/drivers/net/bmac.c
index 00e5257b176f..8dc657fc8afb 100644
--- a/drivers/net/bmac.c
+++ b/drivers/net/bmac.c
@@ -1261,7 +1261,7 @@ static void bmac_reset_and_enable(struct net_device *dev)
1261 spin_unlock_irqrestore(&bp->lock, flags); 1261 spin_unlock_irqrestore(&bp->lock, flags);
1262} 1262}
1263 1263
1264static int __devinit bmac_probe(struct macio_dev *mdev, const struct of_match *match) 1264static int __devinit bmac_probe(struct macio_dev *mdev, const struct of_device_id *match)
1265{ 1265{
1266 int j, rev, ret; 1266 int j, rev, ret;
1267 struct bmac_data *bp; 1267 struct bmac_data *bp;
@@ -1645,16 +1645,13 @@ static int __devexit bmac_remove(struct macio_dev *mdev)
1645 return 0; 1645 return 0;
1646} 1646}
1647 1647
1648static struct of_match bmac_match[] = 1648static struct of_device_id bmac_match[] =
1649{ 1649{
1650 { 1650 {
1651 .name = "bmac", 1651 .name = "bmac",
1652 .type = OF_ANY_MATCH,
1653 .compatible = OF_ANY_MATCH,
1654 .data = (void *)0, 1652 .data = (void *)0,
1655 }, 1653 },
1656 { 1654 {
1657 .name = OF_ANY_MATCH,
1658 .type = "network", 1655 .type = "network",
1659 .compatible = "bmac+", 1656 .compatible = "bmac+",
1660 .data = (void *)1, 1657 .data = (void *)1,
diff --git a/drivers/net/mace.c b/drivers/net/mace.c
index 6ed2d7dbd44c..81d0a26e4f41 100644
--- a/drivers/net/mace.c
+++ b/drivers/net/mace.c
@@ -109,7 +109,7 @@ bitrev(int b)
109} 109}
110 110
111 111
112static int __devinit mace_probe(struct macio_dev *mdev, const struct of_match *match) 112static int __devinit mace_probe(struct macio_dev *mdev, const struct of_device_id *match)
113{ 113{
114 struct device_node *mace = macio_get_of_node(mdev); 114 struct device_node *mace = macio_get_of_node(mdev);
115 struct net_device *dev; 115 struct net_device *dev;
@@ -1009,12 +1009,10 @@ static irqreturn_t mace_rxdma_intr(int irq, void *dev_id, struct pt_regs *regs)
1009 return IRQ_HANDLED; 1009 return IRQ_HANDLED;
1010} 1010}
1011 1011
1012static struct of_match mace_match[] = 1012static struct of_device_id mace_match[] =
1013{ 1013{
1014 { 1014 {
1015 .name = "mace", 1015 .name = "mace",
1016 .type = OF_ANY_MATCH,
1017 .compatible = OF_ANY_MATCH
1018 }, 1016 },
1019 {}, 1017 {},
1020}; 1018};
diff --git a/drivers/net/wireless/airport.c b/drivers/net/wireless/airport.c
index b4f4bd7956a2..9d496703c465 100644
--- a/drivers/net/wireless/airport.c
+++ b/drivers/net/wireless/airport.c
@@ -184,7 +184,7 @@ static int airport_hard_reset(struct orinoco_private *priv)
184} 184}
185 185
186static int 186static int
187airport_attach(struct macio_dev *mdev, const struct of_match *match) 187airport_attach(struct macio_dev *mdev, const struct of_device_id *match)
188{ 188{
189 struct orinoco_private *priv; 189 struct orinoco_private *priv;
190 struct net_device *dev; 190 struct net_device *dev;
@@ -266,16 +266,16 @@ MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
266MODULE_DESCRIPTION("Driver for the Apple Airport wireless card."); 266MODULE_DESCRIPTION("Driver for the Apple Airport wireless card.");
267MODULE_LICENSE("Dual MPL/GPL"); 267MODULE_LICENSE("Dual MPL/GPL");
268 268
269static struct of_match airport_match[] = 269static struct of_device_id airport_match[] =
270{ 270{
271 { 271 {
272 .name = "radio", 272 .name = "radio",
273 .type = OF_ANY_MATCH,
274 .compatible = OF_ANY_MATCH
275 }, 273 },
276 {}, 274 {},
277}; 275};
278 276
277MODULE_DEVICE_TABLE (of, airport_match);
278
279static struct macio_driver airport_driver = 279static struct macio_driver airport_driver =
280{ 280{
281 .name = DRIVER_NAME, 281 .name = DRIVER_NAME,
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index c1bdfb424658..9fe48f712be9 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -74,6 +74,7 @@ pbus_assign_resources_sorted(struct pci_bus *bus)
74 idx = res - &list->dev->resource[0]; 74 idx = res - &list->dev->resource[0];
75 if (pci_assign_resource(list->dev, idx)) { 75 if (pci_assign_resource(list->dev, idx)) {
76 res->start = 0; 76 res->start = 0;
77 res->end = 0;
77 res->flags = 0; 78 res->flags = 0;
78 } 79 }
79 tmp = list; 80 tmp = list;
diff --git a/drivers/scsi/mac53c94.c b/drivers/scsi/mac53c94.c
index edd47d1f0b17..932dcf0366eb 100644
--- a/drivers/scsi/mac53c94.c
+++ b/drivers/scsi/mac53c94.c
@@ -424,7 +424,7 @@ static struct scsi_host_template mac53c94_template = {
424 .use_clustering = DISABLE_CLUSTERING, 424 .use_clustering = DISABLE_CLUSTERING,
425}; 425};
426 426
427static int mac53c94_probe(struct macio_dev *mdev, const struct of_match *match) 427static int mac53c94_probe(struct macio_dev *mdev, const struct of_device_id *match)
428{ 428{
429 struct device_node *node = macio_get_of_node(mdev); 429 struct device_node *node = macio_get_of_node(mdev);
430 struct pci_dev *pdev = macio_get_pci_dev(mdev); 430 struct pci_dev *pdev = macio_get_pci_dev(mdev);
@@ -544,15 +544,14 @@ static int mac53c94_remove(struct macio_dev *mdev)
544} 544}
545 545
546 546
547static struct of_match mac53c94_match[] = 547static struct of_device_id mac53c94_match[] =
548{ 548{
549 { 549 {
550 .name = "53c94", 550 .name = "53c94",
551 .type = OF_ANY_MATCH,
552 .compatible = OF_ANY_MATCH
553 }, 551 },
554 {}, 552 {},
555}; 553};
554MODULE_DEVICE_TABLE (of, mac53c94_match);
556 555
557static struct macio_driver mac53c94_driver = 556static struct macio_driver mac53c94_driver =
558{ 557{
diff --git a/drivers/scsi/mesh.c b/drivers/scsi/mesh.c
index b05737ae5eff..ff1933298da6 100644
--- a/drivers/scsi/mesh.c
+++ b/drivers/scsi/mesh.c
@@ -1847,7 +1847,7 @@ static struct scsi_host_template mesh_template = {
1847 .use_clustering = DISABLE_CLUSTERING, 1847 .use_clustering = DISABLE_CLUSTERING,
1848}; 1848};
1849 1849
1850static int mesh_probe(struct macio_dev *mdev, const struct of_match *match) 1850static int mesh_probe(struct macio_dev *mdev, const struct of_device_id *match)
1851{ 1851{
1852 struct device_node *mesh = macio_get_of_node(mdev); 1852 struct device_node *mesh = macio_get_of_node(mdev);
1853 struct pci_dev* pdev = macio_get_pci_dev(mdev); 1853 struct pci_dev* pdev = macio_get_pci_dev(mdev);
@@ -2012,20 +2012,18 @@ static int mesh_remove(struct macio_dev *mdev)
2012} 2012}
2013 2013
2014 2014
2015static struct of_match mesh_match[] = 2015static struct of_device_id mesh_match[] =
2016{ 2016{
2017 { 2017 {
2018 .name = "mesh", 2018 .name = "mesh",
2019 .type = OF_ANY_MATCH,
2020 .compatible = OF_ANY_MATCH
2021 }, 2019 },
2022 { 2020 {
2023 .name = OF_ANY_MATCH,
2024 .type = "scsi", 2021 .type = "scsi",
2025 .compatible = "chrp,mesh0" 2022 .compatible = "chrp,mesh0"
2026 }, 2023 },
2027 {}, 2024 {},
2028}; 2025};
2026MODULE_DEVICE_TABLE (of, mesh_match);
2029 2027
2030static struct macio_driver mesh_driver = 2028static struct macio_driver mesh_driver =
2031{ 2029{
diff --git a/drivers/serial/pmac_zilog.c b/drivers/serial/pmac_zilog.c
index 1c9f71617123..7db2f37532cf 100644
--- a/drivers/serial/pmac_zilog.c
+++ b/drivers/serial/pmac_zilog.c
@@ -1545,7 +1545,7 @@ static void pmz_dispose_port(struct uart_pmac_port *uap)
1545/* 1545/*
1546 * Called upon match with an escc node in the devive-tree. 1546 * Called upon match with an escc node in the devive-tree.
1547 */ 1547 */
1548static int pmz_attach(struct macio_dev *mdev, const struct of_match *match) 1548static int pmz_attach(struct macio_dev *mdev, const struct of_device_id *match)
1549{ 1549{
1550 int i; 1550 int i;
1551 1551
@@ -1850,20 +1850,17 @@ err_out:
1850 return rc; 1850 return rc;
1851} 1851}
1852 1852
1853static struct of_match pmz_match[] = 1853static struct of_device_id pmz_match[] =
1854{ 1854{
1855 { 1855 {
1856 .name = "ch-a", 1856 .name = "ch-a",
1857 .type = OF_ANY_MATCH,
1858 .compatible = OF_ANY_MATCH
1859 }, 1857 },
1860 { 1858 {
1861 .name = "ch-b", 1859 .name = "ch-b",
1862 .type = OF_ANY_MATCH,
1863 .compatible = OF_ANY_MATCH
1864 }, 1860 },
1865 {}, 1861 {},
1866}; 1862};
1863MODULE_DEVICE_TABLE (of, pmz_match);
1867 1864
1868static struct macio_driver pmz_driver = 1865static struct macio_driver pmz_driver =
1869{ 1866{
diff --git a/drivers/video/platinumfb.c b/drivers/video/platinumfb.c
index 3dd1de1539d2..b00887e9851c 100644
--- a/drivers/video/platinumfb.c
+++ b/drivers/video/platinumfb.c
@@ -523,7 +523,7 @@ int __init platinumfb_setup(char *options)
523#define invalidate_cache(addr) 523#define invalidate_cache(addr)
524#endif 524#endif
525 525
526static int __devinit platinumfb_probe(struct of_device* odev, const struct of_match *match) 526static int __devinit platinumfb_probe(struct of_device* odev, const struct of_device_id *match)
527{ 527{
528 struct device_node *dp = odev->node; 528 struct device_node *dp = odev->node;
529 struct fb_info *info; 529 struct fb_info *info;
@@ -647,12 +647,10 @@ static int __devexit platinumfb_remove(struct of_device* odev)
647 return 0; 647 return 0;
648} 648}
649 649
650static struct of_match platinumfb_match[] = 650static struct of_device_id platinumfb_match[] =
651{ 651{
652 { 652 {
653 .name = "platinum", 653 .name = "platinum",
654 .type = OF_ANY_MATCH,
655 .compatible = OF_ANY_MATCH,
656 }, 654 },
657 {}, 655 {},
658}; 656};
diff --git a/include/asm-arm/arch-ixp4xx/io.h b/include/asm-arm/arch-ixp4xx/io.h
index c27b9d3079a7..7495026e2c18 100644
--- a/include/asm-arm/arch-ixp4xx/io.h
+++ b/include/asm-arm/arch-ixp4xx/io.h
@@ -3,7 +3,7 @@
3 * 3 *
4 * Author: Deepak Saxena <dsaxena@plexity.net> 4 * Author: Deepak Saxena <dsaxena@plexity.net>
5 * 5 *
6 * Copyright (C) 2002-2004 MontaVista Software, Inc. 6 * Copyright (C) 2002-2005 MontaVista Software, Inc.
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as 9 * it under the terms of the GNU General Public License version 2 as
@@ -383,6 +383,180 @@ __ixp4xx_insl(u32 io_addr, u32 *vaddr, u32 count)
383 *vaddr++ = inl(io_addr); 383 *vaddr++ = inl(io_addr);
384} 384}
385 385
386#define __is_io_address(p) (((unsigned long)p >= 0x0) && \
387 ((unsigned long)p <= 0x0000ffff))
388static inline unsigned int
389__ixp4xx_ioread8(void __iomem *port)
390{
391 if (__is_io_address(port))
392 return (unsigned int)__ixp4xx_inb((unsigned int)port);
393 else
394#ifndef CONFIG_IXP4XX_INDIRECT_PCI
395 return (unsigned int)__raw_readb((u32)port);
396#else
397 return (unsigned int)__ixp4xx_readb((u32)port);
398#endif
399}
400
401static inline void
402__ixp4xx_ioread8_rep(u32 port, u8 *vaddr, u32 count)
403{
404 if (__is_io_address(port))
405 __ixp4xx_insb(port, vaddr, count);
406 else
407#ifndef CONFIG_IXP4XX_INDIRECT_PCI
408 __raw_readsb((void __iomem *)port, vaddr, count);
409#else
410 __ixp4xx_readsb(port, vaddr, count);
411#endif
412}
413
414static inline unsigned int
415__ixp4xx_ioread16(void __iomem *port)
416{
417 if (__is_io_address(port))
418 return (unsigned int)__ixp4xx_inw((unsigned int)port);
419 else
420#ifndef CONFIG_IXP4XX_INDIRECT_PCI
421 return le16_to_cpu(__raw_readw((u32)port));
422#else
423 return (unsigned int)__ixp4xx_readw((u32)port);
424#endif
425}
426
427static inline void
428__ixp4xx_ioread16_rep(u32 port, u16 *vaddr, u32 count)
429{
430 if (__is_io_address(port))
431 __ixp4xx_insw(port, vaddr, count);
432 else
433#ifndef CONFIG_IXP4XX_INDIRECT_PCI
434 __raw_readsw((void __iomem *)port, vaddr, count);
435#else
436 __ixp4xx_readsw(port, vaddr, count);
437#endif
438}
439
440static inline unsigned int
441__ixp4xx_ioread32(void __iomem *port)
442{
443 if (__is_io_address(port))
444 return (unsigned int)__ixp4xx_inl((unsigned int)port);
445 else {
446#ifndef CONFIG_IXP4XX_INDIRECT_PCI
447 return le32_to_cpu(__raw_readl((u32)port));
448#else
449 return (unsigned int)__ixp4xx_readl((u32)port);
450#endif
451 }
452}
453
454static inline void
455__ixp4xx_ioread32_rep(u32 port, u32 *vaddr, u32 count)
456{
457 if (__is_io_address(port))
458 __ixp4xx_insl(port, vaddr, count);
459 else
460#ifndef CONFIG_IXP4XX_INDIRECT_PCI
461 __raw_readsl((void __iomem *)port, vaddr, count);
462#else
463 __ixp4xx_readsl(port, vaddr, count);
464#endif
465}
466
467static inline void
468__ixp4xx_iowrite8(u8 value, void __iomem *port)
469{
470 if (__is_io_address(port))
471 __ixp4xx_outb(value, (unsigned int)port);
472 else
473#ifndef CONFIG_IXP4XX_INDIRECT_PCI
474 __raw_writeb(value, (u32)port);
475#else
476 __ixp4xx_writeb(value, (u32)port);
477#endif
478}
479
480static inline void
481__ixp4xx_iowrite8_rep(u32 port, u8 *vaddr, u32 count)
482{
483 if (__is_io_address(port))
484 __ixp4xx_outsb(port, vaddr, count);
485#ifndef CONFIG_IXP4XX_INDIRECT_PCI
486 __raw_writesb((void __iomem *)port, vaddr, count);
487#else
488 __ixp4xx_writesb(port, vaddr, count);
489#endif
490}
491
492static inline void
493__ixp4xx_iowrite16(u16 value, void __iomem *port)
494{
495 if (__is_io_address(port))
496 __ixp4xx_outw(value, (unsigned int)port);
497 else
498#ifndef CONFIG_IXP4XX_INDIRECT_PCI
499 __raw_writew(cpu_to_le16(value), (u32)port);
500#else
501 __ixp4xx_writew(value, (u32)port);
502#endif
503}
504
505static inline void
506__ixp4xx_iowrite16_rep(u32 port, u16 *vaddr, u32 count)
507{
508 if (__is_io_address(port))
509 __ixp4xx_outsw(port, vaddr, count);
510#ifndef CONFIG_IXP4XX_INDIRECT_PCI
511 __raw_readsw((void __iomem *)port, vaddr, count);
512#else
513 __ixp4xx_writesw(port, vaddr, count);
514#endif
515}
516
517static inline void
518__ixp4xx_iowrite32(u32 value, void __iomem *port)
519{
520 if (__is_io_address(port))
521 __ixp4xx_outl(value, (unsigned int)port);
522 else
523#ifndef CONFIG_IXP4XX_INDIRECT_PCI
524 __raw_writel(cpu_to_le32(value), (u32)port);
525#else
526 __ixp4xx_writel(value, (u32)port);
527#endif
528}
529
530static inline void
531__ixp4xx_iowrite32_rep(u32 port, u32 *vaddr, u32 count)
532{
533 if (__is_io_address(port))
534 __ixp4xx_outsl(port, vaddr, count);
535#ifndef CONFIG_IXP4XX_INDIRECT_PCI
536 __raw_readsl((void __iomem *)port, vaddr, count);
537#else
538 __ixp4xx_outsl(port, vaddr, count);
539#endif
540}
541
542#define ioread8(p) __ixp4xx_ioread8(p)
543#define ioread16(p) __ixp4xx_ioread16(p)
544#define ioread32(p) __ixp4xx_ioread32(p)
545
546#define ioread8_rep(p, v, c) __ixp4xx_ioread8_rep(p, v, c)
547#define ioread16_rep(p, v, c) __ixp4xx_ioread16_rep(p, v, c)
548#define ioread32_rep(p, v, c) __ixp4xx_ioread32_rep(p, v, c)
549
550#define iowrite8(v,p) __ixp4xx_iowrite8(v,p)
551#define iowrite16(v,p) __ixp4xx_iowrite16(v,p)
552#define iowrite32(v,p) __ixp4xx_iowrite32(v,p)
553
554#define iowrite8_rep(p, v, c) __ixp4xx_iowrite8_rep(p, v, c)
555#define iowrite16_rep(p, v, c) __ixp4xx_iowrite16_rep(p, v, c)
556#define iowrite32_rep(p, v, c) __ixp4xx_iowrite32_rep(p, v, c)
557
558#define ioport_map(port, nr) ((void __iomem*)port)
559#define ioport_unmap(addr)
386 560
387#endif // __ASM_ARM_ARCH_IO_H 561#endif // __ASM_ARM_ARCH_IO_H
388 562
diff --git a/include/asm-ppc/macio.h b/include/asm-ppc/macio.h
index 2cafc9978607..a481b772d154 100644
--- a/include/asm-ppc/macio.h
+++ b/include/asm-ppc/macio.h
@@ -1,6 +1,7 @@
1#ifndef __MACIO_ASIC_H__ 1#ifndef __MACIO_ASIC_H__
2#define __MACIO_ASIC_H__ 2#define __MACIO_ASIC_H__
3 3
4#include <linux/mod_devicetable.h>
4#include <asm/of_device.h> 5#include <asm/of_device.h>
5 6
6extern struct bus_type macio_bus_type; 7extern struct bus_type macio_bus_type;
@@ -120,10 +121,10 @@ static inline struct pci_dev *macio_get_pci_dev(struct macio_dev *mdev)
120struct macio_driver 121struct macio_driver
121{ 122{
122 char *name; 123 char *name;
123 struct of_match *match_table; 124 struct of_device_id *match_table;
124 struct module *owner; 125 struct module *owner;
125 126
126 int (*probe)(struct macio_dev* dev, const struct of_match *match); 127 int (*probe)(struct macio_dev* dev, const struct of_device_id *match);
127 int (*remove)(struct macio_dev* dev); 128 int (*remove)(struct macio_dev* dev);
128 129
129 int (*suspend)(struct macio_dev* dev, pm_message_t state); 130 int (*suspend)(struct macio_dev* dev, pm_message_t state);
diff --git a/include/asm-ppc/of_device.h b/include/asm-ppc/of_device.h
index 7229735a7c18..4b264cfd3998 100644
--- a/include/asm-ppc/of_device.h
+++ b/include/asm-ppc/of_device.h
@@ -24,20 +24,8 @@ struct of_device
24}; 24};
25#define to_of_device(d) container_of(d, struct of_device, dev) 25#define to_of_device(d) container_of(d, struct of_device, dev)
26 26
27/* 27extern const struct of_device_id *of_match_device(
28 * Struct used for matching a device 28 const struct of_device_id *matches, const struct of_device *dev);
29 */
30struct of_match
31{
32 char *name;
33 char *type;
34 char *compatible;
35 void *data;
36};
37#define OF_ANY_MATCH ((char *)-1L)
38
39extern const struct of_match *of_match_device(
40 const struct of_match *matches, const struct of_device *dev);
41 29
42extern struct of_device *of_dev_get(struct of_device *dev); 30extern struct of_device *of_dev_get(struct of_device *dev);
43extern void of_dev_put(struct of_device *dev); 31extern void of_dev_put(struct of_device *dev);
@@ -49,10 +37,10 @@ extern void of_dev_put(struct of_device *dev);
49struct of_platform_driver 37struct of_platform_driver
50{ 38{
51 char *name; 39 char *name;
52 struct of_match *match_table; 40 struct of_device_id *match_table;
53 struct module *owner; 41 struct module *owner;
54 42
55 int (*probe)(struct of_device* dev, const struct of_match *match); 43 int (*probe)(struct of_device* dev, const struct of_device_id *match);
56 int (*remove)(struct of_device* dev); 44 int (*remove)(struct of_device* dev);
57 45
58 int (*suspend)(struct of_device* dev, pm_message_t state); 46 int (*suspend)(struct of_device* dev, pm_message_t state);
diff --git a/include/asm-sparc64/parport.h b/include/asm-sparc64/parport.h
index b7e635544cec..56b5197d7898 100644
--- a/include/asm-sparc64/parport.h
+++ b/include/asm-sparc64/parport.h
@@ -27,12 +27,12 @@ static struct sparc_ebus_info {
27 27
28static __inline__ void enable_dma(unsigned int dmanr) 28static __inline__ void enable_dma(unsigned int dmanr)
29{ 29{
30 ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 1);
31
30 if (ebus_dma_request(&sparc_ebus_dmas[dmanr].info, 32 if (ebus_dma_request(&sparc_ebus_dmas[dmanr].info,
31 sparc_ebus_dmas[dmanr].addr, 33 sparc_ebus_dmas[dmanr].addr,
32 sparc_ebus_dmas[dmanr].count)) 34 sparc_ebus_dmas[dmanr].count))
33 BUG(); 35 BUG();
34
35 ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 1);
36} 36}
37 37
38static __inline__ void disable_dma(unsigned int dmanr) 38static __inline__ void disable_dma(unsigned int dmanr)
diff --git a/include/linux/crypto.h b/include/linux/crypto.h
index 387da6a3e58c..5e2bcc636a02 100644
--- a/include/linux/crypto.h
+++ b/include/linux/crypto.h
@@ -61,6 +61,15 @@
61#define CRYPTO_DIR_DECRYPT 0 61#define CRYPTO_DIR_DECRYPT 0
62 62
63struct scatterlist; 63struct scatterlist;
64struct crypto_tfm;
65
66struct cipher_desc {
67 struct crypto_tfm *tfm;
68 void (*crfn)(void *ctx, u8 *dst, const u8 *src);
69 unsigned int (*prfn)(const struct cipher_desc *desc, u8 *dst,
70 const u8 *src, unsigned int nbytes);
71 void *info;
72};
64 73
65/* 74/*
66 * Algorithms: modular crypto algorithm implementations, managed 75 * Algorithms: modular crypto algorithm implementations, managed
@@ -73,6 +82,19 @@ struct cipher_alg {
73 unsigned int keylen, u32 *flags); 82 unsigned int keylen, u32 *flags);
74 void (*cia_encrypt)(void *ctx, u8 *dst, const u8 *src); 83 void (*cia_encrypt)(void *ctx, u8 *dst, const u8 *src);
75 void (*cia_decrypt)(void *ctx, u8 *dst, const u8 *src); 84 void (*cia_decrypt)(void *ctx, u8 *dst, const u8 *src);
85
86 unsigned int (*cia_encrypt_ecb)(const struct cipher_desc *desc,
87 u8 *dst, const u8 *src,
88 unsigned int nbytes);
89 unsigned int (*cia_decrypt_ecb)(const struct cipher_desc *desc,
90 u8 *dst, const u8 *src,
91 unsigned int nbytes);
92 unsigned int (*cia_encrypt_cbc)(const struct cipher_desc *desc,
93 u8 *dst, const u8 *src,
94 unsigned int nbytes);
95 unsigned int (*cia_decrypt_cbc)(const struct cipher_desc *desc,
96 u8 *dst, const u8 *src,
97 unsigned int nbytes);
76}; 98};
77 99
78struct digest_alg { 100struct digest_alg {
@@ -102,6 +124,7 @@ struct crypto_alg {
102 u32 cra_flags; 124 u32 cra_flags;
103 unsigned int cra_blocksize; 125 unsigned int cra_blocksize;
104 unsigned int cra_ctxsize; 126 unsigned int cra_ctxsize;
127 unsigned int cra_alignmask;
105 const char cra_name[CRYPTO_MAX_ALG_NAME]; 128 const char cra_name[CRYPTO_MAX_ALG_NAME];
106 129
107 union { 130 union {
@@ -136,7 +159,6 @@ static inline int crypto_alg_available(const char *name, u32 flags)
136 * and core processing logic. Managed via crypto_alloc_tfm() and 159 * and core processing logic. Managed via crypto_alloc_tfm() and
137 * crypto_free_tfm(), as well as the various helpers below. 160 * crypto_free_tfm(), as well as the various helpers below.
138 */ 161 */
139struct crypto_tfm;
140 162
141struct cipher_tfm { 163struct cipher_tfm {
142 void *cit_iv; 164 void *cit_iv;
@@ -266,6 +288,16 @@ static inline unsigned int crypto_tfm_alg_digestsize(struct crypto_tfm *tfm)
266 return tfm->__crt_alg->cra_digest.dia_digestsize; 288 return tfm->__crt_alg->cra_digest.dia_digestsize;
267} 289}
268 290
291static inline unsigned int crypto_tfm_alg_alignmask(struct crypto_tfm *tfm)
292{
293 return tfm->__crt_alg->cra_alignmask;
294}
295
296static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm)
297{
298 return (void *)&tfm[1];
299}
300
269/* 301/*
270 * API wrappers. 302 * API wrappers.
271 */ 303 */
diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
index 9b6d05172ed4..dce53ac1625d 100644
--- a/include/linux/mod_devicetable.h
+++ b/include/linux/mod_devicetable.h
@@ -174,6 +174,17 @@ struct serio_device_id {
174 __u8 proto; 174 __u8 proto;
175}; 175};
176 176
177/*
178 * Struct used for matching a device
179 */
180struct of_device_id
181{
182 char name[32];
183 char type[32];
184 char compatible[128];
185 void *data;
186};
187
177 188
178/* PCMCIA */ 189/* PCMCIA */
179 190
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 908bff6d1eef..5180405c1a84 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -25,6 +25,8 @@ typedef Elf64_Addr kernel_ulong_t;
25#include <stdint.h> 25#include <stdint.h>
26#endif 26#endif
27 27
28#include <ctype.h>
29
28typedef uint32_t __u32; 30typedef uint32_t __u32;
29typedef uint16_t __u16; 31typedef uint16_t __u16;
30typedef unsigned char __u8; 32typedef unsigned char __u8;
@@ -323,6 +325,22 @@ static int do_pcmcia_entry(const char *filename,
323 325
324 326
325 327
328static int do_of_entry (const char *filename, struct of_device_id *of, char *alias)
329{
330 char *tmp;
331 sprintf (alias, "of:N%sT%sC%s",
332 of->name[0] ? of->name : "*",
333 of->type[0] ? of->type : "*",
334 of->compatible[0] ? of->compatible : "*");
335
336 /* Replace all whitespace with underscores */
337 for (tmp = alias; tmp && *tmp; tmp++)
338 if (isspace (*tmp))
339 *tmp = '_';
340
341 return 1;
342}
343
326/* Ignore any prefix, eg. v850 prepends _ */ 344/* Ignore any prefix, eg. v850 prepends _ */
327static inline int sym_is(const char *symbol, const char *name) 345static inline int sym_is(const char *symbol, const char *name)
328{ 346{
@@ -401,6 +419,10 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
401 else if (sym_is(symname, "__mod_pcmcia_device_table")) 419 else if (sym_is(symname, "__mod_pcmcia_device_table"))
402 do_table(symval, sym->st_size, sizeof(struct pcmcia_device_id), 420 do_table(symval, sym->st_size, sizeof(struct pcmcia_device_id),
403 do_pcmcia_entry, mod); 421 do_pcmcia_entry, mod);
422 else if (sym_is(symname, "__mod_of_device_table"))
423 do_table(symval, sym->st_size, sizeof(struct of_device_id),
424 do_of_entry, mod);
425
404} 426}
405 427
406/* Now add out buffered information to the generated C source */ 428/* Now add out buffered information to the generated C source */