diff options
author | Jeff Garzik <jgarzik@pobox.com> | 2005-08-10 13:46:28 -0400 |
---|---|---|
committer | Jeff Garzik <jgarzik@pobox.com> | 2005-08-10 13:46:28 -0400 |
commit | 2f058256cb64e346f4fb4499ff4e0f1c2791a4b4 (patch) | |
tree | 91e06602f4d3abb6812ea8c9bc9ba4501e14c84e /crypto | |
parent | 0274aa2506fd2fe89a58dd6cd64d3b3f7b976af8 (diff) | |
parent | 86b3786078d63242d3194ffc58ae8dae1d1bbef3 (diff) |
Merge /spare/repo/linux-2.6/
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/Kconfig | 22 | ||||
-rw-r--r-- | crypto/aes.c | 2 | ||||
-rw-r--r-- | crypto/api.c | 60 | ||||
-rw-r--r-- | crypto/cipher.c | 312 | ||||
-rw-r--r-- | crypto/des.c | 2005 | ||||
-rw-r--r-- | crypto/hmac.c | 3 | ||||
-rw-r--r-- | crypto/internal.h | 43 | ||||
-rw-r--r-- | crypto/scatterwalk.c | 4 | ||||
-rw-r--r-- | crypto/scatterwalk.h | 12 | ||||
-rw-r--r-- | crypto/serpent.c | 1 | ||||
-rw-r--r-- | crypto/tcrypt.c | 580 | ||||
-rw-r--r-- | crypto/tcrypt.h | 449 |
12 files changed, 1855 insertions, 1638 deletions
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 | ||
147 | config CRYPTO_AES | 147 | config 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 | ||
187 | config 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 | |||
187 | config CRYPTO_CAST5 | 207 | config 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/aes.c b/crypto/aes.c index d0dd7c3c5278..5df92888ef5a 100644 --- a/crypto/aes.c +++ b/crypto/aes.c | |||
@@ -67,7 +67,7 @@ | |||
67 | /* | 67 | /* |
68 | * #define byte(x, nr) ((unsigned char)((x) >> (nr*8))) | 68 | * #define byte(x, nr) ((unsigned char)((x) >> (nr*8))) |
69 | */ | 69 | */ |
70 | inline static u8 | 70 | static inline u8 |
71 | byte(const u32 x, const unsigned n) | 71 | byte(const u32 x, const unsigned n) |
72 | { | 72 | { |
73 | return x >> (n << 3); | 73 | return x >> (n << 3); |
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 | ||
36 | struct crypto_alg *crypto_alg_lookup(const char *name) | 39 | static 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. */ | ||
62 | static 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 | |||
57 | static int crypto_init_flags(struct crypto_tfm *tfm, u32 flags) | 67 | static 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 | ||
130 | static 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 | |||
120 | struct crypto_tfm *crypto_alloc_tfm(const char *name, u32 flags) | 154 | struct 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 | ||
156 | void crypto_free_tfm(struct crypto_tfm *tfm) | 192 | void 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..8da644364cb4 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 | ||
25 | typedef void (cryptfn_t)(void *, u8 *, const u8 *); | ||
26 | typedef void (procfn_t)(struct crypto_tfm *, u8 *, | ||
27 | u8*, cryptfn_t, void *); | ||
28 | |||
29 | static inline void xor_64(u8 *a, const u8 *b) | 26 | static 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 | ||
43 | static inline void *prepare_src(struct scatter_walk *walk, int bsize, | 40 | static 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 long 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 | ||
57 | static inline void *prepare_dst(struct scatter_walk *walk, int bsize, | 61 | static 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 | ||
67 | static 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 | ||
72 | static 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 | */ |
89 | static int crypt(struct crypto_tfm *tfm, | 93 | static 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 | ||
146 | static void cbc_process_encrypt(struct crypto_tfm *tfm, u8 *dst, u8 *src, | 157 | static 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 long 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 | ||
156 | static void cbc_process_decrypt(struct crypto_tfm *tfm, u8 *dst, u8 *src, | 182 | static 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 | ||
166 | static void ecb_process(struct crypto_tfm *tfm, u8 *dst, u8 *src, | 206 | static 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 | |||
238 | static 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 | ||
172 | static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) | 256 | static 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 | ||
193 | static int ecb_decrypt(struct crypto_tfm *tfm, | 282 | static 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 | ||
203 | static int cbc_encrypt(struct crypto_tfm *tfm, | 297 | static 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 | ||
213 | static int cbc_encrypt_iv(struct crypto_tfm *tfm, | 313 | static 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 | ||
223 | static int cbc_decrypt(struct crypto_tfm *tfm, | 329 | static 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 | ||
233 | static int cbc_decrypt_iv(struct crypto_tfm *tfm, | 345 | static 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 | ||
243 | static int nocrypt(struct crypto_tfm *tfm, | 361 | static 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 long 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 | ||
333 | out: | 455 | out: |
@@ -336,6 +458,4 @@ out: | |||
336 | 458 | ||
337 | void crypto_exit_cipher_ops(struct crypto_tfm *tfm) | 459 | void 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 | ||
40 | struct des_ctx { | 32 | struct des_ctx { |
41 | u8 iv[DES_BLOCK_SIZE]; | ||
42 | u32 expkey[DES_EXPKEY_WORDS]; | 33 | u32 expkey[DES_EXPKEY_WORDS]; |
43 | }; | 34 | }; |
44 | 35 | ||
45 | struct des3_ede_ctx { | 36 | struct 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 | ||
50 | static const u32 des_keymap[] = { | 40 | /* Lookup tables for key expansion */ |
51 | 0x02080008, 0x02082000, 0x00002008, 0x00000000, | 41 | |
52 | 0x02002000, 0x00080008, 0x02080000, 0x02082008, | 42 | static 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 | ||
188 | static const u8 rotors[] = { | 77 | static 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 | ||
270 | static const u8 parity[] = { | 112 | static 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 | |||
374 | static 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 | ||
282 | static void des_small_fips_encrypt(u32 *expkey, u8 *dst, const u8 *src) | 393 | static 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 | ||
654 | static void des_small_fips_decrypt(u32 *expkey, u8 *dst, const u8 *src) | 412 | static 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; | 431 | static 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)); | 450 | static 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)); | 469 | static 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)); | 488 | static 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)); | 507 | static 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 | */ |
1029 | static int setkey(u32 *expkey, const u8 *key, unsigned int keylen, u32 *flags) | 635 | static 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; | ||
1103 | weak: | ||
1104 | *flags |= CRYPTO_TFM_RES_WEAK_KEY; | ||
1105 | return -EINVAL; | ||
1106 | } | 705 | } |
1107 | 706 | ||
1108 | not_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 | */ | ||
717 | static 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 | ||
1173 | static int des_setkey(void *ctx, const u8 *key, unsigned int keylen, u32 *flags) | 784 | static 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 | ||
1178 | static void des_encrypt(void *ctx, u8 *dst, const u8 *src) | 804 | static 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 | ||
1183 | static void des_decrypt(void *ctx, u8 *dst, const u8 *src) | 826 | static 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 | */ |
1201 | static int des3_ede_setkey(void *ctx, const u8 *key, | 861 | static 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 | ||
1224 | static void des3_ede_encrypt(void *ctx, u8 *dst, const u8 *src) | 882 | static 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 | ||
1233 | static void des3_ede_decrypt(void *ctx, u8 *dst, const u8 *src) | 913 | static 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 | ||
1242 | static struct crypto_alg des_alg = { | 944 | static 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 | ||
1272 | MODULE_ALIAS("des3_ede"); | 974 | MODULE_ALIAS("des3_ede"); |
@@ -1274,7 +976,7 @@ MODULE_ALIAS("des3_ede"); | |||
1274 | static int __init init(void) | 976 | static 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); |
1285 | out: | 987 | out: |
1286 | return ret; | 988 | return ret; |
1287 | } | 989 | } |
1288 | 990 | ||
@@ -1297,3 +999,4 @@ module_exit(fini); | |||
1297 | 999 | ||
1298 | MODULE_LICENSE("GPL"); | 1000 | MODULE_LICENSE("GPL"); |
1299 | MODULE_DESCRIPTION("DES & Triple DES EDE Cipher Algorithms"); | 1001 | MODULE_DESCRIPTION("DES & Triple DES EDE Cipher Algorithms"); |
1002 | MODULE_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 | ||
50 | void crypto_free_hmac_block(struct crypto_tfm *tfm) | 50 | void 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 | ||
56 | void crypto_hmac_init(struct crypto_tfm *tfm, u8 *key, unsigned int *keylen) | 55 | void crypto_hmac_init(struct crypto_tfm *tfm, u8 *key, unsigned int *keylen) |
diff --git a/crypto/internal.h b/crypto/internal.h index 964b9a60ca24..37515beafc8c 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 | ||
22 | extern enum km_type crypto_km_types[]; | 22 | extern 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 | ||
45 | static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm) | ||
46 | { | ||
47 | return (void *)&tfm[1]; | ||
48 | } | ||
49 | |||
50 | struct 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. */ | ||
54 | static 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 |
60 | int crypto_alloc_hmac_block(struct crypto_tfm *tfm); | 46 | int crypto_alloc_hmac_block(struct crypto_tfm *tfm); |
61 | void crypto_free_hmac_block(struct crypto_tfm *tfm); | 47 | void 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 | ||
65 | static inline unsigned int crypto_digest_ctxsize(struct crypto_alg *alg, | ||
66 | int flags) | ||
67 | { | ||
68 | return alg->cra_ctxsize; | ||
69 | } | ||
70 | |||
71 | static 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, (unsigned long)alg->cra_alignmask + 1); | ||
79 | len += alg->cra_blocksize; | ||
80 | break; | ||
81 | } | ||
82 | |||
83 | return len; | ||
84 | } | ||
85 | |||
86 | static inline unsigned int crypto_compress_ctxsize(struct crypto_alg *alg, | ||
87 | int flags) | ||
88 | { | ||
89 | return alg->cra_ctxsize; | ||
90 | } | ||
91 | |||
79 | int crypto_init_digest_flags(struct crypto_tfm *tfm, u32 flags); | 92 | int crypto_init_digest_flags(struct crypto_tfm *tfm, u32 flags); |
80 | int crypto_init_cipher_flags(struct crypto_tfm *tfm, u32 flags); | 93 | int crypto_init_cipher_flags(struct crypto_tfm *tfm, u32 flags); |
81 | int crypto_init_compress_flags(struct crypto_tfm *tfm, u32 flags); | 94 | int 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) | |||
100 | int scatterwalk_copychunks(void *buf, struct scatter_walk *walk, | 100 | int 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 | ||
43 | static inline int scatterwalk_across_pages(struct scatter_walk *walk, | 43 | static 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 | ||
49 | static inline void scatterwalk_advance(struct scatter_walk *walk, | 49 | static 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 | ||
58 | static inline unsigned int scatterwalk_aligned(struct scatter_walk *walk, | ||
59 | unsigned int alignmask) | ||
60 | { | ||
61 | return !(walk->offset & alignmask); | ||
62 | } | ||
63 | |||
58 | void scatterwalk_start(struct scatter_walk *walk, struct scatterlist *sg); | 64 | void scatterwalk_start(struct scatter_walk *walk, struct scatterlist *sg); |
59 | int scatterwalk_copychunks(void *buf, struct scatter_walk *walk, size_t nbytes, int out); | 65 | int scatterwalk_copychunks(void *buf, struct scatter_walk *walk, size_t nbytes, int out); |
60 | void scatterwalk_map(struct scatter_walk *walk, int out); | 66 | void 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 | ||
212 | struct serpent_ctx { | 212 | struct 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/crypto/tcrypt.c b/crypto/tcrypt.c index 92b0352c8e92..bd7524cfff33 100644 --- a/crypto/tcrypt.c +++ b/crypto/tcrypt.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * Quick & dirty crypto testing module. | 2 | * Quick & dirty crypto testing module. |
3 | * | 3 | * |
4 | * This will only exist until we have a better testing mechanism | 4 | * This will only exist until we have a better testing mechanism |
@@ -9,11 +9,12 @@ | |||
9 | * | 9 | * |
10 | * This program is free software; you can redistribute it and/or modify it | 10 | * This program is free software; you can redistribute it and/or modify it |
11 | * under the terms of the GNU General Public License as published by the Free | 11 | * under the terms of the GNU General Public License as published by the Free |
12 | * Software Foundation; either version 2 of the License, or (at your option) | 12 | * Software Foundation; either version 2 of the License, or (at your option) |
13 | * any later version. | 13 | * any later version. |
14 | * | 14 | * |
15 | * 14 - 09 - 2003 | 15 | * 2004-08-09 Added cipher speed tests (Reyk Floeter <reyk@vantronix.net>) |
16 | * Rewritten by Kartikey Mahendra Bhatt | 16 | * 2003-09-14 Rewritten by Kartikey Mahendra Bhatt |
17 | * | ||
17 | */ | 18 | */ |
18 | 19 | ||
19 | #include <linux/init.h> | 20 | #include <linux/init.h> |
@@ -25,12 +26,15 @@ | |||
25 | #include <linux/crypto.h> | 26 | #include <linux/crypto.h> |
26 | #include <linux/highmem.h> | 27 | #include <linux/highmem.h> |
27 | #include <linux/moduleparam.h> | 28 | #include <linux/moduleparam.h> |
29 | #include <linux/jiffies.h> | ||
30 | #include <linux/timex.h> | ||
31 | #include <linux/interrupt.h> | ||
28 | #include "tcrypt.h" | 32 | #include "tcrypt.h" |
29 | 33 | ||
30 | /* | 34 | /* |
31 | * Need to kmalloc() memory for testing kmap(). | 35 | * Need to kmalloc() memory for testing kmap(). |
32 | */ | 36 | */ |
33 | #define TVMEMSIZE 4096 | 37 | #define TVMEMSIZE 16384 |
34 | #define XBUFSIZE 32768 | 38 | #define XBUFSIZE 32768 |
35 | 39 | ||
36 | /* | 40 | /* |
@@ -55,19 +59,23 @@ | |||
55 | 59 | ||
56 | static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 }; | 60 | static unsigned int IDX[8] = { IDX1, IDX2, IDX3, IDX4, IDX5, IDX6, IDX7, IDX8 }; |
57 | 61 | ||
62 | /* | ||
63 | * Used by test_cipher_speed() | ||
64 | */ | ||
65 | static unsigned int sec; | ||
66 | |||
58 | static int mode; | 67 | static int mode; |
59 | static char *xbuf; | 68 | static char *xbuf; |
60 | static char *tvmem; | 69 | static char *tvmem; |
61 | 70 | ||
62 | static char *check[] = { | 71 | static char *check[] = { |
63 | "des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish", | 72 | "des", "md5", "des3_ede", "rot13", "sha1", "sha256", "blowfish", |
64 | "twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6", | 73 | "twofish", "serpent", "sha384", "sha512", "md4", "aes", "cast6", |
65 | "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", | 74 | "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", |
66 | "khazad", "wp512", "wp384", "wp256", "tnepres", NULL | 75 | "khazad", "wp512", "wp384", "wp256", "tnepres", NULL |
67 | }; | 76 | }; |
68 | 77 | ||
69 | static void | 78 | static void hexdump(unsigned char *buf, unsigned int len) |
70 | hexdump(unsigned char *buf, unsigned int len) | ||
71 | { | 79 | { |
72 | while (len--) | 80 | while (len--) |
73 | printk("%02x", *buf++); | 81 | printk("%02x", *buf++); |
@@ -75,29 +83,29 @@ hexdump(unsigned char *buf, unsigned int len) | |||
75 | printk("\n"); | 83 | printk("\n"); |
76 | } | 84 | } |
77 | 85 | ||
78 | static void | 86 | static void test_hash(char *algo, struct hash_testvec *template, |
79 | test_hash (char * algo, struct hash_testvec * template, unsigned int tcount) | 87 | unsigned int tcount) |
80 | { | 88 | { |
81 | char *p; | 89 | char *p; |
82 | unsigned int i, j, k, temp; | 90 | unsigned int i, j, k, temp; |
83 | struct scatterlist sg[8]; | 91 | struct scatterlist sg[8]; |
84 | char result[64]; | 92 | char result[64]; |
85 | struct crypto_tfm *tfm; | 93 | struct crypto_tfm *tfm; |
86 | struct hash_testvec *hash_tv; | 94 | struct hash_testvec *hash_tv; |
87 | unsigned int tsize; | 95 | unsigned int tsize; |
88 | 96 | ||
89 | printk("\ntesting %s\n", algo); | 97 | printk("\ntesting %s\n", algo); |
90 | 98 | ||
91 | tsize = sizeof (struct hash_testvec); | 99 | tsize = sizeof(struct hash_testvec); |
92 | tsize *= tcount; | 100 | tsize *= tcount; |
93 | 101 | ||
94 | if (tsize > TVMEMSIZE) { | 102 | if (tsize > TVMEMSIZE) { |
95 | printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE); | 103 | printk("template (%u) too big for tvmem (%u)\n", tsize, TVMEMSIZE); |
96 | return; | 104 | return; |
97 | } | 105 | } |
98 | 106 | ||
99 | memcpy(tvmem, template, tsize); | 107 | memcpy(tvmem, template, tsize); |
100 | hash_tv = (void *) tvmem; | 108 | hash_tv = (void *)tvmem; |
101 | tfm = crypto_alloc_tfm(algo, 0); | 109 | tfm = crypto_alloc_tfm(algo, 0); |
102 | if (tfm == NULL) { | 110 | if (tfm == NULL) { |
103 | printk("failed to load transform for %s\n", algo); | 111 | printk("failed to load transform for %s\n", algo); |
@@ -105,70 +113,71 @@ test_hash (char * algo, struct hash_testvec * template, unsigned int tcount) | |||
105 | } | 113 | } |
106 | 114 | ||
107 | for (i = 0; i < tcount; i++) { | 115 | for (i = 0; i < tcount; i++) { |
108 | printk ("test %u:\n", i + 1); | 116 | printk("test %u:\n", i + 1); |
109 | memset (result, 0, 64); | 117 | memset(result, 0, 64); |
110 | 118 | ||
111 | p = hash_tv[i].plaintext; | 119 | p = hash_tv[i].plaintext; |
112 | sg[0].page = virt_to_page (p); | 120 | sg[0].page = virt_to_page(p); |
113 | sg[0].offset = offset_in_page (p); | 121 | sg[0].offset = offset_in_page(p); |
114 | sg[0].length = hash_tv[i].psize; | 122 | sg[0].length = hash_tv[i].psize; |
115 | 123 | ||
116 | crypto_digest_init (tfm); | 124 | crypto_digest_init(tfm); |
117 | if (tfm->crt_u.digest.dit_setkey) { | 125 | if (tfm->crt_u.digest.dit_setkey) { |
118 | crypto_digest_setkey (tfm, hash_tv[i].key, | 126 | crypto_digest_setkey(tfm, hash_tv[i].key, |
119 | hash_tv[i].ksize); | 127 | hash_tv[i].ksize); |
120 | } | 128 | } |
121 | crypto_digest_update (tfm, sg, 1); | 129 | crypto_digest_update(tfm, sg, 1); |
122 | crypto_digest_final (tfm, result); | 130 | crypto_digest_final(tfm, result); |
123 | 131 | ||
124 | hexdump (result, crypto_tfm_alg_digestsize (tfm)); | 132 | hexdump(result, crypto_tfm_alg_digestsize(tfm)); |
125 | printk("%s\n", | 133 | printk("%s\n", |
126 | memcmp(result, hash_tv[i].digest, | 134 | memcmp(result, hash_tv[i].digest, |
127 | crypto_tfm_alg_digestsize(tfm)) ? "fail" : | 135 | crypto_tfm_alg_digestsize(tfm)) ? |
128 | "pass"); | 136 | "fail" : "pass"); |
129 | } | 137 | } |
130 | 138 | ||
131 | printk ("testing %s across pages\n", algo); | 139 | printk("testing %s across pages\n", algo); |
132 | 140 | ||
133 | /* setup the dummy buffer first */ | 141 | /* setup the dummy buffer first */ |
134 | memset(xbuf, 0, XBUFSIZE); | 142 | memset(xbuf, 0, XBUFSIZE); |
135 | 143 | ||
136 | j = 0; | 144 | j = 0; |
137 | for (i = 0; i < tcount; i++) { | 145 | for (i = 0; i < tcount; i++) { |
138 | if (hash_tv[i].np) { | 146 | if (hash_tv[i].np) { |
139 | j++; | 147 | j++; |
140 | printk ("test %u:\n", j); | 148 | printk("test %u:\n", j); |
141 | memset (result, 0, 64); | 149 | memset(result, 0, 64); |
142 | 150 | ||
143 | temp = 0; | 151 | temp = 0; |
144 | for (k = 0; k < hash_tv[i].np; k++) { | 152 | for (k = 0; k < hash_tv[i].np; k++) { |
145 | memcpy (&xbuf[IDX[k]], hash_tv[i].plaintext + temp, | 153 | memcpy(&xbuf[IDX[k]], |
146 | hash_tv[i].tap[k]); | 154 | hash_tv[i].plaintext + temp, |
155 | hash_tv[i].tap[k]); | ||
147 | temp += hash_tv[i].tap[k]; | 156 | temp += hash_tv[i].tap[k]; |
148 | p = &xbuf[IDX[k]]; | 157 | p = &xbuf[IDX[k]]; |
149 | sg[k].page = virt_to_page (p); | 158 | sg[k].page = virt_to_page(p); |
150 | sg[k].offset = offset_in_page (p); | 159 | sg[k].offset = offset_in_page(p); |
151 | sg[k].length = hash_tv[i].tap[k]; | 160 | sg[k].length = hash_tv[i].tap[k]; |
152 | } | 161 | } |
153 | 162 | ||
154 | crypto_digest_digest (tfm, sg, hash_tv[i].np, result); | 163 | crypto_digest_digest(tfm, sg, hash_tv[i].np, result); |
155 | 164 | ||
156 | hexdump (result, crypto_tfm_alg_digestsize (tfm)); | 165 | hexdump(result, crypto_tfm_alg_digestsize(tfm)); |
157 | printk("%s\n", | 166 | printk("%s\n", |
158 | memcmp(result, hash_tv[i].digest, | 167 | memcmp(result, hash_tv[i].digest, |
159 | crypto_tfm_alg_digestsize(tfm)) ? "fail" : | 168 | crypto_tfm_alg_digestsize(tfm)) ? |
160 | "pass"); | 169 | "fail" : "pass"); |
161 | } | 170 | } |
162 | } | 171 | } |
163 | 172 | ||
164 | crypto_free_tfm (tfm); | 173 | crypto_free_tfm(tfm); |
165 | } | 174 | } |
166 | 175 | ||
167 | 176 | ||
168 | #ifdef CONFIG_CRYPTO_HMAC | 177 | #ifdef CONFIG_CRYPTO_HMAC |
169 | 178 | ||
170 | static void | 179 | static void test_hmac(char *algo, struct hmac_testvec *template, |
171 | test_hmac(char *algo, struct hmac_testvec * template, unsigned int tcount) | 180 | unsigned int tcount) |
172 | { | 181 | { |
173 | char *p; | 182 | char *p; |
174 | unsigned int i, j, k, temp; | 183 | unsigned int i, j, k, temp; |
@@ -185,8 +194,8 @@ test_hmac(char *algo, struct hmac_testvec * template, unsigned int tcount) | |||
185 | } | 194 | } |
186 | 195 | ||
187 | printk("\ntesting hmac_%s\n", algo); | 196 | printk("\ntesting hmac_%s\n", algo); |
188 | 197 | ||
189 | tsize = sizeof (struct hmac_testvec); | 198 | tsize = sizeof(struct hmac_testvec); |
190 | tsize *= tcount; | 199 | tsize *= tcount; |
191 | if (tsize > TVMEMSIZE) { | 200 | if (tsize > TVMEMSIZE) { |
192 | printk("template (%u) too big for tvmem (%u)\n", tsize, | 201 | printk("template (%u) too big for tvmem (%u)\n", tsize, |
@@ -195,7 +204,7 @@ test_hmac(char *algo, struct hmac_testvec * template, unsigned int tcount) | |||
195 | } | 204 | } |
196 | 205 | ||
197 | memcpy(tvmem, template, tsize); | 206 | memcpy(tvmem, template, tsize); |
198 | hmac_tv = (void *) tvmem; | 207 | hmac_tv = (void *)tvmem; |
199 | 208 | ||
200 | for (i = 0; i < tcount; i++) { | 209 | for (i = 0; i < tcount; i++) { |
201 | printk("test %u:\n", i + 1); | 210 | printk("test %u:\n", i + 1); |
@@ -219,34 +228,35 @@ test_hmac(char *algo, struct hmac_testvec * template, unsigned int tcount) | |||
219 | printk("\ntesting hmac_%s across pages\n", algo); | 228 | printk("\ntesting hmac_%s across pages\n", algo); |
220 | 229 | ||
221 | memset(xbuf, 0, XBUFSIZE); | 230 | memset(xbuf, 0, XBUFSIZE); |
222 | 231 | ||
223 | j = 0; | 232 | j = 0; |
224 | for (i = 0; i < tcount; i++) { | 233 | for (i = 0; i < tcount; i++) { |
225 | if (hmac_tv[i].np) { | 234 | if (hmac_tv[i].np) { |
226 | j++; | 235 | j++; |
227 | printk ("test %u:\n",j); | 236 | printk("test %u:\n",j); |
228 | memset (result, 0, 64); | 237 | memset(result, 0, 64); |
229 | 238 | ||
230 | temp = 0; | 239 | temp = 0; |
231 | klen = hmac_tv[i].ksize; | 240 | klen = hmac_tv[i].ksize; |
232 | for (k = 0; k < hmac_tv[i].np; k++) { | 241 | for (k = 0; k < hmac_tv[i].np; k++) { |
233 | memcpy (&xbuf[IDX[k]], hmac_tv[i].plaintext + temp, | 242 | memcpy(&xbuf[IDX[k]], |
234 | hmac_tv[i].tap[k]); | 243 | hmac_tv[i].plaintext + temp, |
244 | hmac_tv[i].tap[k]); | ||
235 | temp += hmac_tv[i].tap[k]; | 245 | temp += hmac_tv[i].tap[k]; |
236 | p = &xbuf[IDX[k]]; | 246 | p = &xbuf[IDX[k]]; |
237 | sg[k].page = virt_to_page (p); | 247 | sg[k].page = virt_to_page(p); |
238 | sg[k].offset = offset_in_page (p); | 248 | sg[k].offset = offset_in_page(p); |
239 | sg[k].length = hmac_tv[i].tap[k]; | 249 | sg[k].length = hmac_tv[i].tap[k]; |
240 | } | 250 | } |
241 | 251 | ||
242 | crypto_hmac(tfm, hmac_tv[i].key, &klen, sg, hmac_tv[i].np, | 252 | crypto_hmac(tfm, hmac_tv[i].key, &klen, sg, |
243 | result); | 253 | hmac_tv[i].np, result); |
244 | hexdump(result, crypto_tfm_alg_digestsize(tfm)); | 254 | hexdump(result, crypto_tfm_alg_digestsize(tfm)); |
245 | 255 | ||
246 | printk("%s\n", | 256 | printk("%s\n", |
247 | memcmp(result, hmac_tv[i].digest, | 257 | memcmp(result, hmac_tv[i].digest, |
248 | crypto_tfm_alg_digestsize(tfm)) ? "fail" : | 258 | crypto_tfm_alg_digestsize(tfm)) ? |
249 | "pass"); | 259 | "fail" : "pass"); |
250 | } | 260 | } |
251 | } | 261 | } |
252 | out: | 262 | out: |
@@ -255,8 +265,8 @@ out: | |||
255 | 265 | ||
256 | #endif /* CONFIG_CRYPTO_HMAC */ | 266 | #endif /* CONFIG_CRYPTO_HMAC */ |
257 | 267 | ||
258 | static void | 268 | static void test_cipher(char *algo, int mode, int enc, |
259 | test_cipher(char * algo, int mode, int enc, struct cipher_testvec * template, unsigned int tcount) | 269 | struct cipher_testvec *template, unsigned int tcount) |
260 | { | 270 | { |
261 | unsigned int ret, i, j, k, temp; | 271 | unsigned int ret, i, j, k, temp; |
262 | unsigned int tsize; | 272 | unsigned int tsize; |
@@ -265,22 +275,22 @@ test_cipher(char * algo, int mode, int enc, struct cipher_testvec * template, un | |||
265 | char *key; | 275 | char *key; |
266 | struct cipher_testvec *cipher_tv; | 276 | struct cipher_testvec *cipher_tv; |
267 | struct scatterlist sg[8]; | 277 | struct scatterlist sg[8]; |
268 | char e[11], m[4]; | 278 | const char *e, *m; |
269 | 279 | ||
270 | if (enc == ENCRYPT) | 280 | if (enc == ENCRYPT) |
271 | strncpy(e, "encryption", 11); | 281 | e = "encryption"; |
272 | else | 282 | else |
273 | strncpy(e, "decryption", 11); | 283 | e = "decryption"; |
274 | if (mode == MODE_ECB) | 284 | if (mode == MODE_ECB) |
275 | strncpy(m, "ECB", 4); | 285 | m = "ECB"; |
276 | else | 286 | else |
277 | strncpy(m, "CBC", 4); | 287 | m = "CBC"; |
278 | 288 | ||
279 | printk("\ntesting %s %s %s \n", algo, m, e); | 289 | printk("\ntesting %s %s %s\n", algo, m, e); |
280 | 290 | ||
281 | tsize = sizeof (struct cipher_testvec); | 291 | tsize = sizeof (struct cipher_testvec); |
282 | tsize *= tcount; | 292 | tsize *= tcount; |
283 | 293 | ||
284 | if (tsize > TVMEMSIZE) { | 294 | if (tsize > TVMEMSIZE) { |
285 | printk("template (%u) too big for tvmem (%u)\n", tsize, | 295 | printk("template (%u) too big for tvmem (%u)\n", tsize, |
286 | TVMEMSIZE); | 296 | TVMEMSIZE); |
@@ -288,112 +298,113 @@ test_cipher(char * algo, int mode, int enc, struct cipher_testvec * template, un | |||
288 | } | 298 | } |
289 | 299 | ||
290 | memcpy(tvmem, template, tsize); | 300 | memcpy(tvmem, template, tsize); |
291 | cipher_tv = (void *) tvmem; | 301 | cipher_tv = (void *)tvmem; |
302 | |||
303 | if (mode) | ||
304 | tfm = crypto_alloc_tfm(algo, 0); | ||
305 | else | ||
306 | tfm = crypto_alloc_tfm(algo, CRYPTO_TFM_MODE_CBC); | ||
292 | 307 | ||
293 | if (mode) | ||
294 | tfm = crypto_alloc_tfm (algo, 0); | ||
295 | else | ||
296 | tfm = crypto_alloc_tfm (algo, CRYPTO_TFM_MODE_CBC); | ||
297 | |||
298 | if (tfm == NULL) { | 308 | if (tfm == NULL) { |
299 | printk("failed to load transform for %s %s\n", algo, m); | 309 | printk("failed to load transform for %s %s\n", algo, m); |
300 | return; | 310 | return; |
301 | } | 311 | } |
302 | 312 | ||
303 | j = 0; | 313 | j = 0; |
304 | for (i = 0; i < tcount; i++) { | 314 | for (i = 0; i < tcount; i++) { |
305 | if (!(cipher_tv[i].np)) { | 315 | if (!(cipher_tv[i].np)) { |
306 | j++; | 316 | j++; |
307 | printk("test %u (%d bit key):\n", | 317 | printk("test %u (%d bit key):\n", |
308 | j, cipher_tv[i].klen * 8); | 318 | j, cipher_tv[i].klen * 8); |
309 | 319 | ||
310 | tfm->crt_flags = 0; | 320 | tfm->crt_flags = 0; |
311 | if (cipher_tv[i].wk) | 321 | if (cipher_tv[i].wk) |
312 | tfm->crt_flags |= CRYPTO_TFM_REQ_WEAK_KEY; | 322 | tfm->crt_flags |= CRYPTO_TFM_REQ_WEAK_KEY; |
313 | key = cipher_tv[i].key; | 323 | key = cipher_tv[i].key; |
314 | 324 | ||
315 | ret = crypto_cipher_setkey(tfm, key, cipher_tv[i].klen); | 325 | ret = crypto_cipher_setkey(tfm, key, cipher_tv[i].klen); |
316 | if (ret) { | 326 | if (ret) { |
317 | printk("setkey() failed flags=%x\n", tfm->crt_flags); | 327 | printk("setkey() failed flags=%x\n", tfm->crt_flags); |
318 | 328 | ||
319 | if (!cipher_tv[i].fail) | 329 | if (!cipher_tv[i].fail) |
320 | goto out; | 330 | goto out; |
321 | } | 331 | } |
322 | 332 | ||
323 | p = cipher_tv[i].input; | 333 | p = cipher_tv[i].input; |
324 | sg[0].page = virt_to_page(p); | 334 | sg[0].page = virt_to_page(p); |
325 | sg[0].offset = offset_in_page(p); | 335 | sg[0].offset = offset_in_page(p); |
326 | sg[0].length = cipher_tv[i].ilen; | 336 | sg[0].length = cipher_tv[i].ilen; |
327 | 337 | ||
328 | if (!mode) { | 338 | if (!mode) { |
329 | crypto_cipher_set_iv(tfm, cipher_tv[i].iv, | 339 | crypto_cipher_set_iv(tfm, cipher_tv[i].iv, |
330 | crypto_tfm_alg_ivsize (tfm)); | 340 | crypto_tfm_alg_ivsize(tfm)); |
331 | } | 341 | } |
332 | 342 | ||
333 | if (enc) | 343 | if (enc) |
334 | ret = crypto_cipher_encrypt(tfm, sg, sg, cipher_tv[i].ilen); | 344 | ret = crypto_cipher_encrypt(tfm, sg, sg, cipher_tv[i].ilen); |
335 | else | 345 | else |
336 | ret = crypto_cipher_decrypt(tfm, sg, sg, cipher_tv[i].ilen); | 346 | ret = crypto_cipher_decrypt(tfm, sg, sg, cipher_tv[i].ilen); |
337 | 347 | ||
338 | 348 | ||
339 | if (ret) { | 349 | if (ret) { |
340 | printk("%s () failed flags=%x\n", e, tfm->crt_flags); | 350 | printk("%s () failed flags=%x\n", e, tfm->crt_flags); |
341 | goto out; | 351 | goto out; |
342 | } | 352 | } |
343 | 353 | ||
344 | q = kmap(sg[0].page) + sg[0].offset; | 354 | q = kmap(sg[0].page) + sg[0].offset; |
345 | hexdump(q, cipher_tv[i].rlen); | 355 | hexdump(q, cipher_tv[i].rlen); |
346 | 356 | ||
347 | printk("%s\n", | 357 | printk("%s\n", |
348 | memcmp(q, cipher_tv[i].result, cipher_tv[i].rlen) ? "fail" : | 358 | memcmp(q, cipher_tv[i].result, |
349 | "pass"); | 359 | cipher_tv[i].rlen) ? "fail" : "pass"); |
350 | } | 360 | } |
351 | } | 361 | } |
352 | 362 | ||
353 | printk("\ntesting %s %s %s across pages (chunking) \n", algo, m, e); | 363 | printk("\ntesting %s %s %s across pages (chunking)\n", algo, m, e); |
354 | memset(xbuf, 0, XBUFSIZE); | 364 | memset(xbuf, 0, XBUFSIZE); |
355 | 365 | ||
356 | j = 0; | 366 | j = 0; |
357 | for (i = 0; i < tcount; i++) { | 367 | for (i = 0; i < tcount; i++) { |
358 | if (cipher_tv[i].np) { | 368 | if (cipher_tv[i].np) { |
359 | j++; | 369 | j++; |
360 | printk("test %u (%d bit key):\n", | 370 | printk("test %u (%d bit key):\n", |
361 | j, cipher_tv[i].klen * 8); | 371 | j, cipher_tv[i].klen * 8); |
362 | 372 | ||
363 | tfm->crt_flags = 0; | 373 | tfm->crt_flags = 0; |
364 | if (cipher_tv[i].wk) | 374 | if (cipher_tv[i].wk) |
365 | tfm->crt_flags |= CRYPTO_TFM_REQ_WEAK_KEY; | 375 | tfm->crt_flags |= CRYPTO_TFM_REQ_WEAK_KEY; |
366 | key = cipher_tv[i].key; | 376 | key = cipher_tv[i].key; |
367 | 377 | ||
368 | ret = crypto_cipher_setkey(tfm, key, cipher_tv[i].klen); | 378 | ret = crypto_cipher_setkey(tfm, key, cipher_tv[i].klen); |
369 | if (ret) { | 379 | if (ret) { |
370 | printk("setkey() failed flags=%x\n", tfm->crt_flags); | 380 | printk("setkey() failed flags=%x\n", tfm->crt_flags); |
371 | 381 | ||
372 | if (!cipher_tv[i].fail) | 382 | if (!cipher_tv[i].fail) |
373 | goto out; | 383 | goto out; |
374 | } | 384 | } |
375 | 385 | ||
376 | temp = 0; | 386 | temp = 0; |
377 | for (k = 0; k < cipher_tv[i].np; k++) { | 387 | for (k = 0; k < cipher_tv[i].np; k++) { |
378 | memcpy (&xbuf[IDX[k]], cipher_tv[i].input + temp, | 388 | memcpy(&xbuf[IDX[k]], |
379 | cipher_tv[i].tap[k]); | 389 | cipher_tv[i].input + temp, |
390 | cipher_tv[i].tap[k]); | ||
380 | temp += cipher_tv[i].tap[k]; | 391 | temp += cipher_tv[i].tap[k]; |
381 | p = &xbuf[IDX[k]]; | 392 | p = &xbuf[IDX[k]]; |
382 | sg[k].page = virt_to_page (p); | 393 | sg[k].page = virt_to_page(p); |
383 | sg[k].offset = offset_in_page (p); | 394 | sg[k].offset = offset_in_page(p); |
384 | sg[k].length = cipher_tv[i].tap[k]; | 395 | sg[k].length = cipher_tv[i].tap[k]; |
385 | } | 396 | } |
386 | 397 | ||
387 | if (!mode) { | 398 | if (!mode) { |
388 | crypto_cipher_set_iv(tfm, cipher_tv[i].iv, | 399 | crypto_cipher_set_iv(tfm, cipher_tv[i].iv, |
389 | crypto_tfm_alg_ivsize (tfm)); | 400 | crypto_tfm_alg_ivsize(tfm)); |
390 | } | 401 | } |
391 | 402 | ||
392 | if (enc) | 403 | if (enc) |
393 | ret = crypto_cipher_encrypt(tfm, sg, sg, cipher_tv[i].ilen); | 404 | ret = crypto_cipher_encrypt(tfm, sg, sg, cipher_tv[i].ilen); |
394 | else | 405 | else |
395 | ret = crypto_cipher_decrypt(tfm, sg, sg, cipher_tv[i].ilen); | 406 | ret = crypto_cipher_decrypt(tfm, sg, sg, cipher_tv[i].ilen); |
396 | 407 | ||
397 | if (ret) { | 408 | if (ret) { |
398 | printk("%s () failed flags=%x\n", e, tfm->crt_flags); | 409 | printk("%s () failed flags=%x\n", e, tfm->crt_flags); |
399 | goto out; | 410 | goto out; |
@@ -404,9 +415,9 @@ test_cipher(char * algo, int mode, int enc, struct cipher_testvec * template, un | |||
404 | printk("page %u\n", k); | 415 | printk("page %u\n", k); |
405 | q = kmap(sg[k].page) + sg[k].offset; | 416 | q = kmap(sg[k].page) + sg[k].offset; |
406 | hexdump(q, cipher_tv[i].tap[k]); | 417 | hexdump(q, cipher_tv[i].tap[k]); |
407 | printk("%s\n", | 418 | printk("%s\n", |
408 | memcmp(q, cipher_tv[i].result + temp, | 419 | memcmp(q, cipher_tv[i].result + temp, |
409 | cipher_tv[i].tap[k]) ? "fail" : | 420 | cipher_tv[i].tap[k]) ? "fail" : |
410 | "pass"); | 421 | "pass"); |
411 | temp += cipher_tv[i].tap[k]; | 422 | temp += cipher_tv[i].tap[k]; |
412 | } | 423 | } |
@@ -417,8 +428,169 @@ out: | |||
417 | crypto_free_tfm(tfm); | 428 | crypto_free_tfm(tfm); |
418 | } | 429 | } |
419 | 430 | ||
420 | static void | 431 | static int test_cipher_jiffies(struct crypto_tfm *tfm, int enc, char *p, |
421 | test_deflate(void) | 432 | int blen, int sec) |
433 | { | ||
434 | struct scatterlist sg[8]; | ||
435 | unsigned long start, end; | ||
436 | int bcount; | ||
437 | int ret; | ||
438 | |||
439 | sg[0].page = virt_to_page(p); | ||
440 | sg[0].offset = offset_in_page(p); | ||
441 | sg[0].length = blen; | ||
442 | |||
443 | for (start = jiffies, end = start + sec * HZ, bcount = 0; | ||
444 | time_before(jiffies, end); bcount++) { | ||
445 | if (enc) | ||
446 | ret = crypto_cipher_encrypt(tfm, sg, sg, blen); | ||
447 | else | ||
448 | ret = crypto_cipher_decrypt(tfm, sg, sg, blen); | ||
449 | |||
450 | if (ret) | ||
451 | return ret; | ||
452 | } | ||
453 | |||
454 | printk("%d operations in %d seconds (%ld bytes)\n", | ||
455 | bcount, sec, (long)bcount * blen); | ||
456 | return 0; | ||
457 | } | ||
458 | |||
459 | static int test_cipher_cycles(struct crypto_tfm *tfm, int enc, char *p, | ||
460 | int blen) | ||
461 | { | ||
462 | struct scatterlist sg[8]; | ||
463 | unsigned long cycles = 0; | ||
464 | int ret = 0; | ||
465 | int i; | ||
466 | |||
467 | sg[0].page = virt_to_page(p); | ||
468 | sg[0].offset = offset_in_page(p); | ||
469 | sg[0].length = blen; | ||
470 | |||
471 | local_bh_disable(); | ||
472 | local_irq_disable(); | ||
473 | |||
474 | /* Warm-up run. */ | ||
475 | for (i = 0; i < 4; i++) { | ||
476 | if (enc) | ||
477 | ret = crypto_cipher_encrypt(tfm, sg, sg, blen); | ||
478 | else | ||
479 | ret = crypto_cipher_decrypt(tfm, sg, sg, blen); | ||
480 | |||
481 | if (ret) | ||
482 | goto out; | ||
483 | } | ||
484 | |||
485 | /* The real thing. */ | ||
486 | for (i = 0; i < 8; i++) { | ||
487 | cycles_t start, end; | ||
488 | |||
489 | start = get_cycles(); | ||
490 | if (enc) | ||
491 | ret = crypto_cipher_encrypt(tfm, sg, sg, blen); | ||
492 | else | ||
493 | ret = crypto_cipher_decrypt(tfm, sg, sg, blen); | ||
494 | end = get_cycles(); | ||
495 | |||
496 | if (ret) | ||
497 | goto out; | ||
498 | |||
499 | cycles += end - start; | ||
500 | } | ||
501 | |||
502 | out: | ||
503 | local_irq_enable(); | ||
504 | local_bh_enable(); | ||
505 | |||
506 | if (ret == 0) | ||
507 | printk("1 operation in %lu cycles (%d bytes)\n", | ||
508 | (cycles + 4) / 8, blen); | ||
509 | |||
510 | return ret; | ||
511 | } | ||
512 | |||
513 | static void test_cipher_speed(char *algo, int mode, int enc, unsigned int sec, | ||
514 | struct cipher_testvec *template, | ||
515 | unsigned int tcount, struct cipher_speed *speed) | ||
516 | { | ||
517 | unsigned int ret, i, j, iv_len; | ||
518 | unsigned char *key, *p, iv[128]; | ||
519 | struct crypto_tfm *tfm; | ||
520 | const char *e, *m; | ||
521 | |||
522 | if (enc == ENCRYPT) | ||
523 | e = "encryption"; | ||
524 | else | ||
525 | e = "decryption"; | ||
526 | if (mode == MODE_ECB) | ||
527 | m = "ECB"; | ||
528 | else | ||
529 | m = "CBC"; | ||
530 | |||
531 | printk("\ntesting speed of %s %s %s\n", algo, m, e); | ||
532 | |||
533 | if (mode) | ||
534 | tfm = crypto_alloc_tfm(algo, 0); | ||
535 | else | ||
536 | tfm = crypto_alloc_tfm(algo, CRYPTO_TFM_MODE_CBC); | ||
537 | |||
538 | if (tfm == NULL) { | ||
539 | printk("failed to load transform for %s %s\n", algo, m); | ||
540 | return; | ||
541 | } | ||
542 | |||
543 | for (i = 0; speed[i].klen != 0; i++) { | ||
544 | if ((speed[i].blen + speed[i].klen) > TVMEMSIZE) { | ||
545 | printk("template (%u) too big for tvmem (%u)\n", | ||
546 | speed[i].blen + speed[i].klen, TVMEMSIZE); | ||
547 | goto out; | ||
548 | } | ||
549 | |||
550 | printk("test %u (%d bit key, %d byte blocks): ", i, | ||
551 | speed[i].klen * 8, speed[i].blen); | ||
552 | |||
553 | memset(tvmem, 0xff, speed[i].klen + speed[i].blen); | ||
554 | |||
555 | /* set key, plain text and IV */ | ||
556 | key = (unsigned char *)tvmem; | ||
557 | for (j = 0; j < tcount; j++) { | ||
558 | if (template[j].klen == speed[i].klen) { | ||
559 | key = template[j].key; | ||
560 | break; | ||
561 | } | ||
562 | } | ||
563 | p = (unsigned char *)tvmem + speed[i].klen; | ||
564 | |||
565 | ret = crypto_cipher_setkey(tfm, key, speed[i].klen); | ||
566 | if (ret) { | ||
567 | printk("setkey() failed flags=%x\n", tfm->crt_flags); | ||
568 | goto out; | ||
569 | } | ||
570 | |||
571 | if (!mode) { | ||
572 | iv_len = crypto_tfm_alg_ivsize(tfm); | ||
573 | memset(&iv, 0xff, iv_len); | ||
574 | crypto_cipher_set_iv(tfm, iv, iv_len); | ||
575 | } | ||
576 | |||
577 | if (sec) | ||
578 | ret = test_cipher_jiffies(tfm, enc, p, speed[i].blen, | ||
579 | sec); | ||
580 | else | ||
581 | ret = test_cipher_cycles(tfm, enc, p, speed[i].blen); | ||
582 | |||
583 | if (ret) { | ||
584 | printk("%s() failed flags=%x\n", e, tfm->crt_flags); | ||
585 | break; | ||
586 | } | ||
587 | } | ||
588 | |||
589 | out: | ||
590 | crypto_free_tfm(tfm); | ||
591 | } | ||
592 | |||
593 | static void test_deflate(void) | ||
422 | { | 594 | { |
423 | unsigned int i; | 595 | unsigned int i; |
424 | char result[COMP_BUF_SIZE]; | 596 | char result[COMP_BUF_SIZE]; |
@@ -436,7 +608,7 @@ test_deflate(void) | |||
436 | } | 608 | } |
437 | 609 | ||
438 | memcpy(tvmem, deflate_comp_tv_template, tsize); | 610 | memcpy(tvmem, deflate_comp_tv_template, tsize); |
439 | tv = (void *) tvmem; | 611 | tv = (void *)tvmem; |
440 | 612 | ||
441 | tfm = crypto_alloc_tfm("deflate", 0); | 613 | tfm = crypto_alloc_tfm("deflate", 0); |
442 | if (tfm == NULL) { | 614 | if (tfm == NULL) { |
@@ -446,7 +618,7 @@ test_deflate(void) | |||
446 | 618 | ||
447 | for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) { | 619 | for (i = 0; i < DEFLATE_COMP_TEST_VECTORS; i++) { |
448 | int ilen, ret, dlen = COMP_BUF_SIZE; | 620 | int ilen, ret, dlen = COMP_BUF_SIZE; |
449 | 621 | ||
450 | printk("test %u:\n", i + 1); | 622 | printk("test %u:\n", i + 1); |
451 | memset(result, 0, sizeof (result)); | 623 | memset(result, 0, sizeof (result)); |
452 | 624 | ||
@@ -473,11 +645,11 @@ test_deflate(void) | |||
473 | } | 645 | } |
474 | 646 | ||
475 | memcpy(tvmem, deflate_decomp_tv_template, tsize); | 647 | memcpy(tvmem, deflate_decomp_tv_template, tsize); |
476 | tv = (void *) tvmem; | 648 | tv = (void *)tvmem; |
477 | 649 | ||
478 | for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) { | 650 | for (i = 0; i < DEFLATE_DECOMP_TEST_VECTORS; i++) { |
479 | int ilen, ret, dlen = COMP_BUF_SIZE; | 651 | int ilen, ret, dlen = COMP_BUF_SIZE; |
480 | 652 | ||
481 | printk("test %u:\n", i + 1); | 653 | printk("test %u:\n", i + 1); |
482 | memset(result, 0, sizeof (result)); | 654 | memset(result, 0, sizeof (result)); |
483 | 655 | ||
@@ -497,8 +669,7 @@ out: | |||
497 | crypto_free_tfm(tfm); | 669 | crypto_free_tfm(tfm); |
498 | } | 670 | } |
499 | 671 | ||
500 | static void | 672 | static void test_crc32c(void) |
501 | test_crc32c(void) | ||
502 | { | 673 | { |
503 | #define NUMVEC 6 | 674 | #define NUMVEC 6 |
504 | #define VECSIZE 40 | 675 | #define VECSIZE 40 |
@@ -511,7 +682,7 @@ test_crc32c(void) | |||
511 | 0xd579c862, 0xba979ad0, 0x2b29d913 | 682 | 0xd579c862, 0xba979ad0, 0x2b29d913 |
512 | }; | 683 | }; |
513 | static u32 tot_vec_results = 0x24c5d375; | 684 | static u32 tot_vec_results = 0x24c5d375; |
514 | 685 | ||
515 | struct scatterlist sg[NUMVEC]; | 686 | struct scatterlist sg[NUMVEC]; |
516 | struct crypto_tfm *tfm; | 687 | struct crypto_tfm *tfm; |
517 | char *fmtdata = "testing crc32c initialized to %08x: %s\n"; | 688 | char *fmtdata = "testing crc32c initialized to %08x: %s\n"; |
@@ -525,18 +696,18 @@ test_crc32c(void) | |||
525 | printk("failed to load transform for crc32c\n"); | 696 | printk("failed to load transform for crc32c\n"); |
526 | return; | 697 | return; |
527 | } | 698 | } |
528 | 699 | ||
529 | crypto_digest_init(tfm); | 700 | crypto_digest_init(tfm); |
530 | crypto_digest_final(tfm, (u8*)&crc); | 701 | crypto_digest_final(tfm, (u8*)&crc); |
531 | printk(fmtdata, crc, (crc == 0) ? "pass" : "ERROR"); | 702 | printk(fmtdata, crc, (crc == 0) ? "pass" : "ERROR"); |
532 | 703 | ||
533 | /* | 704 | /* |
534 | * stuff test_vec with known values, simple incrementing | 705 | * stuff test_vec with known values, simple incrementing |
535 | * byte values. | 706 | * byte values. |
536 | */ | 707 | */ |
537 | b = 0; | 708 | b = 0; |
538 | for (i = 0; i < NUMVEC; i++) { | 709 | for (i = 0; i < NUMVEC; i++) { |
539 | for (j = 0; j < VECSIZE; j++) | 710 | for (j = 0; j < VECSIZE; j++) |
540 | test_vec[i][j] = ++b; | 711 | test_vec[i][j] = ++b; |
541 | sg[i].page = virt_to_page(test_vec[i]); | 712 | sg[i].page = virt_to_page(test_vec[i]); |
542 | sg[i].offset = offset_in_page(test_vec[i]); | 713 | sg[i].offset = offset_in_page(test_vec[i]); |
@@ -548,11 +719,11 @@ test_crc32c(void) | |||
548 | crypto_digest_final(tfm, (u8*)&crc); | 719 | crypto_digest_final(tfm, (u8*)&crc); |
549 | printk("testing crc32c setkey returns %08x : %s\n", crc, (crc == (SEEDTESTVAL ^ ~(u32)0)) ? | 720 | printk("testing crc32c setkey returns %08x : %s\n", crc, (crc == (SEEDTESTVAL ^ ~(u32)0)) ? |
550 | "pass" : "ERROR"); | 721 | "pass" : "ERROR"); |
551 | 722 | ||
552 | printk("testing crc32c using update/final:\n"); | 723 | printk("testing crc32c using update/final:\n"); |
553 | 724 | ||
554 | pass = 1; /* assume all is well */ | 725 | pass = 1; /* assume all is well */ |
555 | 726 | ||
556 | for (i = 0; i < NUMVEC; i++) { | 727 | for (i = 0; i < NUMVEC; i++) { |
557 | seed = ~(u32)0; | 728 | seed = ~(u32)0; |
558 | (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32)); | 729 | (void)crypto_digest_setkey(tfm, (const u8*)&seed, sizeof(u32)); |
@@ -591,66 +762,64 @@ test_crc32c(void) | |||
591 | printk(" %08x:BAD, wanted %08x\n", crc, tot_vec_results); | 762 | printk(" %08x:BAD, wanted %08x\n", crc, tot_vec_results); |
592 | pass = 0; | 763 | pass = 0; |
593 | } | 764 | } |
594 | 765 | ||
595 | printk("\n%s\n", pass ? "pass" : "ERROR"); | 766 | printk("\n%s\n", pass ? "pass" : "ERROR"); |
596 | 767 | ||
597 | crypto_free_tfm(tfm); | 768 | crypto_free_tfm(tfm); |
598 | printk("crc32c test complete\n"); | 769 | printk("crc32c test complete\n"); |
599 | } | 770 | } |
600 | 771 | ||
601 | static void | 772 | static void test_available(void) |
602 | test_available(void) | ||
603 | { | 773 | { |
604 | char **name = check; | 774 | char **name = check; |
605 | 775 | ||
606 | while (*name) { | 776 | while (*name) { |
607 | printk("alg %s ", *name); | 777 | printk("alg %s ", *name); |
608 | printk((crypto_alg_available(*name, 0)) ? | 778 | printk((crypto_alg_available(*name, 0)) ? |
609 | "found\n" : "not found\n"); | 779 | "found\n" : "not found\n"); |
610 | name++; | 780 | name++; |
611 | } | 781 | } |
612 | } | 782 | } |
613 | 783 | ||
614 | static void | 784 | static void do_test(void) |
615 | do_test(void) | ||
616 | { | 785 | { |
617 | switch (mode) { | 786 | switch (mode) { |
618 | 787 | ||
619 | case 0: | 788 | case 0: |
620 | test_hash("md5", md5_tv_template, MD5_TEST_VECTORS); | 789 | test_hash("md5", md5_tv_template, MD5_TEST_VECTORS); |
621 | 790 | ||
622 | test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS); | 791 | test_hash("sha1", sha1_tv_template, SHA1_TEST_VECTORS); |
623 | 792 | ||
624 | //DES | 793 | //DES |
625 | test_cipher ("des", MODE_ECB, ENCRYPT, des_enc_tv_template, DES_ENC_TEST_VECTORS); | 794 | test_cipher ("des", MODE_ECB, ENCRYPT, des_enc_tv_template, DES_ENC_TEST_VECTORS); |
626 | test_cipher ("des", MODE_ECB, DECRYPT, des_dec_tv_template, DES_DEC_TEST_VECTORS); | 795 | test_cipher ("des", MODE_ECB, DECRYPT, des_dec_tv_template, DES_DEC_TEST_VECTORS); |
627 | test_cipher ("des", MODE_CBC, ENCRYPT, des_cbc_enc_tv_template, DES_CBC_ENC_TEST_VECTORS); | 796 | test_cipher ("des", MODE_CBC, ENCRYPT, des_cbc_enc_tv_template, DES_CBC_ENC_TEST_VECTORS); |
628 | test_cipher ("des", MODE_CBC, DECRYPT, des_cbc_dec_tv_template, DES_CBC_DEC_TEST_VECTORS); | 797 | test_cipher ("des", MODE_CBC, DECRYPT, des_cbc_dec_tv_template, DES_CBC_DEC_TEST_VECTORS); |
629 | 798 | ||
630 | //DES3_EDE | 799 | //DES3_EDE |
631 | test_cipher ("des3_ede", MODE_ECB, ENCRYPT, des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS); | 800 | test_cipher ("des3_ede", MODE_ECB, ENCRYPT, des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS); |
632 | test_cipher ("des3_ede", MODE_ECB, DECRYPT, des3_ede_dec_tv_template, DES3_EDE_DEC_TEST_VECTORS); | 801 | test_cipher ("des3_ede", MODE_ECB, DECRYPT, des3_ede_dec_tv_template, DES3_EDE_DEC_TEST_VECTORS); |
633 | 802 | ||
634 | test_hash("md4", md4_tv_template, MD4_TEST_VECTORS); | 803 | test_hash("md4", md4_tv_template, MD4_TEST_VECTORS); |
635 | 804 | ||
636 | test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS); | 805 | test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS); |
637 | 806 | ||
638 | //BLOWFISH | 807 | //BLOWFISH |
639 | test_cipher ("blowfish", MODE_ECB, ENCRYPT, bf_enc_tv_template, BF_ENC_TEST_VECTORS); | 808 | test_cipher ("blowfish", MODE_ECB, ENCRYPT, bf_enc_tv_template, BF_ENC_TEST_VECTORS); |
640 | test_cipher ("blowfish", MODE_ECB, DECRYPT, bf_dec_tv_template, BF_DEC_TEST_VECTORS); | 809 | test_cipher ("blowfish", MODE_ECB, DECRYPT, bf_dec_tv_template, BF_DEC_TEST_VECTORS); |
641 | test_cipher ("blowfish", MODE_CBC, ENCRYPT, bf_cbc_enc_tv_template, BF_CBC_ENC_TEST_VECTORS); | 810 | test_cipher ("blowfish", MODE_CBC, ENCRYPT, bf_cbc_enc_tv_template, BF_CBC_ENC_TEST_VECTORS); |
642 | test_cipher ("blowfish", MODE_CBC, DECRYPT, bf_cbc_dec_tv_template, BF_CBC_DEC_TEST_VECTORS); | 811 | test_cipher ("blowfish", MODE_CBC, DECRYPT, bf_cbc_dec_tv_template, BF_CBC_DEC_TEST_VECTORS); |
643 | 812 | ||
644 | //TWOFISH | 813 | //TWOFISH |
645 | test_cipher ("twofish", MODE_ECB, ENCRYPT, tf_enc_tv_template, TF_ENC_TEST_VECTORS); | 814 | test_cipher ("twofish", MODE_ECB, ENCRYPT, tf_enc_tv_template, TF_ENC_TEST_VECTORS); |
646 | test_cipher ("twofish", MODE_ECB, DECRYPT, tf_dec_tv_template, TF_DEC_TEST_VECTORS); | 815 | test_cipher ("twofish", MODE_ECB, DECRYPT, tf_dec_tv_template, TF_DEC_TEST_VECTORS); |
647 | test_cipher ("twofish", MODE_CBC, ENCRYPT, tf_cbc_enc_tv_template, TF_CBC_ENC_TEST_VECTORS); | 816 | test_cipher ("twofish", MODE_CBC, ENCRYPT, tf_cbc_enc_tv_template, TF_CBC_ENC_TEST_VECTORS); |
648 | test_cipher ("twofish", MODE_CBC, DECRYPT, tf_cbc_dec_tv_template, TF_CBC_DEC_TEST_VECTORS); | 817 | test_cipher ("twofish", MODE_CBC, DECRYPT, tf_cbc_dec_tv_template, TF_CBC_DEC_TEST_VECTORS); |
649 | 818 | ||
650 | //SERPENT | 819 | //SERPENT |
651 | test_cipher ("serpent", MODE_ECB, ENCRYPT, serpent_enc_tv_template, SERPENT_ENC_TEST_VECTORS); | 820 | test_cipher ("serpent", MODE_ECB, ENCRYPT, serpent_enc_tv_template, SERPENT_ENC_TEST_VECTORS); |
652 | test_cipher ("serpent", MODE_ECB, DECRYPT, serpent_dec_tv_template, SERPENT_DEC_TEST_VECTORS); | 821 | test_cipher ("serpent", MODE_ECB, DECRYPT, serpent_dec_tv_template, SERPENT_DEC_TEST_VECTORS); |
653 | 822 | ||
654 | //TNEPRES | 823 | //TNEPRES |
655 | test_cipher ("tnepres", MODE_ECB, ENCRYPT, tnepres_enc_tv_template, TNEPRES_ENC_TEST_VECTORS); | 824 | test_cipher ("tnepres", MODE_ECB, ENCRYPT, tnepres_enc_tv_template, TNEPRES_ENC_TEST_VECTORS); |
656 | test_cipher ("tnepres", MODE_ECB, DECRYPT, tnepres_dec_tv_template, TNEPRES_DEC_TEST_VECTORS); | 825 | test_cipher ("tnepres", MODE_ECB, DECRYPT, tnepres_dec_tv_template, TNEPRES_DEC_TEST_VECTORS); |
@@ -662,7 +831,7 @@ do_test(void) | |||
662 | //CAST5 | 831 | //CAST5 |
663 | test_cipher ("cast5", MODE_ECB, ENCRYPT, cast5_enc_tv_template, CAST5_ENC_TEST_VECTORS); | 832 | test_cipher ("cast5", MODE_ECB, ENCRYPT, cast5_enc_tv_template, CAST5_ENC_TEST_VECTORS); |
664 | test_cipher ("cast5", MODE_ECB, DECRYPT, cast5_dec_tv_template, CAST5_DEC_TEST_VECTORS); | 833 | test_cipher ("cast5", MODE_ECB, DECRYPT, cast5_dec_tv_template, CAST5_DEC_TEST_VECTORS); |
665 | 834 | ||
666 | //CAST6 | 835 | //CAST6 |
667 | test_cipher ("cast6", MODE_ECB, ENCRYPT, cast6_enc_tv_template, CAST6_ENC_TEST_VECTORS); | 836 | test_cipher ("cast6", MODE_ECB, ENCRYPT, cast6_enc_tv_template, CAST6_ENC_TEST_VECTORS); |
668 | test_cipher ("cast6", MODE_ECB, DECRYPT, cast6_dec_tv_template, CAST6_DEC_TEST_VECTORS); | 837 | test_cipher ("cast6", MODE_ECB, DECRYPT, cast6_dec_tv_template, CAST6_DEC_TEST_VECTORS); |
@@ -702,9 +871,9 @@ do_test(void) | |||
702 | test_crc32c(); | 871 | test_crc32c(); |
703 | #ifdef CONFIG_CRYPTO_HMAC | 872 | #ifdef CONFIG_CRYPTO_HMAC |
704 | test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS); | 873 | test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS); |
705 | test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS); | 874 | test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS); |
706 | test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS); | 875 | test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS); |
707 | #endif | 876 | #endif |
708 | 877 | ||
709 | test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS); | 878 | test_hash("michael_mic", michael_mic_tv_template, MICHAEL_MIC_TEST_VECTORS); |
710 | break; | 879 | break; |
@@ -726,17 +895,17 @@ do_test(void) | |||
726 | 895 | ||
727 | case 4: | 896 | case 4: |
728 | test_cipher ("des3_ede", MODE_ECB, ENCRYPT, des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS); | 897 | test_cipher ("des3_ede", MODE_ECB, ENCRYPT, des3_ede_enc_tv_template, DES3_EDE_ENC_TEST_VECTORS); |
729 | test_cipher ("des3_ede", MODE_ECB, DECRYPT, des3_ede_dec_tv_template, DES3_EDE_DEC_TEST_VECTORS); | 898 | test_cipher ("des3_ede", MODE_ECB, DECRYPT, des3_ede_dec_tv_template, DES3_EDE_DEC_TEST_VECTORS); |
730 | break; | 899 | break; |
731 | 900 | ||
732 | case 5: | 901 | case 5: |
733 | test_hash("md4", md4_tv_template, MD4_TEST_VECTORS); | 902 | test_hash("md4", md4_tv_template, MD4_TEST_VECTORS); |
734 | break; | 903 | break; |
735 | 904 | ||
736 | case 6: | 905 | case 6: |
737 | test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS); | 906 | test_hash("sha256", sha256_tv_template, SHA256_TEST_VECTORS); |
738 | break; | 907 | break; |
739 | 908 | ||
740 | case 7: | 909 | case 7: |
741 | test_cipher ("blowfish", MODE_ECB, ENCRYPT, bf_enc_tv_template, BF_ENC_TEST_VECTORS); | 910 | test_cipher ("blowfish", MODE_ECB, ENCRYPT, bf_enc_tv_template, BF_ENC_TEST_VECTORS); |
742 | test_cipher ("blowfish", MODE_ECB, DECRYPT, bf_dec_tv_template, BF_DEC_TEST_VECTORS); | 911 | test_cipher ("blowfish", MODE_ECB, DECRYPT, bf_dec_tv_template, BF_DEC_TEST_VECTORS); |
@@ -750,7 +919,7 @@ do_test(void) | |||
750 | test_cipher ("twofish", MODE_CBC, ENCRYPT, tf_cbc_enc_tv_template, TF_CBC_ENC_TEST_VECTORS); | 919 | test_cipher ("twofish", MODE_CBC, ENCRYPT, tf_cbc_enc_tv_template, TF_CBC_ENC_TEST_VECTORS); |
751 | test_cipher ("twofish", MODE_CBC, DECRYPT, tf_cbc_dec_tv_template, TF_CBC_DEC_TEST_VECTORS); | 920 | test_cipher ("twofish", MODE_CBC, DECRYPT, tf_cbc_dec_tv_template, TF_CBC_DEC_TEST_VECTORS); |
752 | break; | 921 | break; |
753 | 922 | ||
754 | case 9: | 923 | case 9: |
755 | test_cipher ("serpent", MODE_ECB, ENCRYPT, serpent_enc_tv_template, SERPENT_ENC_TEST_VECTORS); | 924 | test_cipher ("serpent", MODE_ECB, ENCRYPT, serpent_enc_tv_template, SERPENT_ENC_TEST_VECTORS); |
756 | test_cipher ("serpent", MODE_ECB, DECRYPT, serpent_dec_tv_template, SERPENT_DEC_TEST_VECTORS); | 925 | test_cipher ("serpent", MODE_ECB, DECRYPT, serpent_dec_tv_template, SERPENT_DEC_TEST_VECTORS); |
@@ -758,13 +927,13 @@ do_test(void) | |||
758 | 927 | ||
759 | case 10: | 928 | case 10: |
760 | test_cipher ("aes", MODE_ECB, ENCRYPT, aes_enc_tv_template, AES_ENC_TEST_VECTORS); | 929 | test_cipher ("aes", MODE_ECB, ENCRYPT, aes_enc_tv_template, AES_ENC_TEST_VECTORS); |
761 | test_cipher ("aes", MODE_ECB, DECRYPT, aes_dec_tv_template, AES_DEC_TEST_VECTORS); | 930 | test_cipher ("aes", MODE_ECB, DECRYPT, aes_dec_tv_template, AES_DEC_TEST_VECTORS); |
762 | break; | 931 | break; |
763 | 932 | ||
764 | case 11: | 933 | case 11: |
765 | test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS); | 934 | test_hash("sha384", sha384_tv_template, SHA384_TEST_VECTORS); |
766 | break; | 935 | break; |
767 | 936 | ||
768 | case 12: | 937 | case 12: |
769 | test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS); | 938 | test_hash("sha512", sha512_tv_template, SHA512_TEST_VECTORS); |
770 | break; | 939 | break; |
@@ -852,21 +1021,84 @@ do_test(void) | |||
852 | case 100: | 1021 | case 100: |
853 | test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS); | 1022 | test_hmac("md5", hmac_md5_tv_template, HMAC_MD5_TEST_VECTORS); |
854 | break; | 1023 | break; |
855 | 1024 | ||
856 | case 101: | 1025 | case 101: |
857 | test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS); | 1026 | test_hmac("sha1", hmac_sha1_tv_template, HMAC_SHA1_TEST_VECTORS); |
858 | break; | 1027 | break; |
859 | 1028 | ||
860 | case 102: | 1029 | case 102: |
861 | test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS); | 1030 | test_hmac("sha256", hmac_sha256_tv_template, HMAC_SHA256_TEST_VECTORS); |
862 | break; | 1031 | break; |
863 | 1032 | ||
864 | #endif | 1033 | #endif |
865 | 1034 | ||
1035 | case 200: | ||
1036 | test_cipher_speed("aes", MODE_ECB, ENCRYPT, sec, NULL, 0, | ||
1037 | aes_speed_template); | ||
1038 | test_cipher_speed("aes", MODE_ECB, DECRYPT, sec, NULL, 0, | ||
1039 | aes_speed_template); | ||
1040 | test_cipher_speed("aes", MODE_CBC, ENCRYPT, sec, NULL, 0, | ||
1041 | aes_speed_template); | ||
1042 | test_cipher_speed("aes", MODE_CBC, DECRYPT, sec, NULL, 0, | ||
1043 | aes_speed_template); | ||
1044 | break; | ||
1045 | |||
1046 | case 201: | ||
1047 | test_cipher_speed("des3_ede", MODE_ECB, ENCRYPT, sec, | ||
1048 | des3_ede_enc_tv_template, | ||
1049 | DES3_EDE_ENC_TEST_VECTORS, | ||
1050 | des3_ede_speed_template); | ||
1051 | test_cipher_speed("des3_ede", MODE_ECB, DECRYPT, sec, | ||
1052 | des3_ede_dec_tv_template, | ||
1053 | DES3_EDE_DEC_TEST_VECTORS, | ||
1054 | des3_ede_speed_template); | ||
1055 | test_cipher_speed("des3_ede", MODE_CBC, ENCRYPT, sec, | ||
1056 | des3_ede_enc_tv_template, | ||
1057 | DES3_EDE_ENC_TEST_VECTORS, | ||
1058 | des3_ede_speed_template); | ||
1059 | test_cipher_speed("des3_ede", MODE_CBC, DECRYPT, sec, | ||
1060 | des3_ede_dec_tv_template, | ||
1061 | DES3_EDE_DEC_TEST_VECTORS, | ||
1062 | des3_ede_speed_template); | ||
1063 | break; | ||
1064 | |||
1065 | case 202: | ||
1066 | test_cipher_speed("twofish", MODE_ECB, ENCRYPT, sec, NULL, 0, | ||
1067 | twofish_speed_template); | ||
1068 | test_cipher_speed("twofish", MODE_ECB, DECRYPT, sec, NULL, 0, | ||
1069 | twofish_speed_template); | ||
1070 | test_cipher_speed("twofish", MODE_CBC, ENCRYPT, sec, NULL, 0, | ||
1071 | twofish_speed_template); | ||
1072 | test_cipher_speed("twofish", MODE_CBC, DECRYPT, sec, NULL, 0, | ||
1073 | twofish_speed_template); | ||
1074 | break; | ||
1075 | |||
1076 | case 203: | ||
1077 | test_cipher_speed("blowfish", MODE_ECB, ENCRYPT, sec, NULL, 0, | ||
1078 | blowfish_speed_template); | ||
1079 | test_cipher_speed("blowfish", MODE_ECB, DECRYPT, sec, NULL, 0, | ||
1080 | blowfish_speed_template); | ||
1081 | test_cipher_speed("blowfish", MODE_CBC, ENCRYPT, sec, NULL, 0, | ||
1082 | blowfish_speed_template); | ||
1083 | test_cipher_speed("blowfish", MODE_CBC, DECRYPT, sec, NULL, 0, | ||
1084 | blowfish_speed_template); | ||
1085 | break; | ||
1086 | |||
1087 | case 204: | ||
1088 | test_cipher_speed("des", MODE_ECB, ENCRYPT, sec, NULL, 0, | ||
1089 | des_speed_template); | ||
1090 | test_cipher_speed("des", MODE_ECB, DECRYPT, sec, NULL, 0, | ||
1091 | des_speed_template); | ||
1092 | test_cipher_speed("des", MODE_CBC, ENCRYPT, sec, NULL, 0, | ||
1093 | des_speed_template); | ||
1094 | test_cipher_speed("des", MODE_CBC, DECRYPT, sec, NULL, 0, | ||
1095 | des_speed_template); | ||
1096 | break; | ||
1097 | |||
866 | case 1000: | 1098 | case 1000: |
867 | test_available(); | 1099 | test_available(); |
868 | break; | 1100 | break; |
869 | 1101 | ||
870 | default: | 1102 | default: |
871 | /* useful for debugging */ | 1103 | /* useful for debugging */ |
872 | printk("not testing anything\n"); | 1104 | printk("not testing anything\n"); |
@@ -874,8 +1106,7 @@ do_test(void) | |||
874 | } | 1106 | } |
875 | } | 1107 | } |
876 | 1108 | ||
877 | static int __init | 1109 | static int __init init(void) |
878 | init(void) | ||
879 | { | 1110 | { |
880 | tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL); | 1111 | tvmem = kmalloc(TVMEMSIZE, GFP_KERNEL); |
881 | if (tvmem == NULL) | 1112 | if (tvmem == NULL) |
@@ -904,6 +1135,9 @@ module_init(init); | |||
904 | module_exit(fini); | 1135 | module_exit(fini); |
905 | 1136 | ||
906 | module_param(mode, int, 0); | 1137 | module_param(mode, int, 0); |
1138 | module_param(sec, uint, 0); | ||
1139 | MODULE_PARM_DESC(sec, "Length in seconds of speed tests " | ||
1140 | "(defaults to zero which uses CPU cycles instead)"); | ||
907 | 1141 | ||
908 | MODULE_LICENSE("GPL"); | 1142 | MODULE_LICENSE("GPL"); |
909 | MODULE_DESCRIPTION("Quick & dirty crypto testing module"); | 1143 | MODULE_DESCRIPTION("Quick & dirty crypto testing module"); |
diff --git a/crypto/tcrypt.h b/crypto/tcrypt.h index a3097afae593..c01a0ce9b40a 100644 --- a/crypto/tcrypt.h +++ b/crypto/tcrypt.h | |||
@@ -9,10 +9,11 @@ | |||
9 | * | 9 | * |
10 | * This program is free software; you can redistribute it and/or modify it | 10 | * This program is free software; you can redistribute it and/or modify it |
11 | * under the terms of the GNU General Public License as published by the Free | 11 | * under the terms of the GNU General Public License as published by the Free |
12 | * Software Foundation; either version 2 of the License, or (at your option) | 12 | * Software Foundation; either version 2 of the License, or (at your option) |
13 | * any later version. | 13 | * any later version. |
14 | * | 14 | * |
15 | * 14 - 09 - 2003 Changes by Kartikey Mahendra Bhatt | 15 | * 2004-08-09 Cipher speed tests by Reyk Floeter <reyk@vantronix.net> |
16 | * 2003-09-14 Changes by Kartikey Mahendra Bhatt | ||
16 | * | 17 | * |
17 | */ | 18 | */ |
18 | #ifndef _CRYPTO_TCRYPT_H | 19 | #ifndef _CRYPTO_TCRYPT_H |
@@ -29,19 +30,19 @@ struct hash_testvec { | |||
29 | unsigned char psize; | 30 | unsigned char psize; |
30 | char digest[MAX_DIGEST_SIZE]; | 31 | char digest[MAX_DIGEST_SIZE]; |
31 | unsigned char np; | 32 | unsigned char np; |
32 | unsigned char tap[MAX_TAP]; | 33 | unsigned char tap[MAX_TAP]; |
33 | char key[128]; /* only used with keyed hash algorithms */ | 34 | char key[128]; /* only used with keyed hash algorithms */ |
34 | unsigned char ksize; | 35 | unsigned char ksize; |
35 | }; | 36 | }; |
36 | 37 | ||
37 | struct hmac_testvec { | 38 | struct hmac_testvec { |
38 | char key[128]; | 39 | char key[128]; |
39 | unsigned char ksize; | 40 | unsigned char ksize; |
40 | char plaintext[128]; | 41 | char plaintext[128]; |
41 | unsigned char psize; | 42 | unsigned char psize; |
42 | char digest[MAX_DIGEST_SIZE]; | 43 | char digest[MAX_DIGEST_SIZE]; |
43 | unsigned char np; | 44 | unsigned char np; |
44 | unsigned char tap[MAX_TAP]; | 45 | unsigned char tap[MAX_TAP]; |
45 | }; | 46 | }; |
46 | 47 | ||
47 | struct cipher_testvec { | 48 | struct cipher_testvec { |
@@ -55,7 +56,12 @@ struct cipher_testvec { | |||
55 | char result[48]; | 56 | char result[48]; |
56 | unsigned char rlen; | 57 | unsigned char rlen; |
57 | int np; | 58 | int np; |
58 | unsigned char tap[MAX_TAP]; | 59 | unsigned char tap[MAX_TAP]; |
60 | }; | ||
61 | |||
62 | struct cipher_speed { | ||
63 | unsigned char klen; | ||
64 | unsigned int blen; | ||
59 | }; | 65 | }; |
60 | 66 | ||
61 | /* | 67 | /* |
@@ -155,7 +161,7 @@ static struct hash_testvec md5_tv_template[] = { | |||
155 | #define SHA1_TEST_VECTORS 2 | 161 | #define SHA1_TEST_VECTORS 2 |
156 | 162 | ||
157 | static struct hash_testvec sha1_tv_template[] = { | 163 | static struct hash_testvec sha1_tv_template[] = { |
158 | { | 164 | { |
159 | .plaintext = "abc", | 165 | .plaintext = "abc", |
160 | .psize = 3, | 166 | .psize = 3, |
161 | .digest = { 0xa9, 0x99, 0x3e, 0x36, 0x47, 0x06, 0x81, 0x6a, 0xba, 0x3e, | 167 | .digest = { 0xa9, 0x99, 0x3e, 0x36, 0x47, 0x06, 0x81, 0x6a, 0xba, 0x3e, |
@@ -175,8 +181,8 @@ static struct hash_testvec sha1_tv_template[] = { | |||
175 | */ | 181 | */ |
176 | #define SHA256_TEST_VECTORS 2 | 182 | #define SHA256_TEST_VECTORS 2 |
177 | 183 | ||
178 | static struct hash_testvec sha256_tv_template[] = { | 184 | static struct hash_testvec sha256_tv_template[] = { |
179 | { | 185 | { |
180 | .plaintext = "abc", | 186 | .plaintext = "abc", |
181 | .psize = 3, | 187 | .psize = 3, |
182 | .digest = { 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, | 188 | .digest = { 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, |
@@ -201,7 +207,7 @@ static struct hash_testvec sha256_tv_template[] = { | |||
201 | #define SHA384_TEST_VECTORS 4 | 207 | #define SHA384_TEST_VECTORS 4 |
202 | 208 | ||
203 | static struct hash_testvec sha384_tv_template[] = { | 209 | static struct hash_testvec sha384_tv_template[] = { |
204 | { | 210 | { |
205 | .plaintext= "abc", | 211 | .plaintext= "abc", |
206 | .psize = 3, | 212 | .psize = 3, |
207 | .digest = { 0xcb, 0x00, 0x75, 0x3f, 0x45, 0xa3, 0x5e, 0x8b, | 213 | .digest = { 0xcb, 0x00, 0x75, 0x3f, 0x45, 0xa3, 0x5e, 0x8b, |
@@ -221,7 +227,7 @@ static struct hash_testvec sha384_tv_template[] = { | |||
221 | 0x5f, 0xe9, 0x5b, 0x1f, 0xe3, 0xc8, 0x45, 0x2b}, | 227 | 0x5f, 0xe9, 0x5b, 0x1f, 0xe3, 0xc8, 0x45, 0x2b}, |
222 | }, { | 228 | }, { |
223 | .plaintext = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" | 229 | .plaintext = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" |
224 | "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", | 230 | "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", |
225 | .psize = 112, | 231 | .psize = 112, |
226 | .digest = { 0x09, 0x33, 0x0c, 0x33, 0xf7, 0x11, 0x47, 0xe8, | 232 | .digest = { 0x09, 0x33, 0x0c, 0x33, 0xf7, 0x11, 0x47, 0xe8, |
227 | 0x3d, 0x19, 0x2f, 0xc7, 0x82, 0xcd, 0x1b, 0x47, | 233 | 0x3d, 0x19, 0x2f, 0xc7, 0x82, 0xcd, 0x1b, 0x47, |
@@ -250,7 +256,7 @@ static struct hash_testvec sha384_tv_template[] = { | |||
250 | #define SHA512_TEST_VECTORS 4 | 256 | #define SHA512_TEST_VECTORS 4 |
251 | 257 | ||
252 | static struct hash_testvec sha512_tv_template[] = { | 258 | static struct hash_testvec sha512_tv_template[] = { |
253 | { | 259 | { |
254 | .plaintext = "abc", | 260 | .plaintext = "abc", |
255 | .psize = 3, | 261 | .psize = 3, |
256 | .digest = { 0xdd, 0xaf, 0x35, 0xa1, 0x93, 0x61, 0x7a, 0xba, | 262 | .digest = { 0xdd, 0xaf, 0x35, 0xa1, 0x93, 0x61, 0x7a, 0xba, |
@@ -303,14 +309,14 @@ static struct hash_testvec sha512_tv_template[] = { | |||
303 | 309 | ||
304 | 310 | ||
305 | /* | 311 | /* |
306 | * WHIRLPOOL test vectors from Whirlpool package | 312 | * WHIRLPOOL test vectors from Whirlpool package |
307 | * by Vincent Rijmen and Paulo S. L. M. Barreto as part of the NESSIE | 313 | * by Vincent Rijmen and Paulo S. L. M. Barreto as part of the NESSIE |
308 | * submission | 314 | * submission |
309 | */ | 315 | */ |
310 | #define WP512_TEST_VECTORS 8 | 316 | #define WP512_TEST_VECTORS 8 |
311 | 317 | ||
312 | static struct hash_testvec wp512_tv_template[] = { | 318 | static struct hash_testvec wp512_tv_template[] = { |
313 | { | 319 | { |
314 | .plaintext = "", | 320 | .plaintext = "", |
315 | .psize = 0, | 321 | .psize = 0, |
316 | .digest = { 0x19, 0xFA, 0x61, 0xD7, 0x55, 0x22, 0xA4, 0x66, | 322 | .digest = { 0x19, 0xFA, 0x61, 0xD7, 0x55, 0x22, 0xA4, 0x66, |
@@ -348,13 +354,13 @@ static struct hash_testvec wp512_tv_template[] = { | |||
348 | }, { | 354 | }, { |
349 | .plaintext = "message digest", | 355 | .plaintext = "message digest", |
350 | .psize = 14, | 356 | .psize = 14, |
351 | .digest = { 0x37, 0x8C, 0x84, 0xA4, 0x12, 0x6E, 0x2D, 0xC6, | 357 | .digest = { 0x37, 0x8C, 0x84, 0xA4, 0x12, 0x6E, 0x2D, 0xC6, |
352 | 0xE5, 0x6D, 0xCC, 0x74, 0x58, 0x37, 0x7A, 0xAC, | 358 | 0xE5, 0x6D, 0xCC, 0x74, 0x58, 0x37, 0x7A, 0xAC, |
353 | 0x83, 0x8D, 0x00, 0x03, 0x22, 0x30, 0xF5, 0x3C, | 359 | 0x83, 0x8D, 0x00, 0x03, 0x22, 0x30, 0xF5, 0x3C, |
354 | 0xE1, 0xF5, 0x70, 0x0C, 0x0F, 0xFB, 0x4D, 0x3B, | 360 | 0xE1, 0xF5, 0x70, 0x0C, 0x0F, 0xFB, 0x4D, 0x3B, |
355 | 0x84, 0x21, 0x55, 0x76, 0x59, 0xEF, 0x55, 0xC1, | 361 | 0x84, 0x21, 0x55, 0x76, 0x59, 0xEF, 0x55, 0xC1, |
356 | 0x06, 0xB4, 0xB5, 0x2A, 0xC5, 0xA4, 0xAA, 0xA6, | 362 | 0x06, 0xB4, 0xB5, 0x2A, 0xC5, 0xA4, 0xAA, 0xA6, |
357 | 0x92, 0xED, 0x92, 0x00, 0x52, 0x83, 0x8F, 0x33, | 363 | 0x92, 0xED, 0x92, 0x00, 0x52, 0x83, 0x8F, 0x33, |
358 | 0x62, 0xE8, 0x6D, 0xBD, 0x37, 0xA8, 0x90, 0x3E }, | 364 | 0x62, 0xE8, 0x6D, 0xBD, 0x37, 0xA8, 0x90, 0x3E }, |
359 | }, { | 365 | }, { |
360 | .plaintext = "abcdefghijklmnopqrstuvwxyz", | 366 | .plaintext = "abcdefghijklmnopqrstuvwxyz", |
@@ -394,7 +400,7 @@ static struct hash_testvec wp512_tv_template[] = { | |||
394 | }, { | 400 | }, { |
395 | .plaintext = "abcdbcdecdefdefgefghfghighijhijk", | 401 | .plaintext = "abcdbcdecdefdefgefghfghighijhijk", |
396 | .psize = 32, | 402 | .psize = 32, |
397 | .digest = { 0x2A, 0x98, 0x7E, 0xA4, 0x0F, 0x91, 0x70, 0x61, | 403 | .digest = { 0x2A, 0x98, 0x7E, 0xA4, 0x0F, 0x91, 0x70, 0x61, |
398 | 0xF5, 0xD6, 0xF0, 0xA0, 0xE4, 0x64, 0x4F, 0x48, | 404 | 0xF5, 0xD6, 0xF0, 0xA0, 0xE4, 0x64, 0x4F, 0x48, |
399 | 0x8A, 0x7A, 0x5A, 0x52, 0xDE, 0xEE, 0x65, 0x62, | 405 | 0x8A, 0x7A, 0x5A, 0x52, 0xDE, 0xEE, 0x65, 0x62, |
400 | 0x07, 0xC5, 0x62, 0xF9, 0x88, 0xE9, 0x5C, 0x69, | 406 | 0x07, 0xC5, 0x62, 0xF9, 0x88, 0xE9, 0x5C, 0x69, |
@@ -408,7 +414,7 @@ static struct hash_testvec wp512_tv_template[] = { | |||
408 | #define WP384_TEST_VECTORS 8 | 414 | #define WP384_TEST_VECTORS 8 |
409 | 415 | ||
410 | static struct hash_testvec wp384_tv_template[] = { | 416 | static struct hash_testvec wp384_tv_template[] = { |
411 | { | 417 | { |
412 | .plaintext = "", | 418 | .plaintext = "", |
413 | .psize = 0, | 419 | .psize = 0, |
414 | .digest = { 0x19, 0xFA, 0x61, 0xD7, 0x55, 0x22, 0xA4, 0x66, | 420 | .digest = { 0x19, 0xFA, 0x61, 0xD7, 0x55, 0x22, 0xA4, 0x66, |
@@ -440,11 +446,11 @@ static struct hash_testvec wp384_tv_template[] = { | |||
440 | }, { | 446 | }, { |
441 | .plaintext = "message digest", | 447 | .plaintext = "message digest", |
442 | .psize = 14, | 448 | .psize = 14, |
443 | .digest = { 0x37, 0x8C, 0x84, 0xA4, 0x12, 0x6E, 0x2D, 0xC6, | 449 | .digest = { 0x37, 0x8C, 0x84, 0xA4, 0x12, 0x6E, 0x2D, 0xC6, |
444 | 0xE5, 0x6D, 0xCC, 0x74, 0x58, 0x37, 0x7A, 0xAC, | 450 | 0xE5, 0x6D, 0xCC, 0x74, 0x58, 0x37, 0x7A, 0xAC, |
445 | 0x83, 0x8D, 0x00, 0x03, 0x22, 0x30, 0xF5, 0x3C, | 451 | 0x83, 0x8D, 0x00, 0x03, 0x22, 0x30, 0xF5, 0x3C, |
446 | 0xE1, 0xF5, 0x70, 0x0C, 0x0F, 0xFB, 0x4D, 0x3B, | 452 | 0xE1, 0xF5, 0x70, 0x0C, 0x0F, 0xFB, 0x4D, 0x3B, |
447 | 0x84, 0x21, 0x55, 0x76, 0x59, 0xEF, 0x55, 0xC1, | 453 | 0x84, 0x21, 0x55, 0x76, 0x59, 0xEF, 0x55, 0xC1, |
448 | 0x06, 0xB4, 0xB5, 0x2A, 0xC5, 0xA4, 0xAA, 0xA6 }, | 454 | 0x06, 0xB4, 0xB5, 0x2A, 0xC5, 0xA4, 0xAA, 0xA6 }, |
449 | }, { | 455 | }, { |
450 | .plaintext = "abcdefghijklmnopqrstuvwxyz", | 456 | .plaintext = "abcdefghijklmnopqrstuvwxyz", |
@@ -478,7 +484,7 @@ static struct hash_testvec wp384_tv_template[] = { | |||
478 | }, { | 484 | }, { |
479 | .plaintext = "abcdbcdecdefdefgefghfghighijhijk", | 485 | .plaintext = "abcdbcdecdefdefgefghfghighijhijk", |
480 | .psize = 32, | 486 | .psize = 32, |
481 | .digest = { 0x2A, 0x98, 0x7E, 0xA4, 0x0F, 0x91, 0x70, 0x61, | 487 | .digest = { 0x2A, 0x98, 0x7E, 0xA4, 0x0F, 0x91, 0x70, 0x61, |
482 | 0xF5, 0xD6, 0xF0, 0xA0, 0xE4, 0x64, 0x4F, 0x48, | 488 | 0xF5, 0xD6, 0xF0, 0xA0, 0xE4, 0x64, 0x4F, 0x48, |
483 | 0x8A, 0x7A, 0x5A, 0x52, 0xDE, 0xEE, 0x65, 0x62, | 489 | 0x8A, 0x7A, 0x5A, 0x52, 0xDE, 0xEE, 0x65, 0x62, |
484 | 0x07, 0xC5, 0x62, 0xF9, 0x88, 0xE9, 0x5C, 0x69, | 490 | 0x07, 0xC5, 0x62, 0xF9, 0x88, 0xE9, 0x5C, 0x69, |
@@ -490,7 +496,7 @@ static struct hash_testvec wp384_tv_template[] = { | |||
490 | #define WP256_TEST_VECTORS 8 | 496 | #define WP256_TEST_VECTORS 8 |
491 | 497 | ||
492 | static struct hash_testvec wp256_tv_template[] = { | 498 | static struct hash_testvec wp256_tv_template[] = { |
493 | { | 499 | { |
494 | .plaintext = "", | 500 | .plaintext = "", |
495 | .psize = 0, | 501 | .psize = 0, |
496 | .digest = { 0x19, 0xFA, 0x61, 0xD7, 0x55, 0x22, 0xA4, 0x66, | 502 | .digest = { 0x19, 0xFA, 0x61, 0xD7, 0x55, 0x22, 0xA4, 0x66, |
@@ -516,9 +522,9 @@ static struct hash_testvec wp256_tv_template[] = { | |||
516 | }, { | 522 | }, { |
517 | .plaintext = "message digest", | 523 | .plaintext = "message digest", |
518 | .psize = 14, | 524 | .psize = 14, |
519 | .digest = { 0x37, 0x8C, 0x84, 0xA4, 0x12, 0x6E, 0x2D, 0xC6, | 525 | .digest = { 0x37, 0x8C, 0x84, 0xA4, 0x12, 0x6E, 0x2D, 0xC6, |
520 | 0xE5, 0x6D, 0xCC, 0x74, 0x58, 0x37, 0x7A, 0xAC, | 526 | 0xE5, 0x6D, 0xCC, 0x74, 0x58, 0x37, 0x7A, 0xAC, |
521 | 0x83, 0x8D, 0x00, 0x03, 0x22, 0x30, 0xF5, 0x3C, | 527 | 0x83, 0x8D, 0x00, 0x03, 0x22, 0x30, 0xF5, 0x3C, |
522 | 0xE1, 0xF5, 0x70, 0x0C, 0x0F, 0xFB, 0x4D, 0x3B }, | 528 | 0xE1, 0xF5, 0x70, 0x0C, 0x0F, 0xFB, 0x4D, 0x3B }, |
523 | }, { | 529 | }, { |
524 | .plaintext = "abcdefghijklmnopqrstuvwxyz", | 530 | .plaintext = "abcdefghijklmnopqrstuvwxyz", |
@@ -546,7 +552,7 @@ static struct hash_testvec wp256_tv_template[] = { | |||
546 | }, { | 552 | }, { |
547 | .plaintext = "abcdbcdecdefdefgefghfghighijhijk", | 553 | .plaintext = "abcdbcdecdefdefgefghfghighijhijk", |
548 | .psize = 32, | 554 | .psize = 32, |
549 | .digest = { 0x2A, 0x98, 0x7E, 0xA4, 0x0F, 0x91, 0x70, 0x61, | 555 | .digest = { 0x2A, 0x98, 0x7E, 0xA4, 0x0F, 0x91, 0x70, 0x61, |
550 | 0xF5, 0xD6, 0xF0, 0xA0, 0xE4, 0x64, 0x4F, 0x48, | 556 | 0xF5, 0xD6, 0xF0, 0xA0, 0xE4, 0x64, 0x4F, 0x48, |
551 | 0x8A, 0x7A, 0x5A, 0x52, 0xDE, 0xEE, 0x65, 0x62, | 557 | 0x8A, 0x7A, 0x5A, 0x52, 0xDE, 0xEE, 0x65, 0x62, |
552 | 0x07, 0xC5, 0x62, 0xF9, 0x88, 0xE9, 0x5C, 0x69 }, | 558 | 0x07, 0xC5, 0x62, 0xF9, 0x88, 0xE9, 0x5C, 0x69 }, |
@@ -554,7 +560,7 @@ static struct hash_testvec wp256_tv_template[] = { | |||
554 | }; | 560 | }; |
555 | 561 | ||
556 | /* | 562 | /* |
557 | * TIGER test vectors from Tiger website | 563 | * TIGER test vectors from Tiger website |
558 | */ | 564 | */ |
559 | #define TGR192_TEST_VECTORS 6 | 565 | #define TGR192_TEST_VECTORS 6 |
560 | 566 | ||
@@ -693,7 +699,7 @@ static struct hash_testvec tgr128_tv_template[] = { | |||
693 | #define HMAC_MD5_TEST_VECTORS 7 | 699 | #define HMAC_MD5_TEST_VECTORS 7 |
694 | 700 | ||
695 | static struct hmac_testvec hmac_md5_tv_template[] = | 701 | static struct hmac_testvec hmac_md5_tv_template[] = |
696 | { | 702 | { |
697 | { | 703 | { |
698 | .key = { [0 ... 15] = 0x0b }, | 704 | .key = { [0 ... 15] = 0x0b }, |
699 | .ksize = 16, | 705 | .ksize = 16, |
@@ -756,7 +762,7 @@ static struct hmac_testvec hmac_md5_tv_template[] = | |||
756 | */ | 762 | */ |
757 | #define HMAC_SHA1_TEST_VECTORS 7 | 763 | #define HMAC_SHA1_TEST_VECTORS 7 |
758 | 764 | ||
759 | static struct hmac_testvec hmac_sha1_tv_template[] = { | 765 | static struct hmac_testvec hmac_sha1_tv_template[] = { |
760 | { | 766 | { |
761 | .key = { [0 ... 19] = 0x0b }, | 767 | .key = { [0 ... 19] = 0x0b }, |
762 | .ksize = 20, | 768 | .ksize = 20, |
@@ -766,11 +772,11 @@ static struct hmac_testvec hmac_sha1_tv_template[] = { | |||
766 | 0xe2, 0x8b, 0xc0, 0xb6, 0xfb, 0x37, 0x8c, 0x8e, 0xf1, | 772 | 0xe2, 0x8b, 0xc0, 0xb6, 0xfb, 0x37, 0x8c, 0x8e, 0xf1, |
767 | 0x46, 0xbe }, | 773 | 0x46, 0xbe }, |
768 | }, { | 774 | }, { |
769 | .key = { 'J', 'e', 'f', 'e' }, | 775 | .key = { 'J', 'e', 'f', 'e' }, |
770 | .ksize = 4, | 776 | .ksize = 4, |
771 | .plaintext = "what do ya want for nothing?", | 777 | .plaintext = "what do ya want for nothing?", |
772 | .psize = 28, | 778 | .psize = 28, |
773 | .digest = { 0xef, 0xfc, 0xdf, 0x6a, 0xe5, 0xeb, 0x2f, 0xa2, 0xd2, 0x74, | 779 | .digest = { 0xef, 0xfc, 0xdf, 0x6a, 0xe5, 0xeb, 0x2f, 0xa2, 0xd2, 0x74, |
774 | 0x16, 0xd5, 0xf1, 0x84, 0xdf, 0x9c, 0x25, 0x9a, 0x7c, 0x79 }, | 780 | 0x16, 0xd5, 0xf1, 0x84, 0xdf, 0x9c, 0x25, 0x9a, 0x7c, 0x79 }, |
775 | .np = 2, | 781 | .np = 2, |
776 | .tap = { 14, 14 } | 782 | .tap = { 14, 14 } |
@@ -779,30 +785,30 @@ static struct hmac_testvec hmac_sha1_tv_template[] = { | |||
779 | .ksize = 20, | 785 | .ksize = 20, |
780 | .plaintext = { [0 ... 49] = 0xdd }, | 786 | .plaintext = { [0 ... 49] = 0xdd }, |
781 | .psize = 50, | 787 | .psize = 50, |
782 | .digest = { 0x12, 0x5d, 0x73, 0x42, 0xb9, 0xac, 0x11, 0xcd, 0x91, 0xa3, | 788 | .digest = { 0x12, 0x5d, 0x73, 0x42, 0xb9, 0xac, 0x11, 0xcd, 0x91, 0xa3, |
783 | 0x9a, 0xf4, 0x8a, 0xa1, 0x7b, 0x4f, 0x63, 0xf1, 0x75, 0xd3 }, | 789 | 0x9a, 0xf4, 0x8a, 0xa1, 0x7b, 0x4f, 0x63, 0xf1, 0x75, 0xd3 }, |
784 | }, { | 790 | }, { |
785 | .key = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, | 791 | .key = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
786 | 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, | 792 | 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, |
787 | 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19 }, | 793 | 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19 }, |
788 | .ksize = 25, | 794 | .ksize = 25, |
789 | .plaintext = { [0 ... 49] = 0xcd }, | 795 | .plaintext = { [0 ... 49] = 0xcd }, |
790 | .psize = 50, | 796 | .psize = 50, |
791 | .digest = { 0x4c, 0x90, 0x07, 0xf4, 0x02, 0x62, 0x50, 0xc6, 0xbc, 0x84, | 797 | .digest = { 0x4c, 0x90, 0x07, 0xf4, 0x02, 0x62, 0x50, 0xc6, 0xbc, 0x84, |
792 | 0x14, 0xf9, 0xbf, 0x50, 0xc8, 0x6c, 0x2d, 0x72, 0x35, 0xda }, | 798 | 0x14, 0xf9, 0xbf, 0x50, 0xc8, 0x6c, 0x2d, 0x72, 0x35, 0xda }, |
793 | }, { | 799 | }, { |
794 | .key = { [0 ... 19] = 0x0c }, | 800 | .key = { [0 ... 19] = 0x0c }, |
795 | .ksize = 20, | 801 | .ksize = 20, |
796 | .plaintext = "Test With Truncation", | 802 | .plaintext = "Test With Truncation", |
797 | .psize = 20, | 803 | .psize = 20, |
798 | .digest = { 0x4c, 0x1a, 0x03, 0x42, 0x4b, 0x55, 0xe0, 0x7f, 0xe7, 0xf2, | 804 | .digest = { 0x4c, 0x1a, 0x03, 0x42, 0x4b, 0x55, 0xe0, 0x7f, 0xe7, 0xf2, |
799 | 0x7b, 0xe1, 0xd5, 0x8b, 0xb9, 0x32, 0x4a, 0x9a, 0x5a, 0x04 }, | 805 | 0x7b, 0xe1, 0xd5, 0x8b, 0xb9, 0x32, 0x4a, 0x9a, 0x5a, 0x04 }, |
800 | }, { | 806 | }, { |
801 | .key = { [0 ... 79] = 0xaa }, | 807 | .key = { [0 ... 79] = 0xaa }, |
802 | .ksize = 80, | 808 | .ksize = 80, |
803 | .plaintext = "Test Using Larger Than Block-Size Key - Hash Key First", | 809 | .plaintext = "Test Using Larger Than Block-Size Key - Hash Key First", |
804 | .psize = 54, | 810 | .psize = 54, |
805 | .digest = { 0xaa, 0x4a, 0xe5, 0xe1, 0x52, 0x72, 0xd0, 0x0e, 0x95, 0x70, | 811 | .digest = { 0xaa, 0x4a, 0xe5, 0xe1, 0x52, 0x72, 0xd0, 0x0e, 0x95, 0x70, |
806 | 0x56, 0x37, 0xce, 0x8a, 0x3b, 0x55, 0xed, 0x40, 0x21, 0x12 }, | 812 | 0x56, 0x37, 0xce, 0x8a, 0x3b, 0x55, 0xed, 0x40, 0x21, 0x12 }, |
807 | }, { | 813 | }, { |
808 | .key = { [0 ... 79] = 0xaa }, | 814 | .key = { [0 ... 79] = 0xaa }, |
@@ -810,7 +816,7 @@ static struct hmac_testvec hmac_sha1_tv_template[] = { | |||
810 | .plaintext = "Test Using Larger Than Block-Size Key and Larger Than One " | 816 | .plaintext = "Test Using Larger Than Block-Size Key and Larger Than One " |
811 | "Block-Size Data", | 817 | "Block-Size Data", |
812 | .psize = 73, | 818 | .psize = 73, |
813 | .digest = { 0xe8, 0xe9, 0x9d, 0x0f, 0x45, 0x23, 0x7d, 0x78, 0x6d, 0x6b, | 819 | .digest = { 0xe8, 0xe9, 0x9d, 0x0f, 0x45, 0x23, 0x7d, 0x78, 0x6d, 0x6b, |
814 | 0xba, 0xa7, 0x96, 0x5c, 0x78, 0x08, 0xbb, 0xff, 0x1a, 0x91 }, | 820 | 0xba, 0xa7, 0x96, 0x5c, 0x78, 0x08, 0xbb, 0xff, 0x1a, 0x91 }, |
815 | }, | 821 | }, |
816 | }; | 822 | }; |
@@ -1011,7 +1017,7 @@ static struct cipher_testvec des_enc_tv_template[] = { | |||
1011 | 0xf7, 0x9c, 0x89, 0x2a, 0x33, 0x8f, 0x4a, 0x8b }, | 1017 | 0xf7, 0x9c, 0x89, 0x2a, 0x33, 0x8f, 0x4a, 0x8b }, |
1012 | .rlen = 32, | 1018 | .rlen = 32, |
1013 | .np = 3, | 1019 | .np = 3, |
1014 | .tap = { 14, 10, 8 } | 1020 | .tap = { 14, 10, 8 } |
1015 | }, { | 1021 | }, { |
1016 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }, | 1022 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }, |
1017 | .klen = 8, | 1023 | .klen = 8, |
@@ -1024,7 +1030,7 @@ static struct cipher_testvec des_enc_tv_template[] = { | |||
1024 | 0xb4, 0x99, 0x26, 0xf7, 0x1f, 0xe1, 0xd4, 0x90 }, | 1030 | 0xb4, 0x99, 0x26, 0xf7, 0x1f, 0xe1, 0xd4, 0x90 }, |
1025 | .rlen = 24, | 1031 | .rlen = 24, |
1026 | .np = 4, | 1032 | .np = 4, |
1027 | .tap = { 2, 1, 3, 18 } | 1033 | .tap = { 2, 1, 3, 18 } |
1028 | }, { | 1034 | }, { |
1029 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }, | 1035 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }, |
1030 | .klen = 8, | 1036 | .klen = 8, |
@@ -1035,7 +1041,7 @@ static struct cipher_testvec des_enc_tv_template[] = { | |||
1035 | 0xf7, 0x9c, 0x89, 0x2a, 0x33, 0x8f, 0x4a, 0x8b }, | 1041 | 0xf7, 0x9c, 0x89, 0x2a, 0x33, 0x8f, 0x4a, 0x8b }, |
1036 | .rlen = 16, | 1042 | .rlen = 16, |
1037 | .np = 5, | 1043 | .np = 5, |
1038 | .tap = { 2, 2, 2, 2, 8 } | 1044 | .tap = { 2, 2, 2, 2, 8 } |
1039 | }, { | 1045 | }, { |
1040 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }, | 1046 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }, |
1041 | .klen = 8, | 1047 | .klen = 8, |
@@ -1044,7 +1050,7 @@ static struct cipher_testvec des_enc_tv_template[] = { | |||
1044 | .result = { 0xc9, 0x57, 0x44, 0x25, 0x6a, 0x5e, 0xd3, 0x1d }, | 1050 | .result = { 0xc9, 0x57, 0x44, 0x25, 0x6a, 0x5e, 0xd3, 0x1d }, |
1045 | .rlen = 8, | 1051 | .rlen = 8, |
1046 | .np = 8, | 1052 | .np = 8, |
1047 | .tap = { 1, 1, 1, 1, 1, 1, 1, 1 } | 1053 | .tap = { 1, 1, 1, 1, 1, 1, 1, 1 } |
1048 | }, | 1054 | }, |
1049 | }; | 1055 | }; |
1050 | 1056 | ||
@@ -1057,7 +1063,7 @@ static struct cipher_testvec des_dec_tv_template[] = { | |||
1057 | .result = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xe7 }, | 1063 | .result = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xe7 }, |
1058 | .rlen = 8, | 1064 | .rlen = 8, |
1059 | }, { /* Sbox test from NBS */ | 1065 | }, { /* Sbox test from NBS */ |
1060 | .key = { 0x7c, 0xa1, 0x10, 0x45, 0x4a, 0x1a, 0x6e, 0x57 }, | 1066 | .key = { 0x7c, 0xa1, 0x10, 0x45, 0x4a, 0x1a, 0x6e, 0x57 }, |
1061 | .klen = 8, | 1067 | .klen = 8, |
1062 | .input = { 0x69, 0x0f, 0x5b, 0x0d, 0x9a, 0x26, 0x93, 0x9b }, | 1068 | .input = { 0x69, 0x0f, 0x5b, 0x0d, 0x9a, 0x26, 0x93, 0x9b }, |
1063 | .ilen = 8, | 1069 | .ilen = 8, |
@@ -1092,19 +1098,19 @@ static struct cipher_testvec des_cbc_enc_tv_template[] = { | |||
1092 | { /* From OpenSSL */ | 1098 | { /* From OpenSSL */ |
1093 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}, | 1099 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}, |
1094 | .klen = 8, | 1100 | .klen = 8, |
1095 | .iv = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10}, | 1101 | .iv = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10}, |
1096 | .input = { 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x20, | 1102 | .input = { 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x20, |
1097 | 0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74, | 1103 | 0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74, |
1098 | 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20 }, | 1104 | 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20 }, |
1099 | .ilen = 24, | 1105 | .ilen = 24, |
1100 | .result = { 0xcc, 0xd1, 0x73, 0xff, 0xab, 0x20, 0x39, 0xf4, | 1106 | .result = { 0xcc, 0xd1, 0x73, 0xff, 0xab, 0x20, 0x39, 0xf4, |
1101 | 0xac, 0xd8, 0xae, 0xfd, 0xdf, 0xd8, 0xa1, 0xeb, | 1107 | 0xac, 0xd8, 0xae, 0xfd, 0xdf, 0xd8, 0xa1, 0xeb, |
1102 | 0x46, 0x8e, 0x91, 0x15, 0x78, 0x88, 0xba, 0x68 }, | 1108 | 0x46, 0x8e, 0x91, 0x15, 0x78, 0x88, 0xba, 0x68 }, |
1103 | .rlen = 24, | 1109 | .rlen = 24, |
1104 | }, { /* FIPS Pub 81 */ | 1110 | }, { /* FIPS Pub 81 */ |
1105 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }, | 1111 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }, |
1106 | .klen = 8, | 1112 | .klen = 8, |
1107 | .iv = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef }, | 1113 | .iv = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef }, |
1108 | .input = { 0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74 }, | 1114 | .input = { 0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74 }, |
1109 | .ilen = 8, | 1115 | .ilen = 8, |
1110 | .result = { 0xe5, 0xc7, 0xcd, 0xde, 0x87, 0x2b, 0xf2, 0x7c }, | 1116 | .result = { 0xe5, 0xc7, 0xcd, 0xde, 0x87, 0x2b, 0xf2, 0x7c }, |
@@ -1117,7 +1123,7 @@ static struct cipher_testvec des_cbc_enc_tv_template[] = { | |||
1117 | .ilen = 8, | 1123 | .ilen = 8, |
1118 | .result = { 0x43, 0xe9, 0x34, 0x00, 0x8c, 0x38, 0x9c, 0x0f }, | 1124 | .result = { 0x43, 0xe9, 0x34, 0x00, 0x8c, 0x38, 0x9c, 0x0f }, |
1119 | .rlen = 8, | 1125 | .rlen = 8, |
1120 | }, { | 1126 | }, { |
1121 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }, | 1127 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }, |
1122 | .klen = 8, | 1128 | .klen = 8, |
1123 | .iv = { 0x43, 0xe9, 0x34, 0x00, 0x8c, 0x38, 0x9c, 0x0f }, | 1129 | .iv = { 0x43, 0xe9, 0x34, 0x00, 0x8c, 0x38, 0x9c, 0x0f }, |
@@ -1125,18 +1131,18 @@ static struct cipher_testvec des_cbc_enc_tv_template[] = { | |||
1125 | .ilen = 8, | 1131 | .ilen = 8, |
1126 | .result = { 0x68, 0x37, 0x88, 0x49, 0x9a, 0x7c, 0x05, 0xf6 }, | 1132 | .result = { 0x68, 0x37, 0x88, 0x49, 0x9a, 0x7c, 0x05, 0xf6 }, |
1127 | .rlen = 8, | 1133 | .rlen = 8, |
1128 | }, { /* Copy of openssl vector for chunk testing */ | 1134 | }, { /* Copy of openssl vector for chunk testing */ |
1129 | /* From OpenSSL */ | 1135 | /* From OpenSSL */ |
1130 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}, | 1136 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}, |
1131 | .klen = 8, | 1137 | .klen = 8, |
1132 | .iv = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10}, | 1138 | .iv = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10}, |
1133 | .input = { 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x20, | 1139 | .input = { 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x20, |
1134 | 0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74, | 1140 | 0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74, |
1135 | 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20 }, | 1141 | 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20 }, |
1136 | .ilen = 24, | 1142 | .ilen = 24, |
1137 | .result = { 0xcc, 0xd1, 0x73, 0xff, 0xab, 0x20, 0x39, 0xf4, | 1143 | .result = { 0xcc, 0xd1, 0x73, 0xff, 0xab, 0x20, 0x39, 0xf4, |
1138 | 0xac, 0xd8, 0xae, 0xfd, 0xdf, 0xd8, 0xa1, 0xeb, | 1144 | 0xac, 0xd8, 0xae, 0xfd, 0xdf, 0xd8, 0xa1, 0xeb, |
1139 | 0x46, 0x8e, 0x91, 0x15, 0x78, 0x88, 0xba, 0x68 }, | 1145 | 0x46, 0x8e, 0x91, 0x15, 0x78, 0x88, 0xba, 0x68 }, |
1140 | .rlen = 24, | 1146 | .rlen = 24, |
1141 | .np = 2, | 1147 | .np = 2, |
1142 | .tap = { 13, 11 } | 1148 | .tap = { 13, 11 } |
@@ -1155,24 +1161,24 @@ static struct cipher_testvec des_cbc_dec_tv_template[] = { | |||
1155 | }, { | 1161 | }, { |
1156 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }, | 1162 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }, |
1157 | .klen = 8, | 1163 | .klen = 8, |
1158 | .iv = { 0xe5, 0xc7, 0xcd, 0xde, 0x87, 0x2b, 0xf2, 0x7c }, | 1164 | .iv = { 0xe5, 0xc7, 0xcd, 0xde, 0x87, 0x2b, 0xf2, 0x7c }, |
1159 | .input = { 0x43, 0xe9, 0x34, 0x00, 0x8c, 0x38, 0x9c, 0x0f }, | 1165 | .input = { 0x43, 0xe9, 0x34, 0x00, 0x8c, 0x38, 0x9c, 0x0f }, |
1160 | .ilen = 8, | 1166 | .ilen = 8, |
1161 | .result = { 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20 }, | 1167 | .result = { 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20 }, |
1162 | .rlen = 8, | 1168 | .rlen = 8, |
1163 | }, { | 1169 | }, { |
1164 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }, | 1170 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }, |
1165 | .klen = 8, | 1171 | .klen = 8, |
1166 | .iv = { 0x43, 0xe9, 0x34, 0x00, 0x8c, 0x38, 0x9c, 0x0f }, | 1172 | .iv = { 0x43, 0xe9, 0x34, 0x00, 0x8c, 0x38, 0x9c, 0x0f }, |
1167 | .input = { 0x68, 0x37, 0x88, 0x49, 0x9a, 0x7c, 0x05, 0xf6 }, | 1173 | .input = { 0x68, 0x37, 0x88, 0x49, 0x9a, 0x7c, 0x05, 0xf6 }, |
1168 | .ilen = 8, | 1174 | .ilen = 8, |
1169 | .result = { 0x66, 0x6f, 0x72, 0x20, 0x61, 0x6c, 0x6c, 0x20 }, | 1175 | .result = { 0x66, 0x6f, 0x72, 0x20, 0x61, 0x6c, 0x6c, 0x20 }, |
1170 | .rlen = 8, | 1176 | .rlen = 8, |
1171 | }, { /* Copy of above, for chunk testing */ | 1177 | }, { /* Copy of above, for chunk testing */ |
1172 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }, | 1178 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }, |
1173 | .klen = 8, | 1179 | .klen = 8, |
1174 | .iv = { 0x43, 0xe9, 0x34, 0x00, 0x8c, 0x38, 0x9c, 0x0f }, | 1180 | .iv = { 0x43, 0xe9, 0x34, 0x00, 0x8c, 0x38, 0x9c, 0x0f }, |
1175 | .input = { 0x68, 0x37, 0x88, 0x49, 0x9a, 0x7c, 0x05, 0xf6 }, | 1181 | .input = { 0x68, 0x37, 0x88, 0x49, 0x9a, 0x7c, 0x05, 0xf6 }, |
1176 | .ilen = 8, | 1182 | .ilen = 8, |
1177 | .result = { 0x66, 0x6f, 0x72, 0x20, 0x61, 0x6c, 0x6c, 0x20 }, | 1183 | .result = { 0x66, 0x6f, 0x72, 0x20, 0x61, 0x6c, 0x6c, 0x20 }, |
1178 | .rlen = 8, | 1184 | .rlen = 8, |
@@ -1276,7 +1282,7 @@ static struct cipher_testvec bf_enc_tv_template[] = { | |||
1276 | .ilen = 8, | 1282 | .ilen = 8, |
1277 | .result = { 0xe8, 0x7a, 0x24, 0x4e, 0x2c, 0xc8, 0x5e, 0x82 }, | 1283 | .result = { 0xe8, 0x7a, 0x24, 0x4e, 0x2c, 0xc8, 0x5e, 0x82 }, |
1278 | .rlen = 8, | 1284 | .rlen = 8, |
1279 | }, { /* Vary the keylength... */ | 1285 | }, { /* Vary the keylength... */ |
1280 | .key = { 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87, | 1286 | .key = { 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87, |
1281 | 0x78, 0x69, 0x5a, 0x4b, 0x3c, 0x2d, 0x1e, 0x0f }, | 1287 | 0x78, 0x69, 0x5a, 0x4b, 0x3c, 0x2d, 0x1e, 0x0f }, |
1282 | .klen = 16, | 1288 | .klen = 16, |
@@ -1297,9 +1303,9 @@ static struct cipher_testvec bf_enc_tv_template[] = { | |||
1297 | .key = { 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87, | 1303 | .key = { 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87, |
1298 | 0x78, 0x69, 0x5a, 0x4b, 0x3c, 0x2d, 0x1e, 0x0f, | 1304 | 0x78, 0x69, 0x5a, 0x4b, 0x3c, 0x2d, 0x1e, 0x0f, |
1299 | 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | 1305 | 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, |
1300 | 0x04, 0x68, 0x91, 0x04, 0xc2, 0xfd, 0x3b, 0x2f, | 1306 | 0x04, 0x68, 0x91, 0x04, 0xc2, 0xfd, 0x3b, 0x2f, |
1301 | 0x58, 0x40, 0x23, 0x64, 0x1a, 0xba, 0x61, 0x76, | 1307 | 0x58, 0x40, 0x23, 0x64, 0x1a, 0xba, 0x61, 0x76, |
1302 | 0x1f, 0x1f, 0x1f, 0x1f, 0x0e, 0x0e, 0x0e, 0x0e, | 1308 | 0x1f, 0x1f, 0x1f, 0x1f, 0x0e, 0x0e, 0x0e, 0x0e, |
1303 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, | 1309 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, |
1304 | .klen = 56, | 1310 | .klen = 56, |
1305 | .input = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 }, | 1311 | .input = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 }, |
@@ -1331,7 +1337,7 @@ static struct cipher_testvec bf_dec_tv_template[] = { | |||
1331 | .ilen = 8, | 1337 | .ilen = 8, |
1332 | .result = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 }, | 1338 | .result = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 }, |
1333 | .rlen = 8, | 1339 | .rlen = 8, |
1334 | }, { /* Vary the keylength... */ | 1340 | }, { /* Vary the keylength... */ |
1335 | .key = { 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87, | 1341 | .key = { 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87, |
1336 | 0x78, 0x69, 0x5a, 0x4b, 0x3c, 0x2d, 0x1e, 0x0f }, | 1342 | 0x78, 0x69, 0x5a, 0x4b, 0x3c, 0x2d, 0x1e, 0x0f }, |
1337 | .klen = 16, | 1343 | .klen = 16, |
@@ -1352,9 +1358,9 @@ static struct cipher_testvec bf_dec_tv_template[] = { | |||
1352 | .key = { 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87, | 1358 | .key = { 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87, |
1353 | 0x78, 0x69, 0x5a, 0x4b, 0x3c, 0x2d, 0x1e, 0x0f, | 1359 | 0x78, 0x69, 0x5a, 0x4b, 0x3c, 0x2d, 0x1e, 0x0f, |
1354 | 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | 1360 | 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, |
1355 | 0x04, 0x68, 0x91, 0x04, 0xc2, 0xfd, 0x3b, 0x2f, | 1361 | 0x04, 0x68, 0x91, 0x04, 0xc2, 0xfd, 0x3b, 0x2f, |
1356 | 0x58, 0x40, 0x23, 0x64, 0x1a, 0xba, 0x61, 0x76, | 1362 | 0x58, 0x40, 0x23, 0x64, 0x1a, 0xba, 0x61, 0x76, |
1357 | 0x1f, 0x1f, 0x1f, 0x1f, 0x0e, 0x0e, 0x0e, 0x0e, | 1363 | 0x1f, 0x1f, 0x1f, 0x1f, 0x0e, 0x0e, 0x0e, 0x0e, |
1358 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, | 1364 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, |
1359 | .klen = 56, | 1365 | .klen = 56, |
1360 | .input = { 0xc0, 0x45, 0x04, 0x01, 0x2e, 0x4e, 0x1f, 0x53 }, | 1366 | .input = { 0xc0, 0x45, 0x04, 0x01, 0x2e, 0x4e, 0x1f, 0x53 }, |
@@ -1369,7 +1375,7 @@ static struct cipher_testvec bf_cbc_enc_tv_template[] = { | |||
1369 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, | 1375 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, |
1370 | 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87 }, | 1376 | 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87 }, |
1371 | .klen = 16, | 1377 | .klen = 16, |
1372 | .iv = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 }, | 1378 | .iv = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 }, |
1373 | .input = { 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x20, | 1379 | .input = { 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x20, |
1374 | 0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74, | 1380 | 0x4e, 0x6f, 0x77, 0x20, 0x69, 0x73, 0x20, 0x74, |
1375 | 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20, | 1381 | 0x68, 0x65, 0x20, 0x74, 0x69, 0x6d, 0x65, 0x20, |
@@ -1388,7 +1394,7 @@ static struct cipher_testvec bf_cbc_dec_tv_template[] = { | |||
1388 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, | 1394 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, |
1389 | 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87 }, | 1395 | 0xf0, 0xe1, 0xd2, 0xc3, 0xb4, 0xa5, 0x96, 0x87 }, |
1390 | .klen = 16, | 1396 | .klen = 16, |
1391 | .iv = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 }, | 1397 | .iv = { 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 }, |
1392 | .input = { 0x6b, 0x77, 0xb4, 0xd6, 0x30, 0x06, 0xde, 0xe6, | 1398 | .input = { 0x6b, 0x77, 0xb4, 0xd6, 0x30, 0x06, 0xde, 0xe6, |
1393 | 0x05, 0xb1, 0x56, 0xe2, 0x74, 0x03, 0x97, 0x93, | 1399 | 0x05, 0xb1, 0x56, 0xe2, 0x74, 0x03, 0x97, 0x93, |
1394 | 0x58, 0xde, 0xb9, 0xe7, 0x15, 0x46, 0x16, 0xd9, | 1400 | 0x58, 0xde, 0xb9, 0xe7, 0x15, 0x46, 0x16, 0xd9, |
@@ -1490,7 +1496,7 @@ static struct cipher_testvec tf_cbc_enc_tv_template[] = { | |||
1490 | .key = { [0 ... 15] = 0x00 }, | 1496 | .key = { [0 ... 15] = 0x00 }, |
1491 | .klen = 16, | 1497 | .klen = 16, |
1492 | .iv = { 0x9f, 0x58, 0x9f, 0x5c, 0xf6, 0x12, 0x2c, 0x32, | 1498 | .iv = { 0x9f, 0x58, 0x9f, 0x5c, 0xf6, 0x12, 0x2c, 0x32, |
1493 | 0xb6, 0xbf, 0xec, 0x2f, 0x2a, 0xe8, 0xc3, 0x5a }, | 1499 | 0xb6, 0xbf, 0xec, 0x2f, 0x2a, 0xe8, 0xc3, 0x5a }, |
1494 | .input = { [0 ... 15] = 0x00 }, | 1500 | .input = { [0 ... 15] = 0x00 }, |
1495 | .ilen = 16, | 1501 | .ilen = 16, |
1496 | .result = { 0xd4, 0x91, 0xdb, 0x16, 0xe7, 0xb1, 0xc3, 0x9e, | 1502 | .result = { 0xd4, 0x91, 0xdb, 0x16, 0xe7, 0xb1, 0xc3, 0x9e, |
@@ -1528,7 +1534,7 @@ static struct cipher_testvec tf_cbc_dec_tv_template[] = { | |||
1528 | .klen = 16, | 1534 | .klen = 16, |
1529 | .iv = { [0 ... 15] = 0x00 }, | 1535 | .iv = { [0 ... 15] = 0x00 }, |
1530 | .input = { 0x9f, 0x58, 0x9f, 0x5c, 0xf6, 0x12, 0x2c, 0x32, | 1536 | .input = { 0x9f, 0x58, 0x9f, 0x5c, 0xf6, 0x12, 0x2c, 0x32, |
1531 | 0xb6, 0xbf, 0xec, 0x2f, 0x2a, 0xe8, 0xc3, 0x5a }, | 1537 | 0xb6, 0xbf, 0xec, 0x2f, 0x2a, 0xe8, 0xc3, 0x5a }, |
1532 | .ilen = 16, | 1538 | .ilen = 16, |
1533 | .result = { [0 ... 15] = 0x00 }, | 1539 | .result = { [0 ... 15] = 0x00 }, |
1534 | .rlen = 16, | 1540 | .rlen = 16, |
@@ -1578,8 +1584,7 @@ static struct cipher_testvec tf_cbc_dec_tv_template[] = { | |||
1578 | #define TNEPRES_ENC_TEST_VECTORS 4 | 1584 | #define TNEPRES_ENC_TEST_VECTORS 4 |
1579 | #define TNEPRES_DEC_TEST_VECTORS 4 | 1585 | #define TNEPRES_DEC_TEST_VECTORS 4 |
1580 | 1586 | ||
1581 | static struct cipher_testvec serpent_enc_tv_template[] = | 1587 | static struct cipher_testvec serpent_enc_tv_template[] = { |
1582 | { | ||
1583 | { | 1588 | { |
1584 | .input = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 1589 | .input = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
1585 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, | 1590 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, |
@@ -1620,8 +1625,7 @@ static struct cipher_testvec serpent_enc_tv_template[] = | |||
1620 | }, | 1625 | }, |
1621 | }; | 1626 | }; |
1622 | 1627 | ||
1623 | static struct cipher_testvec tnepres_enc_tv_template[] = | 1628 | static struct cipher_testvec tnepres_enc_tv_template[] = { |
1624 | { | ||
1625 | { /* KeySize=128, PT=0, I=1 */ | 1629 | { /* KeySize=128, PT=0, I=1 */ |
1626 | .input = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1630 | .input = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1627 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | 1631 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
@@ -1629,7 +1633,7 @@ static struct cipher_testvec tnepres_enc_tv_template[] = | |||
1629 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | 1633 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
1630 | .klen = 16, | 1634 | .klen = 16, |
1631 | .ilen = 16, | 1635 | .ilen = 16, |
1632 | .result = { 0x49, 0xaf, 0xbf, 0xad, 0x9d, 0x5a, 0x34, 0x05, | 1636 | .result = { 0x49, 0xaf, 0xbf, 0xad, 0x9d, 0x5a, 0x34, 0x05, |
1633 | 0x2c, 0xd8, 0xff, 0xa5, 0x98, 0x6b, 0xd2, 0xdd }, | 1637 | 0x2c, 0xd8, 0xff, 0xa5, 0x98, 0x6b, 0xd2, 0xdd }, |
1634 | .rlen = 16, | 1638 | .rlen = 16, |
1635 | }, { /* KeySize=192, PT=0, I=1 */ | 1639 | }, { /* KeySize=192, PT=0, I=1 */ |
@@ -1640,7 +1644,7 @@ static struct cipher_testvec tnepres_enc_tv_template[] = | |||
1640 | .input = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1644 | .input = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1641 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | 1645 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
1642 | .ilen = 16, | 1646 | .ilen = 16, |
1643 | .result = { 0xe7, 0x8e, 0x54, 0x02, 0xc7, 0x19, 0x55, 0x68, | 1647 | .result = { 0xe7, 0x8e, 0x54, 0x02, 0xc7, 0x19, 0x55, 0x68, |
1644 | 0xac, 0x36, 0x78, 0xf7, 0xa3, 0xf6, 0x0c, 0x66 }, | 1648 | 0xac, 0x36, 0x78, 0xf7, 0xa3, 0xf6, 0x0c, 0x66 }, |
1645 | .rlen = 16, | 1649 | .rlen = 16, |
1646 | }, { /* KeySize=256, PT=0, I=1 */ | 1650 | }, { /* KeySize=256, PT=0, I=1 */ |
@@ -1652,7 +1656,7 @@ static struct cipher_testvec tnepres_enc_tv_template[] = | |||
1652 | .input = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1656 | .input = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
1653 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | 1657 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
1654 | .ilen = 16, | 1658 | .ilen = 16, |
1655 | .result = { 0xab, 0xed, 0x96, 0xe7, 0x66, 0xbf, 0x28, 0xcb, | 1659 | .result = { 0xab, 0xed, 0x96, 0xe7, 0x66, 0xbf, 0x28, 0xcb, |
1656 | 0xc0, 0xeb, 0xd2, 0x1a, 0x82, 0xef, 0x08, 0x19 }, | 1660 | 0xc0, 0xeb, 0xd2, 0x1a, 0x82, 0xef, 0x08, 0x19 }, |
1657 | .rlen = 16, | 1661 | .rlen = 16, |
1658 | }, { /* KeySize=256, I=257 */ | 1662 | }, { /* KeySize=256, I=257 */ |
@@ -1664,15 +1668,14 @@ static struct cipher_testvec tnepres_enc_tv_template[] = | |||
1664 | .input = { 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, | 1668 | .input = { 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, |
1665 | 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00 }, | 1669 | 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00 }, |
1666 | .ilen = 16, | 1670 | .ilen = 16, |
1667 | .result = { 0x5c, 0xe7, 0x1c, 0x70, 0xd2, 0x88, 0x2e, 0x5b, | 1671 | .result = { 0x5c, 0xe7, 0x1c, 0x70, 0xd2, 0x88, 0x2e, 0x5b, |
1668 | 0xb8, 0x32, 0xe4, 0x33, 0xf8, 0x9f, 0x26, 0xde }, | 1672 | 0xb8, 0x32, 0xe4, 0x33, 0xf8, 0x9f, 0x26, 0xde }, |
1669 | .rlen = 16, | 1673 | .rlen = 16, |
1670 | }, | 1674 | }, |
1671 | }; | 1675 | }; |
1672 | 1676 | ||
1673 | 1677 | ||
1674 | static struct cipher_testvec serpent_dec_tv_template[] = | 1678 | static struct cipher_testvec serpent_dec_tv_template[] = { |
1675 | { | ||
1676 | { | 1679 | { |
1677 | .input = { 0x12, 0x07, 0xfc, 0xce, 0x9b, 0xd0, 0xd6, 0x47, | 1680 | .input = { 0x12, 0x07, 0xfc, 0xce, 0x9b, 0xd0, 0xd6, 0x47, |
1678 | 0x6a, 0xe9, 0x8f, 0xbe, 0xd1, 0x43, 0xa0, 0xe2 }, | 1681 | 0x6a, 0xe9, 0x8f, 0xbe, 0xd1, 0x43, 0xa0, 0xe2 }, |
@@ -1713,8 +1716,7 @@ static struct cipher_testvec serpent_dec_tv_template[] = | |||
1713 | }, | 1716 | }, |
1714 | }; | 1717 | }; |
1715 | 1718 | ||
1716 | static struct cipher_testvec tnepres_dec_tv_template[] = | 1719 | static struct cipher_testvec tnepres_dec_tv_template[] = { |
1717 | { | ||
1718 | { | 1720 | { |
1719 | .input = { 0x41, 0xcc, 0x6b, 0x31, 0x59, 0x31, 0x45, 0x97, | 1721 | .input = { 0x41, 0xcc, 0x6b, 0x31, 0x59, 0x31, 0x45, 0x97, |
1720 | 0x6d, 0x6f, 0xbb, 0x38, 0x4b, 0x37, 0x21, 0x28 }, | 1722 | 0x6d, 0x6f, 0xbb, 0x38, 0x4b, 0x37, 0x21, 0x28 }, |
@@ -1726,7 +1728,7 @@ static struct cipher_testvec tnepres_dec_tv_template[] = | |||
1726 | .key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 1728 | .key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
1727 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, | 1729 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, |
1728 | .klen = 16, | 1730 | .klen = 16, |
1729 | .input = { 0xea, 0xf4, 0xd7, 0xfc, 0xd8, 0x01, 0x34, 0x47, | 1731 | .input = { 0xea, 0xf4, 0xd7, 0xfc, 0xd8, 0x01, 0x34, 0x47, |
1730 | 0x81, 0x45, 0x0b, 0xfa, 0x0c, 0xd6, 0xad, 0x6e }, | 1732 | 0x81, 0x45, 0x0b, 0xfa, 0x0c, 0xd6, 0xad, 0x6e }, |
1731 | .ilen = 16, | 1733 | .ilen = 16, |
1732 | .result = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 1734 | .result = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
@@ -1738,7 +1740,7 @@ static struct cipher_testvec tnepres_dec_tv_template[] = | |||
1738 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, | 1740 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
1739 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }, | 1741 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }, |
1740 | .klen = 32, | 1742 | .klen = 32, |
1741 | .input = { 0x64, 0xa9, 0x1a, 0x37, 0xed, 0x9f, 0xe7, 0x49, | 1743 | .input = { 0x64, 0xa9, 0x1a, 0x37, 0xed, 0x9f, 0xe7, 0x49, |
1742 | 0xa8, 0x4e, 0x76, 0xd6, 0xf5, 0x0d, 0x78, 0xee }, | 1744 | 0xa8, 0x4e, 0x76, 0xd6, 0xf5, 0x0d, 0x78, 0xee }, |
1743 | .ilen = 16, | 1745 | .ilen = 16, |
1744 | .result = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 1746 | .result = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
@@ -1747,7 +1749,7 @@ static struct cipher_testvec tnepres_dec_tv_template[] = | |||
1747 | }, { /* KeySize=128, I=121 */ | 1749 | }, { /* KeySize=128, I=121 */ |
1748 | .key = { [15] = 0x80 }, | 1750 | .key = { [15] = 0x80 }, |
1749 | .klen = 16, | 1751 | .klen = 16, |
1750 | .input = { 0x3d, 0xda, 0xbf, 0xc0, 0x06, 0xda, 0xab, 0x06, | 1752 | .input = { 0x3d, 0xda, 0xbf, 0xc0, 0x06, 0xda, 0xab, 0x06, |
1751 | 0x46, 0x2a, 0xf4, 0xef, 0x81, 0x54, 0x4e, 0x26 }, | 1753 | 0x46, 0x2a, 0xf4, 0xef, 0x81, 0x54, 0x4e, 0x26 }, |
1752 | .ilen = 16, | 1754 | .ilen = 16, |
1753 | .result = { [0 ... 15] = 0x00 }, | 1755 | .result = { [0 ... 15] = 0x00 }, |
@@ -1760,58 +1762,56 @@ static struct cipher_testvec tnepres_dec_tv_template[] = | |||
1760 | #define CAST6_ENC_TEST_VECTORS 3 | 1762 | #define CAST6_ENC_TEST_VECTORS 3 |
1761 | #define CAST6_DEC_TEST_VECTORS 3 | 1763 | #define CAST6_DEC_TEST_VECTORS 3 |
1762 | 1764 | ||
1763 | static struct cipher_testvec cast6_enc_tv_template[] = | 1765 | static struct cipher_testvec cast6_enc_tv_template[] = { |
1764 | { | ||
1765 | { | 1766 | { |
1766 | .key = { 0x23, 0x42, 0xbb, 0x9e, 0xfa, 0x38, 0x54, 0x2c, | 1767 | .key = { 0x23, 0x42, 0xbb, 0x9e, 0xfa, 0x38, 0x54, 0x2c, |
1767 | 0x0a, 0xf7, 0x56, 0x47, 0xf2, 0x9f, 0x61, 0x5d }, | 1768 | 0x0a, 0xf7, 0x56, 0x47, 0xf2, 0x9f, 0x61, 0x5d }, |
1768 | .klen = 16, | 1769 | .klen = 16, |
1769 | .input = { [0 ... 15] = 0x00 }, | 1770 | .input = { [0 ... 15] = 0x00 }, |
1770 | .ilen = 16, | 1771 | .ilen = 16, |
1771 | .result = { 0xc8, 0x42, 0xa0, 0x89, 0x72, 0xb4, 0x3d, 0x20, | 1772 | .result = { 0xc8, 0x42, 0xa0, 0x89, 0x72, 0xb4, 0x3d, 0x20, |
1772 | 0x83, 0x6c, 0x91, 0xd1, 0xb7, 0x53, 0x0f, 0x6b }, | 1773 | 0x83, 0x6c, 0x91, 0xd1, 0xb7, 0x53, 0x0f, 0x6b }, |
1773 | .rlen = 16, | 1774 | .rlen = 16, |
1774 | }, { | 1775 | }, { |
1775 | .key = { 0x23, 0x42, 0xbb, 0x9e, 0xfa, 0x38, 0x54, 0x2c, | 1776 | .key = { 0x23, 0x42, 0xbb, 0x9e, 0xfa, 0x38, 0x54, 0x2c, |
1776 | 0xbe, 0xd0, 0xac, 0x83, 0x94, 0x0a, 0xc2, 0x98, | 1777 | 0xbe, 0xd0, 0xac, 0x83, 0x94, 0x0a, 0xc2, 0x98, |
1777 | 0xba, 0xc7, 0x7a, 0x77, 0x17, 0x94, 0x28, 0x63 }, | 1778 | 0xba, 0xc7, 0x7a, 0x77, 0x17, 0x94, 0x28, 0x63 }, |
1778 | .klen = 24, | 1779 | .klen = 24, |
1779 | .input = { [0 ... 15] = 0x00 }, | 1780 | .input = { [0 ... 15] = 0x00 }, |
1780 | .ilen = 16, | 1781 | .ilen = 16, |
1781 | .result = { 0x1b, 0x38, 0x6c, 0x02, 0x10, 0xdc, 0xad, 0xcb, | 1782 | .result = { 0x1b, 0x38, 0x6c, 0x02, 0x10, 0xdc, 0xad, 0xcb, |
1782 | 0xdd, 0x0e, 0x41, 0xaa, 0x08, 0xa7, 0xa7, 0xe8 }, | 1783 | 0xdd, 0x0e, 0x41, 0xaa, 0x08, 0xa7, 0xa7, 0xe8 }, |
1783 | .rlen = 16, | 1784 | .rlen = 16, |
1784 | }, { | 1785 | }, { |
1785 | .key = { 0x23, 0x42, 0xbb, 0x9e, 0xfa, 0x38, 0x54, 0x2c, | 1786 | .key = { 0x23, 0x42, 0xbb, 0x9e, 0xfa, 0x38, 0x54, 0x2c, |
1786 | 0xbe, 0xd0, 0xac, 0x83, 0x94, 0x0a, 0xc2, 0x98, | 1787 | 0xbe, 0xd0, 0xac, 0x83, 0x94, 0x0a, 0xc2, 0x98, |
1787 | 0x8d, 0x7c, 0x47, 0xce, 0x26, 0x49, 0x08, 0x46, | 1788 | 0x8d, 0x7c, 0x47, 0xce, 0x26, 0x49, 0x08, 0x46, |
1788 | 0x1c, 0xc1, 0xb5, 0x13, 0x7a, 0xe6, 0xb6, 0x04 }, | 1789 | 0x1c, 0xc1, 0xb5, 0x13, 0x7a, 0xe6, 0xb6, 0x04 }, |
1789 | .klen = 32, | 1790 | .klen = 32, |
1790 | .input = { [0 ... 15] = 0x00 }, | 1791 | .input = { [0 ... 15] = 0x00 }, |
1791 | .ilen = 16, | 1792 | .ilen = 16, |
1792 | .result = { 0x4f, 0x6a, 0x20, 0x38, 0x28, 0x68, 0x97, 0xb9, | 1793 | .result = { 0x4f, 0x6a, 0x20, 0x38, 0x28, 0x68, 0x97, 0xb9, |
1793 | 0xc9, 0x87, 0x01, 0x36, 0x55, 0x33, 0x17, 0xfa }, | 1794 | 0xc9, 0x87, 0x01, 0x36, 0x55, 0x33, 0x17, 0xfa }, |
1794 | .rlen = 16, | 1795 | .rlen = 16, |
1795 | }, | 1796 | }, |
1796 | }; | 1797 | }; |
1797 | 1798 | ||
1798 | static struct cipher_testvec cast6_dec_tv_template[] = | 1799 | static struct cipher_testvec cast6_dec_tv_template[] = { |
1799 | { | ||
1800 | { | 1800 | { |
1801 | .key = { 0x23, 0x42, 0xbb, 0x9e, 0xfa, 0x38, 0x54, 0x2c, | 1801 | .key = { 0x23, 0x42, 0xbb, 0x9e, 0xfa, 0x38, 0x54, 0x2c, |
1802 | 0x0a, 0xf7, 0x56, 0x47, 0xf2, 0x9f, 0x61, 0x5d }, | 1802 | 0x0a, 0xf7, 0x56, 0x47, 0xf2, 0x9f, 0x61, 0x5d }, |
1803 | .klen = 16, | 1803 | .klen = 16, |
1804 | .input = { 0xc8, 0x42, 0xa0, 0x89, 0x72, 0xb4, 0x3d, 0x20, | 1804 | .input = { 0xc8, 0x42, 0xa0, 0x89, 0x72, 0xb4, 0x3d, 0x20, |
1805 | 0x83, 0x6c, 0x91, 0xd1, 0xb7, 0x53, 0x0f, 0x6b }, | 1805 | 0x83, 0x6c, 0x91, 0xd1, 0xb7, 0x53, 0x0f, 0x6b }, |
1806 | .ilen = 16, | 1806 | .ilen = 16, |
1807 | .result = { [0 ... 15] = 0x00 }, | 1807 | .result = { [0 ... 15] = 0x00 }, |
1808 | .rlen = 16, | 1808 | .rlen = 16, |
1809 | }, { | 1809 | }, { |
1810 | .key = { 0x23, 0x42, 0xbb, 0x9e, 0xfa, 0x38, 0x54, 0x2c, | 1810 | .key = { 0x23, 0x42, 0xbb, 0x9e, 0xfa, 0x38, 0x54, 0x2c, |
1811 | 0xbe, 0xd0, 0xac, 0x83, 0x94, 0x0a, 0xc2, 0x98, | 1811 | 0xbe, 0xd0, 0xac, 0x83, 0x94, 0x0a, 0xc2, 0x98, |
1812 | 0xba, 0xc7, 0x7a, 0x77, 0x17, 0x94, 0x28, 0x63 }, | 1812 | 0xba, 0xc7, 0x7a, 0x77, 0x17, 0x94, 0x28, 0x63 }, |
1813 | .klen = 24, | 1813 | .klen = 24, |
1814 | .input = { 0x1b, 0x38, 0x6c, 0x02, 0x10, 0xdc, 0xad, 0xcb, | 1814 | .input = { 0x1b, 0x38, 0x6c, 0x02, 0x10, 0xdc, 0xad, 0xcb, |
1815 | 0xdd, 0x0e, 0x41, 0xaa, 0x08, 0xa7, 0xa7, 0xe8 }, | 1815 | 0xdd, 0x0e, 0x41, 0xaa, 0x08, 0xa7, 0xa7, 0xe8 }, |
1816 | .ilen = 16, | 1816 | .ilen = 16, |
1817 | .result = { [0 ... 15] = 0x00 }, | 1817 | .result = { [0 ... 15] = 0x00 }, |
@@ -1820,9 +1820,9 @@ static struct cipher_testvec cast6_dec_tv_template[] = | |||
1820 | .key = { 0x23, 0x42, 0xbb, 0x9e, 0xfa, 0x38, 0x54, 0x2c, | 1820 | .key = { 0x23, 0x42, 0xbb, 0x9e, 0xfa, 0x38, 0x54, 0x2c, |
1821 | 0xbe, 0xd0, 0xac, 0x83, 0x94, 0x0a, 0xc2, 0x98, | 1821 | 0xbe, 0xd0, 0xac, 0x83, 0x94, 0x0a, 0xc2, 0x98, |
1822 | 0x8d, 0x7c, 0x47, 0xce, 0x26, 0x49, 0x08, 0x46, | 1822 | 0x8d, 0x7c, 0x47, 0xce, 0x26, 0x49, 0x08, 0x46, |
1823 | 0x1c, 0xc1, 0xb5, 0x13, 0x7a, 0xe6, 0xb6, 0x04 }, | 1823 | 0x1c, 0xc1, 0xb5, 0x13, 0x7a, 0xe6, 0xb6, 0x04 }, |
1824 | .klen = 32, | 1824 | .klen = 32, |
1825 | .input = { 0x4f, 0x6a, 0x20, 0x38, 0x28, 0x68, 0x97, 0xb9, | 1825 | .input = { 0x4f, 0x6a, 0x20, 0x38, 0x28, 0x68, 0x97, 0xb9, |
1826 | 0xc9, 0x87, 0x01, 0x36, 0x55, 0x33, 0x17, 0xfa }, | 1826 | 0xc9, 0x87, 0x01, 0x36, 0x55, 0x33, 0x17, 0xfa }, |
1827 | .ilen = 16, | 1827 | .ilen = 16, |
1828 | .result = { [0 ... 15] = 0x00 }, | 1828 | .result = { [0 ... 15] = 0x00 }, |
@@ -1837,9 +1837,9 @@ static struct cipher_testvec cast6_dec_tv_template[] = | |||
1837 | #define AES_ENC_TEST_VECTORS 3 | 1837 | #define AES_ENC_TEST_VECTORS 3 |
1838 | #define AES_DEC_TEST_VECTORS 3 | 1838 | #define AES_DEC_TEST_VECTORS 3 |
1839 | 1839 | ||
1840 | static struct cipher_testvec aes_enc_tv_template[] = { | 1840 | static struct cipher_testvec aes_enc_tv_template[] = { |
1841 | { /* From FIPS-197 */ | 1841 | { /* From FIPS-197 */ |
1842 | .key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 1842 | .key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
1843 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, | 1843 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, |
1844 | .klen = 16, | 1844 | .klen = 16, |
1845 | .input = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | 1845 | .input = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, |
@@ -1853,7 +1853,7 @@ static struct cipher_testvec aes_enc_tv_template[] = { | |||
1853 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | 1853 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
1854 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 }, | 1854 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 }, |
1855 | .klen = 24, | 1855 | .klen = 24, |
1856 | .input = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | 1856 | .input = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, |
1857 | 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }, | 1857 | 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }, |
1858 | .ilen = 16, | 1858 | .ilen = 16, |
1859 | .result = { 0xdd, 0xa9, 0x7c, 0xa4, 0x86, 0x4c, 0xdf, 0xe0, | 1859 | .result = { 0xdd, 0xa9, 0x7c, 0xa4, 0x86, 0x4c, 0xdf, 0xe0, |
@@ -1865,7 +1865,7 @@ static struct cipher_testvec aes_enc_tv_template[] = { | |||
1865 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, | 1865 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
1866 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }, | 1866 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }, |
1867 | .klen = 32, | 1867 | .klen = 32, |
1868 | .input = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | 1868 | .input = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, |
1869 | 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }, | 1869 | 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }, |
1870 | .ilen = 16, | 1870 | .ilen = 16, |
1871 | .result = { 0x8e, 0xa2, 0xb7, 0xca, 0x51, 0x67, 0x45, 0xbf, | 1871 | .result = { 0x8e, 0xa2, 0xb7, 0xca, 0x51, 0x67, 0x45, 0xbf, |
@@ -1874,9 +1874,9 @@ static struct cipher_testvec aes_enc_tv_template[] = { | |||
1874 | }, | 1874 | }, |
1875 | }; | 1875 | }; |
1876 | 1876 | ||
1877 | static struct cipher_testvec aes_dec_tv_template[] = { | 1877 | static struct cipher_testvec aes_dec_tv_template[] = { |
1878 | { /* From FIPS-197 */ | 1878 | { /* From FIPS-197 */ |
1879 | .key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 1879 | .key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
1880 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, | 1880 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, |
1881 | .klen = 16, | 1881 | .klen = 16, |
1882 | .input = { 0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30, | 1882 | .input = { 0x69, 0xc4, 0xe0, 0xd8, 0x6a, 0x7b, 0x04, 0x30, |
@@ -1893,8 +1893,8 @@ static struct cipher_testvec aes_dec_tv_template[] = { | |||
1893 | .input = { 0xdd, 0xa9, 0x7c, 0xa4, 0x86, 0x4c, 0xdf, 0xe0, | 1893 | .input = { 0xdd, 0xa9, 0x7c, 0xa4, 0x86, 0x4c, 0xdf, 0xe0, |
1894 | 0x6e, 0xaf, 0x70, 0xa0, 0xec, 0x0d, 0x71, 0x91 }, | 1894 | 0x6e, 0xaf, 0x70, 0xa0, 0xec, 0x0d, 0x71, 0x91 }, |
1895 | .ilen = 16, | 1895 | .ilen = 16, |
1896 | .result = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | 1896 | .result = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, |
1897 | 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }, | 1897 | 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }, |
1898 | .rlen = 16, | 1898 | .rlen = 16, |
1899 | }, { | 1899 | }, { |
1900 | .key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 1900 | .key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
@@ -1905,7 +1905,7 @@ static struct cipher_testvec aes_dec_tv_template[] = { | |||
1905 | .input = { 0x8e, 0xa2, 0xb7, 0xca, 0x51, 0x67, 0x45, 0xbf, | 1905 | .input = { 0x8e, 0xa2, 0xb7, 0xca, 0x51, 0x67, 0x45, 0xbf, |
1906 | 0xea, 0xfc, 0x49, 0x90, 0x4b, 0x49, 0x60, 0x89 }, | 1906 | 0xea, 0xfc, 0x49, 0x90, 0x4b, 0x49, 0x60, 0x89 }, |
1907 | .ilen = 16, | 1907 | .ilen = 16, |
1908 | .result = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | 1908 | .result = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, |
1909 | 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }, | 1909 | 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }, |
1910 | .rlen = 16, | 1910 | .rlen = 16, |
1911 | }, | 1911 | }, |
@@ -1915,8 +1915,7 @@ static struct cipher_testvec aes_dec_tv_template[] = { | |||
1915 | #define CAST5_ENC_TEST_VECTORS 3 | 1915 | #define CAST5_ENC_TEST_VECTORS 3 |
1916 | #define CAST5_DEC_TEST_VECTORS 3 | 1916 | #define CAST5_DEC_TEST_VECTORS 3 |
1917 | 1917 | ||
1918 | static struct cipher_testvec cast5_enc_tv_template[] = | 1918 | static struct cipher_testvec cast5_enc_tv_template[] = { |
1919 | { | ||
1920 | { | 1919 | { |
1921 | .key = { 0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78, | 1920 | .key = { 0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78, |
1922 | 0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9a }, | 1921 | 0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9a }, |
@@ -1943,8 +1942,7 @@ static struct cipher_testvec cast5_enc_tv_template[] = | |||
1943 | }, | 1942 | }, |
1944 | }; | 1943 | }; |
1945 | 1944 | ||
1946 | static struct cipher_testvec cast5_dec_tv_template[] = | 1945 | static struct cipher_testvec cast5_dec_tv_template[] = { |
1947 | { | ||
1948 | { | 1946 | { |
1949 | .key = { 0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78, | 1947 | .key = { 0x01, 0x23, 0x45, 0x67, 0x12, 0x34, 0x56, 0x78, |
1950 | 0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9a }, | 1948 | 0x23, 0x45, 0x67, 0x89, 0x34, 0x56, 0x78, 0x9a }, |
@@ -1971,14 +1969,13 @@ static struct cipher_testvec cast5_dec_tv_template[] = | |||
1971 | }, | 1969 | }, |
1972 | }; | 1970 | }; |
1973 | 1971 | ||
1974 | /* | 1972 | /* |
1975 | * ARC4 test vectors from OpenSSL | 1973 | * ARC4 test vectors from OpenSSL |
1976 | */ | 1974 | */ |
1977 | #define ARC4_ENC_TEST_VECTORS 7 | 1975 | #define ARC4_ENC_TEST_VECTORS 7 |
1978 | #define ARC4_DEC_TEST_VECTORS 7 | 1976 | #define ARC4_DEC_TEST_VECTORS 7 |
1979 | 1977 | ||
1980 | static struct cipher_testvec arc4_enc_tv_template[] = | 1978 | static struct cipher_testvec arc4_enc_tv_template[] = { |
1981 | { | ||
1982 | { | 1979 | { |
1983 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }, | 1980 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }, |
1984 | .klen = 8, | 1981 | .klen = 8, |
@@ -2044,8 +2041,7 @@ static struct cipher_testvec arc4_enc_tv_template[] = | |||
2044 | }, | 2041 | }, |
2045 | }; | 2042 | }; |
2046 | 2043 | ||
2047 | static struct cipher_testvec arc4_dec_tv_template[] = | 2044 | static struct cipher_testvec arc4_dec_tv_template[] = { |
2048 | { | ||
2049 | { | 2045 | { |
2050 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }, | 2046 | .key = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }, |
2051 | .klen = 8, | 2047 | .klen = 8, |
@@ -2111,14 +2107,13 @@ static struct cipher_testvec arc4_dec_tv_template[] = | |||
2111 | }, | 2107 | }, |
2112 | }; | 2108 | }; |
2113 | 2109 | ||
2114 | /* | 2110 | /* |
2115 | * TEA test vectors | 2111 | * TEA test vectors |
2116 | */ | 2112 | */ |
2117 | #define TEA_ENC_TEST_VECTORS 4 | 2113 | #define TEA_ENC_TEST_VECTORS 4 |
2118 | #define TEA_DEC_TEST_VECTORS 4 | 2114 | #define TEA_DEC_TEST_VECTORS 4 |
2119 | 2115 | ||
2120 | static struct cipher_testvec tea_enc_tv_template[] = | 2116 | static struct cipher_testvec tea_enc_tv_template[] = { |
2121 | { | ||
2122 | { | 2117 | { |
2123 | .key = { [0 ... 15] = 0x00 }, | 2118 | .key = { [0 ... 15] = 0x00 }, |
2124 | .klen = 16, | 2119 | .klen = 16, |
@@ -2138,31 +2133,30 @@ static struct cipher_testvec tea_enc_tv_template[] = | |||
2138 | .key = { 0x09, 0x65, 0x43, 0x11, 0x66, 0x44, 0x39, 0x25, | 2133 | .key = { 0x09, 0x65, 0x43, 0x11, 0x66, 0x44, 0x39, 0x25, |
2139 | 0x51, 0x3a, 0x16, 0x10, 0x0a, 0x08, 0x12, 0x6e }, | 2134 | 0x51, 0x3a, 0x16, 0x10, 0x0a, 0x08, 0x12, 0x6e }, |
2140 | .klen = 16, | 2135 | .klen = 16, |
2141 | .input = { 0x6c, 0x6f, 0x6e, 0x67, 0x65, 0x72, 0x5f, 0x74, | 2136 | .input = { 0x6c, 0x6f, 0x6e, 0x67, 0x65, 0x72, 0x5f, 0x74, |
2142 | 0x65, 0x73, 0x74, 0x5f, 0x76, 0x65, 0x63, 0x74 }, | 2137 | 0x65, 0x73, 0x74, 0x5f, 0x76, 0x65, 0x63, 0x74 }, |
2143 | .ilen = 16, | 2138 | .ilen = 16, |
2144 | .result = { 0xbe, 0x7a, 0xbb, 0x81, 0x95, 0x2d, 0x1f, 0x1e, | 2139 | .result = { 0xbe, 0x7a, 0xbb, 0x81, 0x95, 0x2d, 0x1f, 0x1e, |
2145 | 0xdd, 0x89, 0xa1, 0x25, 0x04, 0x21, 0xdf, 0x95 }, | 2140 | 0xdd, 0x89, 0xa1, 0x25, 0x04, 0x21, 0xdf, 0x95 }, |
2146 | .rlen = 16, | 2141 | .rlen = 16, |
2147 | }, { | 2142 | }, { |
2148 | .key = { 0x4d, 0x76, 0x32, 0x17, 0x05, 0x3f, 0x75, 0x2c, | 2143 | .key = { 0x4d, 0x76, 0x32, 0x17, 0x05, 0x3f, 0x75, 0x2c, |
2149 | 0x5d, 0x04, 0x16, 0x36, 0x15, 0x72, 0x63, 0x2f }, | 2144 | 0x5d, 0x04, 0x16, 0x36, 0x15, 0x72, 0x63, 0x2f }, |
2150 | .klen = 16, | 2145 | .klen = 16, |
2151 | .input = { 0x54, 0x65, 0x61, 0x20, 0x69, 0x73, 0x20, 0x67, | 2146 | .input = { 0x54, 0x65, 0x61, 0x20, 0x69, 0x73, 0x20, 0x67, |
2152 | 0x6f, 0x6f, 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, | 2147 | 0x6f, 0x6f, 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, |
2153 | 0x79, 0x6f, 0x75, 0x21, 0x21, 0x21, 0x20, 0x72, | 2148 | 0x79, 0x6f, 0x75, 0x21, 0x21, 0x21, 0x20, 0x72, |
2154 | 0x65, 0x61, 0x6c, 0x6c, 0x79, 0x21, 0x21, 0x21 }, | 2149 | 0x65, 0x61, 0x6c, 0x6c, 0x79, 0x21, 0x21, 0x21 }, |
2155 | .ilen = 32, | 2150 | .ilen = 32, |
2156 | .result = { 0xe0, 0x4d, 0x5d, 0x3c, 0xb7, 0x8c, 0x36, 0x47, | 2151 | .result = { 0xe0, 0x4d, 0x5d, 0x3c, 0xb7, 0x8c, 0x36, 0x47, |
2157 | 0x94, 0x18, 0x95, 0x91, 0xa9, 0xfc, 0x49, 0xf8, | 2152 | 0x94, 0x18, 0x95, 0x91, 0xa9, 0xfc, 0x49, 0xf8, |
2158 | 0x44, 0xd1, 0x2d, 0xc2, 0x99, 0xb8, 0x08, 0x2a, | 2153 | 0x44, 0xd1, 0x2d, 0xc2, 0x99, 0xb8, 0x08, 0x2a, |
2159 | 0x07, 0x89, 0x73, 0xc2, 0x45, 0x92, 0xc6, 0x90 }, | 2154 | 0x07, 0x89, 0x73, 0xc2, 0x45, 0x92, 0xc6, 0x90 }, |
2160 | .rlen = 32, | 2155 | .rlen = 32, |
2161 | } | 2156 | } |
2162 | }; | 2157 | }; |
2163 | 2158 | ||
2164 | static struct cipher_testvec tea_dec_tv_template[] = | 2159 | static struct cipher_testvec tea_dec_tv_template[] = { |
2165 | { | ||
2166 | { | 2160 | { |
2167 | .key = { [0 ... 15] = 0x00 }, | 2161 | .key = { [0 ... 15] = 0x00 }, |
2168 | .klen = 16, | 2162 | .klen = 16, |
@@ -2183,9 +2177,9 @@ static struct cipher_testvec tea_dec_tv_template[] = | |||
2183 | 0x51, 0x3a, 0x16, 0x10, 0x0a, 0x08, 0x12, 0x6e }, | 2177 | 0x51, 0x3a, 0x16, 0x10, 0x0a, 0x08, 0x12, 0x6e }, |
2184 | .klen = 16, | 2178 | .klen = 16, |
2185 | .input = { 0xbe, 0x7a, 0xbb, 0x81, 0x95, 0x2d, 0x1f, 0x1e, | 2179 | .input = { 0xbe, 0x7a, 0xbb, 0x81, 0x95, 0x2d, 0x1f, 0x1e, |
2186 | 0xdd, 0x89, 0xa1, 0x25, 0x04, 0x21, 0xdf, 0x95 }, | 2180 | 0xdd, 0x89, 0xa1, 0x25, 0x04, 0x21, 0xdf, 0x95 }, |
2187 | .ilen = 16, | 2181 | .ilen = 16, |
2188 | .result = { 0x6c, 0x6f, 0x6e, 0x67, 0x65, 0x72, 0x5f, 0x74, | 2182 | .result = { 0x6c, 0x6f, 0x6e, 0x67, 0x65, 0x72, 0x5f, 0x74, |
2189 | 0x65, 0x73, 0x74, 0x5f, 0x76, 0x65, 0x63, 0x74 }, | 2183 | 0x65, 0x73, 0x74, 0x5f, 0x76, 0x65, 0x63, 0x74 }, |
2190 | .rlen = 16, | 2184 | .rlen = 16, |
2191 | }, { | 2185 | }, { |
@@ -2193,26 +2187,25 @@ static struct cipher_testvec tea_dec_tv_template[] = | |||
2193 | 0x5d, 0x04, 0x16, 0x36, 0x15, 0x72, 0x63, 0x2f }, | 2187 | 0x5d, 0x04, 0x16, 0x36, 0x15, 0x72, 0x63, 0x2f }, |
2194 | .klen = 16, | 2188 | .klen = 16, |
2195 | .input = { 0xe0, 0x4d, 0x5d, 0x3c, 0xb7, 0x8c, 0x36, 0x47, | 2189 | .input = { 0xe0, 0x4d, 0x5d, 0x3c, 0xb7, 0x8c, 0x36, 0x47, |
2196 | 0x94, 0x18, 0x95, 0x91, 0xa9, 0xfc, 0x49, 0xf8, | 2190 | 0x94, 0x18, 0x95, 0x91, 0xa9, 0xfc, 0x49, 0xf8, |
2197 | 0x44, 0xd1, 0x2d, 0xc2, 0x99, 0xb8, 0x08, 0x2a, | 2191 | 0x44, 0xd1, 0x2d, 0xc2, 0x99, 0xb8, 0x08, 0x2a, |
2198 | 0x07, 0x89, 0x73, 0xc2, 0x45, 0x92, 0xc6, 0x90 }, | 2192 | 0x07, 0x89, 0x73, 0xc2, 0x45, 0x92, 0xc6, 0x90 }, |
2199 | .ilen = 32, | 2193 | .ilen = 32, |
2200 | .result = { 0x54, 0x65, 0x61, 0x20, 0x69, 0x73, 0x20, 0x67, | 2194 | .result = { 0x54, 0x65, 0x61, 0x20, 0x69, 0x73, 0x20, 0x67, |
2201 | 0x6f, 0x6f, 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, | 2195 | 0x6f, 0x6f, 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, |
2202 | 0x79, 0x6f, 0x75, 0x21, 0x21, 0x21, 0x20, 0x72, | 2196 | 0x79, 0x6f, 0x75, 0x21, 0x21, 0x21, 0x20, 0x72, |
2203 | 0x65, 0x61, 0x6c, 0x6c, 0x79, 0x21, 0x21, 0x21 }, | 2197 | 0x65, 0x61, 0x6c, 0x6c, 0x79, 0x21, 0x21, 0x21 }, |
2204 | .rlen = 32, | 2198 | .rlen = 32, |
2205 | } | 2199 | } |
2206 | }; | 2200 | }; |
2207 | 2201 | ||
2208 | /* | 2202 | /* |
2209 | * XTEA test vectors | 2203 | * XTEA test vectors |
2210 | */ | 2204 | */ |
2211 | #define XTEA_ENC_TEST_VECTORS 4 | 2205 | #define XTEA_ENC_TEST_VECTORS 4 |
2212 | #define XTEA_DEC_TEST_VECTORS 4 | 2206 | #define XTEA_DEC_TEST_VECTORS 4 |
2213 | 2207 | ||
2214 | static struct cipher_testvec xtea_enc_tv_template[] = | 2208 | static struct cipher_testvec xtea_enc_tv_template[] = { |
2215 | { | ||
2216 | { | 2209 | { |
2217 | .key = { [0 ... 15] = 0x00 }, | 2210 | .key = { [0 ... 15] = 0x00 }, |
2218 | .klen = 16, | 2211 | .klen = 16, |
@@ -2232,31 +2225,30 @@ static struct cipher_testvec xtea_enc_tv_template[] = | |||
2232 | .key = { 0x09, 0x65, 0x43, 0x11, 0x66, 0x44, 0x39, 0x25, | 2225 | .key = { 0x09, 0x65, 0x43, 0x11, 0x66, 0x44, 0x39, 0x25, |
2233 | 0x51, 0x3a, 0x16, 0x10, 0x0a, 0x08, 0x12, 0x6e }, | 2226 | 0x51, 0x3a, 0x16, 0x10, 0x0a, 0x08, 0x12, 0x6e }, |
2234 | .klen = 16, | 2227 | .klen = 16, |
2235 | .input = { 0x6c, 0x6f, 0x6e, 0x67, 0x65, 0x72, 0x5f, 0x74, | 2228 | .input = { 0x6c, 0x6f, 0x6e, 0x67, 0x65, 0x72, 0x5f, 0x74, |
2236 | 0x65, 0x73, 0x74, 0x5f, 0x76, 0x65, 0x63, 0x74 }, | 2229 | 0x65, 0x73, 0x74, 0x5f, 0x76, 0x65, 0x63, 0x74 }, |
2237 | .ilen = 16, | 2230 | .ilen = 16, |
2238 | .result = { 0xe2, 0x04, 0xdb, 0xf2, 0x89, 0x85, 0x9e, 0xea, | 2231 | .result = { 0xe2, 0x04, 0xdb, 0xf2, 0x89, 0x85, 0x9e, 0xea, |
2239 | 0x61, 0x35, 0xaa, 0xed, 0xb5, 0xcb, 0x71, 0x2c }, | 2232 | 0x61, 0x35, 0xaa, 0xed, 0xb5, 0xcb, 0x71, 0x2c }, |
2240 | .rlen = 16, | 2233 | .rlen = 16, |
2241 | }, { | 2234 | }, { |
2242 | .key = { 0x4d, 0x76, 0x32, 0x17, 0x05, 0x3f, 0x75, 0x2c, | 2235 | .key = { 0x4d, 0x76, 0x32, 0x17, 0x05, 0x3f, 0x75, 0x2c, |
2243 | 0x5d, 0x04, 0x16, 0x36, 0x15, 0x72, 0x63, 0x2f }, | 2236 | 0x5d, 0x04, 0x16, 0x36, 0x15, 0x72, 0x63, 0x2f }, |
2244 | .klen = 16, | 2237 | .klen = 16, |
2245 | .input = { 0x54, 0x65, 0x61, 0x20, 0x69, 0x73, 0x20, 0x67, | 2238 | .input = { 0x54, 0x65, 0x61, 0x20, 0x69, 0x73, 0x20, 0x67, |
2246 | 0x6f, 0x6f, 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, | 2239 | 0x6f, 0x6f, 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, |
2247 | 0x79, 0x6f, 0x75, 0x21, 0x21, 0x21, 0x20, 0x72, | 2240 | 0x79, 0x6f, 0x75, 0x21, 0x21, 0x21, 0x20, 0x72, |
2248 | 0x65, 0x61, 0x6c, 0x6c, 0x79, 0x21, 0x21, 0x21 }, | 2241 | 0x65, 0x61, 0x6c, 0x6c, 0x79, 0x21, 0x21, 0x21 }, |
2249 | .ilen = 32, | 2242 | .ilen = 32, |
2250 | .result = { 0x0b, 0x03, 0xcd, 0x8a, 0xbe, 0x95, 0xfd, 0xb1, | 2243 | .result = { 0x0b, 0x03, 0xcd, 0x8a, 0xbe, 0x95, 0xfd, 0xb1, |
2251 | 0xc1, 0x44, 0x91, 0x0b, 0xa5, 0xc9, 0x1b, 0xb4, | 2244 | 0xc1, 0x44, 0x91, 0x0b, 0xa5, 0xc9, 0x1b, 0xb4, |
2252 | 0xa9, 0xda, 0x1e, 0x9e, 0xb1, 0x3e, 0x2a, 0x8f, | 2245 | 0xa9, 0xda, 0x1e, 0x9e, 0xb1, 0x3e, 0x2a, 0x8f, |
2253 | 0xea, 0xa5, 0x6a, 0x85, 0xd1, 0xf4, 0xa8, 0xa5 }, | 2246 | 0xea, 0xa5, 0x6a, 0x85, 0xd1, 0xf4, 0xa8, 0xa5 }, |
2254 | .rlen = 32, | 2247 | .rlen = 32, |
2255 | } | 2248 | } |
2256 | }; | 2249 | }; |
2257 | 2250 | ||
2258 | static struct cipher_testvec xtea_dec_tv_template[] = | 2251 | static struct cipher_testvec xtea_dec_tv_template[] = { |
2259 | { | ||
2260 | { | 2252 | { |
2261 | .key = { [0 ... 15] = 0x00 }, | 2253 | .key = { [0 ... 15] = 0x00 }, |
2262 | .klen = 16, | 2254 | .klen = 16, |
@@ -2276,24 +2268,24 @@ static struct cipher_testvec xtea_dec_tv_template[] = | |||
2276 | .key = { 0x09, 0x65, 0x43, 0x11, 0x66, 0x44, 0x39, 0x25, | 2268 | .key = { 0x09, 0x65, 0x43, 0x11, 0x66, 0x44, 0x39, 0x25, |
2277 | 0x51, 0x3a, 0x16, 0x10, 0x0a, 0x08, 0x12, 0x6e }, | 2269 | 0x51, 0x3a, 0x16, 0x10, 0x0a, 0x08, 0x12, 0x6e }, |
2278 | .klen = 16, | 2270 | .klen = 16, |
2279 | .input = { 0xe2, 0x04, 0xdb, 0xf2, 0x89, 0x85, 0x9e, 0xea, | 2271 | .input = { 0xe2, 0x04, 0xdb, 0xf2, 0x89, 0x85, 0x9e, 0xea, |
2280 | 0x61, 0x35, 0xaa, 0xed, 0xb5, 0xcb, 0x71, 0x2c }, | 2272 | 0x61, 0x35, 0xaa, 0xed, 0xb5, 0xcb, 0x71, 0x2c }, |
2281 | .ilen = 16, | 2273 | .ilen = 16, |
2282 | .result = { 0x6c, 0x6f, 0x6e, 0x67, 0x65, 0x72, 0x5f, 0x74, | 2274 | .result = { 0x6c, 0x6f, 0x6e, 0x67, 0x65, 0x72, 0x5f, 0x74, |
2283 | 0x65, 0x73, 0x74, 0x5f, 0x76, 0x65, 0x63, 0x74 }, | 2275 | 0x65, 0x73, 0x74, 0x5f, 0x76, 0x65, 0x63, 0x74 }, |
2284 | .rlen = 16, | 2276 | .rlen = 16, |
2285 | }, { | 2277 | }, { |
2286 | .key = { 0x4d, 0x76, 0x32, 0x17, 0x05, 0x3f, 0x75, 0x2c, | 2278 | .key = { 0x4d, 0x76, 0x32, 0x17, 0x05, 0x3f, 0x75, 0x2c, |
2287 | 0x5d, 0x04, 0x16, 0x36, 0x15, 0x72, 0x63, 0x2f }, | 2279 | 0x5d, 0x04, 0x16, 0x36, 0x15, 0x72, 0x63, 0x2f }, |
2288 | .klen = 16, | 2280 | .klen = 16, |
2289 | .input = { 0x0b, 0x03, 0xcd, 0x8a, 0xbe, 0x95, 0xfd, 0xb1, | 2281 | .input = { 0x0b, 0x03, 0xcd, 0x8a, 0xbe, 0x95, 0xfd, 0xb1, |
2290 | 0xc1, 0x44, 0x91, 0x0b, 0xa5, 0xc9, 0x1b, 0xb4, | 2282 | 0xc1, 0x44, 0x91, 0x0b, 0xa5, 0xc9, 0x1b, 0xb4, |
2291 | 0xa9, 0xda, 0x1e, 0x9e, 0xb1, 0x3e, 0x2a, 0x8f, | 2283 | 0xa9, 0xda, 0x1e, 0x9e, 0xb1, 0x3e, 0x2a, 0x8f, |
2292 | 0xea, 0xa5, 0x6a, 0x85, 0xd1, 0xf4, 0xa8, 0xa5 }, | 2284 | 0xea, 0xa5, 0x6a, 0x85, 0xd1, 0xf4, 0xa8, 0xa5 }, |
2293 | .ilen = 32, | 2285 | .ilen = 32, |
2294 | .result = { 0x54, 0x65, 0x61, 0x20, 0x69, 0x73, 0x20, 0x67, | 2286 | .result = { 0x54, 0x65, 0x61, 0x20, 0x69, 0x73, 0x20, 0x67, |
2295 | 0x6f, 0x6f, 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, | 2287 | 0x6f, 0x6f, 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20, |
2296 | 0x79, 0x6f, 0x75, 0x21, 0x21, 0x21, 0x20, 0x72, | 2288 | 0x79, 0x6f, 0x75, 0x21, 0x21, 0x21, 0x20, 0x72, |
2297 | 0x65, 0x61, 0x6c, 0x6c, 0x79, 0x21, 0x21, 0x21 }, | 2289 | 0x65, 0x61, 0x6c, 0x6c, 0x79, 0x21, 0x21, 0x21 }, |
2298 | .rlen = 32, | 2290 | .rlen = 32, |
2299 | } | 2291 | } |
@@ -2305,9 +2297,9 @@ static struct cipher_testvec xtea_dec_tv_template[] = | |||
2305 | #define KHAZAD_ENC_TEST_VECTORS 5 | 2297 | #define KHAZAD_ENC_TEST_VECTORS 5 |
2306 | #define KHAZAD_DEC_TEST_VECTORS 5 | 2298 | #define KHAZAD_DEC_TEST_VECTORS 5 |
2307 | 2299 | ||
2308 | static struct cipher_testvec khazad_enc_tv_template[] = { | 2300 | static struct cipher_testvec khazad_enc_tv_template[] = { |
2309 | { | 2301 | { |
2310 | .key = { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 2302 | .key = { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
2311 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | 2303 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
2312 | .klen = 16, | 2304 | .klen = 16, |
2313 | .input = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | 2305 | .input = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
@@ -2351,9 +2343,9 @@ static struct cipher_testvec khazad_enc_tv_template[] = { | |||
2351 | }, | 2343 | }, |
2352 | }; | 2344 | }; |
2353 | 2345 | ||
2354 | static struct cipher_testvec khazad_dec_tv_template[] = { | 2346 | static struct cipher_testvec khazad_dec_tv_template[] = { |
2355 | { | 2347 | { |
2356 | .key = { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 2348 | .key = { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
2357 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | 2349 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
2358 | .klen = 16, | 2350 | .klen = 16, |
2359 | .input = { 0X49, 0Xa4, 0Xce, 0X32, 0Xac, 0X19, 0X0e, 0X3f }, | 2351 | .input = { 0X49, 0Xa4, 0Xce, 0X32, 0Xac, 0X19, 0X0e, 0X3f }, |
@@ -2697,8 +2689,7 @@ static struct comp_testvec deflate_decomp_tv_template[] = { | |||
2697 | */ | 2689 | */ |
2698 | #define MICHAEL_MIC_TEST_VECTORS 6 | 2690 | #define MICHAEL_MIC_TEST_VECTORS 6 |
2699 | 2691 | ||
2700 | static struct hash_testvec michael_mic_tv_template[] = | 2692 | static struct hash_testvec michael_mic_tv_template[] = { |
2701 | { | ||
2702 | { | 2693 | { |
2703 | .key = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | 2694 | .key = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
2704 | .ksize = 8, | 2695 | .ksize = 8, |
@@ -2743,4 +2734,88 @@ static struct hash_testvec michael_mic_tv_template[] = | |||
2743 | } | 2734 | } |
2744 | }; | 2735 | }; |
2745 | 2736 | ||
2737 | /* | ||
2738 | * Cipher speed tests | ||
2739 | */ | ||
2740 | static struct cipher_speed aes_speed_template[] = { | ||
2741 | { .klen = 16, .blen = 16, }, | ||
2742 | { .klen = 16, .blen = 64, }, | ||
2743 | { .klen = 16, .blen = 256, }, | ||
2744 | { .klen = 16, .blen = 1024, }, | ||
2745 | { .klen = 16, .blen = 8192, }, | ||
2746 | { .klen = 24, .blen = 16, }, | ||
2747 | { .klen = 24, .blen = 64, }, | ||
2748 | { .klen = 24, .blen = 256, }, | ||
2749 | { .klen = 24, .blen = 1024, }, | ||
2750 | { .klen = 24, .blen = 8192, }, | ||
2751 | { .klen = 32, .blen = 16, }, | ||
2752 | { .klen = 32, .blen = 64, }, | ||
2753 | { .klen = 32, .blen = 256, }, | ||
2754 | { .klen = 32, .blen = 1024, }, | ||
2755 | { .klen = 32, .blen = 8192, }, | ||
2756 | |||
2757 | /* End marker */ | ||
2758 | { .klen = 0, .blen = 0, } | ||
2759 | }; | ||
2760 | |||
2761 | static struct cipher_speed des3_ede_speed_template[] = { | ||
2762 | { .klen = 24, .blen = 16, }, | ||
2763 | { .klen = 24, .blen = 64, }, | ||
2764 | { .klen = 24, .blen = 256, }, | ||
2765 | { .klen = 24, .blen = 1024, }, | ||
2766 | { .klen = 24, .blen = 8192, }, | ||
2767 | |||
2768 | /* End marker */ | ||
2769 | { .klen = 0, .blen = 0, } | ||
2770 | }; | ||
2771 | |||
2772 | static struct cipher_speed twofish_speed_template[] = { | ||
2773 | { .klen = 16, .blen = 16, }, | ||
2774 | { .klen = 16, .blen = 64, }, | ||
2775 | { .klen = 16, .blen = 256, }, | ||
2776 | { .klen = 16, .blen = 1024, }, | ||
2777 | { .klen = 16, .blen = 8192, }, | ||
2778 | { .klen = 24, .blen = 16, }, | ||
2779 | { .klen = 24, .blen = 64, }, | ||
2780 | { .klen = 24, .blen = 256, }, | ||
2781 | { .klen = 24, .blen = 1024, }, | ||
2782 | { .klen = 24, .blen = 8192, }, | ||
2783 | { .klen = 32, .blen = 16, }, | ||
2784 | { .klen = 32, .blen = 64, }, | ||
2785 | { .klen = 32, .blen = 256, }, | ||
2786 | { .klen = 32, .blen = 1024, }, | ||
2787 | { .klen = 32, .blen = 8192, }, | ||
2788 | |||
2789 | /* End marker */ | ||
2790 | { .klen = 0, .blen = 0, } | ||
2791 | }; | ||
2792 | |||
2793 | static struct cipher_speed blowfish_speed_template[] = { | ||
2794 | /* Don't support blowfish keys > 256 bit in this test */ | ||
2795 | { .klen = 8, .blen = 16, }, | ||
2796 | { .klen = 8, .blen = 64, }, | ||
2797 | { .klen = 8, .blen = 256, }, | ||
2798 | { .klen = 8, .blen = 1024, }, | ||
2799 | { .klen = 8, .blen = 8192, }, | ||
2800 | { .klen = 32, .blen = 16, }, | ||
2801 | { .klen = 32, .blen = 64, }, | ||
2802 | { .klen = 32, .blen = 256, }, | ||
2803 | { .klen = 32, .blen = 1024, }, | ||
2804 | { .klen = 32, .blen = 8192, }, | ||
2805 | |||
2806 | /* End marker */ | ||
2807 | { .klen = 0, .blen = 0, } | ||
2808 | }; | ||
2809 | |||
2810 | static struct cipher_speed des_speed_template[] = { | ||
2811 | { .klen = 8, .blen = 16, }, | ||
2812 | { .klen = 8, .blen = 64, }, | ||
2813 | { .klen = 8, .blen = 256, }, | ||
2814 | { .klen = 8, .blen = 1024, }, | ||
2815 | { .klen = 8, .blen = 8192, }, | ||
2816 | |||
2817 | /* End marker */ | ||
2818 | { .klen = 0, .blen = 0, } | ||
2819 | }; | ||
2820 | |||
2746 | #endif /* _CRYPTO_TCRYPT_H */ | 2821 | #endif /* _CRYPTO_TCRYPT_H */ |