~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/crypto/cast6_generic.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /crypto/cast6_generic.c (Version linux-6.12-rc7) and /crypto/cast6_generic.c (Version linux-3.10.108)


  1 // SPDX-License-Identifier: GPL-2.0-or-later   << 
  2 /* Kernel cryptographic api.                        1 /* Kernel cryptographic api.
  3  * cast6.c - Cast6 cipher algorithm [rfc2612].      2  * cast6.c - Cast6 cipher algorithm [rfc2612].
  4  *                                                  3  *
  5  * CAST-256 (*cast6*) is a DES like Substituti      4  * CAST-256 (*cast6*) is a DES like Substitution-Permutation Network (SPN)
  6  * cryptosystem built upon the CAST-128 (*cast      5  * cryptosystem built upon the CAST-128 (*cast5*) [rfc2144] encryption
  7  * algorithm.                                       6  * algorithm.
  8  *                                                  7  *
  9  * Copyright (C) 2003 Kartikey Mahendra Bhatt       8  * Copyright (C) 2003 Kartikey Mahendra Bhatt <kartik_me@hotmail.com>.
                                                   >>   9  *
                                                   >>  10  * This program is free software; you can redistribute it and/or modify it
                                                   >>  11  * under the terms of GNU General Public License as published by the Free
                                                   >>  12  * Software Foundation; either version 2 of the License, or (at your option)
                                                   >>  13  * any later version.
                                                   >>  14  *
                                                   >>  15  * You should have received a copy of the GNU General Public License
                                                   >>  16  * along with this program; if not, write to the Free Software
                                                   >>  17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 10  */                                                18  */
 11                                                    19 
 12                                                    20 
 13 #include <linux/unaligned.h>                   !!  21 #include <asm/byteorder.h>
 14 #include <crypto/algapi.h>                     << 
 15 #include <linux/init.h>                            22 #include <linux/init.h>
                                                   >>  23 #include <linux/crypto.h>
 16 #include <linux/module.h>                          24 #include <linux/module.h>
 17 #include <linux/errno.h>                           25 #include <linux/errno.h>
 18 #include <linux/string.h>                          26 #include <linux/string.h>
 19 #include <linux/types.h>                           27 #include <linux/types.h>
 20 #include <crypto/cast6.h>                          28 #include <crypto/cast6.h>
 21                                                    29 
 22 #define s1 cast_s1                                 30 #define s1 cast_s1
 23 #define s2 cast_s2                                 31 #define s2 cast_s2
 24 #define s3 cast_s3                                 32 #define s3 cast_s3
 25 #define s4 cast_s4                                 33 #define s4 cast_s4
 26                                                    34 
 27 #define F1(D, r, m)  ((I = ((m) + (D))), (I =      35 #define F1(D, r, m)  ((I = ((m) + (D))), (I = rol32(I, (r))),   \
 28         (((s1[I >> 24] ^ s2[(I>>16)&0xff]) - s     36         (((s1[I >> 24] ^ s2[(I>>16)&0xff]) - s3[(I>>8)&0xff]) + s4[I&0xff]))
 29 #define F2(D, r, m)  ((I = ((m) ^ (D))), (I =      37 #define F2(D, r, m)  ((I = ((m) ^ (D))), (I = rol32(I, (r))),   \
 30         (((s1[I >> 24] - s2[(I>>16)&0xff]) + s     38         (((s1[I >> 24] - s2[(I>>16)&0xff]) + s3[(I>>8)&0xff]) ^ s4[I&0xff]))
 31 #define F3(D, r, m)  ((I = ((m) - (D))), (I =      39 #define F3(D, r, m)  ((I = ((m) - (D))), (I = rol32(I, (r))),   \
 32         (((s1[I >> 24] + s2[(I>>16)&0xff]) ^ s     40         (((s1[I >> 24] + s2[(I>>16)&0xff]) ^ s3[(I>>8)&0xff]) - s4[I&0xff]))
 33                                                    41 
 34 static const u32 Tm[24][8] = {                     42 static const u32 Tm[24][8] = {
 35         { 0x5a827999, 0xc95c653a, 0x383650db,      43         { 0x5a827999, 0xc95c653a, 0x383650db, 0xa7103c7c, 0x15ea281d,
 36                 0x84c413be, 0xf39dff5f, 0x6277     44                 0x84c413be, 0xf39dff5f, 0x6277eb00 } ,
 37         { 0xd151d6a1, 0x402bc242, 0xaf05ade3,      45         { 0xd151d6a1, 0x402bc242, 0xaf05ade3, 0x1ddf9984, 0x8cb98525,
 38                 0xfb9370c6, 0x6a6d5c67, 0xd947     46                 0xfb9370c6, 0x6a6d5c67, 0xd9474808 } ,
 39         { 0x482133a9, 0xb6fb1f4a, 0x25d50aeb,      47         { 0x482133a9, 0xb6fb1f4a, 0x25d50aeb, 0x94aef68c, 0x0388e22d,
 40                 0x7262cdce, 0xe13cb96f, 0x5016     48                 0x7262cdce, 0xe13cb96f, 0x5016a510 } ,
 41         { 0xbef090b1, 0x2dca7c52, 0x9ca467f3,      49         { 0xbef090b1, 0x2dca7c52, 0x9ca467f3, 0x0b7e5394, 0x7a583f35,
 42                 0xe9322ad6, 0x580c1677, 0xc6e6     50                 0xe9322ad6, 0x580c1677, 0xc6e60218 } ,
 43         { 0x35bfedb9, 0xa499d95a, 0x1373c4fb,      51         { 0x35bfedb9, 0xa499d95a, 0x1373c4fb, 0x824db09c, 0xf1279c3d,
 44                 0x600187de, 0xcedb737f, 0x3db5     52                 0x600187de, 0xcedb737f, 0x3db55f20 } ,
 45         { 0xac8f4ac1, 0x1b693662, 0x8a432203,      53         { 0xac8f4ac1, 0x1b693662, 0x8a432203, 0xf91d0da4, 0x67f6f945,
 46                 0xd6d0e4e6, 0x45aad087, 0xb484     54                 0xd6d0e4e6, 0x45aad087, 0xb484bc28 } ,
 47         { 0x235ea7c9, 0x9238936a, 0x01127f0b,      55         { 0x235ea7c9, 0x9238936a, 0x01127f0b, 0x6fec6aac, 0xdec6564d,
 48                 0x4da041ee, 0xbc7a2d8f, 0x2b54     56                 0x4da041ee, 0xbc7a2d8f, 0x2b541930 } ,
 49         { 0x9a2e04d1, 0x0907f072, 0x77e1dc13,      57         { 0x9a2e04d1, 0x0907f072, 0x77e1dc13, 0xe6bbc7b4, 0x5595b355,
 50                 0xc46f9ef6, 0x33498a97, 0xa223     58                 0xc46f9ef6, 0x33498a97, 0xa2237638 } ,
 51         { 0x10fd61d9, 0x7fd74d7a, 0xeeb1391b,      59         { 0x10fd61d9, 0x7fd74d7a, 0xeeb1391b, 0x5d8b24bc, 0xcc65105d,
 52                 0x3b3efbfe, 0xaa18e79f, 0x18f2     60                 0x3b3efbfe, 0xaa18e79f, 0x18f2d340 } ,
 53         { 0x87ccbee1, 0xf6a6aa82, 0x65809623,      61         { 0x87ccbee1, 0xf6a6aa82, 0x65809623, 0xd45a81c4, 0x43346d65,
 54                 0xb20e5906, 0x20e844a7, 0x8fc2     62                 0xb20e5906, 0x20e844a7, 0x8fc23048 } ,
 55         { 0xfe9c1be9, 0x6d76078a, 0xdc4ff32b,      63         { 0xfe9c1be9, 0x6d76078a, 0xdc4ff32b, 0x4b29decc, 0xba03ca6d,
 56                 0x28ddb60e, 0x97b7a1af, 0x0691     64                 0x28ddb60e, 0x97b7a1af, 0x06918d50 } ,
 57         { 0x756b78f1, 0xe4456492, 0x531f5033,      65         { 0x756b78f1, 0xe4456492, 0x531f5033, 0xc1f93bd4, 0x30d32775,
 58                 0x9fad1316, 0x0e86feb7, 0x7d60     66                 0x9fad1316, 0x0e86feb7, 0x7d60ea58 } ,
 59         { 0xec3ad5f9, 0x5b14c19a, 0xc9eead3b,      67         { 0xec3ad5f9, 0x5b14c19a, 0xc9eead3b, 0x38c898dc, 0xa7a2847d,
 60                 0x167c701e, 0x85565bbf, 0xf430     68                 0x167c701e, 0x85565bbf, 0xf4304760 } ,
 61         { 0x630a3301, 0xd1e41ea2, 0x40be0a43,      69         { 0x630a3301, 0xd1e41ea2, 0x40be0a43, 0xaf97f5e4, 0x1e71e185,
 62                 0x8d4bcd26, 0xfc25b8c7, 0x6aff     70                 0x8d4bcd26, 0xfc25b8c7, 0x6affa468 } ,
 63         { 0xd9d99009, 0x48b37baa, 0xb78d674b,      71         { 0xd9d99009, 0x48b37baa, 0xb78d674b, 0x266752ec, 0x95413e8d,
 64                 0x041b2a2e, 0x72f515cf, 0xe1cf     72                 0x041b2a2e, 0x72f515cf, 0xe1cf0170 } ,
 65         { 0x50a8ed11, 0xbf82d8b2, 0x2e5cc453,      73         { 0x50a8ed11, 0xbf82d8b2, 0x2e5cc453, 0x9d36aff4, 0x0c109b95,
 66                 0x7aea8736, 0xe9c472d7, 0x589e     74                 0x7aea8736, 0xe9c472d7, 0x589e5e78 } ,
 67         { 0xc7784a19, 0x365235ba, 0xa52c215b,      75         { 0xc7784a19, 0x365235ba, 0xa52c215b, 0x14060cfc, 0x82dff89d,
 68                 0xf1b9e43e, 0x6093cfdf, 0xcf6d     76                 0xf1b9e43e, 0x6093cfdf, 0xcf6dbb80 } ,
 69         { 0x3e47a721, 0xad2192c2, 0x1bfb7e63,      77         { 0x3e47a721, 0xad2192c2, 0x1bfb7e63, 0x8ad56a04, 0xf9af55a5,
 70                 0x68894146, 0xd7632ce7, 0x463d     78                 0x68894146, 0xd7632ce7, 0x463d1888 } ,
 71         { 0xb5170429, 0x23f0efca, 0x92cadb6b,      79         { 0xb5170429, 0x23f0efca, 0x92cadb6b, 0x01a4c70c, 0x707eb2ad,
 72                 0xdf589e4e, 0x4e3289ef, 0xbd0c     80                 0xdf589e4e, 0x4e3289ef, 0xbd0c7590 } ,
 73         { 0x2be66131, 0x9ac04cd2, 0x099a3873,      81         { 0x2be66131, 0x9ac04cd2, 0x099a3873, 0x78742414, 0xe74e0fb5,
 74                 0x5627fb56, 0xc501e6f7, 0x33db     82                 0x5627fb56, 0xc501e6f7, 0x33dbd298 } ,
 75         { 0xa2b5be39, 0x118fa9da, 0x8069957b,      83         { 0xa2b5be39, 0x118fa9da, 0x8069957b, 0xef43811c, 0x5e1d6cbd,
 76                 0xccf7585e, 0x3bd143ff, 0xaaab     84                 0xccf7585e, 0x3bd143ff, 0xaaab2fa0 } ,
 77         { 0x19851b41, 0x885f06e2, 0xf738f283,      85         { 0x19851b41, 0x885f06e2, 0xf738f283, 0x6612de24, 0xd4ecc9c5,
 78                 0x43c6b566, 0xb2a0a107, 0x217a     86                 0x43c6b566, 0xb2a0a107, 0x217a8ca8 } ,
 79         { 0x90547849, 0xff2e63ea, 0x6e084f8b,      87         { 0x90547849, 0xff2e63ea, 0x6e084f8b, 0xdce23b2c, 0x4bbc26cd,
 80                 0xba96126e, 0x296ffe0f, 0x9849     88                 0xba96126e, 0x296ffe0f, 0x9849e9b0 } ,
 81         { 0x0723d551, 0x75fdc0f2, 0xe4d7ac93,      89         { 0x0723d551, 0x75fdc0f2, 0xe4d7ac93, 0x53b19834, 0xc28b83d5,
 82                 0x31656f76, 0xa03f5b17, 0x0f19     90                 0x31656f76, 0xa03f5b17, 0x0f1946b8 }
 83 };                                                 91 };
 84                                                    92 
 85 static const u8 Tr[4][8] = {                       93 static const u8 Tr[4][8] = {
 86         { 0x13, 0x04, 0x15, 0x06, 0x17, 0x08,      94         { 0x13, 0x04, 0x15, 0x06, 0x17, 0x08, 0x19, 0x0a } ,
 87         { 0x1b, 0x0c, 0x1d, 0x0e, 0x1f, 0x10,      95         { 0x1b, 0x0c, 0x1d, 0x0e, 0x1f, 0x10, 0x01, 0x12 } ,
 88         { 0x03, 0x14, 0x05, 0x16, 0x07, 0x18,      96         { 0x03, 0x14, 0x05, 0x16, 0x07, 0x18, 0x09, 0x1a } ,
 89         { 0x0b, 0x1c, 0x0d, 0x1e, 0x0f, 0x00,      97         { 0x0b, 0x1c, 0x0d, 0x1e, 0x0f, 0x00, 0x11, 0x02 }
 90 };                                                 98 };
 91                                                    99 
 92 /* forward octave */                              100 /* forward octave */
 93 static inline void W(u32 *key, unsigned int i)    101 static inline void W(u32 *key, unsigned int i)
 94 {                                                 102 {
 95         u32 I;                                    103         u32 I;
 96         key[6] ^= F1(key[7], Tr[i % 4][0], Tm[    104         key[6] ^= F1(key[7], Tr[i % 4][0], Tm[i][0]);
 97         key[5] ^= F2(key[6], Tr[i % 4][1], Tm[    105         key[5] ^= F2(key[6], Tr[i % 4][1], Tm[i][1]);
 98         key[4] ^= F3(key[5], Tr[i % 4][2], Tm[    106         key[4] ^= F3(key[5], Tr[i % 4][2], Tm[i][2]);
 99         key[3] ^= F1(key[4], Tr[i % 4][3], Tm[    107         key[3] ^= F1(key[4], Tr[i % 4][3], Tm[i][3]);
100         key[2] ^= F2(key[3], Tr[i % 4][4], Tm[    108         key[2] ^= F2(key[3], Tr[i % 4][4], Tm[i][4]);
101         key[1] ^= F3(key[2], Tr[i % 4][5], Tm[    109         key[1] ^= F3(key[2], Tr[i % 4][5], Tm[i][5]);
102         key[0] ^= F1(key[1], Tr[i % 4][6], Tm[    110         key[0] ^= F1(key[1], Tr[i % 4][6], Tm[i][6]);
103         key[7] ^= F2(key[0], Tr[i % 4][7], Tm[    111         key[7] ^= F2(key[0], Tr[i % 4][7], Tm[i][7]);
104 }                                                 112 }
105                                                   113 
106 int __cast6_setkey(struct cast6_ctx *c, const  !! 114 int __cast6_setkey(struct cast6_ctx *c, const u8 *in_key,
                                                   >> 115                    unsigned key_len, u32 *flags)
107 {                                                 116 {
108         int i;                                    117         int i;
109         u32 key[8];                               118         u32 key[8];
110         __be32 p_key[8]; /* padded key */         119         __be32 p_key[8]; /* padded key */
111                                                   120 
112         if (key_len % 4 != 0)                  !! 121         if (key_len % 4 != 0) {
                                                   >> 122                 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
113                 return -EINVAL;                   123                 return -EINVAL;
                                                   >> 124         }
114                                                   125 
115         memset(p_key, 0, 32);                     126         memset(p_key, 0, 32);
116         memcpy(p_key, in_key, key_len);           127         memcpy(p_key, in_key, key_len);
117                                                   128 
118         key[0] = be32_to_cpu(p_key[0]);           129         key[0] = be32_to_cpu(p_key[0]);         /* A */
119         key[1] = be32_to_cpu(p_key[1]);           130         key[1] = be32_to_cpu(p_key[1]);         /* B */
120         key[2] = be32_to_cpu(p_key[2]);           131         key[2] = be32_to_cpu(p_key[2]);         /* C */
121         key[3] = be32_to_cpu(p_key[3]);           132         key[3] = be32_to_cpu(p_key[3]);         /* D */
122         key[4] = be32_to_cpu(p_key[4]);           133         key[4] = be32_to_cpu(p_key[4]);         /* E */
123         key[5] = be32_to_cpu(p_key[5]);           134         key[5] = be32_to_cpu(p_key[5]);         /* F */
124         key[6] = be32_to_cpu(p_key[6]);           135         key[6] = be32_to_cpu(p_key[6]);         /* G */
125         key[7] = be32_to_cpu(p_key[7]);           136         key[7] = be32_to_cpu(p_key[7]);         /* H */
126                                                   137 
127         for (i = 0; i < 12; i++) {                138         for (i = 0; i < 12; i++) {
128                 W(key, 2 * i);                    139                 W(key, 2 * i);
129                 W(key, 2 * i + 1);                140                 W(key, 2 * i + 1);
130                                                   141 
131                 c->Kr[i][0] = key[0] & 0x1f;      142                 c->Kr[i][0] = key[0] & 0x1f;
132                 c->Kr[i][1] = key[2] & 0x1f;      143                 c->Kr[i][1] = key[2] & 0x1f;
133                 c->Kr[i][2] = key[4] & 0x1f;      144                 c->Kr[i][2] = key[4] & 0x1f;
134                 c->Kr[i][3] = key[6] & 0x1f;      145                 c->Kr[i][3] = key[6] & 0x1f;
135                                                   146 
136                 c->Km[i][0] = key[7];             147                 c->Km[i][0] = key[7];
137                 c->Km[i][1] = key[5];             148                 c->Km[i][1] = key[5];
138                 c->Km[i][2] = key[3];             149                 c->Km[i][2] = key[3];
139                 c->Km[i][3] = key[1];             150                 c->Km[i][3] = key[1];
140         }                                         151         }
141                                                   152 
142         return 0;                                 153         return 0;
143 }                                                 154 }
144 EXPORT_SYMBOL_GPL(__cast6_setkey);                155 EXPORT_SYMBOL_GPL(__cast6_setkey);
145                                                   156 
146 int cast6_setkey(struct crypto_tfm *tfm, const    157 int cast6_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
147 {                                                 158 {
148         return __cast6_setkey(crypto_tfm_ctx(t !! 159         return __cast6_setkey(crypto_tfm_ctx(tfm), key, keylen,
                                                   >> 160                               &tfm->crt_flags);
149 }                                                 161 }
150 EXPORT_SYMBOL_GPL(cast6_setkey);                  162 EXPORT_SYMBOL_GPL(cast6_setkey);
151                                                   163 
152 /*forward quad round*/                            164 /*forward quad round*/
153 static inline void Q(u32 *block, const u8 *Kr, !! 165 static inline void Q(u32 *block, u8 *Kr, u32 *Km)
154 {                                                 166 {
155         u32 I;                                    167         u32 I;
156         block[2] ^= F1(block[3], Kr[0], Km[0])    168         block[2] ^= F1(block[3], Kr[0], Km[0]);
157         block[1] ^= F2(block[2], Kr[1], Km[1])    169         block[1] ^= F2(block[2], Kr[1], Km[1]);
158         block[0] ^= F3(block[1], Kr[2], Km[2])    170         block[0] ^= F3(block[1], Kr[2], Km[2]);
159         block[3] ^= F1(block[0], Kr[3], Km[3])    171         block[3] ^= F1(block[0], Kr[3], Km[3]);
160 }                                                 172 }
161                                                   173 
162 /*reverse quad round*/                            174 /*reverse quad round*/
163 static inline void QBAR(u32 *block, const u8 * !! 175 static inline void QBAR(u32 *block, u8 *Kr, u32 *Km)
164 {                                                 176 {
165         u32 I;                                    177         u32 I;
166         block[3] ^= F1(block[0], Kr[3], Km[3])    178         block[3] ^= F1(block[0], Kr[3], Km[3]);
167         block[0] ^= F3(block[1], Kr[2], Km[2])    179         block[0] ^= F3(block[1], Kr[2], Km[2]);
168         block[1] ^= F2(block[2], Kr[1], Km[1])    180         block[1] ^= F2(block[2], Kr[1], Km[1]);
169         block[2] ^= F1(block[3], Kr[0], Km[0])    181         block[2] ^= F1(block[3], Kr[0], Km[0]);
170 }                                                 182 }
171                                                   183 
172 void __cast6_encrypt(const void *ctx, u8 *outb !! 184 void __cast6_encrypt(struct cast6_ctx *c, u8 *outbuf, const u8 *inbuf)
173 {                                                 185 {
174         const struct cast6_ctx *c = ctx;       !! 186         const __be32 *src = (const __be32 *)inbuf;
                                                   >> 187         __be32 *dst = (__be32 *)outbuf;
175         u32 block[4];                             188         u32 block[4];
176         const u32 *Km;                         !! 189         u32 *Km;
177         const u8 *Kr;                          !! 190         u8 *Kr;
178                                                   191 
179         block[0] = get_unaligned_be32(inbuf);  !! 192         block[0] = be32_to_cpu(src[0]);
180         block[1] = get_unaligned_be32(inbuf +  !! 193         block[1] = be32_to_cpu(src[1]);
181         block[2] = get_unaligned_be32(inbuf +  !! 194         block[2] = be32_to_cpu(src[2]);
182         block[3] = get_unaligned_be32(inbuf +  !! 195         block[3] = be32_to_cpu(src[3]);
183                                                   196 
184         Km = c->Km[0]; Kr = c->Kr[0]; Q(block,    197         Km = c->Km[0]; Kr = c->Kr[0]; Q(block, Kr, Km);
185         Km = c->Km[1]; Kr = c->Kr[1]; Q(block,    198         Km = c->Km[1]; Kr = c->Kr[1]; Q(block, Kr, Km);
186         Km = c->Km[2]; Kr = c->Kr[2]; Q(block,    199         Km = c->Km[2]; Kr = c->Kr[2]; Q(block, Kr, Km);
187         Km = c->Km[3]; Kr = c->Kr[3]; Q(block,    200         Km = c->Km[3]; Kr = c->Kr[3]; Q(block, Kr, Km);
188         Km = c->Km[4]; Kr = c->Kr[4]; Q(block,    201         Km = c->Km[4]; Kr = c->Kr[4]; Q(block, Kr, Km);
189         Km = c->Km[5]; Kr = c->Kr[5]; Q(block,    202         Km = c->Km[5]; Kr = c->Kr[5]; Q(block, Kr, Km);
190         Km = c->Km[6]; Kr = c->Kr[6]; QBAR(blo    203         Km = c->Km[6]; Kr = c->Kr[6]; QBAR(block, Kr, Km);
191         Km = c->Km[7]; Kr = c->Kr[7]; QBAR(blo    204         Km = c->Km[7]; Kr = c->Kr[7]; QBAR(block, Kr, Km);
192         Km = c->Km[8]; Kr = c->Kr[8]; QBAR(blo    205         Km = c->Km[8]; Kr = c->Kr[8]; QBAR(block, Kr, Km);
193         Km = c->Km[9]; Kr = c->Kr[9]; QBAR(blo    206         Km = c->Km[9]; Kr = c->Kr[9]; QBAR(block, Kr, Km);
194         Km = c->Km[10]; Kr = c->Kr[10]; QBAR(b    207         Km = c->Km[10]; Kr = c->Kr[10]; QBAR(block, Kr, Km);
195         Km = c->Km[11]; Kr = c->Kr[11]; QBAR(b    208         Km = c->Km[11]; Kr = c->Kr[11]; QBAR(block, Kr, Km);
196                                                   209 
197         put_unaligned_be32(block[0], outbuf);  !! 210         dst[0] = cpu_to_be32(block[0]);
198         put_unaligned_be32(block[1], outbuf +  !! 211         dst[1] = cpu_to_be32(block[1]);
199         put_unaligned_be32(block[2], outbuf +  !! 212         dst[2] = cpu_to_be32(block[2]);
200         put_unaligned_be32(block[3], outbuf +  !! 213         dst[3] = cpu_to_be32(block[3]);
201 }                                                 214 }
202 EXPORT_SYMBOL_GPL(__cast6_encrypt);               215 EXPORT_SYMBOL_GPL(__cast6_encrypt);
203                                                   216 
204 static void cast6_encrypt(struct crypto_tfm *t    217 static void cast6_encrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf)
205 {                                                 218 {
206         __cast6_encrypt(crypto_tfm_ctx(tfm), o    219         __cast6_encrypt(crypto_tfm_ctx(tfm), outbuf, inbuf);
207 }                                                 220 }
208                                                   221 
209 void __cast6_decrypt(const void *ctx, u8 *outb !! 222 void __cast6_decrypt(struct cast6_ctx *c, u8 *outbuf, const u8 *inbuf)
210 {                                                 223 {
211         const struct cast6_ctx *c = ctx;       !! 224         const __be32 *src = (const __be32 *)inbuf;
                                                   >> 225         __be32 *dst = (__be32 *)outbuf;
212         u32 block[4];                             226         u32 block[4];
213         const u32 *Km;                         !! 227         u32 *Km;
214         const u8 *Kr;                          !! 228         u8 *Kr;
215                                                   229 
216         block[0] = get_unaligned_be32(inbuf);  !! 230         block[0] = be32_to_cpu(src[0]);
217         block[1] = get_unaligned_be32(inbuf +  !! 231         block[1] = be32_to_cpu(src[1]);
218         block[2] = get_unaligned_be32(inbuf +  !! 232         block[2] = be32_to_cpu(src[2]);
219         block[3] = get_unaligned_be32(inbuf +  !! 233         block[3] = be32_to_cpu(src[3]);
220                                                   234 
221         Km = c->Km[11]; Kr = c->Kr[11]; Q(bloc    235         Km = c->Km[11]; Kr = c->Kr[11]; Q(block, Kr, Km);
222         Km = c->Km[10]; Kr = c->Kr[10]; Q(bloc    236         Km = c->Km[10]; Kr = c->Kr[10]; Q(block, Kr, Km);
223         Km = c->Km[9]; Kr = c->Kr[9]; Q(block,    237         Km = c->Km[9]; Kr = c->Kr[9]; Q(block, Kr, Km);
224         Km = c->Km[8]; Kr = c->Kr[8]; Q(block,    238         Km = c->Km[8]; Kr = c->Kr[8]; Q(block, Kr, Km);
225         Km = c->Km[7]; Kr = c->Kr[7]; Q(block,    239         Km = c->Km[7]; Kr = c->Kr[7]; Q(block, Kr, Km);
226         Km = c->Km[6]; Kr = c->Kr[6]; Q(block,    240         Km = c->Km[6]; Kr = c->Kr[6]; Q(block, Kr, Km);
227         Km = c->Km[5]; Kr = c->Kr[5]; QBAR(blo    241         Km = c->Km[5]; Kr = c->Kr[5]; QBAR(block, Kr, Km);
228         Km = c->Km[4]; Kr = c->Kr[4]; QBAR(blo    242         Km = c->Km[4]; Kr = c->Kr[4]; QBAR(block, Kr, Km);
229         Km = c->Km[3]; Kr = c->Kr[3]; QBAR(blo    243         Km = c->Km[3]; Kr = c->Kr[3]; QBAR(block, Kr, Km);
230         Km = c->Km[2]; Kr = c->Kr[2]; QBAR(blo    244         Km = c->Km[2]; Kr = c->Kr[2]; QBAR(block, Kr, Km);
231         Km = c->Km[1]; Kr = c->Kr[1]; QBAR(blo    245         Km = c->Km[1]; Kr = c->Kr[1]; QBAR(block, Kr, Km);
232         Km = c->Km[0]; Kr = c->Kr[0]; QBAR(blo    246         Km = c->Km[0]; Kr = c->Kr[0]; QBAR(block, Kr, Km);
233                                                   247 
234         put_unaligned_be32(block[0], outbuf);  !! 248         dst[0] = cpu_to_be32(block[0]);
235         put_unaligned_be32(block[1], outbuf +  !! 249         dst[1] = cpu_to_be32(block[1]);
236         put_unaligned_be32(block[2], outbuf +  !! 250         dst[2] = cpu_to_be32(block[2]);
237         put_unaligned_be32(block[3], outbuf +  !! 251         dst[3] = cpu_to_be32(block[3]);
238 }                                                 252 }
239 EXPORT_SYMBOL_GPL(__cast6_decrypt);               253 EXPORT_SYMBOL_GPL(__cast6_decrypt);
240                                                   254 
241 static void cast6_decrypt(struct crypto_tfm *t    255 static void cast6_decrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf)
242 {                                                 256 {
243         __cast6_decrypt(crypto_tfm_ctx(tfm), o    257         __cast6_decrypt(crypto_tfm_ctx(tfm), outbuf, inbuf);
244 }                                                 258 }
245                                                   259 
246 static struct crypto_alg alg = {                  260 static struct crypto_alg alg = {
247         .cra_name = "cast6",                      261         .cra_name = "cast6",
248         .cra_driver_name = "cast6-generic",       262         .cra_driver_name = "cast6-generic",
249         .cra_priority = 100,                      263         .cra_priority = 100,
250         .cra_flags = CRYPTO_ALG_TYPE_CIPHER,      264         .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
251         .cra_blocksize = CAST6_BLOCK_SIZE,        265         .cra_blocksize = CAST6_BLOCK_SIZE,
252         .cra_ctxsize = sizeof(struct cast6_ctx    266         .cra_ctxsize = sizeof(struct cast6_ctx),
                                                   >> 267         .cra_alignmask = 3,
253         .cra_module = THIS_MODULE,                268         .cra_module = THIS_MODULE,
254         .cra_u = {                                269         .cra_u = {
255                   .cipher = {                     270                   .cipher = {
256                              .cia_min_keysize     271                              .cia_min_keysize = CAST6_MIN_KEY_SIZE,
257                              .cia_max_keysize     272                              .cia_max_keysize = CAST6_MAX_KEY_SIZE,
258                              .cia_setkey = cas    273                              .cia_setkey = cast6_setkey,
259                              .cia_encrypt = ca    274                              .cia_encrypt = cast6_encrypt,
260                              .cia_decrypt = ca    275                              .cia_decrypt = cast6_decrypt}
261                   }                               276                   }
262 };                                                277 };
263                                                   278 
264 static int __init cast6_mod_init(void)            279 static int __init cast6_mod_init(void)
265 {                                                 280 {
266         return crypto_register_alg(&alg);         281         return crypto_register_alg(&alg);
267 }                                                 282 }
268                                                   283 
269 static void __exit cast6_mod_fini(void)           284 static void __exit cast6_mod_fini(void)
270 {                                                 285 {
271         crypto_unregister_alg(&alg);              286         crypto_unregister_alg(&alg);
272 }                                                 287 }
273                                                   288 
274 subsys_initcall(cast6_mod_init);               !! 289 module_init(cast6_mod_init);
275 module_exit(cast6_mod_fini);                      290 module_exit(cast6_mod_fini);
276                                                   291 
277 MODULE_LICENSE("GPL");                            292 MODULE_LICENSE("GPL");
278 MODULE_DESCRIPTION("Cast6 Cipher Algorithm");     293 MODULE_DESCRIPTION("Cast6 Cipher Algorithm");
279 MODULE_ALIAS_CRYPTO("cast6");                     294 MODULE_ALIAS_CRYPTO("cast6");
280 MODULE_ALIAS_CRYPTO("cast6-generic");             295 MODULE_ALIAS_CRYPTO("cast6-generic");
281                                                   296 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php